]> Git Repo - linux.git/blob - drivers/media/dvb-core/dvb_demux.h
Merge tag 'ceph-for-4.15-rc1' of git://github.com/ceph/ceph-client
[linux.git] / drivers / media / dvb-core / dvb_demux.h
1 /*
2  * dvb_demux.h: DVB kernel demux API
3  *
4  * Copyright (C) 2000-2001 Marcus Metzler & Ralph Metzler
5  *                         for convergence integrated media GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  */
18
19 #ifndef _DVB_DEMUX_H_
20 #define _DVB_DEMUX_H_
21
22 #include <linux/time.h>
23 #include <linux/timer.h>
24 #include <linux/spinlock.h>
25 #include <linux/mutex.h>
26
27 #include "demux.h"
28
29 /**
30  * enum dvb_dmx_filter_type - type of demux feed.
31  *
32  * @DMX_TYPE_TS:        feed is in TS mode.
33  * @DMX_TYPE_SEC:       feed is in Section mode.
34  */
35 enum dvb_dmx_filter_type {
36         DMX_TYPE_TS,
37         DMX_TYPE_SEC,
38 };
39
40 /**
41  * enum dvb_dmx_state - state machine for a demux filter.
42  *
43  * @DMX_STATE_FREE:             indicates that the filter is freed.
44  * @DMX_STATE_ALLOCATED:        indicates that the filter was allocated
45  *                              to be used.
46  * @DMX_STATE_READY:            indicates that the filter is ready
47  *                              to be used.
48  * @DMX_STATE_GO:               indicates that the filter is running.
49  */
50 enum dvb_dmx_state {
51         DMX_STATE_FREE,
52         DMX_STATE_ALLOCATED,
53         DMX_STATE_READY,
54         DMX_STATE_GO,
55 };
56
57 #define DVB_DEMUX_MASK_MAX 18
58
59 #define MAX_PID 0x1fff
60
61 #define SPEED_PKTS_INTERVAL 50000
62
63 /**
64  * struct dvb_demux_filter - Describes a DVB demux section filter.
65  *
66  * @filter:             Section filter as defined by &struct dmx_section_filter.
67  * @maskandmode:        logical ``and`` bit mask.
68  * @maskandnotmode:     logical ``and not`` bit mask.
69  * @doneq:              flag that indicates when a filter is ready.
70  * @next:               pointer to the next section filter.
71  * @feed:               &struct dvb_demux_feed pointer.
72  * @index:              index of the used demux filter.
73  * @state:              state of the filter as described by &enum dvb_dmx_state.
74  * @type:               type of the filter as described
75  *                      by &enum dvb_dmx_filter_type.
76  */
77
78 struct dvb_demux_filter {
79         struct dmx_section_filter filter;
80         u8 maskandmode[DMX_MAX_FILTER_SIZE];
81         u8 maskandnotmode[DMX_MAX_FILTER_SIZE];
82         bool doneq;
83
84         struct dvb_demux_filter *next;
85         struct dvb_demux_feed *feed;
86         int index;
87         enum dvb_dmx_state state;
88         enum dvb_dmx_filter_type type;
89
90         /* private: used only by av7110 */
91         u16 hw_handle;
92 };
93
94 /**
95  * struct dvb_demux_feed - describes a DVB field
96  *
97  * @feed:       a digital TV feed. It can either be a TS or a section feed:
98  *              if the feed is TS, it contains &struct dvb_ts_feed @ts;
99  *              if the feed is section, it contains
100  *              &struct dmx_section_feed @sec.
101  * @cb:         digital TV callbacks. depending on the feed type, it can be:
102  *              if the feed is TS, it contains a dmx_ts_cb() @ts callback;
103  *              if the feed is section, it contains a dmx_section_cb() @sec
104  *              callback.
105  *
106  * @demux:      pointer to &struct dvb_demux.
107  * @priv:       private data that can optionally be used by a DVB driver.
108  * @type:       type of the filter, as defined by &enum dvb_dmx_filter_type.
109  * @state:      state of the filter as defined by &enum dvb_dmx_state.
110  * @pid:        PID to be filtered.
111  * @timeout:    feed timeout.
112  * @filter:     pointer to &struct dvb_demux_filter.
113  * @ts_type:    type of TS, as defined by &enum ts_filter_type.
114  * @pes_type:   type of PES, as defined by &enum dmx_ts_pes.
115  * @cc:         MPEG-TS packet continuity counter
116  * @pusi_seen:  if true, indicates that a discontinuity was detected.
117  *              it is used to prevent feeding of garbage from previous section.
118  * @peslen:     length of the PES (Packet Elementary Stream).
119  * @list_head:  head for the list of digital TV demux feeds.
120  * @index:      a unique index for each feed. Can be used as hardware
121  *              pid filter index.
122  */
123 struct dvb_demux_feed {
124         union {
125                 struct dmx_ts_feed ts;
126                 struct dmx_section_feed sec;
127         } feed;
128
129         union {
130                 dmx_ts_cb ts;
131                 dmx_section_cb sec;
132         } cb;
133
134         struct dvb_demux *demux;
135         void *priv;
136         enum dvb_dmx_filter_type type;
137         enum dvb_dmx_state state;
138         u16 pid;
139
140         ktime_t timeout;
141         struct dvb_demux_filter *filter;
142
143         enum ts_filter_type ts_type;
144         enum dmx_ts_pes pes_type;
145
146         int cc;
147         bool pusi_seen;
148
149         u16 peslen;
150
151         struct list_head list_head;
152         unsigned int index;
153 };
154
155 /**
156  * struct dvb_demux - represents a digital TV demux
157  * @dmx:                embedded &struct dmx_demux with demux capabilities
158  *                      and callbacks.
159  * @priv:               private data that can optionally be used by
160  *                      a DVB driver.
161  * @filternum:          maximum amount of DVB filters.
162  * @feednum:            maximum amount of DVB feeds.
163  * @start_feed:         callback routine to be called in order to start
164  *                      a DVB feed.
165  * @stop_feed:          callback routine to be called in order to stop
166  *                      a DVB feed.
167  * @write_to_decoder:   callback routine to be called if the feed is TS and
168  *                      it is routed to an A/V decoder, when a new TS packet
169  *                      is received.
170  *                      Used only on av7110-av.c.
171  * @check_crc32:        callback routine to check CRC. If not initialized,
172  *                      dvb_demux will use an internal one.
173  * @memcopy:            callback routine to memcopy received data.
174  *                      If not initialized, dvb_demux will default to memcpy().
175  * @users:              counter for the number of demux opened file descriptors.
176  *                      Currently, it is limited to 10 users.
177  * @filter:             pointer to &struct dvb_demux_filter.
178  * @feed:               pointer to &struct dvb_demux_feed.
179  * @frontend_list:      &struct list_head with frontends used by the demux.
180  * @pesfilter:          array of &struct dvb_demux_feed with the PES types
181  *                      that will be filtered.
182  * @pids:               list of filtered program IDs.
183  * @feed_list:          &struct list_head with feeds.
184  * @tsbuf:              temporary buffer used internally to store TS packets.
185  * @tsbufp:             temporary buffer index used internally.
186  * @mutex:              pointer to &struct mutex used to protect feed set
187  *                      logic.
188  * @lock:               pointer to &spinlock_t, used to protect buffer handling.
189  * @cnt_storage:        buffer used for TS/TEI continuity check.
190  * @speed_last_time:    &ktime_t used for TS speed check.
191  * @speed_pkts_cnt:     packets count used for TS speed check.
192  */
193 struct dvb_demux {
194         struct dmx_demux dmx;
195         void *priv;
196         int filternum;
197         int feednum;
198         int (*start_feed)(struct dvb_demux_feed *feed);
199         int (*stop_feed)(struct dvb_demux_feed *feed);
200         int (*write_to_decoder)(struct dvb_demux_feed *feed,
201                                  const u8 *buf, size_t len);
202         u32 (*check_crc32)(struct dvb_demux_feed *feed,
203                             const u8 *buf, size_t len);
204         void (*memcopy)(struct dvb_demux_feed *feed, u8 *dst,
205                          const u8 *src, size_t len);
206
207         int users;
208 #define MAX_DVB_DEMUX_USERS 10
209         struct dvb_demux_filter *filter;
210         struct dvb_demux_feed *feed;
211
212         struct list_head frontend_list;
213
214         struct dvb_demux_feed *pesfilter[DMX_PES_OTHER];
215         u16 pids[DMX_PES_OTHER];
216
217 #define DMX_MAX_PID 0x2000
218         struct list_head feed_list;
219         u8 tsbuf[204];
220         int tsbufp;
221
222         struct mutex mutex;
223         spinlock_t lock;
224
225         uint8_t *cnt_storage; /* for TS continuity check */
226
227         ktime_t speed_last_time; /* for TS speed check */
228         uint32_t speed_pkts_cnt; /* for TS speed check */
229
230         /* private: used only on av7110 */
231         int playing;
232         int recording;
233 };
234
235 /**
236  * dvb_dmx_init - initialize a digital TV demux struct.
237  *
238  * @demux: &struct dvb_demux to be initialized.
239  *
240  * Before being able to register a digital TV demux struct, drivers
241  * should call this routine. On its typical usage, some fields should
242  * be initialized at the driver before calling it.
243  *
244  * A typical usecase is::
245  *
246  *      dvb->demux.dmx.capabilities =
247  *              DMX_TS_FILTERING | DMX_SECTION_FILTERING |
248  *              DMX_MEMORY_BASED_FILTERING;
249  *      dvb->demux.priv       = dvb;
250  *      dvb->demux.filternum  = 256;
251  *      dvb->demux.feednum    = 256;
252  *      dvb->demux.start_feed = driver_start_feed;
253  *      dvb->demux.stop_feed  = driver_stop_feed;
254  *      ret = dvb_dmx_init(&dvb->demux);
255  *      if (ret < 0)
256  *              return ret;
257  */
258 int dvb_dmx_init(struct dvb_demux *demux);
259
260 /**
261  * dvb_dmx_release - releases a digital TV demux internal buffers.
262  *
263  * @demux: &struct dvb_demux to be released.
264  *
265  * The DVB core internally allocates data at @demux. This routine
266  * releases those data. Please notice that the struct itelf is not
267  * released, as it can be embedded on other structs.
268  */
269 void dvb_dmx_release(struct dvb_demux *demux);
270
271 /**
272  * dvb_dmx_swfilter_packets - use dvb software filter for a buffer with
273  *      multiple MPEG-TS packets with 188 bytes each.
274  *
275  * @demux: pointer to &struct dvb_demux
276  * @buf: buffer with data to be filtered
277  * @count: number of MPEG-TS packets with size of 188.
278  *
279  * The routine will discard a DVB packet that don't start with 0x47.
280  *
281  * Use this routine if the DVB demux fills MPEG-TS buffers that are
282  * already aligned.
283  *
284  * NOTE: The @buf size should have size equal to ``count * 188``.
285  */
286 void dvb_dmx_swfilter_packets(struct dvb_demux *demux, const u8 *buf,
287                               size_t count);
288
289 /**
290  * dvb_dmx_swfilter -  use dvb software filter for a buffer with
291  *      multiple MPEG-TS packets with 188 bytes each.
292  *
293  * @demux: pointer to &struct dvb_demux
294  * @buf: buffer with data to be filtered
295  * @count: number of MPEG-TS packets with size of 188.
296  *
297  * If a DVB packet doesn't start with 0x47, it will seek for the first
298  * byte that starts with 0x47.
299  *
300  * Use this routine if the DVB demux fill buffers that may not start with
301  * a packet start mark (0x47).
302  *
303  * NOTE: The @buf size should have size equal to ``count * 188``.
304  */
305 void dvb_dmx_swfilter(struct dvb_demux *demux, const u8 *buf, size_t count);
306
307 /**
308  * dvb_dmx_swfilter_204 -  use dvb software filter for a buffer with
309  *      multiple MPEG-TS packets with 204 bytes each.
310  *
311  * @demux: pointer to &struct dvb_demux
312  * @buf: buffer with data to be filtered
313  * @count: number of MPEG-TS packets with size of 204.
314  *
315  * If a DVB packet doesn't start with 0x47, it will seek for the first
316  * byte that starts with 0x47.
317  *
318  * Use this routine if the DVB demux fill buffers that may not start with
319  * a packet start mark (0x47).
320  *
321  * NOTE: The @buf size should have size equal to ``count * 204``.
322  */
323 void dvb_dmx_swfilter_204(struct dvb_demux *demux, const u8 *buf,
324                           size_t count);
325
326 /**
327  * dvb_dmx_swfilter_raw -  make the raw data available to userspace without
328  *      filtering
329  *
330  * @demux: pointer to &struct dvb_demux
331  * @buf: buffer with data
332  * @count: number of packets to be passed. The actual size of each packet
333  *      depends on the &dvb_demux->feed->cb.ts logic.
334  *
335  * Use it if the driver needs to deliver the raw payload to userspace without
336  * passing through the kernel demux. That is meant to support some
337  * delivery systems that aren't based on MPEG-TS.
338  *
339  * This function relies on &dvb_demux->feed->cb.ts to actually handle the
340  * buffer.
341  */
342 void dvb_dmx_swfilter_raw(struct dvb_demux *demux, const u8 *buf,
343                           size_t count);
344
345 #endif /* _DVB_DEMUX_H_ */
This page took 0.059694 seconds and 4 git commands to generate.