Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * demux.h |
| 3 | * |
Mauro Carvalho Chehab | d26a5d4 | 2016-07-17 07:20:06 -0300 | [diff] [blame] | 4 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Oberritter | c051005 | 2005-09-09 13:02:21 -0700 | [diff] [blame] | 33 | #include <linux/dvb/dmx.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 35 | /* |
| 36 | * Common definitions |
| 37 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 48 | * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed |
| 49 | * filter. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
| 51 | |
Mark Adams | b3967d6 | 2005-11-08 21:35:50 -0800 | [diff] [blame] | 52 | #ifndef DMX_MAX_SECTION_SIZE |
| 53 | #define DMX_MAX_SECTION_SIZE 4096 |
| 54 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #ifndef DMX_MAX_SECFEED_SIZE |
Mark Adams | b3967d6 | 2005-11-08 21:35:50 -0800 | [diff] [blame] | 56 | #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #endif |
| 58 | |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 59 | /* |
| 60 | * TS packet reception |
| 61 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Mauro Carvalho Chehab | 0e6f2d1 | 2015-10-08 17:21:48 -0300 | [diff] [blame] | 63 | /** |
Mauro Carvalho Chehab | 564aaf6 | 2016-07-23 07:12:03 -0300 | [diff] [blame] | 64 | * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\) |
Mauro Carvalho Chehab | 0e6f2d1 | 2015-10-08 17:21:48 -0300 | [diff] [blame] | 65 | * |
| 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 | */ |
| 73 | enum ts_filter_type { |
| 74 | TS_PACKET = 1, |
| 75 | TS_PAYLOAD_ONLY = 2, |
| 76 | TS_DECODER = 4, |
| 77 | TS_DEMUX = 8, |
| 78 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 80 | /** |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | struct dmx_ts_feed { |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 95 | int is_filtering; |
| 96 | struct dmx_demux *parent; |
| 97 | void *priv; |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 98 | int (*set)(struct dmx_ts_feed *feed, |
| 99 | u16 pid, |
| 100 | int type, |
| 101 | enum dmx_ts_pes pes_type, |
Arnd Bergmann | e95be15 | 2016-06-17 17:46:28 -0300 | [diff] [blame] | 102 | ktime_t timeout); |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 103 | int (*start_filtering)(struct dmx_ts_feed *feed); |
| 104 | int (*stop_filtering)(struct dmx_ts_feed *feed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | }; |
| 106 | |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 107 | /* |
| 108 | * Section reception |
| 109 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 111 | /** |
| 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 Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 120 | * @parent: Back-pointer to struct dmx_section_feed. |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 121 | * @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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | struct dmx_section_filter { |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 130 | 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 Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 133 | struct dmx_section_feed *parent; |
| 134 | |
| 135 | void *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 138 | /** |
| 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 Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 151 | * previously allocated section filter. The function |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 152 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | struct dmx_section_feed { |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 164 | int is_filtering; |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 165 | struct dmx_demux *parent; |
| 166 | void *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 168 | int check_crc; |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 169 | |
| 170 | /* private: Used internally at dvb_demux.c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | u32 crc_val; |
| 172 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 173 | u8 *secbuf; |
| 174 | u8 secbuf_base[DMX_MAX_SECFEED_SIZE]; |
| 175 | u16 secbufp, seclen, tsfeedp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 177 | /* public: */ |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 178 | int (*set)(struct dmx_section_feed *feed, |
| 179 | u16 pid, |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 180 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | }; |
| 188 | |
Mauro Carvalho Chehab | 7b6e55b | 2015-11-04 11:07:09 -0200 | [diff] [blame] | 189 | /** |
Mauro Carvalho Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 190 | * 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 Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 197 | * @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 Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 201 | * |
| 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 Chehab | bb501b7 | 2016-08-29 10:05:49 -0300 | [diff] [blame] | 204 | * on a TS feed has been enabled using the start_filtering\(\) function at |
Mauro Carvalho Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 205 | * 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 Chehab | dd79d27 | 2016-10-13 07:14:38 -0300 | [diff] [blame] | 208 | * callback function. |
Mauro Carvalho Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 209 | * 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 Verkuil | 0e50e84 | 2017-07-16 04:07:59 -0400 | [diff] [blame] | 218 | * "wrapped" to the beginning of the buffer. In the latter case the @buffer1 |
Mauro Carvalho Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 219 | * 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 Chehab | bb501b7 | 2016-08-29 10:05:49 -0300 | [diff] [blame] | 244 | * |
| 245 | * - 0, on success; |
| 246 | * |
| 247 | * - -EOVERFLOW, on buffer overflow. |
Mauro Carvalho Chehab | 0cf35e8 | 2015-10-08 17:05:11 -0300 | [diff] [blame] | 248 | */ |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 249 | typedef int (*dmx_ts_cb)(const u8 *buffer1, |
| 250 | size_t buffer1_length, |
| 251 | const u8 *buffer2, |
| 252 | size_t buffer2_length, |
Mauro Carvalho Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 253 | struct dmx_ts_feed *source, |
| 254 | u32 *buffer_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Mauro Carvalho Chehab | 4be45fb | 2015-10-10 10:22:20 -0300 | [diff] [blame] | 256 | /** |
| 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 Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 270 | * @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 Chehab | 4be45fb | 2015-10-10 10:22:20 -0300 | [diff] [blame] | 274 | * |
| 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 Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 295 | typedef int (*dmx_section_cb)(const u8 *buffer1, |
| 296 | size_t buffer1_len, |
| 297 | const u8 *buffer2, |
| 298 | size_t buffer2_len, |
Mauro Carvalho Chehab | fdbeb96 | 2018-02-09 07:30:46 -0500 | [diff] [blame] | 299 | struct dmx_section_filter *source, |
| 300 | u32 *buffer_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Mauro Carvalho Chehab | bb501b7 | 2016-08-29 10:05:49 -0300 | [diff] [blame] | 302 | /* |
| 303 | * DVB Front-End |
| 304 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 306 | /** |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | enum dmx_frontend_source { |
| 317 | DMX_MEMORY_FE, |
| 318 | DMX_FRONTEND_0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 321 | /** |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | struct dmx_frontend { |
Mauro Carvalho Chehab | 548e5ae | 2015-10-07 16:11:03 -0300 | [diff] [blame] | 333 | struct list_head connectivity_list; |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 334 | enum dmx_frontend_source source; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | }; |
| 336 | |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 337 | /* |
| 338 | * MPEG-2 TS Demux |
| 339 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Mauro Carvalho Chehab | 9be91db | 2015-10-08 17:33:47 -0300 | [diff] [blame] | 341 | /** |
| 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 Chehab | 564aaf6 | 2016-07-23 07:12:03 -0300 | [diff] [blame] | 348 | * Those flags are OR'ed in the &dmx_demux.capabilities field |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | */ |
Mauro Carvalho Chehab | 9be91db | 2015-10-08 17:33:47 -0300 | [diff] [blame] | 350 | enum dmx_demux_caps { |
| 351 | DMX_TS_FILTERING = 1, |
| 352 | DMX_SECTION_FILTERING = 4, |
| 353 | DMX_MEMORY_BASED_FILTERING = 8, |
| 354 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | /* |
| 357 | * Demux resource type identifier. |
Mauro Carvalho Chehab | bb501b7 | 2016-08-29 10:05:49 -0300 | [diff] [blame] | 358 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Mauro Carvalho Chehab | bb501b7 | 2016-08-29 10:05:49 -0300 | [diff] [blame] | 360 | /** |
| 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 Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 367 | #define DMX_FE_ENTRY(list) \ |
| 368 | list_entry(list, struct dmx_frontend, connectivity_list) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 370 | /** |
| 371 | * struct dmx_demux - Structure that contains the demux capabilities and |
| 372 | * callbacks. |
| 373 | * |
Mauro Carvalho Chehab | 9be91db | 2015-10-08 17:33:47 -0300 | [diff] [blame] | 374 | * @capabilities: Bitfield of capability flags. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 375 | * |
| 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 Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 382 | * the function @close should be called. It should be possible for |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 383 | * multiple clients to access the demux at the same time. Thus, the |
| 384 | * function implementation should increment the demux usage count when |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 385 | * @open is called and decrement it when @close is called. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 386 | * The @demux function parameter contains a pointer to the demux API and |
| 387 | * instance data. |
Mauro Carvalho Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 388 | * It returns: |
| 389 | * 0 on success; |
| 390 | * -EUSERS, if maximum usage count was reached; |
| 391 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 392 | * |
| 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 395 | * the function @close should be called. It should be possible for |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 396 | * multiple clients to access the demux at the same time. Thus, the |
| 397 | * function implementation should increment the demux usage count when |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 398 | * @open is called and decrement it when @close is called. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 399 | * The @demux function parameter contains a pointer to the demux API and |
| 400 | * instance data. |
Mauro Carvalho Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 401 | * 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 Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 405 | * |
| 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 419 | * 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 Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 425 | * |
| 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 435 | * 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 Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 440 | * |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 441 | * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 442 | * 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 448 | * It returns: |
| 449 | * 0 on success; |
| 450 | * -EINVAL on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 451 | * |
| 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 466 | * It returns: |
| 467 | * 0 on success; |
| 468 | * -EBUSY, if no more TS feeds is available; |
| 469 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 470 | * |
| 471 | * @release_section_feed: Releases the resources allocated with |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 472 | * @allocate_section_feed, including allocated filters. Any filtering in |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 473 | * 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 479 | * It returns: |
| 480 | * 0 on success; |
| 481 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 482 | * |
| 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 485 | * @connect_frontend to use the given front-end as a TS source. The |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 486 | * 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 490 | * struct before successfully calling @remove_frontend. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 491 | * 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 495 | * It returns: |
| 496 | * 0 on success; |
| 497 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 498 | * |
| 499 | * @remove_frontend: Indicates that the given front-end, registered by a call |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 500 | * to @add_frontend, can no longer be connected as a TS source by this |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 501 | * 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 505 | * struct if it was dynamically allocated before the @add_frontend |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 506 | * 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 511 | * It returns: |
| 512 | * 0 on success; |
| 513 | * -ENODEV, if the front-end was not found, |
| 514 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 515 | * |
| 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 518 | * call can be used as a parameter for @connect_frontend. The include |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 519 | * file demux.h contains the macro DMX_FE_ENTRY() for converting an |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 520 | * element of the generic type struct &list_head * to the type |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 521 | * struct &dmx_frontend *. The caller must not free the memory of any of |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 522 | * the elements obtained via this function call. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 523 | * 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 530 | * the demux with the function @add_frontend. It may or may not be |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 531 | * 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 Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 533 | * should be released by calling @disconnect_frontend. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 534 | * 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 538 | * It returns: |
| 539 | * 0 on success; |
| 540 | * -EINVAL, on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 541 | * |
| 542 | * @disconnect_frontend: Disconnects the demux and a front-end previously |
Mauro Carvalho Chehab | 28cff82 | 2015-10-06 15:30:46 -0300 | [diff] [blame] | 543 | * connected by a @connect_frontend call. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 544 | * The @demux function parameter contains a pointer to the demux API and |
| 545 | * instance data. |
Mauro Carvalho Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 546 | * It returns: |
| 547 | * 0 on success; |
| 548 | * -EINVAL on bad parameter. |
Mauro Carvalho Chehab | 4bc645d | 2015-10-06 18:39:40 -0300 | [diff] [blame] | 549 | * |
| 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 Chehab | d2f0198 | 2016-07-17 11:25:37 -0300 | [diff] [blame] | 556 | * It returns: |
| 557 | * 0 on success; |
| 558 | * -EINVAL on bad parameter. |
Mauro Carvalho Chehab | 95abfdb | 2015-10-05 15:10:55 -0300 | [diff] [blame] | 559 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | struct dmx_demux { |
Mauro Carvalho Chehab | 9be91db | 2015-10-08 17:33:47 -0300 | [diff] [blame] | 561 | enum dmx_demux_caps capabilities; |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 562 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 587 | int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Mauro Carvalho Chehab | 36aefa3 | 2016-08-29 16:04:01 -0300 | [diff] [blame] | 589 | /* private: */ |
| 590 | |
Mauro Carvalho Chehab | 4bc645d | 2015-10-06 18:39:40 -0300 | [diff] [blame] | 591 | /* |
Mauro Carvalho Chehab | 36aefa3 | 2016-08-29 16:04:01 -0300 | [diff] [blame] | 592 | * 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 Chehab | 4bc645d | 2015-10-06 18:39:40 -0300 | [diff] [blame] | 595 | */ |
Mauro Carvalho Chehab | abfc97f | 2015-10-07 16:27:24 -0300 | [diff] [blame] | 596 | int (*get_stc)(struct dmx_demux *demux, unsigned int num, |
| 597 | u64 *stc, unsigned int *base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | #endif /* #ifndef __DEMUX_H */ |