1 /* SPDX-License-Identifier: LGPL-2.1+ WITH Linux-syscall-note */ 2 /* 3 * dmx.h 4 * 5 * Copyright (C) 2000 Marcus Metzler <marcus@convergence.de> 6 * & Ralph Metzler <ralph@convergence.de> 7 * for convergence integrated media GmbH 8 * 9 * This program is free software; you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public License 11 * as published by the Free Software Foundation; either version 2.1 12 * of the License, or (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22 * 23 */ 24 25 #ifndef _DVBDMX_H_ 26 #define _DVBDMX_H_ 27 28 #include <linux/types.h> 29 #include <time.h> 30 31 32 #define DMX_FILTER_SIZE 16 33 34 /** 35 * enum dmx_output - Output for the demux. 36 * 37 * @DMX_OUT_DECODER: 38 * Streaming directly to decoder. 39 * @DMX_OUT_TAP: 40 * Output going to a memory buffer (to be retrieved via the read command). 41 * Delivers the stream output to the demux device on which the ioctl 42 * is called. 43 * @DMX_OUT_TS_TAP: 44 * Output multiplexed into a new TS (to be retrieved by reading from the 45 * logical DVR device). Routes output to the logical DVR device 46 * ``/dev/dvb/adapter?/dvr?``, which delivers a TS multiplexed from all 47 * filters for which @DMX_OUT_TS_TAP was specified. 48 * @DMX_OUT_TSDEMUX_TAP: 49 * Like @DMX_OUT_TS_TAP but retrieved from the DMX device. 50 */ 51 enum dmx_output { 52 DMX_OUT_DECODER, 53 DMX_OUT_TAP, 54 DMX_OUT_TS_TAP, 55 DMX_OUT_TSDEMUX_TAP 56 }; 57 58 59 /** 60 * enum dmx_input - Input from the demux. 61 * 62 * @DMX_IN_FRONTEND: Input from a front-end device. 63 * @DMX_IN_DVR: Input from the logical DVR device. 64 */ 65 enum dmx_input { 66 DMX_IN_FRONTEND, 67 DMX_IN_DVR 68 }; 69 70 /** 71 * enum dmx_ts_pes - type of the PES filter. 72 * 73 * @DMX_PES_AUDIO0: first audio PID. Also referred as @DMX_PES_AUDIO. 74 * @DMX_PES_VIDEO0: first video PID. Also referred as @DMX_PES_VIDEO. 75 * @DMX_PES_TELETEXT0: first teletext PID. Also referred as @DMX_PES_TELETEXT. 76 * @DMX_PES_SUBTITLE0: first subtitle PID. Also referred as @DMX_PES_SUBTITLE. 77 * @DMX_PES_PCR0: first Program Clock Reference PID. 78 * Also referred as @DMX_PES_PCR. 79 * 80 * @DMX_PES_AUDIO1: second audio PID. 81 * @DMX_PES_VIDEO1: second video PID. 82 * @DMX_PES_TELETEXT1: second teletext PID. 83 * @DMX_PES_SUBTITLE1: second subtitle PID. 84 * @DMX_PES_PCR1: second Program Clock Reference PID. 85 * 86 * @DMX_PES_AUDIO2: third audio PID. 87 * @DMX_PES_VIDEO2: third video PID. 88 * @DMX_PES_TELETEXT2: third teletext PID. 89 * @DMX_PES_SUBTITLE2: third subtitle PID. 90 * @DMX_PES_PCR2: third Program Clock Reference PID. 91 * 92 * @DMX_PES_AUDIO3: fourth audio PID. 93 * @DMX_PES_VIDEO3: fourth video PID. 94 * @DMX_PES_TELETEXT3: fourth teletext PID. 95 * @DMX_PES_SUBTITLE3: fourth subtitle PID. 96 * @DMX_PES_PCR3: fourth Program Clock Reference PID. 97 * 98 * @DMX_PES_OTHER: any other PID. 99 */ 100 101 enum dmx_ts_pes { 102 DMX_PES_AUDIO0, 103 DMX_PES_VIDEO0, 104 DMX_PES_TELETEXT0, 105 DMX_PES_SUBTITLE0, 106 DMX_PES_PCR0, 107 108 DMX_PES_AUDIO1, 109 DMX_PES_VIDEO1, 110 DMX_PES_TELETEXT1, 111 DMX_PES_SUBTITLE1, 112 DMX_PES_PCR1, 113 114 DMX_PES_AUDIO2, 115 DMX_PES_VIDEO2, 116 DMX_PES_TELETEXT2, 117 DMX_PES_SUBTITLE2, 118 DMX_PES_PCR2, 119 120 DMX_PES_AUDIO3, 121 DMX_PES_VIDEO3, 122 DMX_PES_TELETEXT3, 123 DMX_PES_SUBTITLE3, 124 DMX_PES_PCR3, 125 126 DMX_PES_OTHER 127 }; 128 129 #define DMX_PES_AUDIO DMX_PES_AUDIO0 130 #define DMX_PES_VIDEO DMX_PES_VIDEO0 131 #define DMX_PES_TELETEXT DMX_PES_TELETEXT0 132 #define DMX_PES_SUBTITLE DMX_PES_SUBTITLE0 133 #define DMX_PES_PCR DMX_PES_PCR0 134 135 136 137 /** 138 * struct dmx_filter - Specifies a section header filter. 139 * 140 * @filter: bit array with bits to be matched at the section header. 141 * @mask: bits that are valid at the filter bit array. 142 * @mode: mode of match: if bit is zero, it will match if equal (positive 143 * match); if bit is one, it will match if the bit is negated. 144 * 145 * Note: All arrays in this struct have a size of DMX_FILTER_SIZE (16 bytes). 146 */ 147 struct dmx_filter { 148 uint8_t filter[DMX_FILTER_SIZE]; 149 uint8_t mask[DMX_FILTER_SIZE]; 150 uint8_t mode[DMX_FILTER_SIZE]; 151 }; 152 153 /** 154 * struct dmx_sct_filter_params - Specifies a section filter. 155 * 156 * @pid: PID to be filtered. 157 * @filter: section header filter, as defined by &struct dmx_filter. 158 * @timeout: maximum time to filter, in milliseconds. 159 * @flags: extra flags for the section filter. 160 * 161 * Carries the configuration for a MPEG-TS section filter. 162 * 163 * The @flags can be: 164 * 165 * - %DMX_CHECK_CRC - only deliver sections where the CRC check succeeded; 166 * - %DMX_ONESHOT - disable the section filter after one section 167 * has been delivered; 168 * - %DMX_IMMEDIATE_START - Start filter immediately without requiring a 169 * :ref:`DMX_START`. 170 */ 171 struct dmx_sct_filter_params { 172 uint16_t pid; 173 struct dmx_filter filter; 174 uint32_t timeout; 175 uint32_t flags; 176 #define DMX_CHECK_CRC 1 177 #define DMX_ONESHOT 2 178 #define DMX_IMMEDIATE_START 4 179 }; 180 181 /** 182 * struct dmx_pes_filter_params - Specifies Packetized Elementary Stream (PES) 183 * filter parameters. 184 * 185 * @pid: PID to be filtered. 186 * @input: Demux input, as specified by &enum dmx_input. 187 * @output: Demux output, as specified by &enum dmx_output. 188 * @pes_type: Type of the pes filter, as specified by &enum dmx_pes_type. 189 * @flags: Demux PES flags. 190 */ 191 struct dmx_pes_filter_params { 192 uint16_t pid; 193 enum dmx_input input; 194 enum dmx_output output; 195 enum dmx_ts_pes pes_type; 196 uint32_t flags; 197 }; 198 199 /** 200 * struct dmx_stc - Stores System Time Counter (STC) information. 201 * 202 * @num: input data: number of the STC, from 0 to N. 203 * @base: output: divisor for STC to get 90 kHz clock. 204 * @stc: output: stc in @base * 90 kHz units. 205 */ 206 struct dmx_stc { 207 unsigned int num; 208 unsigned int base; 209 uint64_t stc; 210 }; 211 212 /** 213 * enum dmx_buffer_flags - DMX memory-mapped buffer flags 214 * 215 * @DMX_BUFFER_FLAG_HAD_CRC32_DISCARD: 216 * Indicates that the Kernel discarded one or more frames due to wrong 217 * CRC32 checksum. 218 * @DMX_BUFFER_FLAG_TEI: 219 * Indicates that the Kernel has detected a Transport Error indicator 220 * (TEI) on a filtered pid. 221 * @DMX_BUFFER_PKT_COUNTER_MISMATCH: 222 * Indicates that the Kernel has detected a packet counter mismatch 223 * on a filtered pid. 224 * @DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED: 225 * Indicates that the Kernel has detected one or more frame discontinuity. 226 * @DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR: 227 * Received at least one packet with a frame discontinuity indicator. 228 */ 229 230 enum dmx_buffer_flags { 231 DMX_BUFFER_FLAG_HAD_CRC32_DISCARD = 1 << 0, 232 DMX_BUFFER_FLAG_TEI = 1 << 1, 233 DMX_BUFFER_PKT_COUNTER_MISMATCH = 1 << 2, 234 DMX_BUFFER_FLAG_DISCONTINUITY_DETECTED = 1 << 3, 235 DMX_BUFFER_FLAG_DISCONTINUITY_INDICATOR = 1 << 4, 236 }; 237 238 /** 239 * struct dmx_buffer - dmx buffer info 240 * 241 * @index: id number of the buffer 242 * @bytesused: number of bytes occupied by data in the buffer (payload); 243 * @offset: for buffers with memory == DMX_MEMORY_MMAP; 244 * offset from the start of the device memory for this plane, 245 * (or a "cookie" that should be passed to mmap() as offset) 246 * @length: size in bytes of the buffer 247 * @flags: bit array of buffer flags as defined by &enum dmx_buffer_flags. 248 * Filled only at &DMX_DQBUF. 249 * @count: monotonic counter for filled buffers. Helps to identify 250 * data stream loses. Filled only at &DMX_DQBUF. 251 * 252 * Contains data exchanged by application and driver using one of the streaming 253 * I/O methods. 254 * 255 * Please notice that, for &DMX_QBUF, only @index should be filled. 256 * On &DMX_DQBUF calls, all fields will be filled by the Kernel. 257 */ 258 struct dmx_buffer { 259 uint32_t index; 260 uint32_t bytesused; 261 uint32_t offset; 262 uint32_t length; 263 uint32_t flags; 264 uint32_t count; 265 }; 266 267 /** 268 * struct dmx_requestbuffers - request dmx buffer information 269 * 270 * @count: number of requested buffers, 271 * @size: size in bytes of the requested buffer 272 * 273 * Contains data used for requesting a dmx buffer. 274 * All reserved fields must be set to zero. 275 */ 276 struct dmx_requestbuffers { 277 uint32_t count; 278 uint32_t size; 279 }; 280 281 /** 282 * struct dmx_exportbuffer - export of dmx buffer as DMABUF file descriptor 283 * 284 * @index: id number of the buffer 285 * @flags: flags for newly created file, currently only O_CLOEXEC is 286 * supported, refer to manual of open syscall for more details 287 * @fd: file descriptor associated with DMABUF (set by driver) 288 * 289 * Contains data used for exporting a dmx buffer as DMABUF file descriptor. 290 * The buffer is identified by a 'cookie' returned by DMX_QUERYBUF 291 * (identical to the cookie used to mmap() the buffer to userspace). All 292 * reserved fields must be set to zero. The field reserved0 is expected to 293 * become a structure 'type' allowing an alternative layout of the structure 294 * content. Therefore this field should not be used for any other extensions. 295 */ 296 struct dmx_exportbuffer { 297 uint32_t index; 298 uint32_t flags; 299 int32_t fd; 300 }; 301 302 #define DMX_START _IO('o', 41) 303 #define DMX_STOP _IO('o', 42) 304 #define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params) 305 #define DMX_SET_PES_FILTER _IOW('o', 44, struct dmx_pes_filter_params) 306 #define DMX_SET_BUFFER_SIZE _IO('o', 45) 307 #define DMX_GET_PES_PIDS _IOR('o', 47, uint16_t[5]) 308 #define DMX_GET_STC _IOWR('o', 50, struct dmx_stc) 309 #define DMX_ADD_PID _IOW('o', 51, uint16_t) 310 #define DMX_REMOVE_PID _IOW('o', 52, uint16_t) 311 312 313 /* This is needed for legacy userspace support */ 314 typedef enum dmx_output dmx_output_t; 315 typedef enum dmx_input dmx_input_t; 316 typedef enum dmx_ts_pes dmx_pes_type_t; 317 typedef struct dmx_filter dmx_filter_t; 318 319 320 #define DMX_REQBUFS _IOWR('o', 60, struct dmx_requestbuffers) 321 #define DMX_QUERYBUF _IOWR('o', 61, struct dmx_buffer) 322 #define DMX_EXPBUF _IOWR('o', 62, struct dmx_exportbuffer) 323 #define DMX_QBUF _IOWR('o', 63, struct dmx_buffer) 324 #define DMX_DQBUF _IOWR('o', 64, struct dmx_buffer) 325 326 #endif /* _DVBDMX_H_ */ 327