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