blob: eb91fd808c16307a9d7259f960ff89be70efbd96 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * demux.h
3 *
4 * Copyright (c) 2002 Convergence GmbH
5 *
6 * based on code:
7 * Copyright (c) 2000 Nokia Research Center
8 * Tampere, FINLAND
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public License
12 * as published by the Free Software Foundation; either version 2.1
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 */
25
26#ifndef __DEMUX_H
27#define __DEMUX_H
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/list.h>
32#include <linux/time.h>
Andreas Oberritterc0510052005-09-09 13:02:21 -070033#include <linux/dvb/dmx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35/*--------------------------------------------------------------------------*/
36/* Common definitions */
37/*--------------------------------------------------------------------------*/
38
39/*
40 * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
41 */
42
43#ifndef DMX_MAX_FILTER_SIZE
44#define DMX_MAX_FILTER_SIZE 18
45#endif
46
47/*
48 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
49 */
50
Mark Adamsb3967d62005-11-08 21:35:50 -080051#ifndef DMX_MAX_SECTION_SIZE
52#define DMX_MAX_SECTION_SIZE 4096
53#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#ifndef DMX_MAX_SECFEED_SIZE
Mark Adamsb3967d62005-11-08 21:35:50 -080055#define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#endif
57
58
59/*
60 * enum dmx_success: Success codes for the Demux Callback API.
61 */
62
63enum dmx_success {
64 DMX_OK = 0, /* Received Ok */
65 DMX_LENGTH_ERROR, /* Incorrect length */
66 DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
67 DMX_CRC_ERROR, /* Incorrect CRC */
68 DMX_FRAME_ERROR, /* Frame alignment error */
69 DMX_FIFO_ERROR, /* Receiver FIFO overrun */
70 DMX_MISSED_ERROR /* Receiver missed packet */
71} ;
72
73/*--------------------------------------------------------------------------*/
74/* TS packet reception */
75/*--------------------------------------------------------------------------*/
76
77/* TS filter type for set() */
78
79#define TS_PACKET 1 /* send TS packets (188 bytes) to callback (default) */
80#define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
81 payload (<=184 bytes per packet) to callback */
82#define TS_DECODER 4 /* send stream to built-in decoder (if present) */
Andreas Oberritter4a24ce32008-04-22 14:45:47 -030083#define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to
84 the demux device, not to the dvr device */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86/* PES type for filters which write to built-in decoder */
87/* these should be kept identical to the types in dmx.h */
88
89enum dmx_ts_pes
90{ /* also send packets to decoder (if it exists) */
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080091 DMX_TS_PES_AUDIO0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 DMX_TS_PES_VIDEO0,
93 DMX_TS_PES_TELETEXT0,
94 DMX_TS_PES_SUBTITLE0,
95 DMX_TS_PES_PCR0,
96
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080097 DMX_TS_PES_AUDIO1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 DMX_TS_PES_VIDEO1,
99 DMX_TS_PES_TELETEXT1,
100 DMX_TS_PES_SUBTITLE1,
101 DMX_TS_PES_PCR1,
102
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800103 DMX_TS_PES_AUDIO2,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 DMX_TS_PES_VIDEO2,
105 DMX_TS_PES_TELETEXT2,
106 DMX_TS_PES_SUBTITLE2,
107 DMX_TS_PES_PCR2,
108
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800109 DMX_TS_PES_AUDIO3,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 DMX_TS_PES_VIDEO3,
111 DMX_TS_PES_TELETEXT3,
112 DMX_TS_PES_SUBTITLE3,
113 DMX_TS_PES_PCR3,
114
115 DMX_TS_PES_OTHER
116};
117
118#define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
119#define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
120#define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
121#define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
122#define DMX_TS_PES_PCR DMX_TS_PES_PCR0
123
124
125struct dmx_ts_feed {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800126 int is_filtering; /* Set to non-zero when filtering in progress */
127 struct dmx_demux *parent; /* Back-pointer */
128 void *priv; /* Pointer to private data of the API client */
129 int (*set) (struct dmx_ts_feed *feed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 u16 pid,
131 int type,
132 enum dmx_ts_pes pes_type,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 size_t circular_buffer_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 struct timespec timeout);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800135 int (*start_filtering) (struct dmx_ts_feed* feed);
136 int (*stop_filtering) (struct dmx_ts_feed* feed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137};
138
139/*--------------------------------------------------------------------------*/
140/* Section reception */
141/*--------------------------------------------------------------------------*/
142
143struct dmx_section_filter {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800144 u8 filter_value [DMX_MAX_FILTER_SIZE];
145 u8 filter_mask [DMX_MAX_FILTER_SIZE];
146 u8 filter_mode [DMX_MAX_FILTER_SIZE];
147 struct dmx_section_feed* parent; /* Back-pointer */
148 void* priv; /* Pointer to private data of the API client */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
151struct dmx_section_feed {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800152 int is_filtering; /* Set to non-zero when filtering in progress */
153 struct dmx_demux* parent; /* Back-pointer */
154 void* priv; /* Pointer to private data of the API client */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800156 int check_crc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 u32 crc_val;
158
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800159 u8 *secbuf;
160 u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
161 u16 secbufp, seclen, tsfeedp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800163 int (*set) (struct dmx_section_feed* feed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 u16 pid,
165 size_t circular_buffer_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 int check_crc);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800167 int (*allocate_filter) (struct dmx_section_feed* feed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 struct dmx_section_filter** filter);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800169 int (*release_filter) (struct dmx_section_feed* feed,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct dmx_section_filter* filter);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800171 int (*start_filtering) (struct dmx_section_feed* feed);
172 int (*stop_filtering) (struct dmx_section_feed* feed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175/*--------------------------------------------------------------------------*/
176/* Callback functions */
177/*--------------------------------------------------------------------------*/
178
179typedef int (*dmx_ts_cb) ( const u8 * buffer1,
180 size_t buffer1_length,
181 const u8 * buffer2,
182 size_t buffer2_length,
183 struct dmx_ts_feed* source,
184 enum dmx_success success);
185
186typedef int (*dmx_section_cb) ( const u8 * buffer1,
187 size_t buffer1_len,
188 const u8 * buffer2,
189 size_t buffer2_len,
190 struct dmx_section_filter * source,
191 enum dmx_success success);
192
193/*--------------------------------------------------------------------------*/
194/* DVB Front-End */
195/*--------------------------------------------------------------------------*/
196
197enum dmx_frontend_source {
198 DMX_MEMORY_FE,
199 DMX_FRONTEND_0,
200 DMX_FRONTEND_1,
201 DMX_FRONTEND_2,
202 DMX_FRONTEND_3,
203 DMX_STREAM_0, /* external stream input, e.g. LVDS */
204 DMX_STREAM_1,
205 DMX_STREAM_2,
206 DMX_STREAM_3
207};
208
209struct dmx_frontend {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800210 struct list_head connectivity_list; /* List of front-ends that can
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 be connected to a particular
212 demux */
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800213 enum dmx_frontend_source source;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214};
215
216/*--------------------------------------------------------------------------*/
217/* MPEG-2 TS Demux */
218/*--------------------------------------------------------------------------*/
219
220/*
Alexey Dobriyan8a598222006-03-07 22:20:23 -0300221 * Flags OR'ed in the capabilities field of struct dmx_demux.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 */
223
224#define DMX_TS_FILTERING 1
225#define DMX_PES_FILTERING 2
226#define DMX_SECTION_FILTERING 4
227#define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
228#define DMX_CRC_CHECKING 16
229#define DMX_TS_DESCRAMBLING 32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231/*
232 * Demux resource type identifier.
233*/
234
235/*
236 * DMX_FE_ENTRY(): Casts elements in the list of registered
237 * front-ends from the generic type struct list_head
238 * to the type * struct dmx_frontend
239 *.
240*/
241
242#define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
243
244struct dmx_demux {
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800245 u32 capabilities; /* Bitfield of capability flags */
246 struct dmx_frontend* frontend; /* Front-end connected to the demux */
247 void* priv; /* Pointer to private data of the API client */
248 int (*open) (struct dmx_demux* demux);
249 int (*close) (struct dmx_demux* demux);
Al Viro947a0802008-06-22 14:20:19 -0300250 int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800251 int (*allocate_ts_feed) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 struct dmx_ts_feed** feed,
253 dmx_ts_cb callback);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800254 int (*release_ts_feed) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 struct dmx_ts_feed* feed);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800256 int (*allocate_section_feed) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 struct dmx_section_feed** feed,
258 dmx_section_cb callback);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800259 int (*release_section_feed) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 struct dmx_section_feed* feed);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800261 int (*add_frontend) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 struct dmx_frontend* frontend);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800263 int (*remove_frontend) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 struct dmx_frontend* frontend);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800265 struct list_head* (*get_frontends) (struct dmx_demux* demux);
266 int (*connect_frontend) (struct dmx_demux* demux,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 struct dmx_frontend* frontend);
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800268 int (*disconnect_frontend) (struct dmx_demux* demux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800270 int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Andreas Oberritterc0510052005-09-09 13:02:21 -0700272 int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
273
274 int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
275
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800276 int (*get_stc) (struct dmx_demux* demux, unsigned int num,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 u64 *stc, unsigned int *base);
278};
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280#endif /* #ifndef __DEMUX_H */