blob: bf00a5a41a90643437e3a750456ff534e9fa7945 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * demux.h
3 *
Mauro Carvalho Chehabd26a5d42016-07-17 07:20:06 -03004 * The Kernel Digital TV Demux kABI defines a driver-internal interface for
5 * registering low-level, hardware specific driver to a hardware independent
6 * demux layer.
7 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Copyright (c) 2002 Convergence GmbH
9 *
10 * based on code:
11 * Copyright (c) 2000 Nokia Research Center
12 * Tampere, FINLAND
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public License
16 * as published by the Free Software Foundation; either version 2.1
17 * of the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070024 */
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
Mauro Carvalho Chehab0e6f2d12015-10-08 17:21:48 -030063/**
Mauro Carvalho Chehab564aaf62016-07-23 07:12:03 -030064 * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\)
Mauro Carvalho Chehab0e6f2d12015-10-08 17:21:48 -030065 *
66 * @TS_PACKET: Send TS packets (188 bytes) to callback (default).
67 * @TS_PAYLOAD_ONLY: In case TS_PACKET is set, only send the TS payload
68 * (<=184 bytes per packet) to callback
69 * @TS_DECODER: Send stream to built-in decoder (if present).
70 * @TS_DEMUX: In case TS_PACKET is set, send the TS to the demux
71 * device, not to the dvr device
72 */
73enum ts_filter_type {
74 TS_PACKET = 1,
75 TS_PAYLOAD_ONLY = 2,
76 TS_DECODER = 4,
77 TS_DEMUX = 8,
78};
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -030080/**
81 * struct dmx_ts_feed - Structure that contains a TS feed filter
82 *
83 * @is_filtering: Set to non-zero when filtering in progress
84 * @parent: pointer to struct dmx_demux
85 * @priv: pointer to private data of the API client
86 * @set: sets the TS filter
87 * @start_filtering: starts TS filtering
88 * @stop_filtering: stops TS filtering
89 *
90 * A TS feed is typically mapped to a hardware PID filter on the demux chip.
91 * Using this API, the client can set the filtering properties to start/stop
92 * filtering TS packets on a particular TS feed.
93 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094struct dmx_ts_feed {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -030095 int is_filtering;
96 struct dmx_demux *parent;
97 void *priv;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -030098 int (*set)(struct dmx_ts_feed *feed,
99 u16 pid,
100 int type,
101 enum dmx_ts_pes pes_type,
Arnd Bergmanne95be152016-06-17 17:46:28 -0300102 ktime_t timeout);
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300103 int (*start_filtering)(struct dmx_ts_feed *feed);
104 int (*stop_filtering)(struct dmx_ts_feed *feed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105};
106
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300107/*
108 * Section reception
109 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300111/**
112 * struct dmx_section_filter - Structure that describes a section filter
113 *
114 * @filter_value: Contains up to 16 bytes (128 bits) of the TS section header
115 * that will be matched by the section filter
116 * @filter_mask: Contains a 16 bytes (128 bits) filter mask with the bits
117 * specified by @filter_value that will be used on the filter
118 * match logic.
119 * @filter_mode: Contains a 16 bytes (128 bits) filter mode.
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500120 * @parent: Back-pointer to struct dmx_section_feed.
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300121 * @priv: Pointer to private data of the API client.
122 *
123 *
124 * The @filter_mask controls which bits of @filter_value are compared with
125 * the section headers/payload. On a binary value of 1 in filter_mask, the
126 * corresponding bits are compared. The filter only accepts sections that are
127 * equal to filter_value in all the tested bit positions.
128 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129struct dmx_section_filter {
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300130 u8 filter_value[DMX_MAX_FILTER_SIZE];
131 u8 filter_mask[DMX_MAX_FILTER_SIZE];
132 u8 filter_mode[DMX_MAX_FILTER_SIZE];
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500133 struct dmx_section_feed *parent;
134
135 void *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300138/**
139 * struct dmx_section_feed - Structure that contains a section feed filter
140 *
141 * @is_filtering: Set to non-zero when filtering in progress
142 * @parent: pointer to struct dmx_demux
143 * @priv: pointer to private data of the API client
144 * @check_crc: If non-zero, check the CRC values of filtered sections.
145 * @set: sets the section filter
146 * @allocate_filter: This function is used to allocate a section filter on
147 * the demux. It should only be called when no filtering
148 * is in progress on this section feed. If a filter cannot
149 * be allocated, the function fails with -ENOSPC.
150 * @release_filter: This function releases all the resources of a
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300151 * previously allocated section filter. The function
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300152 * should not be called while filtering is in progress
153 * on this section feed. After calling this function,
154 * the caller should not try to dereference the filter
155 * pointer.
156 * @start_filtering: starts section filtering
157 * @stop_filtering: stops section filtering
158 *
159 * A TS feed is typically mapped to a hardware PID filter on the demux chip.
160 * Using this API, the client can set the filtering properties to start/stop
161 * filtering TS packets on a particular TS feed.
162 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163struct dmx_section_feed {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300164 int is_filtering;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300165 struct dmx_demux *parent;
166 void *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800168 int check_crc;
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300169
170 /* private: Used internally at dvb_demux.c */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 u32 crc_val;
172
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800173 u8 *secbuf;
174 u8 secbuf_base[DMX_MAX_SECFEED_SIZE];
175 u16 secbufp, seclen, tsfeedp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300177 /* public: */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300178 int (*set)(struct dmx_section_feed *feed,
179 u16 pid,
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300180 int check_crc);
181 int (*allocate_filter)(struct dmx_section_feed *feed,
182 struct dmx_section_filter **filter);
183 int (*release_filter)(struct dmx_section_feed *feed,
184 struct dmx_section_filter *filter);
185 int (*start_filtering)(struct dmx_section_feed *feed);
186 int (*stop_filtering)(struct dmx_section_feed *feed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187};
188
Mauro Carvalho Chehab7b6e55b2015-11-04 11:07:09 -0200189/**
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300190 * typedef dmx_ts_cb - DVB demux TS filter callback function prototype
191 *
192 * @buffer1: Pointer to the start of the filtered TS packets.
193 * @buffer1_length: Length of the TS data in buffer1.
194 * @buffer2: Pointer to the tail of the filtered TS packets, or NULL.
195 * @buffer2_length: Length of the TS data in buffer2.
196 * @source: Indicates which TS feed is the source of the callback.
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500197 * @buffer_flags: Address where buffer flags are stored. Those are
198 * used to report discontinuity users via DVB
199 * memory mapped API, as defined by
200 * &enum dmx_buffer_flags.
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300201 *
202 * This function callback prototype, provided by the client of the demux API,
203 * is called from the demux code. The function is only called when filtering
Mauro Carvalho Chehabbb501b72016-08-29 10:05:49 -0300204 * on a TS feed has been enabled using the start_filtering\(\) function at
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300205 * the &dmx_demux.
206 * Any TS packets that match the filter settings are copied to a circular
207 * buffer. The filtered TS packets are delivered to the client using this
Mauro Carvalho Chehabdd79d272016-10-13 07:14:38 -0300208 * callback function.
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300209 * It is expected that the @buffer1 and @buffer2 callback parameters point to
210 * addresses within the circular buffer, but other implementations are also
211 * possible. Note that the called party should not try to free the memory
212 * the @buffer1 and @buffer2 parameters point to.
213 *
214 * When this function is called, the @buffer1 parameter typically points to
215 * the start of the first undelivered TS packet within a circular buffer.
216 * The @buffer2 buffer parameter is normally NULL, except when the received
217 * TS packets have crossed the last address of the circular buffer and
Hans Verkuil0e50e842017-07-16 04:07:59 -0400218 * "wrapped" to the beginning of the buffer. In the latter case the @buffer1
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300219 * parameter would contain an address within the circular buffer, while the
220 * @buffer2 parameter would contain the first address of the circular buffer.
221 * The number of bytes delivered with this function (i.e. @buffer1_length +
222 * @buffer2_length) is usually equal to the value of callback_length parameter
223 * given in the set() function, with one exception: if a timeout occurs before
224 * receiving callback_length bytes of TS data, any undelivered packets are
225 * immediately delivered to the client by calling this function. The timeout
226 * duration is controlled by the set() function in the TS Feed API.
227 *
228 * If a TS packet is received with errors that could not be fixed by the
229 * TS-level forward error correction (FEC), the Transport_error_indicator
230 * flag of the TS packet header should be set. The TS packet should not be
231 * discarded, as the error can possibly be corrected by a higher layer
232 * protocol. If the called party is slow in processing the callback, it
233 * is possible that the circular buffer eventually fills up. If this happens,
234 * the demux driver should discard any TS packets received while the buffer
235 * is full and return -EOVERFLOW.
236 *
237 * The type of data returned to the callback can be selected by the
238 * &dmx_ts_feed.@set function. The type parameter decides if the raw
239 * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY)
240 * should be returned. If additionally the TS_DECODER bit is set the stream
241 * will also be sent to the hardware MPEG decoder.
242 *
243 * Return:
Mauro Carvalho Chehabbb501b72016-08-29 10:05:49 -0300244 *
245 * - 0, on success;
246 *
247 * - -EOVERFLOW, on buffer overflow.
Mauro Carvalho Chehab0cf35e82015-10-08 17:05:11 -0300248 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300249typedef int (*dmx_ts_cb)(const u8 *buffer1,
250 size_t buffer1_length,
251 const u8 *buffer2,
252 size_t buffer2_length,
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500253 struct dmx_ts_feed *source,
254 u32 *buffer_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Mauro Carvalho Chehab4be45fb2015-10-10 10:22:20 -0300256/**
257 * typedef dmx_section_cb - DVB demux TS filter callback function prototype
258 *
259 * @buffer1: Pointer to the start of the filtered section, e.g.
260 * within the circular buffer of the demux driver.
261 * @buffer1_len: Length of the filtered section data in @buffer1,
262 * including headers and CRC.
263 * @buffer2: Pointer to the tail of the filtered section data,
264 * or NULL. Useful to handle the wrapping of a
265 * circular buffer.
266 * @buffer2_len: Length of the filtered section data in @buffer2,
267 * including headers and CRC.
268 * @source: Indicates which section feed is the source of the
269 * callback.
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500270 * @buffer_flags: Address where buffer flags are stored. Those are
271 * used to report discontinuity users via DVB
272 * memory mapped API, as defined by
273 * &enum dmx_buffer_flags.
Mauro Carvalho Chehab4be45fb2015-10-10 10:22:20 -0300274 *
275 * This function callback prototype, provided by the client of the demux API,
276 * is called from the demux code. The function is only called when
277 * filtering of sections has been enabled using the function
278 * &dmx_ts_feed.@start_filtering. When the demux driver has received a
279 * complete section that matches at least one section filter, the client
280 * is notified via this callback function. Normally this function is called
281 * for each received section; however, it is also possible to deliver
282 * multiple sections with one callback, for example when the system load
283 * is high. If an error occurs while receiving a section, this
284 * function should be called with the corresponding error type set in the
285 * success field, whether or not there is data to deliver. The Section Feed
286 * implementation should maintain a circular buffer for received sections.
287 * However, this is not necessary if the Section Feed API is implemented as
288 * a client of the TS Feed API, because the TS Feed implementation then
289 * buffers the received data. The size of the circular buffer can be
290 * configured using the &dmx_ts_feed.@set function in the Section Feed API.
291 * If there is no room in the circular buffer when a new section is received,
292 * the section must be discarded. If this happens, the value of the success
293 * parameter should be DMX_OVERRUN_ERROR on the next callback.
294 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300295typedef int (*dmx_section_cb)(const u8 *buffer1,
296 size_t buffer1_len,
297 const u8 *buffer2,
298 size_t buffer2_len,
Mauro Carvalho Chehabfdbeb962018-02-09 07:30:46 -0500299 struct dmx_section_filter *source,
300 u32 *buffer_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Mauro Carvalho Chehabbb501b72016-08-29 10:05:49 -0300302/*
303 * DVB Front-End
304 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300306/**
307 * enum dmx_frontend_source - Used to identify the type of frontend
308 *
309 * @DMX_MEMORY_FE: The source of the demux is memory. It means that
310 * the MPEG-TS to be filtered comes from userspace,
311 * via write() syscall.
312 *
313 * @DMX_FRONTEND_0: The source of the demux is a frontend connected
314 * to the demux.
315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316enum dmx_frontend_source {
317 DMX_MEMORY_FE,
318 DMX_FRONTEND_0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319};
320
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300321/**
322 * struct dmx_frontend - Structure that lists the frontends associated with
323 * a demux
324 *
325 * @connectivity_list: List of front-ends that can be connected to a
326 * particular demux;
327 * @source: Type of the frontend.
328 *
329 * FIXME: this structure should likely be replaced soon by some
330 * media-controller based logic.
331 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332struct dmx_frontend {
Mauro Carvalho Chehab548e5ae2015-10-07 16:11:03 -0300333 struct list_head connectivity_list;
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -0800334 enum dmx_frontend_source source;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335};
336
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300337/*
338 * MPEG-2 TS Demux
339 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Mauro Carvalho Chehab9be91db2015-10-08 17:33:47 -0300341/**
342 * enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap
343 *
344 * @DMX_TS_FILTERING: set if TS filtering is supported;
345 * @DMX_SECTION_FILTERING: set if section filtering is supported;
346 * @DMX_MEMORY_BASED_FILTERING: set if write() available.
347 *
Mauro Carvalho Chehab564aaf62016-07-23 07:12:03 -0300348 * Those flags are OR'ed in the &dmx_demux.capabilities field
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 */
Mauro Carvalho Chehab9be91db2015-10-08 17:33:47 -0300350enum dmx_demux_caps {
351 DMX_TS_FILTERING = 1,
352 DMX_SECTION_FILTERING = 4,
353 DMX_MEMORY_BASED_FILTERING = 8,
354};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356/*
357 * Demux resource type identifier.
Mauro Carvalho Chehabbb501b72016-08-29 10:05:49 -0300358 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Mauro Carvalho Chehabbb501b72016-08-29 10:05:49 -0300360/**
361 * DMX_FE_ENTRY - Casts elements in the list of registered
362 * front-ends from the generic type struct list_head
363 * to the type * struct dmx_frontend
364 *
365 * @list: list of struct dmx_frontend
366 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300367#define DMX_FE_ENTRY(list) \
368 list_entry(list, struct dmx_frontend, connectivity_list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300370/**
371 * struct dmx_demux - Structure that contains the demux capabilities and
372 * callbacks.
373 *
Mauro Carvalho Chehab9be91db2015-10-08 17:33:47 -0300374 * @capabilities: Bitfield of capability flags.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300375 *
376 * @frontend: Front-end connected to the demux
377 *
378 * @priv: Pointer to private data of the API client
379 *
380 * @open: This function reserves the demux for use by the caller and, if
381 * necessary, initializes the demux. When the demux is no longer needed,
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300382 * the function @close should be called. It should be possible for
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300383 * multiple clients to access the demux at the same time. Thus, the
384 * function implementation should increment the demux usage count when
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300385 * @open is called and decrement it when @close is called.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300386 * The @demux function parameter contains a pointer to the demux API and
387 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300388 * It returns:
389 * 0 on success;
390 * -EUSERS, if maximum usage count was reached;
391 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300392 *
393 * @close: This function reserves the demux for use by the caller and, if
394 * necessary, initializes the demux. When the demux is no longer needed,
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300395 * the function @close should be called. It should be possible for
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300396 * multiple clients to access the demux at the same time. Thus, the
397 * function implementation should increment the demux usage count when
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300398 * @open is called and decrement it when @close is called.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300399 * The @demux function parameter contains a pointer to the demux API and
400 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300401 * It returns:
402 * 0 on success;
403 * -ENODEV, if demux was not in use (e. g. no users);
404 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300405 *
406 * @write: This function provides the demux driver with a memory buffer
407 * containing TS packets. Instead of receiving TS packets from the DVB
408 * front-end, the demux driver software will read packets from memory.
409 * Any clients of this demux with active TS, PES or Section filters will
410 * receive filtered data via the Demux callback API (see 0). The function
411 * returns when all the data in the buffer has been consumed by the demux.
412 * Demux hardware typically cannot read TS from memory. If this is the
413 * case, memory-based filtering has to be implemented entirely in software.
414 * The @demux function parameter contains a pointer to the demux API and
415 * instance data.
416 * The @buf function parameter contains a pointer to the TS data in
417 * kernel-space memory.
418 * The @count function parameter contains the length of the TS data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300419 * It returns:
420 * 0 on success;
421 * -ERESTARTSYS, if mutex lock was interrupted;
422 * -EINTR, if a signal handling is pending;
423 * -ENODEV, if demux was removed;
424 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300425 *
426 * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS
427 * packets carrying a certain PID. The TS feed normally corresponds to a
428 * hardware PID filter on the demux chip.
429 * The @demux function parameter contains a pointer to the demux API and
430 * instance data.
431 * The @feed function parameter contains a pointer to the TS feed API and
432 * instance data.
433 * The @callback function parameter contains a pointer to the callback
434 * function for passing received TS packet.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300435 * It returns:
436 * 0 on success;
437 * -ERESTARTSYS, if mutex lock was interrupted;
438 * -EBUSY, if no more TS feeds is available;
439 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300440 *
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300441 * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300442 * Any filtering in progress on the TS feed should be stopped before
443 * calling this function.
444 * The @demux function parameter contains a pointer to the demux API and
445 * instance data.
446 * The @feed function parameter contains a pointer to the TS feed API and
447 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300448 * It returns:
449 * 0 on success;
450 * -EINVAL on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300451 *
452 * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource
453 * for filtering and receiving sections. On platforms with hardware
454 * support for section filtering, a section feed is directly mapped to
455 * the demux HW. On other platforms, TS packets are first PID filtered in
456 * hardware and a hardware section filter then emulated in software. The
457 * caller obtains an API pointer of type dmx_section_feed_t as an out
458 * parameter. Using this API the caller can set filtering parameters and
459 * start receiving sections.
460 * The @demux function parameter contains a pointer to the demux API and
461 * instance data.
462 * The @feed function parameter contains a pointer to the TS feed API and
463 * instance data.
464 * The @callback function parameter contains a pointer to the callback
465 * function for passing received TS packet.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300466 * It returns:
467 * 0 on success;
468 * -EBUSY, if no more TS feeds is available;
469 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300470 *
471 * @release_section_feed: Releases the resources allocated with
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300472 * @allocate_section_feed, including allocated filters. Any filtering in
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300473 * progress on the section feed should be stopped before calling this
474 * function.
475 * The @demux function parameter contains a pointer to the demux API and
476 * instance data.
477 * The @feed function parameter contains a pointer to the TS feed API and
478 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300479 * It returns:
480 * 0 on success;
481 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300482 *
483 * @add_frontend: Registers a connectivity between a demux and a front-end,
484 * i.e., indicates that the demux can be connected via a call to
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300485 * @connect_frontend to use the given front-end as a TS source. The
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300486 * client of this function has to allocate dynamic or static memory for
487 * the frontend structure and initialize its fields before calling this
488 * function. This function is normally called during the driver
489 * initialization. The caller must not free the memory of the frontend
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300490 * struct before successfully calling @remove_frontend.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300491 * The @demux function parameter contains a pointer to the demux API and
492 * instance data.
493 * The @frontend function parameter contains a pointer to the front-end
494 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300495 * It returns:
496 * 0 on success;
497 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300498 *
499 * @remove_frontend: Indicates that the given front-end, registered by a call
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300500 * to @add_frontend, can no longer be connected as a TS source by this
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300501 * demux. The function should be called when a front-end driver or a demux
502 * driver is removed from the system. If the front-end is in use, the
503 * function fails with the return value of -EBUSY. After successfully
504 * calling this function, the caller can free the memory of the frontend
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300505 * struct if it was dynamically allocated before the @add_frontend
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300506 * operation.
507 * The @demux function parameter contains a pointer to the demux API and
508 * instance data.
509 * The @frontend function parameter contains a pointer to the front-end
510 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300511 * It returns:
512 * 0 on success;
513 * -ENODEV, if the front-end was not found,
514 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300515 *
516 * @get_frontends: Provides the APIs of the front-ends that have been
517 * registered for this demux. Any of the front-ends obtained with this
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300518 * call can be used as a parameter for @connect_frontend. The include
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300519 * file demux.h contains the macro DMX_FE_ENTRY() for converting an
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300520 * element of the generic type struct &list_head * to the type
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300521 * struct &dmx_frontend *. The caller must not free the memory of any of
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300522 * the elements obtained via this function call.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300523 * The @demux function parameter contains a pointer to the demux API and
524 * instance data.
525 * It returns a struct list_head pointer to the list of front-end
526 * interfaces, or NULL in the case of an empty list.
527 *
528 * @connect_frontend: Connects the TS output of the front-end to the input of
529 * the demux. A demux can only be connected to a front-end registered to
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300530 * the demux with the function @add_frontend. It may or may not be
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300531 * possible to connect multiple demuxes to the same front-end, depending
532 * on the capabilities of the HW platform. When not used, the front-end
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300533 * should be released by calling @disconnect_frontend.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300534 * The @demux function parameter contains a pointer to the demux API and
535 * instance data.
536 * The @frontend function parameter contains a pointer to the front-end
537 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300538 * It returns:
539 * 0 on success;
540 * -EINVAL, on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300541 *
542 * @disconnect_frontend: Disconnects the demux and a front-end previously
Mauro Carvalho Chehab28cff822015-10-06 15:30:46 -0300543 * connected by a @connect_frontend call.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300544 * The @demux function parameter contains a pointer to the demux API and
545 * instance data.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300546 * It returns:
547 * 0 on success;
548 * -EINVAL on bad parameter.
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300549 *
550 * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0,
551 * DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0.
552 * The @demux function parameter contains a pointer to the demux API and
553 * instance data.
554 * The @pids function parameter contains an array with five u16 elements
555 * where the PIDs will be stored.
Mauro Carvalho Chehabd2f01982016-07-17 11:25:37 -0300556 * It returns:
557 * 0 on success;
558 * -EINVAL on bad parameter.
Mauro Carvalho Chehab95abfdb2015-10-05 15:10:55 -0300559 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560struct dmx_demux {
Mauro Carvalho Chehab9be91db2015-10-08 17:33:47 -0300561 enum dmx_demux_caps capabilities;
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300562 struct dmx_frontend *frontend;
563 void *priv;
564 int (*open)(struct dmx_demux *demux);
565 int (*close)(struct dmx_demux *demux);
566 int (*write)(struct dmx_demux *demux, const char __user *buf,
567 size_t count);
568 int (*allocate_ts_feed)(struct dmx_demux *demux,
569 struct dmx_ts_feed **feed,
570 dmx_ts_cb callback);
571 int (*release_ts_feed)(struct dmx_demux *demux,
572 struct dmx_ts_feed *feed);
573 int (*allocate_section_feed)(struct dmx_demux *demux,
574 struct dmx_section_feed **feed,
575 dmx_section_cb callback);
576 int (*release_section_feed)(struct dmx_demux *demux,
577 struct dmx_section_feed *feed);
578 int (*add_frontend)(struct dmx_demux *demux,
579 struct dmx_frontend *frontend);
580 int (*remove_frontend)(struct dmx_demux *demux,
581 struct dmx_frontend *frontend);
582 struct list_head *(*get_frontends)(struct dmx_demux *demux);
583 int (*connect_frontend)(struct dmx_demux *demux,
584 struct dmx_frontend *frontend);
585 int (*disconnect_frontend)(struct dmx_demux *demux);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300587 int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Mauro Carvalho Chehab36aefa32016-08-29 16:04:01 -0300589 /* private: */
590
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300591 /*
Mauro Carvalho Chehab36aefa32016-08-29 16:04:01 -0300592 * Only used at av7110, to read some data from firmware.
593 * As this was never documented, we have no clue about what's
594 * there, and its usage on other drivers aren't encouraged.
Mauro Carvalho Chehab4bc645d2015-10-06 18:39:40 -0300595 */
Mauro Carvalho Chehababfc97f2015-10-07 16:27:24 -0300596 int (*get_stc)(struct dmx_demux *demux, unsigned int num,
597 u64 *stc, unsigned int *base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598};
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600#endif /* #ifndef __DEMUX_H */