Merge master.kernel.org:/home/rmk/linux-2.6-arm
[pandora-kernel.git] / drivers / media / dvb / dvb-core / demux.h
1 /*
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>
33 #include <linux/dvb/dmx.h>
34
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
51 #ifndef DMX_MAX_SECFEED_SIZE
52 #define DMX_MAX_SECFEED_SIZE 4096
53 #endif
54
55
56 /*
57  * enum dmx_success: Success codes for the Demux Callback API.
58  */
59
60 enum dmx_success {
61   DMX_OK = 0, /* Received Ok */
62   DMX_LENGTH_ERROR, /* Incorrect length */
63   DMX_OVERRUN_ERROR, /* Receiver ring buffer overrun */
64   DMX_CRC_ERROR, /* Incorrect CRC */
65   DMX_FRAME_ERROR, /* Frame alignment error */
66   DMX_FIFO_ERROR, /* Receiver FIFO overrun */
67   DMX_MISSED_ERROR /* Receiver missed packet */
68 } ;
69
70 /*--------------------------------------------------------------------------*/
71 /* TS packet reception */
72 /*--------------------------------------------------------------------------*/
73
74 /* TS filter type for set() */
75
76 #define TS_PACKET       1   /* send TS packets (188 bytes) to callback (default) */
77 #define TS_PAYLOAD_ONLY 2   /* in case TS_PACKET is set, only send the TS
78                                payload (<=184 bytes per packet) to callback */
79 #define TS_DECODER      4   /* send stream to built-in decoder (if present) */
80
81 /* PES type for filters which write to built-in decoder */
82 /* these should be kept identical to the types in dmx.h */
83
84 enum dmx_ts_pes
85 {  /* also send packets to decoder (if it exists) */
86         DMX_TS_PES_AUDIO0,
87         DMX_TS_PES_VIDEO0,
88         DMX_TS_PES_TELETEXT0,
89         DMX_TS_PES_SUBTITLE0,
90         DMX_TS_PES_PCR0,
91
92         DMX_TS_PES_AUDIO1,
93         DMX_TS_PES_VIDEO1,
94         DMX_TS_PES_TELETEXT1,
95         DMX_TS_PES_SUBTITLE1,
96         DMX_TS_PES_PCR1,
97
98         DMX_TS_PES_AUDIO2,
99         DMX_TS_PES_VIDEO2,
100         DMX_TS_PES_TELETEXT2,
101         DMX_TS_PES_SUBTITLE2,
102         DMX_TS_PES_PCR2,
103
104         DMX_TS_PES_AUDIO3,
105         DMX_TS_PES_VIDEO3,
106         DMX_TS_PES_TELETEXT3,
107         DMX_TS_PES_SUBTITLE3,
108         DMX_TS_PES_PCR3,
109
110         DMX_TS_PES_OTHER
111 };
112
113 #define DMX_TS_PES_AUDIO    DMX_TS_PES_AUDIO0
114 #define DMX_TS_PES_VIDEO    DMX_TS_PES_VIDEO0
115 #define DMX_TS_PES_TELETEXT DMX_TS_PES_TELETEXT0
116 #define DMX_TS_PES_SUBTITLE DMX_TS_PES_SUBTITLE0
117 #define DMX_TS_PES_PCR      DMX_TS_PES_PCR0
118
119
120 struct dmx_ts_feed {
121         int is_filtering; /* Set to non-zero when filtering in progress */
122         struct dmx_demux *parent; /* Back-pointer */
123         void *priv; /* Pointer to private data of the API client */
124         int (*set) (struct dmx_ts_feed *feed,
125                     u16 pid,
126                     int type,
127                     enum dmx_ts_pes pes_type,
128                     size_t circular_buffer_size,
129                     struct timespec timeout);
130         int (*start_filtering) (struct dmx_ts_feed* feed);
131         int (*stop_filtering) (struct dmx_ts_feed* feed);
132 };
133
134 /*--------------------------------------------------------------------------*/
135 /* Section reception */
136 /*--------------------------------------------------------------------------*/
137
138 struct dmx_section_filter {
139         u8 filter_value [DMX_MAX_FILTER_SIZE];
140         u8 filter_mask [DMX_MAX_FILTER_SIZE];
141         u8 filter_mode [DMX_MAX_FILTER_SIZE];
142         struct dmx_section_feed* parent; /* Back-pointer */
143         void* priv; /* Pointer to private data of the API client */
144 };
145
146 struct dmx_section_feed {
147         int is_filtering; /* Set to non-zero when filtering in progress */
148         struct dmx_demux* parent; /* Back-pointer */
149         void* priv; /* Pointer to private data of the API client */
150
151         int check_crc;
152         u32 crc_val;
153
154         u8 *secbuf;
155         u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
156         u16 secbufp, seclen, tsfeedp;
157
158         int (*set) (struct dmx_section_feed* feed,
159                     u16 pid,
160                     size_t circular_buffer_size,
161                     int check_crc);
162         int (*allocate_filter) (struct dmx_section_feed* feed,
163                                 struct dmx_section_filter** filter);
164         int (*release_filter) (struct dmx_section_feed* feed,
165                                struct dmx_section_filter* filter);
166         int (*start_filtering) (struct dmx_section_feed* feed);
167         int (*stop_filtering) (struct dmx_section_feed* feed);
168 };
169
170 /*--------------------------------------------------------------------------*/
171 /* Callback functions */
172 /*--------------------------------------------------------------------------*/
173
174 typedef int (*dmx_ts_cb) ( const u8 * buffer1,
175                            size_t buffer1_length,
176                            const u8 * buffer2,
177                            size_t buffer2_length,
178                            struct dmx_ts_feed* source,
179                            enum dmx_success success);
180
181 typedef int (*dmx_section_cb) ( const u8 * buffer1,
182                                 size_t buffer1_len,
183                                 const u8 * buffer2,
184                                 size_t buffer2_len,
185                                 struct dmx_section_filter * source,
186                                 enum dmx_success success);
187
188 /*--------------------------------------------------------------------------*/
189 /* DVB Front-End */
190 /*--------------------------------------------------------------------------*/
191
192 enum dmx_frontend_source {
193         DMX_MEMORY_FE,
194         DMX_FRONTEND_0,
195         DMX_FRONTEND_1,
196         DMX_FRONTEND_2,
197         DMX_FRONTEND_3,
198         DMX_STREAM_0,    /* external stream input, e.g. LVDS */
199         DMX_STREAM_1,
200         DMX_STREAM_2,
201         DMX_STREAM_3
202 };
203
204 struct dmx_frontend {
205         struct list_head connectivity_list; /* List of front-ends that can
206                                                be connected to a particular
207                                                demux */
208         enum dmx_frontend_source source;
209 };
210
211 /*--------------------------------------------------------------------------*/
212 /* MPEG-2 TS Demux */
213 /*--------------------------------------------------------------------------*/
214
215 /*
216  * Flags OR'ed in the capabilites field of struct dmx_demux.
217  */
218
219 #define DMX_TS_FILTERING                        1
220 #define DMX_PES_FILTERING                       2
221 #define DMX_SECTION_FILTERING                   4
222 #define DMX_MEMORY_BASED_FILTERING              8    /* write() available */
223 #define DMX_CRC_CHECKING                        16
224 #define DMX_TS_DESCRAMBLING                     32
225
226 /*
227  * Demux resource type identifier.
228 */
229
230 /*
231  * DMX_FE_ENTRY(): Casts elements in the list of registered
232  * front-ends from the generic type struct list_head
233  * to the type * struct dmx_frontend
234  *.
235 */
236
237 #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
238
239 struct dmx_demux {
240         u32 capabilities;            /* Bitfield of capability flags */
241         struct dmx_frontend* frontend;    /* Front-end connected to the demux */
242         void* priv;                  /* Pointer to private data of the API client */
243         int (*open) (struct dmx_demux* demux);
244         int (*close) (struct dmx_demux* demux);
245         int (*write) (struct dmx_demux* demux, const char* buf, size_t count);
246         int (*allocate_ts_feed) (struct dmx_demux* demux,
247                                  struct dmx_ts_feed** feed,
248                                  dmx_ts_cb callback);
249         int (*release_ts_feed) (struct dmx_demux* demux,
250                                 struct dmx_ts_feed* feed);
251         int (*allocate_section_feed) (struct dmx_demux* demux,
252                                       struct dmx_section_feed** feed,
253                                       dmx_section_cb callback);
254         int (*release_section_feed) (struct dmx_demux* demux,
255                                      struct dmx_section_feed* feed);
256         int (*add_frontend) (struct dmx_demux* demux,
257                              struct dmx_frontend* frontend);
258         int (*remove_frontend) (struct dmx_demux* demux,
259                                 struct dmx_frontend* frontend);
260         struct list_head* (*get_frontends) (struct dmx_demux* demux);
261         int (*connect_frontend) (struct dmx_demux* demux,
262                                  struct dmx_frontend* frontend);
263         int (*disconnect_frontend) (struct dmx_demux* demux);
264
265         int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
266
267         int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
268
269         int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
270
271         int (*get_stc) (struct dmx_demux* demux, unsigned int num,
272                         u64 *stc, unsigned int *base);
273 };
274
275 #endif /* #ifndef __DEMUX_H */