1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * demux.h 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * The Kernel Digital TV Demux kABI defines a driver-internal interface for 5*4882a593Smuzhiyun * registering low-level, hardware specific driver to a hardware independent 6*4882a593Smuzhiyun * demux layer. 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Copyright (c) 2002 Convergence GmbH 9*4882a593Smuzhiyun * 10*4882a593Smuzhiyun * based on code: 11*4882a593Smuzhiyun * Copyright (c) 2000 Nokia Research Center 12*4882a593Smuzhiyun * Tampere, FINLAND 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or 15*4882a593Smuzhiyun * modify it under the terms of the GNU Lesser General Public License 16*4882a593Smuzhiyun * as published by the Free Software Foundation; either version 2.1 17*4882a593Smuzhiyun * of the License, or (at your option) any later version. 18*4882a593Smuzhiyun * 19*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, 20*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of 21*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22*4882a593Smuzhiyun * GNU General Public License for more details. 23*4882a593Smuzhiyun * 24*4882a593Smuzhiyun */ 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun #ifndef __DEMUX_H 27*4882a593Smuzhiyun #define __DEMUX_H 28*4882a593Smuzhiyun 29*4882a593Smuzhiyun #include <linux/types.h> 30*4882a593Smuzhiyun #include <linux/errno.h> 31*4882a593Smuzhiyun #include <linux/list.h> 32*4882a593Smuzhiyun #include <linux/time.h> 33*4882a593Smuzhiyun #include <linux/dvb/dmx.h> 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun /* 36*4882a593Smuzhiyun * Common definitions 37*4882a593Smuzhiyun */ 38*4882a593Smuzhiyun 39*4882a593Smuzhiyun /* 40*4882a593Smuzhiyun * DMX_MAX_FILTER_SIZE: Maximum length (in bytes) of a section/PES filter. 41*4882a593Smuzhiyun */ 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun #ifndef DMX_MAX_FILTER_SIZE 44*4882a593Smuzhiyun #define DMX_MAX_FILTER_SIZE 18 45*4882a593Smuzhiyun #endif 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun /* 48*4882a593Smuzhiyun * DMX_MAX_SECFEED_SIZE: Maximum length (in bytes) of a private section feed 49*4882a593Smuzhiyun * filter. 50*4882a593Smuzhiyun */ 51*4882a593Smuzhiyun 52*4882a593Smuzhiyun #ifndef DMX_MAX_SECTION_SIZE 53*4882a593Smuzhiyun #define DMX_MAX_SECTION_SIZE 4096 54*4882a593Smuzhiyun #endif 55*4882a593Smuzhiyun #ifndef DMX_MAX_SECFEED_SIZE 56*4882a593Smuzhiyun #define DMX_MAX_SECFEED_SIZE (DMX_MAX_SECTION_SIZE + 188) 57*4882a593Smuzhiyun #endif 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun /* 60*4882a593Smuzhiyun * TS packet reception 61*4882a593Smuzhiyun */ 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun /** 64*4882a593Smuzhiyun * enum ts_filter_type - filter type bitmap for dmx_ts_feed.set\(\) 65*4882a593Smuzhiyun * 66*4882a593Smuzhiyun * @TS_PACKET: Send TS packets (188 bytes) to callback (default). 67*4882a593Smuzhiyun * @TS_PAYLOAD_ONLY: In case TS_PACKET is set, only send the TS payload 68*4882a593Smuzhiyun * (<=184 bytes per packet) to callback 69*4882a593Smuzhiyun * @TS_DECODER: Send stream to built-in decoder (if present). 70*4882a593Smuzhiyun * @TS_DEMUX: In case TS_PACKET is set, send the TS to the demux 71*4882a593Smuzhiyun * device, not to the dvr device 72*4882a593Smuzhiyun */ 73*4882a593Smuzhiyun enum ts_filter_type { 74*4882a593Smuzhiyun TS_PACKET = 1, 75*4882a593Smuzhiyun TS_PAYLOAD_ONLY = 2, 76*4882a593Smuzhiyun TS_DECODER = 4, 77*4882a593Smuzhiyun TS_DEMUX = 8, 78*4882a593Smuzhiyun }; 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun /** 81*4882a593Smuzhiyun * struct dmx_ts_feed - Structure that contains a TS feed filter 82*4882a593Smuzhiyun * 83*4882a593Smuzhiyun * @is_filtering: Set to non-zero when filtering in progress 84*4882a593Smuzhiyun * @parent: pointer to struct dmx_demux 85*4882a593Smuzhiyun * @priv: pointer to private data of the API client 86*4882a593Smuzhiyun * @set: sets the TS filter 87*4882a593Smuzhiyun * @start_filtering: starts TS filtering 88*4882a593Smuzhiyun * @stop_filtering: stops TS filtering 89*4882a593Smuzhiyun * 90*4882a593Smuzhiyun * A TS feed is typically mapped to a hardware PID filter on the demux chip. 91*4882a593Smuzhiyun * Using this API, the client can set the filtering properties to start/stop 92*4882a593Smuzhiyun * filtering TS packets on a particular TS feed. 93*4882a593Smuzhiyun */ 94*4882a593Smuzhiyun struct dmx_ts_feed { 95*4882a593Smuzhiyun int is_filtering; 96*4882a593Smuzhiyun struct dmx_demux *parent; 97*4882a593Smuzhiyun void *priv; 98*4882a593Smuzhiyun int (*set)(struct dmx_ts_feed *feed, 99*4882a593Smuzhiyun u16 pid, 100*4882a593Smuzhiyun int type, 101*4882a593Smuzhiyun enum dmx_ts_pes pes_type, 102*4882a593Smuzhiyun ktime_t timeout); 103*4882a593Smuzhiyun int (*start_filtering)(struct dmx_ts_feed *feed); 104*4882a593Smuzhiyun int (*stop_filtering)(struct dmx_ts_feed *feed); 105*4882a593Smuzhiyun }; 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun /* 108*4882a593Smuzhiyun * Section reception 109*4882a593Smuzhiyun */ 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun /** 112*4882a593Smuzhiyun * struct dmx_section_filter - Structure that describes a section filter 113*4882a593Smuzhiyun * 114*4882a593Smuzhiyun * @filter_value: Contains up to 16 bytes (128 bits) of the TS section header 115*4882a593Smuzhiyun * that will be matched by the section filter 116*4882a593Smuzhiyun * @filter_mask: Contains a 16 bytes (128 bits) filter mask with the bits 117*4882a593Smuzhiyun * specified by @filter_value that will be used on the filter 118*4882a593Smuzhiyun * match logic. 119*4882a593Smuzhiyun * @filter_mode: Contains a 16 bytes (128 bits) filter mode. 120*4882a593Smuzhiyun * @parent: Back-pointer to struct dmx_section_feed. 121*4882a593Smuzhiyun * @priv: Pointer to private data of the API client. 122*4882a593Smuzhiyun * 123*4882a593Smuzhiyun * 124*4882a593Smuzhiyun * The @filter_mask controls which bits of @filter_value are compared with 125*4882a593Smuzhiyun * the section headers/payload. On a binary value of 1 in filter_mask, the 126*4882a593Smuzhiyun * corresponding bits are compared. The filter only accepts sections that are 127*4882a593Smuzhiyun * equal to filter_value in all the tested bit positions. 128*4882a593Smuzhiyun */ 129*4882a593Smuzhiyun struct dmx_section_filter { 130*4882a593Smuzhiyun u8 filter_value[DMX_MAX_FILTER_SIZE]; 131*4882a593Smuzhiyun u8 filter_mask[DMX_MAX_FILTER_SIZE]; 132*4882a593Smuzhiyun u8 filter_mode[DMX_MAX_FILTER_SIZE]; 133*4882a593Smuzhiyun struct dmx_section_feed *parent; 134*4882a593Smuzhiyun 135*4882a593Smuzhiyun void *priv; 136*4882a593Smuzhiyun }; 137*4882a593Smuzhiyun 138*4882a593Smuzhiyun /** 139*4882a593Smuzhiyun * struct dmx_section_feed - Structure that contains a section feed filter 140*4882a593Smuzhiyun * 141*4882a593Smuzhiyun * @is_filtering: Set to non-zero when filtering in progress 142*4882a593Smuzhiyun * @parent: pointer to struct dmx_demux 143*4882a593Smuzhiyun * @priv: pointer to private data of the API client 144*4882a593Smuzhiyun * @check_crc: If non-zero, check the CRC values of filtered sections. 145*4882a593Smuzhiyun * @set: sets the section filter 146*4882a593Smuzhiyun * @allocate_filter: This function is used to allocate a section filter on 147*4882a593Smuzhiyun * the demux. It should only be called when no filtering 148*4882a593Smuzhiyun * is in progress on this section feed. If a filter cannot 149*4882a593Smuzhiyun * be allocated, the function fails with -ENOSPC. 150*4882a593Smuzhiyun * @release_filter: This function releases all the resources of a 151*4882a593Smuzhiyun * previously allocated section filter. The function 152*4882a593Smuzhiyun * should not be called while filtering is in progress 153*4882a593Smuzhiyun * on this section feed. After calling this function, 154*4882a593Smuzhiyun * the caller should not try to dereference the filter 155*4882a593Smuzhiyun * pointer. 156*4882a593Smuzhiyun * @start_filtering: starts section filtering 157*4882a593Smuzhiyun * @stop_filtering: stops section filtering 158*4882a593Smuzhiyun * 159*4882a593Smuzhiyun * A TS feed is typically mapped to a hardware PID filter on the demux chip. 160*4882a593Smuzhiyun * Using this API, the client can set the filtering properties to start/stop 161*4882a593Smuzhiyun * filtering TS packets on a particular TS feed. 162*4882a593Smuzhiyun */ 163*4882a593Smuzhiyun struct dmx_section_feed { 164*4882a593Smuzhiyun int is_filtering; 165*4882a593Smuzhiyun struct dmx_demux *parent; 166*4882a593Smuzhiyun void *priv; 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun int check_crc; 169*4882a593Smuzhiyun 170*4882a593Smuzhiyun /* private: Used internally at dvb_demux.c */ 171*4882a593Smuzhiyun u32 crc_val; 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun u8 *secbuf; 174*4882a593Smuzhiyun u8 secbuf_base[DMX_MAX_SECFEED_SIZE]; 175*4882a593Smuzhiyun u16 secbufp, seclen, tsfeedp; 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun /* public: */ 178*4882a593Smuzhiyun int (*set)(struct dmx_section_feed *feed, 179*4882a593Smuzhiyun u16 pid, 180*4882a593Smuzhiyun int check_crc); 181*4882a593Smuzhiyun int (*allocate_filter)(struct dmx_section_feed *feed, 182*4882a593Smuzhiyun struct dmx_section_filter **filter); 183*4882a593Smuzhiyun int (*release_filter)(struct dmx_section_feed *feed, 184*4882a593Smuzhiyun struct dmx_section_filter *filter); 185*4882a593Smuzhiyun int (*start_filtering)(struct dmx_section_feed *feed); 186*4882a593Smuzhiyun int (*stop_filtering)(struct dmx_section_feed *feed); 187*4882a593Smuzhiyun }; 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun /** 190*4882a593Smuzhiyun * typedef dmx_ts_cb - DVB demux TS filter callback function prototype 191*4882a593Smuzhiyun * 192*4882a593Smuzhiyun * @buffer1: Pointer to the start of the filtered TS packets. 193*4882a593Smuzhiyun * @buffer1_length: Length of the TS data in buffer1. 194*4882a593Smuzhiyun * @buffer2: Pointer to the tail of the filtered TS packets, or NULL. 195*4882a593Smuzhiyun * @buffer2_length: Length of the TS data in buffer2. 196*4882a593Smuzhiyun * @source: Indicates which TS feed is the source of the callback. 197*4882a593Smuzhiyun * @buffer_flags: Address where buffer flags are stored. Those are 198*4882a593Smuzhiyun * used to report discontinuity users via DVB 199*4882a593Smuzhiyun * memory mapped API, as defined by 200*4882a593Smuzhiyun * &enum dmx_buffer_flags. 201*4882a593Smuzhiyun * 202*4882a593Smuzhiyun * This function callback prototype, provided by the client of the demux API, 203*4882a593Smuzhiyun * is called from the demux code. The function is only called when filtering 204*4882a593Smuzhiyun * on a TS feed has been enabled using the start_filtering\(\) function at 205*4882a593Smuzhiyun * the &dmx_demux. 206*4882a593Smuzhiyun * Any TS packets that match the filter settings are copied to a circular 207*4882a593Smuzhiyun * buffer. The filtered TS packets are delivered to the client using this 208*4882a593Smuzhiyun * callback function. 209*4882a593Smuzhiyun * It is expected that the @buffer1 and @buffer2 callback parameters point to 210*4882a593Smuzhiyun * addresses within the circular buffer, but other implementations are also 211*4882a593Smuzhiyun * possible. Note that the called party should not try to free the memory 212*4882a593Smuzhiyun * the @buffer1 and @buffer2 parameters point to. 213*4882a593Smuzhiyun * 214*4882a593Smuzhiyun * When this function is called, the @buffer1 parameter typically points to 215*4882a593Smuzhiyun * the start of the first undelivered TS packet within a circular buffer. 216*4882a593Smuzhiyun * The @buffer2 buffer parameter is normally NULL, except when the received 217*4882a593Smuzhiyun * TS packets have crossed the last address of the circular buffer and 218*4882a593Smuzhiyun * "wrapped" to the beginning of the buffer. In the latter case the @buffer1 219*4882a593Smuzhiyun * parameter would contain an address within the circular buffer, while the 220*4882a593Smuzhiyun * @buffer2 parameter would contain the first address of the circular buffer. 221*4882a593Smuzhiyun * The number of bytes delivered with this function (i.e. @buffer1_length + 222*4882a593Smuzhiyun * @buffer2_length) is usually equal to the value of callback_length parameter 223*4882a593Smuzhiyun * given in the set() function, with one exception: if a timeout occurs before 224*4882a593Smuzhiyun * receiving callback_length bytes of TS data, any undelivered packets are 225*4882a593Smuzhiyun * immediately delivered to the client by calling this function. The timeout 226*4882a593Smuzhiyun * duration is controlled by the set() function in the TS Feed API. 227*4882a593Smuzhiyun * 228*4882a593Smuzhiyun * If a TS packet is received with errors that could not be fixed by the 229*4882a593Smuzhiyun * TS-level forward error correction (FEC), the Transport_error_indicator 230*4882a593Smuzhiyun * flag of the TS packet header should be set. The TS packet should not be 231*4882a593Smuzhiyun * discarded, as the error can possibly be corrected by a higher layer 232*4882a593Smuzhiyun * protocol. If the called party is slow in processing the callback, it 233*4882a593Smuzhiyun * is possible that the circular buffer eventually fills up. If this happens, 234*4882a593Smuzhiyun * the demux driver should discard any TS packets received while the buffer 235*4882a593Smuzhiyun * is full and return -EOVERFLOW. 236*4882a593Smuzhiyun * 237*4882a593Smuzhiyun * The type of data returned to the callback can be selected by the 238*4882a593Smuzhiyun * &dmx_ts_feed.@set function. The type parameter decides if the raw 239*4882a593Smuzhiyun * TS packet (TS_PACKET) or just the payload (TS_PACKET|TS_PAYLOAD_ONLY) 240*4882a593Smuzhiyun * should be returned. If additionally the TS_DECODER bit is set the stream 241*4882a593Smuzhiyun * will also be sent to the hardware MPEG decoder. 242*4882a593Smuzhiyun * 243*4882a593Smuzhiyun * Return: 244*4882a593Smuzhiyun * 245*4882a593Smuzhiyun * - 0, on success; 246*4882a593Smuzhiyun * 247*4882a593Smuzhiyun * - -EOVERFLOW, on buffer overflow. 248*4882a593Smuzhiyun */ 249*4882a593Smuzhiyun typedef int (*dmx_ts_cb)(const u8 *buffer1, 250*4882a593Smuzhiyun size_t buffer1_length, 251*4882a593Smuzhiyun const u8 *buffer2, 252*4882a593Smuzhiyun size_t buffer2_length, 253*4882a593Smuzhiyun struct dmx_ts_feed *source, 254*4882a593Smuzhiyun u32 *buffer_flags); 255*4882a593Smuzhiyun 256*4882a593Smuzhiyun /** 257*4882a593Smuzhiyun * typedef dmx_section_cb - DVB demux TS filter callback function prototype 258*4882a593Smuzhiyun * 259*4882a593Smuzhiyun * @buffer1: Pointer to the start of the filtered section, e.g. 260*4882a593Smuzhiyun * within the circular buffer of the demux driver. 261*4882a593Smuzhiyun * @buffer1_len: Length of the filtered section data in @buffer1, 262*4882a593Smuzhiyun * including headers and CRC. 263*4882a593Smuzhiyun * @buffer2: Pointer to the tail of the filtered section data, 264*4882a593Smuzhiyun * or NULL. Useful to handle the wrapping of a 265*4882a593Smuzhiyun * circular buffer. 266*4882a593Smuzhiyun * @buffer2_len: Length of the filtered section data in @buffer2, 267*4882a593Smuzhiyun * including headers and CRC. 268*4882a593Smuzhiyun * @source: Indicates which section feed is the source of the 269*4882a593Smuzhiyun * callback. 270*4882a593Smuzhiyun * @buffer_flags: Address where buffer flags are stored. Those are 271*4882a593Smuzhiyun * used to report discontinuity users via DVB 272*4882a593Smuzhiyun * memory mapped API, as defined by 273*4882a593Smuzhiyun * &enum dmx_buffer_flags. 274*4882a593Smuzhiyun * 275*4882a593Smuzhiyun * This function callback prototype, provided by the client of the demux API, 276*4882a593Smuzhiyun * is called from the demux code. The function is only called when 277*4882a593Smuzhiyun * filtering of sections has been enabled using the function 278*4882a593Smuzhiyun * &dmx_ts_feed.@start_filtering. When the demux driver has received a 279*4882a593Smuzhiyun * complete section that matches at least one section filter, the client 280*4882a593Smuzhiyun * is notified via this callback function. Normally this function is called 281*4882a593Smuzhiyun * for each received section; however, it is also possible to deliver 282*4882a593Smuzhiyun * multiple sections with one callback, for example when the system load 283*4882a593Smuzhiyun * is high. If an error occurs while receiving a section, this 284*4882a593Smuzhiyun * function should be called with the corresponding error type set in the 285*4882a593Smuzhiyun * success field, whether or not there is data to deliver. The Section Feed 286*4882a593Smuzhiyun * implementation should maintain a circular buffer for received sections. 287*4882a593Smuzhiyun * However, this is not necessary if the Section Feed API is implemented as 288*4882a593Smuzhiyun * a client of the TS Feed API, because the TS Feed implementation then 289*4882a593Smuzhiyun * buffers the received data. The size of the circular buffer can be 290*4882a593Smuzhiyun * configured using the &dmx_ts_feed.@set function in the Section Feed API. 291*4882a593Smuzhiyun * If there is no room in the circular buffer when a new section is received, 292*4882a593Smuzhiyun * the section must be discarded. If this happens, the value of the success 293*4882a593Smuzhiyun * parameter should be DMX_OVERRUN_ERROR on the next callback. 294*4882a593Smuzhiyun */ 295*4882a593Smuzhiyun typedef int (*dmx_section_cb)(const u8 *buffer1, 296*4882a593Smuzhiyun size_t buffer1_len, 297*4882a593Smuzhiyun const u8 *buffer2, 298*4882a593Smuzhiyun size_t buffer2_len, 299*4882a593Smuzhiyun struct dmx_section_filter *source, 300*4882a593Smuzhiyun u32 *buffer_flags); 301*4882a593Smuzhiyun 302*4882a593Smuzhiyun /* 303*4882a593Smuzhiyun * DVB Front-End 304*4882a593Smuzhiyun */ 305*4882a593Smuzhiyun 306*4882a593Smuzhiyun /** 307*4882a593Smuzhiyun * enum dmx_frontend_source - Used to identify the type of frontend 308*4882a593Smuzhiyun * 309*4882a593Smuzhiyun * @DMX_MEMORY_FE: The source of the demux is memory. It means that 310*4882a593Smuzhiyun * the MPEG-TS to be filtered comes from userspace, 311*4882a593Smuzhiyun * via write() syscall. 312*4882a593Smuzhiyun * 313*4882a593Smuzhiyun * @DMX_FRONTEND_0: The source of the demux is a frontend connected 314*4882a593Smuzhiyun * to the demux. 315*4882a593Smuzhiyun */ 316*4882a593Smuzhiyun enum dmx_frontend_source { 317*4882a593Smuzhiyun DMX_MEMORY_FE, 318*4882a593Smuzhiyun DMX_FRONTEND_0, 319*4882a593Smuzhiyun }; 320*4882a593Smuzhiyun 321*4882a593Smuzhiyun /** 322*4882a593Smuzhiyun * struct dmx_frontend - Structure that lists the frontends associated with 323*4882a593Smuzhiyun * a demux 324*4882a593Smuzhiyun * 325*4882a593Smuzhiyun * @connectivity_list: List of front-ends that can be connected to a 326*4882a593Smuzhiyun * particular demux; 327*4882a593Smuzhiyun * @source: Type of the frontend. 328*4882a593Smuzhiyun * 329*4882a593Smuzhiyun * FIXME: this structure should likely be replaced soon by some 330*4882a593Smuzhiyun * media-controller based logic. 331*4882a593Smuzhiyun */ 332*4882a593Smuzhiyun struct dmx_frontend { 333*4882a593Smuzhiyun struct list_head connectivity_list; 334*4882a593Smuzhiyun enum dmx_frontend_source source; 335*4882a593Smuzhiyun }; 336*4882a593Smuzhiyun 337*4882a593Smuzhiyun /* 338*4882a593Smuzhiyun * MPEG-2 TS Demux 339*4882a593Smuzhiyun */ 340*4882a593Smuzhiyun 341*4882a593Smuzhiyun /** 342*4882a593Smuzhiyun * enum dmx_demux_caps - MPEG-2 TS Demux capabilities bitmap 343*4882a593Smuzhiyun * 344*4882a593Smuzhiyun * @DMX_TS_FILTERING: set if TS filtering is supported; 345*4882a593Smuzhiyun * @DMX_SECTION_FILTERING: set if section filtering is supported; 346*4882a593Smuzhiyun * @DMX_MEMORY_BASED_FILTERING: set if write() available. 347*4882a593Smuzhiyun * 348*4882a593Smuzhiyun * Those flags are OR'ed in the &dmx_demux.capabilities field 349*4882a593Smuzhiyun */ 350*4882a593Smuzhiyun enum dmx_demux_caps { 351*4882a593Smuzhiyun DMX_TS_FILTERING = 1, 352*4882a593Smuzhiyun DMX_SECTION_FILTERING = 4, 353*4882a593Smuzhiyun DMX_MEMORY_BASED_FILTERING = 8, 354*4882a593Smuzhiyun }; 355*4882a593Smuzhiyun 356*4882a593Smuzhiyun /* 357*4882a593Smuzhiyun * Demux resource type identifier. 358*4882a593Smuzhiyun */ 359*4882a593Smuzhiyun 360*4882a593Smuzhiyun /** 361*4882a593Smuzhiyun * DMX_FE_ENTRY - Casts elements in the list of registered 362*4882a593Smuzhiyun * front-ends from the generic type struct list_head 363*4882a593Smuzhiyun * to the type * struct dmx_frontend 364*4882a593Smuzhiyun * 365*4882a593Smuzhiyun * @list: list of struct dmx_frontend 366*4882a593Smuzhiyun */ 367*4882a593Smuzhiyun #define DMX_FE_ENTRY(list) \ 368*4882a593Smuzhiyun list_entry(list, struct dmx_frontend, connectivity_list) 369*4882a593Smuzhiyun 370*4882a593Smuzhiyun /** 371*4882a593Smuzhiyun * struct dmx_demux - Structure that contains the demux capabilities and 372*4882a593Smuzhiyun * callbacks. 373*4882a593Smuzhiyun * 374*4882a593Smuzhiyun * @capabilities: Bitfield of capability flags. 375*4882a593Smuzhiyun * 376*4882a593Smuzhiyun * @frontend: Front-end connected to the demux 377*4882a593Smuzhiyun * 378*4882a593Smuzhiyun * @priv: Pointer to private data of the API client 379*4882a593Smuzhiyun * 380*4882a593Smuzhiyun * @open: This function reserves the demux for use by the caller and, if 381*4882a593Smuzhiyun * necessary, initializes the demux. When the demux is no longer needed, 382*4882a593Smuzhiyun * the function @close should be called. It should be possible for 383*4882a593Smuzhiyun * multiple clients to access the demux at the same time. Thus, the 384*4882a593Smuzhiyun * function implementation should increment the demux usage count when 385*4882a593Smuzhiyun * @open is called and decrement it when @close is called. 386*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 387*4882a593Smuzhiyun * instance data. 388*4882a593Smuzhiyun * It returns: 389*4882a593Smuzhiyun * 0 on success; 390*4882a593Smuzhiyun * -EUSERS, if maximum usage count was reached; 391*4882a593Smuzhiyun * -EINVAL, on bad parameter. 392*4882a593Smuzhiyun * 393*4882a593Smuzhiyun * @close: This function reserves the demux for use by the caller and, if 394*4882a593Smuzhiyun * necessary, initializes the demux. When the demux is no longer needed, 395*4882a593Smuzhiyun * the function @close should be called. It should be possible for 396*4882a593Smuzhiyun * multiple clients to access the demux at the same time. Thus, the 397*4882a593Smuzhiyun * function implementation should increment the demux usage count when 398*4882a593Smuzhiyun * @open is called and decrement it when @close is called. 399*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 400*4882a593Smuzhiyun * instance data. 401*4882a593Smuzhiyun * It returns: 402*4882a593Smuzhiyun * 0 on success; 403*4882a593Smuzhiyun * -ENODEV, if demux was not in use (e. g. no users); 404*4882a593Smuzhiyun * -EINVAL, on bad parameter. 405*4882a593Smuzhiyun * 406*4882a593Smuzhiyun * @write: This function provides the demux driver with a memory buffer 407*4882a593Smuzhiyun * containing TS packets. Instead of receiving TS packets from the DVB 408*4882a593Smuzhiyun * front-end, the demux driver software will read packets from memory. 409*4882a593Smuzhiyun * Any clients of this demux with active TS, PES or Section filters will 410*4882a593Smuzhiyun * receive filtered data via the Demux callback API (see 0). The function 411*4882a593Smuzhiyun * returns when all the data in the buffer has been consumed by the demux. 412*4882a593Smuzhiyun * Demux hardware typically cannot read TS from memory. If this is the 413*4882a593Smuzhiyun * case, memory-based filtering has to be implemented entirely in software. 414*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 415*4882a593Smuzhiyun * instance data. 416*4882a593Smuzhiyun * The @buf function parameter contains a pointer to the TS data in 417*4882a593Smuzhiyun * kernel-space memory. 418*4882a593Smuzhiyun * The @count function parameter contains the length of the TS data. 419*4882a593Smuzhiyun * It returns: 420*4882a593Smuzhiyun * 0 on success; 421*4882a593Smuzhiyun * -ERESTARTSYS, if mutex lock was interrupted; 422*4882a593Smuzhiyun * -EINTR, if a signal handling is pending; 423*4882a593Smuzhiyun * -ENODEV, if demux was removed; 424*4882a593Smuzhiyun * -EINVAL, on bad parameter. 425*4882a593Smuzhiyun * 426*4882a593Smuzhiyun * @allocate_ts_feed: Allocates a new TS feed, which is used to filter the TS 427*4882a593Smuzhiyun * packets carrying a certain PID. The TS feed normally corresponds to a 428*4882a593Smuzhiyun * hardware PID filter on the demux chip. 429*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 430*4882a593Smuzhiyun * instance data. 431*4882a593Smuzhiyun * The @feed function parameter contains a pointer to the TS feed API and 432*4882a593Smuzhiyun * instance data. 433*4882a593Smuzhiyun * The @callback function parameter contains a pointer to the callback 434*4882a593Smuzhiyun * function for passing received TS packet. 435*4882a593Smuzhiyun * It returns: 436*4882a593Smuzhiyun * 0 on success; 437*4882a593Smuzhiyun * -ERESTARTSYS, if mutex lock was interrupted; 438*4882a593Smuzhiyun * -EBUSY, if no more TS feeds is available; 439*4882a593Smuzhiyun * -EINVAL, on bad parameter. 440*4882a593Smuzhiyun * 441*4882a593Smuzhiyun * @release_ts_feed: Releases the resources allocated with @allocate_ts_feed. 442*4882a593Smuzhiyun * Any filtering in progress on the TS feed should be stopped before 443*4882a593Smuzhiyun * calling this function. 444*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 445*4882a593Smuzhiyun * instance data. 446*4882a593Smuzhiyun * The @feed function parameter contains a pointer to the TS feed API and 447*4882a593Smuzhiyun * instance data. 448*4882a593Smuzhiyun * It returns: 449*4882a593Smuzhiyun * 0 on success; 450*4882a593Smuzhiyun * -EINVAL on bad parameter. 451*4882a593Smuzhiyun * 452*4882a593Smuzhiyun * @allocate_section_feed: Allocates a new section feed, i.e. a demux resource 453*4882a593Smuzhiyun * for filtering and receiving sections. On platforms with hardware 454*4882a593Smuzhiyun * support for section filtering, a section feed is directly mapped to 455*4882a593Smuzhiyun * the demux HW. On other platforms, TS packets are first PID filtered in 456*4882a593Smuzhiyun * hardware and a hardware section filter then emulated in software. The 457*4882a593Smuzhiyun * caller obtains an API pointer of type dmx_section_feed_t as an out 458*4882a593Smuzhiyun * parameter. Using this API the caller can set filtering parameters and 459*4882a593Smuzhiyun * start receiving sections. 460*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 461*4882a593Smuzhiyun * instance data. 462*4882a593Smuzhiyun * The @feed function parameter contains a pointer to the TS feed API and 463*4882a593Smuzhiyun * instance data. 464*4882a593Smuzhiyun * The @callback function parameter contains a pointer to the callback 465*4882a593Smuzhiyun * function for passing received TS packet. 466*4882a593Smuzhiyun * It returns: 467*4882a593Smuzhiyun * 0 on success; 468*4882a593Smuzhiyun * -EBUSY, if no more TS feeds is available; 469*4882a593Smuzhiyun * -EINVAL, on bad parameter. 470*4882a593Smuzhiyun * 471*4882a593Smuzhiyun * @release_section_feed: Releases the resources allocated with 472*4882a593Smuzhiyun * @allocate_section_feed, including allocated filters. Any filtering in 473*4882a593Smuzhiyun * progress on the section feed should be stopped before calling this 474*4882a593Smuzhiyun * function. 475*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 476*4882a593Smuzhiyun * instance data. 477*4882a593Smuzhiyun * The @feed function parameter contains a pointer to the TS feed API and 478*4882a593Smuzhiyun * instance data. 479*4882a593Smuzhiyun * It returns: 480*4882a593Smuzhiyun * 0 on success; 481*4882a593Smuzhiyun * -EINVAL, on bad parameter. 482*4882a593Smuzhiyun * 483*4882a593Smuzhiyun * @add_frontend: Registers a connectivity between a demux and a front-end, 484*4882a593Smuzhiyun * i.e., indicates that the demux can be connected via a call to 485*4882a593Smuzhiyun * @connect_frontend to use the given front-end as a TS source. The 486*4882a593Smuzhiyun * client of this function has to allocate dynamic or static memory for 487*4882a593Smuzhiyun * the frontend structure and initialize its fields before calling this 488*4882a593Smuzhiyun * function. This function is normally called during the driver 489*4882a593Smuzhiyun * initialization. The caller must not free the memory of the frontend 490*4882a593Smuzhiyun * struct before successfully calling @remove_frontend. 491*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 492*4882a593Smuzhiyun * instance data. 493*4882a593Smuzhiyun * The @frontend function parameter contains a pointer to the front-end 494*4882a593Smuzhiyun * instance data. 495*4882a593Smuzhiyun * It returns: 496*4882a593Smuzhiyun * 0 on success; 497*4882a593Smuzhiyun * -EINVAL, on bad parameter. 498*4882a593Smuzhiyun * 499*4882a593Smuzhiyun * @remove_frontend: Indicates that the given front-end, registered by a call 500*4882a593Smuzhiyun * to @add_frontend, can no longer be connected as a TS source by this 501*4882a593Smuzhiyun * demux. The function should be called when a front-end driver or a demux 502*4882a593Smuzhiyun * driver is removed from the system. If the front-end is in use, the 503*4882a593Smuzhiyun * function fails with the return value of -EBUSY. After successfully 504*4882a593Smuzhiyun * calling this function, the caller can free the memory of the frontend 505*4882a593Smuzhiyun * struct if it was dynamically allocated before the @add_frontend 506*4882a593Smuzhiyun * operation. 507*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 508*4882a593Smuzhiyun * instance data. 509*4882a593Smuzhiyun * The @frontend function parameter contains a pointer to the front-end 510*4882a593Smuzhiyun * instance data. 511*4882a593Smuzhiyun * It returns: 512*4882a593Smuzhiyun * 0 on success; 513*4882a593Smuzhiyun * -ENODEV, if the front-end was not found, 514*4882a593Smuzhiyun * -EINVAL, on bad parameter. 515*4882a593Smuzhiyun * 516*4882a593Smuzhiyun * @get_frontends: Provides the APIs of the front-ends that have been 517*4882a593Smuzhiyun * registered for this demux. Any of the front-ends obtained with this 518*4882a593Smuzhiyun * call can be used as a parameter for @connect_frontend. The include 519*4882a593Smuzhiyun * file demux.h contains the macro DMX_FE_ENTRY() for converting an 520*4882a593Smuzhiyun * element of the generic type struct &list_head * to the type 521*4882a593Smuzhiyun * struct &dmx_frontend *. The caller must not free the memory of any of 522*4882a593Smuzhiyun * the elements obtained via this function call. 523*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 524*4882a593Smuzhiyun * instance data. 525*4882a593Smuzhiyun * It returns a struct list_head pointer to the list of front-end 526*4882a593Smuzhiyun * interfaces, or NULL in the case of an empty list. 527*4882a593Smuzhiyun * 528*4882a593Smuzhiyun * @connect_frontend: Connects the TS output of the front-end to the input of 529*4882a593Smuzhiyun * the demux. A demux can only be connected to a front-end registered to 530*4882a593Smuzhiyun * the demux with the function @add_frontend. It may or may not be 531*4882a593Smuzhiyun * possible to connect multiple demuxes to the same front-end, depending 532*4882a593Smuzhiyun * on the capabilities of the HW platform. When not used, the front-end 533*4882a593Smuzhiyun * should be released by calling @disconnect_frontend. 534*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 535*4882a593Smuzhiyun * instance data. 536*4882a593Smuzhiyun * The @frontend function parameter contains a pointer to the front-end 537*4882a593Smuzhiyun * instance data. 538*4882a593Smuzhiyun * It returns: 539*4882a593Smuzhiyun * 0 on success; 540*4882a593Smuzhiyun * -EINVAL, on bad parameter. 541*4882a593Smuzhiyun * 542*4882a593Smuzhiyun * @disconnect_frontend: Disconnects the demux and a front-end previously 543*4882a593Smuzhiyun * connected by a @connect_frontend call. 544*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 545*4882a593Smuzhiyun * instance data. 546*4882a593Smuzhiyun * It returns: 547*4882a593Smuzhiyun * 0 on success; 548*4882a593Smuzhiyun * -EINVAL on bad parameter. 549*4882a593Smuzhiyun * 550*4882a593Smuzhiyun * @get_pes_pids: Get the PIDs for DMX_PES_AUDIO0, DMX_PES_VIDEO0, 551*4882a593Smuzhiyun * DMX_PES_TELETEXT0, DMX_PES_SUBTITLE0 and DMX_PES_PCR0. 552*4882a593Smuzhiyun * The @demux function parameter contains a pointer to the demux API and 553*4882a593Smuzhiyun * instance data. 554*4882a593Smuzhiyun * The @pids function parameter contains an array with five u16 elements 555*4882a593Smuzhiyun * where the PIDs will be stored. 556*4882a593Smuzhiyun * It returns: 557*4882a593Smuzhiyun * 0 on success; 558*4882a593Smuzhiyun * -EINVAL on bad parameter. 559*4882a593Smuzhiyun */ 560*4882a593Smuzhiyun struct dmx_demux { 561*4882a593Smuzhiyun enum dmx_demux_caps capabilities; 562*4882a593Smuzhiyun struct dmx_frontend *frontend; 563*4882a593Smuzhiyun void *priv; 564*4882a593Smuzhiyun int (*open)(struct dmx_demux *demux); 565*4882a593Smuzhiyun int (*close)(struct dmx_demux *demux); 566*4882a593Smuzhiyun int (*write)(struct dmx_demux *demux, const char __user *buf, 567*4882a593Smuzhiyun size_t count); 568*4882a593Smuzhiyun int (*allocate_ts_feed)(struct dmx_demux *demux, 569*4882a593Smuzhiyun struct dmx_ts_feed **feed, 570*4882a593Smuzhiyun dmx_ts_cb callback); 571*4882a593Smuzhiyun int (*release_ts_feed)(struct dmx_demux *demux, 572*4882a593Smuzhiyun struct dmx_ts_feed *feed); 573*4882a593Smuzhiyun int (*allocate_section_feed)(struct dmx_demux *demux, 574*4882a593Smuzhiyun struct dmx_section_feed **feed, 575*4882a593Smuzhiyun dmx_section_cb callback); 576*4882a593Smuzhiyun int (*release_section_feed)(struct dmx_demux *demux, 577*4882a593Smuzhiyun struct dmx_section_feed *feed); 578*4882a593Smuzhiyun int (*add_frontend)(struct dmx_demux *demux, 579*4882a593Smuzhiyun struct dmx_frontend *frontend); 580*4882a593Smuzhiyun int (*remove_frontend)(struct dmx_demux *demux, 581*4882a593Smuzhiyun struct dmx_frontend *frontend); 582*4882a593Smuzhiyun struct list_head *(*get_frontends)(struct dmx_demux *demux); 583*4882a593Smuzhiyun int (*connect_frontend)(struct dmx_demux *demux, 584*4882a593Smuzhiyun struct dmx_frontend *frontend); 585*4882a593Smuzhiyun int (*disconnect_frontend)(struct dmx_demux *demux); 586*4882a593Smuzhiyun 587*4882a593Smuzhiyun int (*get_pes_pids)(struct dmx_demux *demux, u16 *pids); 588*4882a593Smuzhiyun 589*4882a593Smuzhiyun /* private: */ 590*4882a593Smuzhiyun 591*4882a593Smuzhiyun /* 592*4882a593Smuzhiyun * Only used at av7110, to read some data from firmware. 593*4882a593Smuzhiyun * As this was never documented, we have no clue about what's 594*4882a593Smuzhiyun * there, and its usage on other drivers aren't encouraged. 595*4882a593Smuzhiyun */ 596*4882a593Smuzhiyun int (*get_stc)(struct dmx_demux *demux, unsigned int num, 597*4882a593Smuzhiyun u64 *stc, unsigned int *base); 598*4882a593Smuzhiyun }; 599*4882a593Smuzhiyun 600*4882a593Smuzhiyun #endif /* #ifndef __DEMUX_H */ 601