Linux v2.6.13
[linux-2.6/next.git] / drivers / media / dvb / dvb-core / demux.h
blobfb55eaa5c8e70525073427372c9ea3f6191e3592
1 /*
2 * demux.h
4 * Copyright (c) 2002 Convergence GmbH
6 * based on code:
7 * Copyright (c) 2000 Nokia Research Center
8 * Tampere, FINLAND
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.
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.
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.
26 #ifndef __DEMUX_H
27 #define __DEMUX_H
29 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/list.h>
32 #include <linux/time.h>
34 /*--------------------------------------------------------------------------*/
35 /* Common definitions */
36 /*--------------------------------------------------------------------------*/
39 * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter.
42 #ifndef DMX_MAX_FILTER_SIZE
43 #define DMX_MAX_FILTER_SIZE 18
44 #endif
47 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed filter.
50 #ifndef DMX_MAX_SECFEED_SIZE
51 #define DMX_MAX_SECFEED_SIZE 4096
52 #endif
56 * enum dmx_success: Success codes for the Demux Callback API.
59 enum dmx_success {
60 DMX_OK = 0, /* Received Ok */
61 DMX_LENGTH_ERROR, /* Incorrect length */
62 DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
63 DMX_CRC_ERROR, /* Incorrect CRC */
64 DMX_FRAME_ERROR, /* Frame alignment error */
65 DMX_FIFO_ERROR, /* Receiver FIFO overrun */
66 DMX_MISSED_ERROR /* Receiver missed packet */
67 } ;
69 /*--------------------------------------------------------------------------*/
70 /* TS packet reception */
71 /*--------------------------------------------------------------------------*/
73 /* TS filter type for set() */
75 #define TS_PACKET 1 /* send TS packets (188 bytes) to callback (default) */
76 #define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
77 payload (<=184 bytes per packet) to callback */
78 #define TS_DECODER 4 /* send stream to built-in decoder (if present) */
80 /* PES type for filters which write to built-in decoder */
81 /* these should be kept identical to the types in dmx.h */
83 enum dmx_ts_pes
84 { /* also send packets to decoder (if it exists) */
85 DMX_TS_PES_AUDIO0,
86 DMX_TS_PES_VIDEO0,
87 DMX_TS_PES_TELETEXT0,
88 DMX_TS_PES_SUBTITLE0,
89 DMX_TS_PES_PCR0,
91 DMX_TS_PES_AUDIO1,
92 DMX_TS_PES_VIDEO1,
93 DMX_TS_PES_TELETEXT1,
94 DMX_TS_PES_SUBTITLE1,
95 DMX_TS_PES_PCR1,
97 DMX_TS_PES_AUDIO2,
98 DMX_TS_PES_VIDEO2,
99 DMX_TS_PES_TELETEXT2,
100 DMX_TS_PES_SUBTITLE2,
101 DMX_TS_PES_PCR2,
103 DMX_TS_PES_AUDIO3,
104 DMX_TS_PES_VIDEO3,
105 DMX_TS_PES_TELETEXT3,
106 DMX_TS_PES_SUBTITLE3,
107 DMX_TS_PES_PCR3,
109 DMX_TS_PES_OTHER
112 #define DMX_TS_PES_AUDIO DMX_TS_PES_AUDIO0
113 #define DMX_TS_PES_VIDEO DMX_TS_PES_VIDEO0
114 #define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
115 #define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
116 #define DMX_TS_PES_PCR DMX_TS_PES_PCR0
119 struct dmx_ts_feed {
120 int is_filtering; /* Set to non-zero when filtering in progress */
121 struct dmx_demux *parent; /* Back-pointer */
122 void *priv; /* Pointer to private data of the API client */
123 int (*set) (struct dmx_ts_feed *feed,
124 u16 pid,
125 int type,
126 enum dmx_ts_pes pes_type,
127 size_t callback_length,
128 size_t circular_buffer_size,
129 int descramble,
130 struct timespec timeout);
131 int (*start_filtering) (struct dmx_ts_feed* feed);
132 int (*stop_filtering) (struct dmx_ts_feed* feed);
135 /*--------------------------------------------------------------------------*/
136 /* Section reception */
137 /*--------------------------------------------------------------------------*/
139 struct dmx_section_filter {
140 u8 filter_value [DMX_MAX_FILTER_SIZE];
141 u8 filter_mask [DMX_MAX_FILTER_SIZE];
142 u8 filter_mode [DMX_MAX_FILTER_SIZE];
143 struct dmx_section_feed* parent; /* Back-pointer */
144 void* priv; /* Pointer to private data of the API client */
147 struct dmx_section_feed {
148 int is_filtering; /* Set to non-zero when filtering in progress */
149 struct dmx_demux* parent; /* Back-pointer */
150 void* priv; /* Pointer to private data of the API client */
152 int check_crc;
153 u32 crc_val;
155 u8 *secbuf;
156 u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
157 u16 secbufp, seclen, tsfeedp;
159 int (*set) (struct dmx_section_feed* feed,
160 u16 pid,
161 size_t circular_buffer_size,
162 int descramble,
163 int check_crc);
164 int (*allocate_filter) (struct dmx_section_feed* feed,
165 struct dmx_section_filter** filter);
166 int (*release_filter) (struct dmx_section_feed* feed,
167 struct dmx_section_filter* filter);
168 int (*start_filtering) (struct dmx_section_feed* feed);
169 int (*stop_filtering) (struct dmx_section_feed* feed);
172 /*--------------------------------------------------------------------------*/
173 /* Callback functions */
174 /*--------------------------------------------------------------------------*/
176 typedef int (*dmx_ts_cb) ( const u8 * buffer1,
177 size_t buffer1_length,
178 const u8 * buffer2,
179 size_t buffer2_length,
180 struct dmx_ts_feed* source,
181 enum dmx_success success);
183 typedef int (*dmx_section_cb) ( const u8 * buffer1,
184 size_t buffer1_len,
185 const u8 * buffer2,
186 size_t buffer2_len,
187 struct dmx_section_filter * source,
188 enum dmx_success success);
190 /*--------------------------------------------------------------------------*/
191 /* DVB Front-End */
192 /*--------------------------------------------------------------------------*/
194 enum dmx_frontend_source {
195 DMX_MEMORY_FE,
196 DMX_FRONTEND_0,
197 DMX_FRONTEND_1,
198 DMX_FRONTEND_2,
199 DMX_FRONTEND_3,
200 DMX_STREAM_0, /* external stream input, e.g. LVDS */
201 DMX_STREAM_1,
202 DMX_STREAM_2,
203 DMX_STREAM_3
206 struct dmx_frontend {
207 struct list_head connectivity_list; /* List of front-ends that can
208 be connected to a particular
209 demux */
210 void* priv; /* Pointer to private data of the API client */
211 enum dmx_frontend_source source;
214 /*--------------------------------------------------------------------------*/
215 /* MPEG-2 TS Demux */
216 /*--------------------------------------------------------------------------*/
219 * Flags OR'ed in the capabilites field of struct dmx_demux.
222 #define DMX_TS_FILTERING 1
223 #define DMX_PES_FILTERING 2
224 #define DMX_SECTION_FILTERING 4
225 #define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
226 #define DMX_CRC_CHECKING 16
227 #define DMX_TS_DESCRAMBLING 32
228 #define DMX_SECTION_PAYLOAD_DESCRAMBLING 64
229 #define DMX_MAC_ADDRESS_DESCRAMBLING 128
232 * Demux resource type identifier.
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
242 #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
244 struct dmx_demux {
245 u32 capabilities; /* Bitfield of capability flags */
246 struct dmx_frontend* frontend; /* Front-end connected to the demux */
247 struct list_head reg_list; /* List of registered demuxes */
248 void* priv; /* Pointer to private data of the API client */
249 int users; /* Number of users */
250 int (*open) (struct dmx_demux* demux);
251 int (*close) (struct dmx_demux* demux);
252 int (*write) (struct dmx_demux* demux, const char* buf, size_t count);
253 int (*allocate_ts_feed) (struct dmx_demux* demux,
254 struct dmx_ts_feed** feed,
255 dmx_ts_cb callback);
256 int (*release_ts_feed) (struct dmx_demux* demux,
257 struct dmx_ts_feed* feed);
258 int (*allocate_section_feed) (struct dmx_demux* demux,
259 struct dmx_section_feed** feed,
260 dmx_section_cb callback);
261 int (*release_section_feed) (struct dmx_demux* demux,
262 struct dmx_section_feed* feed);
263 int (*descramble_mac_address) (struct dmx_demux* demux,
264 u8* buffer1,
265 size_t buffer1_length,
266 u8* buffer2,
267 size_t buffer2_length,
268 u16 pid);
269 int (*descramble_section_payload) (struct dmx_demux* demux,
270 u8* buffer1,
271 size_t buffer1_length,
272 u8* buffer2, size_t buffer2_length,
273 u16 pid);
274 int (*add_frontend) (struct dmx_demux* demux,
275 struct dmx_frontend* frontend);
276 int (*remove_frontend) (struct dmx_demux* demux,
277 struct dmx_frontend* frontend);
278 struct list_head* (*get_frontends) (struct dmx_demux* demux);
279 int (*connect_frontend) (struct dmx_demux* demux,
280 struct dmx_frontend* frontend);
281 int (*disconnect_frontend) (struct dmx_demux* demux);
283 int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
285 int (*get_stc) (struct dmx_demux* demux, unsigned int num,
286 u64 *stc, unsigned int *base);
289 /*--------------------------------------------------------------------------*/
290 /* Demux directory */
291 /*--------------------------------------------------------------------------*/
294 * DMX_DIR_ENTRY(): Casts elements in the list of registered
295 * demuxes from the generic type struct list_head* to the type struct dmx_demux
299 #define DMX_DIR_ENTRY(list) list_entry(list, struct dmx_demux, reg_list)
301 #endif /* #ifndef __DEMUX_H */