blob: 39e6441133508458dc433c0a26d7817989a9da83 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Andreas Oberritterc0510052005-09-09 13:02:21 -070033#include <linux/dvb/dmx.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -030035/*
36 * Common definitions
37 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
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/*
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -030048 * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed
49 * filter.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
51
Mark Adamsb3967d62005-11-08 21:35:50 -080052#ifndef DMX_MAX_SECTION_SIZE
53#define DMX_MAX_SECTION_SIZE 4096
54#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#ifndef DMX_MAX_SECFEED_SIZE
Mark Adamsb3967d62005-11-08 21:35:50 -080056#define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#endif
58
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -030059/*
60 * TS packet reception
61 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63/* TS filter type for set() */
64
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -030065#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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -030084/**
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098struct dmx_ts_feed {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -030099 int is_filtering;
100 struct dmx_demux *parent;
101 void *priv;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300102 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110};
111
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300112/*
113 * Section reception
114 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300116/**
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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134struct dmx_section_filter {
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300135 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140};
141
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300142/**
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
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300155 * previously allocated section filter. The function
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300156 * 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167struct dmx_section_feed {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300168 int is_filtering;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300169 struct dmx_demux *parent;
170 void *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800172 int check_crc;
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300173
174 /* private: Used internally at dvb_demux.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 u32 crc_val;
176
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800177 u8 *secbuf;
178 u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
179 u16 secbufp, seclen, tsfeedp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300181 /* public: */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300182 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192};
193
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300194/*
195 * Callback functions
196 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300198/**
199 * typedef dmx_ts_cb - DVB demux TS filter callback function prototype
200 *
201 * @buffer1: Pointer to the start of the filtered TS packets.
202 * @buffer1_length: Length of the TS data in buffer1.
203 * @buffer2: Pointer to the tail of the filtered TS packets, or NULL.
204 * @buffer2_length: Length of the TS data in buffer2.
205 * @source: Indicates which TS feed is the source of the callback.
206 *
207 * This function callback prototype, provided by the client of the demux API,
208 * is called from the demux code. The function is only called when filtering
209 * on ae TS feed has been enabled using the start_filtering() function at
210 * the &dmx_demux.
211 * Any TS packets that match the filter settings are copied to a circular
212 * buffer. The filtered TS packets are delivered to the client using this
213 * callback function. The size of the circular buffer is controlled by the
214 * circular_buffer_size parameter of the &dmx_ts_feed.@set function.
215 * It is expected that the @buffer1 and @buffer2 callback parameters point to
216 * addresses within the circular buffer, but other implementations are also
217 * possible. Note that the called party should not try to free the memory
218 * the @buffer1 and @buffer2 parameters point to.
219 *
220 * When this function is called, the @buffer1 parameter typically points to
221 * the start of the first undelivered TS packet within a circular buffer.
222 * The @buffer2 buffer parameter is normally NULL, except when the received
223 * TS packets have crossed the last address of the circular buffer and
224 * ”wrapped” to the beginning of the buffer. In the latter case the @buffer1
225 * parameter would contain an address within the circular buffer, while the
226 * @buffer2 parameter would contain the first address of the circular buffer.
227 * The number of bytes delivered with this function (i.e. @buffer1_length +
228 * @buffer2_length) is usually equal to the value of callback_length parameter
229 * given in the set() function, with one exception: if a timeout occurs before
230 * receiving callback_length bytes of TS data, any undelivered packets are
231 * immediately delivered to the client by calling this function. The timeout
232 * duration is controlled by the set() function in the TS Feed API.
233 *
234 * If a TS packet is received with errors that could not be fixed by the
235 * TS-level forward error correction (FEC), the Transport_error_indicator
236 * flag of the TS packet header should be set. The TS packet should not be
237 * discarded, as the error can possibly be corrected by a higher layer
238 * protocol. If the called party is slow in processing the callback, it
239 * is possible that the circular buffer eventually fills up. If this happens,
240 * the demux driver should discard any TS packets received while the buffer
241 * is full and return -EOVERFLOW.
242 *
243 * The type of data returned to the callback can be selected by the
244 * &dmx_ts_feed.@set function. The type parameter decides if the raw
245 * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY)
246 * should be returned. If additionally the TS_DECODER bit is set the stream
247 * will also be sent to the hardware MPEG decoder.
248 *
249 * Return:
250 * 0, on success;
251 * -EOVERFLOW, on buffer overflow.
252 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300253typedef int (*dmx_ts_cb)(const u8 *buffer1,
254 size_t buffer1_length,
255 const u8 *buffer2,
256 size_t buffer2_length,
257 struct dmx_ts_feed *source);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300259typedef int (*dmx_section_cb)(const u8 *buffer1,
260 size_t buffer1_len,
261 const u8 *buffer2,
262 size_t buffer2_len,
263 struct dmx_section_filter *source);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265/*--------------------------------------------------------------------------*/
266/* DVB Front-End */
267/*--------------------------------------------------------------------------*/
268
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300269/**
270 * enum dmx_frontend_source - Used to identify the type of frontend
271 *
272 * @DMX_MEMORY_FE: The source of the demux is memory. It means that
273 * the MPEG-TS to be filtered comes from userspace,
274 * via write() syscall.
275 *
276 * @DMX_FRONTEND_0: The source of the demux is a frontend connected
277 * to the demux.
278 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279enum dmx_frontend_source {
280 DMX_MEMORY_FE,
281 DMX_FRONTEND_0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282};
283
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300284/**
285 * struct dmx_frontend - Structure that lists the frontends associated with
286 * a demux
287 *
288 * @connectivity_list: List of front-ends that can be connected to a
289 * particular demux;
290 * @source: Type of the frontend.
291 *
292 * FIXME: this structure should likely be replaced soon by some
293 * media-controller based logic.
294 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295struct dmx_frontend {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300296 struct list_head connectivity_list;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800297 enum dmx_frontend_source source;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298};
299
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300300/*
301 * MPEG-2 TS Demux
302 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304/*
Alexey Dobriyan8a598222006-03-07 22:20:23 -0300305 * Flags OR'ed in the capabilities field of struct dmx_demux.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
307
308#define DMX_TS_FILTERING 1
309#define DMX_PES_FILTERING 2
310#define DMX_SECTION_FILTERING 4
311#define DMX_MEMORY_BASED_FILTERING 8 /* write() available */
312#define DMX_CRC_CHECKING 16
313#define DMX_TS_DESCRAMBLING 32
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315/*
316 * Demux resource type identifier.
317*/
318
319/*
320 * DMX_FE_ENTRY(): Casts elements in the list of registered
321 * front-ends from the generic type struct list_head
322 * to the type * struct dmx_frontend
323 *.
324*/
325
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300326#define DMX_FE_ENTRY(list) \
327 list_entry(list, struct dmx_frontend, connectivity_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300329/**
330 * struct dmx_demux - Structure that contains the demux capabilities and
331 * callbacks.
332 *
333 * @capabilities: Bitfield of capability flags
334 *
335 * @frontend: Front-end connected to the demux
336 *
337 * @priv: Pointer to private data of the API client
338 *
339 * @open: This function reserves the demux for use by the caller and, if
340 * necessary, initializes the demux. When the demux is no longer needed,
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300341 * the function @close should be called. It should be possible for
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300342 * multiple clients to access the demux at the same time. Thus, the
343 * function implementation should increment the demux usage count when
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300344 * @open is called and decrement it when @close is called.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300345 * The @demux function parameter contains a pointer to the demux API and
346 * instance data.
347 * It returns
348 * 0 on success;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300349 * -EUSERS, if maximum usage count was reached;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300350 * -EINVAL, on bad parameter.
351 *
352 * @close: This function reserves the demux for use by the caller and, if
353 * necessary, initializes the demux. When the demux is no longer needed,
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300354 * the function @close should be called. It should be possible for
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300355 * multiple clients to access the demux at the same time. Thus, the
356 * function implementation should increment the demux usage count when
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300357 * @open is called and decrement it when @close is called.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300358 * The @demux function parameter contains a pointer to the demux API and
359 * instance data.
360 * It returns
361 * 0 on success;
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300362 * -ENODEV, if demux was not in use (e. g. no users);
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300363 * -EINVAL, on bad parameter.
364 *
365 * @write: This function provides the demux driver with a memory buffer
366 * containing TS packets. Instead of receiving TS packets from the DVB
367 * front-end, the demux driver software will read packets from memory.
368 * Any clients of this demux with active TS, PES or Section filters will
369 * receive filtered data via the Demux callback API (see 0). The function
370 * returns when all the data in the buffer has been consumed by the demux.
371 * Demux hardware typically cannot read TS from memory. If this is the
372 * case, memory-based filtering has to be implemented entirely in software.
373 * The @demux function parameter contains a pointer to the demux API and
374 * instance data.
375 * The @buf function parameter contains a pointer to the TS data in
376 * kernel-space memory.
377 * The @count function parameter contains the length of the TS data.
378 * It returns
379 * 0 on success;
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300380 * -ERESTARTSYS, if mutex lock was interrupted;
381 * -EINTR, if a signal handling is pending;
382 * -ENODEV, if demux was removed;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300383 * -EINVAL, on bad parameter.
384 *
385 * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
386 * packets carrying a certain PID. The TS feed normally corresponds to a
387 * hardware PID filter on the demux chip.
388 * The @demux function parameter contains a pointer to the demux API and
389 * instance data.
390 * The @feed function parameter contains a pointer to the TS feed API and
391 * instance data.
392 * The @callback function parameter contains a pointer to the callback
393 * function for passing received TS packet.
394 * It returns
395 * 0 on success;
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300396 * -ERESTARTSYS, if mutex lock was interrupted;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300397 * -EBUSY, if no more TS feeds is available;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300398 * -EINVAL, on bad parameter.
399 *
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300400 * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300401 * Any filtering in progress on the TS feed should be stopped before
402 * calling this function.
403 * The @demux function parameter contains a pointer to the demux API and
404 * instance data.
405 * The @feed function parameter contains a pointer to the TS feed API and
406 * instance data.
407 * It returns
408 * 0 on success;
409 * -EINVAL on bad parameter.
410 *
411 * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
412 * for filtering and receiving sections. On platforms with hardware
413 * support for section filtering, a section feed is directly mapped to
414 * the demux HW. On other platforms, TS packets are first PID filtered in
415 * hardware and a hardware section filter then emulated in software. The
416 * caller obtains an API pointer of type dmx_section_feed_t as an out
417 * parameter. Using this API the caller can set filtering parameters and
418 * start receiving sections.
419 * The @demux function parameter contains a pointer to the demux API and
420 * instance data.
421 * The @feed function parameter contains a pointer to the TS feed API and
422 * instance data.
423 * The @callback function parameter contains a pointer to the callback
424 * function for passing received TS packet.
425 * It returns
426 * 0 on success;
427 * -EBUSY, if no more TS feeds is available;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300428 * -EINVAL, on bad parameter.
429 *
430 * @release_section_feed: Releases the resources allocated with
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300431 * @allocate_section_feed, including allocated filters. Any filtering in
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300432 * progress on the section feed should be stopped before calling this
433 * function.
434 * The @demux function parameter contains a pointer to the demux API and
435 * instance data.
436 * The @feed function parameter contains a pointer to the TS feed API and
437 * instance data.
438 * It returns
439 * 0 on success;
440 * -EINVAL, on bad parameter.
441 *
442 * @add_frontend: Registers a connectivity between a demux and a front-end,
443 * i.e., indicates that the demux can be connected via a call to
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300444 * @connect_frontend to use the given front-end as a TS source. The
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300445 * client of this function has to allocate dynamic or static memory for
446 * the frontend structure and initialize its fields before calling this
447 * function. This function is normally called during the driver
448 * initialization. The caller must not free the memory of the frontend
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300449 * struct before successfully calling @remove_frontend.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300450 * The @demux function parameter contains a pointer to the demux API and
451 * instance data.
452 * The @frontend function parameter contains a pointer to the front-end
453 * instance data.
454 * It returns
455 * 0 on success;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300456 * -EINVAL, on bad parameter.
457 *
458 * @remove_frontend: Indicates that the given front-end, registered by a call
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300459 * to @add_frontend, can no longer be connected as a TS source by this
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300460 * demux. The function should be called when a front-end driver or a demux
461 * driver is removed from the system. If the front-end is in use, the
462 * function fails with the return value of -EBUSY. After successfully
463 * calling this function, the caller can free the memory of the frontend
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300464 * struct if it was dynamically allocated before the @add_frontend
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300465 * operation.
466 * The @demux function parameter contains a pointer to the demux API and
467 * instance data.
468 * The @frontend function parameter contains a pointer to the front-end
469 * instance data.
470 * It returns
471 * 0 on success;
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300472 * -ENODEV, if the front-end was not found,
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300473 * -EINVAL, on bad parameter.
474 *
475 * @get_frontends: Provides the APIs of the front-ends that have been
476 * registered for this demux. Any of the front-ends obtained with this
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300477 * call can be used as a parameter for @connect_frontend. The include
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300478 * file demux.h contains the macro DMX_FE_ENTRY() for converting an
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300479 * element of the generic type struct &list_head * to the type
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300480 * struct &dmx_frontend *. The caller must not free the memory of any of
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300481 * the elements obtained via this function call.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300482 * The @demux function parameter contains a pointer to the demux API and
483 * instance data.
484 * It returns a struct list_head pointer to the list of front-end
485 * interfaces, or NULL in the case of an empty list.
486 *
487 * @connect_frontend: Connects the TS output of the front-end to the input of
488 * the demux. A demux can only be connected to a front-end registered to
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300489 * the demux with the function @add_frontend. It may or may not be
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300490 * possible to connect multiple demuxes to the same front-end, depending
491 * on the capabilities of the HW platform. When not used, the front-end
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300492 * should be released by calling @disconnect_frontend.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300493 * The @demux function parameter contains a pointer to the demux API and
494 * instance data.
495 * The @frontend function parameter contains a pointer to the front-end
496 * instance data.
497 * It returns
498 * 0 on success;
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300499 * -EINVAL, on bad parameter.
500 *
501 * @disconnect_frontend: Disconnects the demux and a front-end previously
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300502 * connected by a @connect_frontend call.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300503 * The @demux function parameter contains a pointer to the demux API and
504 * instance data.
505 * It returns
506 * 0 on success;
507 * -EINVAL on bad parameter.
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300508 *
509 * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,
510 * DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.
511 * The @demux function parameter contains a pointer to the demux API and
512 * instance data.
513 * The @pids function parameter contains an array with five u16 elements
514 * where the PIDs will be stored.
515 * It returns
516 * 0 on success;
517 * -EINVAL on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300518 */
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520struct dmx_demux {
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300521 u32 capabilities;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300522 struct dmx_frontend *frontend;
523 void *priv;
524 int (*open)(struct dmx_demux *demux);
525 int (*close)(struct dmx_demux *demux);
526 int (*write)(struct dmx_demux *demux, const char __user *buf,
527 size_t count);
528 int (*allocate_ts_feed)(struct dmx_demux *demux,
529 struct dmx_ts_feed **feed,
530 dmx_ts_cb callback);
531 int (*release_ts_feed)(struct dmx_demux *demux,
532 struct dmx_ts_feed *feed);
533 int (*allocate_section_feed)(struct dmx_demux *demux,
534 struct dmx_section_feed **feed,
535 dmx_section_cb callback);
536 int (*release_section_feed)(struct dmx_demux *demux,
537 struct dmx_section_feed *feed);
538 int (*add_frontend)(struct dmx_demux *demux,
539 struct dmx_frontend *frontend);
540 int (*remove_frontend)(struct dmx_demux *demux,
541 struct dmx_frontend *frontend);
542 struct list_head *(*get_frontends)(struct dmx_demux *demux);
543 int (*connect_frontend)(struct dmx_demux *demux,
544 struct dmx_frontend *frontend);
545 int (*disconnect_frontend)(struct dmx_demux *demux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300547 int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Mauro Carvalho Chehab1e92bbe2015-10-06 18:36:20 -0300549 /* private: Not used upstream and never documented */
550#if 0
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300551 int (*get_caps)(struct dmx_demux *demux, struct dmx_caps *caps);
552 int (*set_source)(struct dmx_demux *demux, const dmx_source_t *src);
Mauro Carvalho Chehab1e92bbe2015-10-06 18:36:20 -0300553#endif
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300554 /*
555 * private: Only used at av7110, to read some data from firmware.
556 * As this was never documented, we have no clue about what's
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300557 * there, and its usage on other drivers aren't encouraged.
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300558 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300559 int (*get_stc)(struct dmx_demux *demux, unsigned int num,
560 u64 *stc, unsigned int *base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561};
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563#endif /* #ifndef __DEMUX_H */