]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/media/dvb-core/demux.h
2d036b36f551a1c8be3cfe994dd8a291f2d02739
[karo-tx-linux.git] / drivers / media / 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_SECTION_SIZE
52 #define DMX_MAX_SECTION_SIZE 4096
53 #endif
54 #ifndef DMX_MAX_SECFEED_SIZE
55 #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
56 #endif
57
58 /*--------------------------------------------------------------------------*/
59 /* TS packet reception */
60 /*--------------------------------------------------------------------------*/
61
62 /* TS filter type for set() */
63
64 #define TS_PACKET       1   /* send TS packets (188 bytes) to callback (default) */
65 #define TS_PAYLOAD_ONLY 2   /* in case TS_PACKET is set, only send the TS
66                                payload (<=184 bytes per packet) to callback */
67 #define TS_DECODER      4   /* send stream to built-in decoder (if present) */
68 #define TS_DEMUX        8   /* in case TS_PACKET is set, send the TS to
69                                the demux device, not to the dvr device */
70
71 struct dmx_ts_feed {
72         int is_filtering; /* Set to non-zero when filtering in progress */
73         struct dmx_demux *parent; /* Back-pointer */
74         void *priv; /* Pointer to private data of the API client */
75         int (*set) (struct dmx_ts_feed *feed,
76                     u16 pid,
77                     int type,
78                     enum dmx_ts_pes pes_type,
79                     size_t circular_buffer_size,
80                     struct timespec timeout);
81         int (*start_filtering) (struct dmx_ts_feed* feed);
82         int (*stop_filtering) (struct dmx_ts_feed* feed);
83 };
84
85 /*--------------------------------------------------------------------------*/
86 /* Section reception */
87 /*--------------------------------------------------------------------------*/
88
89 struct dmx_section_filter {
90         u8 filter_value [DMX_MAX_FILTER_SIZE];
91         u8 filter_mask [DMX_MAX_FILTER_SIZE];
92         u8 filter_mode [DMX_MAX_FILTER_SIZE];
93         struct dmx_section_feed* parent; /* Back-pointer */
94         void* priv; /* Pointer to private data of the API client */
95 };
96
97 struct dmx_section_feed {
98         int is_filtering; /* Set to non-zero when filtering in progress */
99         struct dmx_demux* parent; /* Back-pointer */
100         void* priv; /* Pointer to private data of the API client */
101
102         int check_crc;
103         u32 crc_val;
104
105         u8 *secbuf;
106         u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
107         u16 secbufp, seclen, tsfeedp;
108
109         int (*set) (struct dmx_section_feed* feed,
110                     u16 pid,
111                     size_t circular_buffer_size,
112                     int check_crc);
113         int (*allocate_filter) (struct dmx_section_feed* feed,
114                                 struct dmx_section_filter** filter);
115         int (*release_filter) (struct dmx_section_feed* feed,
116                                struct dmx_section_filter* filter);
117         int (*start_filtering) (struct dmx_section_feed* feed);
118         int (*stop_filtering) (struct dmx_section_feed* feed);
119 };
120
121 /*--------------------------------------------------------------------------*/
122 /* Callback functions */
123 /*--------------------------------------------------------------------------*/
124
125 typedef int (*dmx_ts_cb) ( const u8 * buffer1,
126                            size_t buffer1_length,
127                            const u8 * buffer2,
128                            size_t buffer2_length,
129                            struct dmx_ts_feed* source);
130
131 typedef int (*dmx_section_cb) ( const u8 * buffer1,
132                                 size_t buffer1_len,
133                                 const u8 * buffer2,
134                                 size_t buffer2_len,
135                                 struct dmx_section_filter * source);
136
137 /*--------------------------------------------------------------------------*/
138 /* DVB Front-End */
139 /*--------------------------------------------------------------------------*/
140
141 enum dmx_frontend_source {
142         DMX_MEMORY_FE,
143         DMX_FRONTEND_0,
144         DMX_FRONTEND_1,
145         DMX_FRONTEND_2,
146         DMX_FRONTEND_3,
147         DMX_STREAM_0,    /* external stream input, e.g. LVDS */
148         DMX_STREAM_1,
149         DMX_STREAM_2,
150         DMX_STREAM_3
151 };
152
153 struct dmx_frontend {
154         struct list_head connectivity_list; /* List of front-ends that can
155                                                be connected to a particular
156                                                demux */
157         enum dmx_frontend_source source;
158 };
159
160 /*--------------------------------------------------------------------------*/
161 /* MPEG-2 TS Demux */
162 /*--------------------------------------------------------------------------*/
163
164 /*
165  * Flags OR'ed in the capabilities field of struct dmx_demux.
166  */
167
168 #define DMX_TS_FILTERING                        1
169 #define DMX_PES_FILTERING                       2
170 #define DMX_SECTION_FILTERING                   4
171 #define DMX_MEMORY_BASED_FILTERING              8    /* write() available */
172 #define DMX_CRC_CHECKING                        16
173 #define DMX_TS_DESCRAMBLING                     32
174
175 /*
176  * Demux resource type identifier.
177 */
178
179 /*
180  * DMX_FE_ENTRY(): Casts elements in the list of registered
181  * front-ends from the generic type struct list_head
182  * to the type * struct dmx_frontend
183  *.
184 */
185
186 #define DMX_FE_ENTRY(list) list_entry(list, struct dmx_frontend, connectivity_list)
187
188 /**
189  * struct dmx_demux - Structure that contains the demux capabilities and
190  *                    callbacks.
191  *
192  * @capabilities: Bitfield of capability flags
193  *
194  * @frontend: Front-end connected to the demux
195  *
196  * @priv: Pointer to private data of the API client
197  *
198  * @open: This function reserves the demux for use by the caller and, if
199  *      necessary, initializes the demux. When the demux is no longer needed,
200  *      the function @close should be called. It should be possible for
201  *      multiple clients to access the demux at the same time. Thus, the
202  *      function implementation should increment the demux usage count when
203  *      @open is called and decrement it when @close is called.
204  *      The @demux function parameter contains a pointer to the demux API and
205  *      instance data.
206  *      It returns
207  *              0 on success;
208  *              -EUSERS, if maximum usage count was reached;
209  *              -EINVAL, on bad parameter.
210  *
211  * @close: This function reserves the demux for use by the caller and, if
212  *      necessary, initializes the demux. When the demux is no longer needed,
213  *      the function @close should be called. It should be possible for
214  *      multiple clients to access the demux at the same time. Thus, the
215  *      function implementation should increment the demux usage count when
216  *      @open is called and decrement it when @close is called.
217  *      The @demux function parameter contains a pointer to the demux API and
218  *      instance data.
219  *      It returns
220  *              0 on success;
221  *              -ENODEV, if demux was not in use (e. g. no users);
222  *              -EINVAL, on bad parameter.
223  *
224  * @write: This function provides the demux driver with a memory buffer
225  *      containing TS packets. Instead of receiving TS packets from the DVB
226  *      front-end, the demux driver software will read packets from memory.
227  *      Any clients of this demux with active TS, PES or Section filters will
228  *      receive filtered data via the Demux callback API (see 0). The function
229  *      returns when all the data in the buffer has been consumed by the demux.
230  *      Demux hardware typically cannot read TS from memory. If this is the
231  *      case, memory-based filtering has to be implemented entirely in software.
232  *      The @demux function parameter contains a pointer to the demux API and
233  *      instance data.
234  *      The @buf function parameter contains a pointer to the TS data in
235  *      kernel-space memory.
236  *      The @count function parameter contains the length of the TS data.
237  *      It returns
238  *              0 on success;
239  *              -ERESTARTSYS, if mutex lock was interrupted;
240  *              -EINTR, if a signal handling is pending;
241  *              -ENODEV, if demux was removed;
242  *              -EINVAL, on bad parameter.
243  *
244  * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
245  *      packets carrying a certain PID. The TS feed normally corresponds to a
246  *      hardware PID filter on the demux chip.
247  *      The @demux function parameter contains a pointer to the demux API and
248  *      instance data.
249  *      The @feed function parameter contains a pointer to the TS feed API and
250  *      instance data.
251  *      The @callback function parameter contains a pointer to the callback
252  *      function for passing received TS packet.
253  *      It returns
254  *              0 on success;
255  *              -ERESTARTSYS, if mutex lock was interrupted;
256  *              -EBUSY, if no more TS feeds is available;
257  *              -EINVAL, on bad parameter.
258  *
259  * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
260  *      Any filtering in progress on the TS feed should be stopped before
261  *      calling this function.
262  *      The @demux function parameter contains a pointer to the demux API and
263  *      instance data.
264  *      The @feed function parameter contains a pointer to the TS feed API and
265  *      instance data.
266  *      It returns
267  *              0 on success;
268  *              -EINVAL on bad parameter.
269  *
270  * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
271  *      for filtering and receiving sections. On platforms with hardware
272  *      support for section filtering, a section feed is directly mapped to
273  *      the demux HW. On other platforms, TS packets are first PID filtered in
274  *      hardware and a hardware section filter then emulated in software. The
275  *      caller obtains an API pointer of type dmx_section_feed_t as an out
276  *      parameter. Using this API the caller can set filtering parameters and
277  *      start receiving sections.
278  *      The @demux function parameter contains a pointer to the demux API and
279  *      instance data.
280  *      The @feed function parameter contains a pointer to the TS feed API and
281  *      instance data.
282  *      The @callback function parameter contains a pointer to the callback
283  *      function for passing received TS packet.
284  *      It returns
285  *              0 on success;
286  *              -EBUSY, if no more TS feeds is available;
287  *              -EINVAL, on bad parameter.
288  *
289  * @release_section_feed: Releases the resources allocated with
290  *      @allocate_section_feed, including allocated filters. Any filtering in
291  *      progress on the section feed should be stopped before calling this
292  *      function.
293  *      The @demux function parameter contains a pointer to the demux API and
294  *      instance data.
295  *      The @feed function parameter contains a pointer to the TS feed API and
296  *      instance data.
297  *      It returns
298  *              0 on success;
299  *              -EINVAL, on bad parameter.
300  *
301  * @add_frontend: Registers a connectivity between a demux and a front-end,
302  *      i.e., indicates that the demux can be connected via a call to
303  *      @connect_frontend to use the given front-end as a TS source. The
304  *      client of this function has to allocate dynamic or static memory for
305  *      the frontend structure and initialize its fields before calling this
306  *      function. This function is normally called during the driver
307  *      initialization. The caller must not free the memory of the frontend
308  *      struct before successfully calling @remove_frontend.
309  *      The @demux function parameter contains a pointer to the demux API and
310  *      instance data.
311  *      The @frontend function parameter contains a pointer to the front-end
312  *      instance data.
313  *      It returns
314  *              0 on success;
315  *              -EINVAL, on bad parameter.
316  *
317  * @remove_frontend: Indicates that the given front-end, registered by a call
318  *      to @add_frontend, can no longer be connected as a TS source by this
319  *      demux. The function should be called when a front-end driver or a demux
320  *      driver is removed from the system. If the front-end is in use, the
321  *      function fails with the return value of -EBUSY. After successfully
322  *      calling this function, the caller can free the memory of the frontend
323  *      struct if it was dynamically allocated before the @add_frontend
324  *      operation.
325  *      The @demux function parameter contains a pointer to the demux API and
326  *      instance data.
327  *      The @frontend function parameter contains a pointer to the front-end
328  *      instance data.
329  *      It returns
330  *              0 on success;
331  *              -ENODEV, if the front-end was not found,
332  *              -EINVAL, on bad parameter.
333  *
334  * @get_frontends: Provides the APIs of the front-ends that have been
335  *      registered for this demux. Any of the front-ends obtained with this
336  *      call can be used as a parameter for @connect_frontend. The include
337  *      file demux.h contains the macro DMX_FE_ENTRY() for converting an
338  *      element of the generic type struct &list_head * to the type
339  *      struct &dmx_frontend *. The caller must not free the memory of any of
340  *      the elements obtained via this function call.
341  *      The @demux function parameter contains a pointer to the demux API and
342  *      instance data.
343  *      It returns a struct list_head pointer to the list of front-end
344  *      interfaces, or NULL in the case of an empty list.
345  *
346  * @connect_frontend: Connects the TS output of the front-end to the input of
347  *      the demux. A demux can only be connected to a front-end registered to
348  *      the demux with the function @add_frontend. It may or may not be
349  *      possible to connect multiple demuxes to the same front-end, depending
350  *      on the capabilities of the HW platform. When not used, the front-end
351  *      should be released by calling @disconnect_frontend.
352  *      The @demux function parameter contains a pointer to the demux API and
353  *      instance data.
354  *      The @frontend function parameter contains a pointer to the front-end
355  *      instance data.
356  *      It returns
357  *              0 on success;
358  *              -EINVAL, on bad parameter.
359  *
360  * @disconnect_frontend: Disconnects the demux and a front-end previously
361  *      connected by a @connect_frontend call.
362  *      The @demux function parameter contains a pointer to the demux API and
363  *      instance data.
364  *      It returns
365  *              0 on success;
366  *              -EINVAL on bad parameter.
367  *
368  * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,
369  *      DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.
370  *      The @demux function parameter contains a pointer to the demux API and
371  *      instance data.
372  *      The @pids function parameter contains an array with five u16 elements
373  *      where the PIDs will be stored.
374  *      It returns
375  *              0 on success;
376  *              -EINVAL on bad parameter.
377  */
378
379 struct dmx_demux {
380         u32 capabilities;
381         struct dmx_frontend* frontend;
382         void* priv;
383         int (*open) (struct dmx_demux* demux);
384         int (*close) (struct dmx_demux* demux);
385         int (*write) (struct dmx_demux* demux, const char __user *buf, size_t count);
386         int (*allocate_ts_feed) (struct dmx_demux* demux,
387                                  struct dmx_ts_feed** feed,
388                                  dmx_ts_cb callback);
389         int (*release_ts_feed) (struct dmx_demux* demux,
390                                 struct dmx_ts_feed* feed);
391         int (*allocate_section_feed) (struct dmx_demux* demux,
392                                       struct dmx_section_feed** feed,
393                                       dmx_section_cb callback);
394         int (*release_section_feed) (struct dmx_demux* demux,
395                                      struct dmx_section_feed* feed);
396         int (*add_frontend) (struct dmx_demux* demux,
397                              struct dmx_frontend* frontend);
398         int (*remove_frontend) (struct dmx_demux* demux,
399                                 struct dmx_frontend* frontend);
400         struct list_head* (*get_frontends) (struct dmx_demux* demux);
401         int (*connect_frontend) (struct dmx_demux* demux,
402                                  struct dmx_frontend* frontend);
403         int (*disconnect_frontend) (struct dmx_demux* demux);
404
405         int (*get_pes_pids) (struct dmx_demux* demux, u16 *pids);
406
407         /* private: Not used upstream and never documented */
408 #if 0
409         int (*get_caps) (struct dmx_demux* demux, struct dmx_caps *caps);
410         int (*set_source) (struct dmx_demux* demux, const dmx_source_t *src);
411 #endif
412         /*
413          * private: Only used at av7110, to read some data from firmware.
414          *      As this was never documented, we have no clue about what's
415          *      there, and its usage on other drivers aren't encouraged.
416          */
417         int (*get_stc) (struct dmx_demux* demux, unsigned int num,
418                         u64 *stc, unsigned int *base);
419 };
420
421 #endif /* #ifndef __DEMUX_H */