Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * dmx.h |
| 3 | * |
| 4 | * Copyright (C) 2000 Marcus Metzler <marcus@convergence.de> |
| 5 | * & Ralph Metzler <ralph@convergence.de> |
| 6 | * for convergence integrated media GmbH |
| 7 | * |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 8 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 9 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public License |
| 12 | * as published by the Free Software Foundation; either version 2.1 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | #ifndef _DVBDMX_H_ |
| 27 | #define _DVBDMX_H_ |
| 28 | |
Jaswinder Singh Rajput | c86629c | 2009-01-30 19:55:32 +0530 | [diff] [blame] | 29 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #ifdef __KERNEL__ |
| 31 | #include <linux/time.h> |
| 32 | #else |
| 33 | #include <time.h> |
| 34 | #endif |
| 35 | |
| 36 | |
| 37 | #define DMX_FILTER_SIZE 16 |
| 38 | |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame^] | 39 | /* Min recording chunk upon which event is generated */ |
| 40 | #define DMX_REC_BUFF_CHUNK_MIN_SIZE (100*188) |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | typedef enum |
| 43 | { |
| 44 | DMX_OUT_DECODER, /* Streaming directly to decoder. */ |
| 45 | DMX_OUT_TAP, /* Output going to a memory buffer */ |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 46 | /* (to be retrieved via the read command).*/ |
Peter Hartley | b01cd93 | 2008-04-22 14:45:36 -0300 | [diff] [blame] | 47 | DMX_OUT_TS_TAP, /* Output multiplexed into a new TS */ |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 48 | /* (to be retrieved by reading from the */ |
| 49 | /* logical DVR device). */ |
Peter Hartley | b01cd93 | 2008-04-22 14:45:36 -0300 | [diff] [blame] | 50 | DMX_OUT_TSDEMUX_TAP /* Like TS_TAP but retrieved from the DMX device */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } dmx_output_t; |
| 52 | |
| 53 | |
| 54 | typedef enum |
| 55 | { |
| 56 | DMX_IN_FRONTEND, /* Input from a front-end device. */ |
| 57 | DMX_IN_DVR /* Input from the logical DVR device. */ |
| 58 | } dmx_input_t; |
| 59 | |
| 60 | |
| 61 | typedef enum |
| 62 | { |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 63 | DMX_PES_AUDIO0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | DMX_PES_VIDEO0, |
| 65 | DMX_PES_TELETEXT0, |
| 66 | DMX_PES_SUBTITLE0, |
| 67 | DMX_PES_PCR0, |
| 68 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 69 | DMX_PES_AUDIO1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | DMX_PES_VIDEO1, |
| 71 | DMX_PES_TELETEXT1, |
| 72 | DMX_PES_SUBTITLE1, |
| 73 | DMX_PES_PCR1, |
| 74 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 75 | DMX_PES_AUDIO2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | DMX_PES_VIDEO2, |
| 77 | DMX_PES_TELETEXT2, |
| 78 | DMX_PES_SUBTITLE2, |
| 79 | DMX_PES_PCR2, |
| 80 | |
Mauro Carvalho Chehab | afd1a0c | 2005-12-12 00:37:27 -0800 | [diff] [blame] | 81 | DMX_PES_AUDIO3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | DMX_PES_VIDEO3, |
| 83 | DMX_PES_TELETEXT3, |
| 84 | DMX_PES_SUBTITLE3, |
| 85 | DMX_PES_PCR3, |
| 86 | |
| 87 | DMX_PES_OTHER |
| 88 | } dmx_pes_type_t; |
| 89 | |
| 90 | #define DMX_PES_AUDIO DMX_PES_AUDIO0 |
| 91 | #define DMX_PES_VIDEO DMX_PES_VIDEO0 |
| 92 | #define DMX_PES_TELETEXT DMX_PES_TELETEXT0 |
| 93 | #define DMX_PES_SUBTITLE DMX_PES_SUBTITLE0 |
| 94 | #define DMX_PES_PCR DMX_PES_PCR0 |
| 95 | |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | typedef struct dmx_filter |
| 98 | { |
| 99 | __u8 filter[DMX_FILTER_SIZE]; |
| 100 | __u8 mask[DMX_FILTER_SIZE]; |
| 101 | __u8 mode[DMX_FILTER_SIZE]; |
| 102 | } dmx_filter_t; |
| 103 | |
| 104 | |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 105 | /* Filter flags */ |
| 106 | #define DMX_CHECK_CRC 0x01 |
| 107 | #define DMX_ONESHOT 0x02 |
| 108 | #define DMX_IMMEDIATE_START 0x04 |
| 109 | #define DMX_ENABLE_INDEXING 0x08 |
| 110 | #define DMX_KERNEL_CLIENT 0x8000 |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct dmx_sct_filter_params |
| 113 | { |
| 114 | __u16 pid; |
| 115 | dmx_filter_t filter; |
| 116 | __u32 timeout; |
| 117 | __u32 flags; |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | |
| 121 | /* Indexing: supported video standards */ |
| 122 | enum dmx_indexing_video_standard { |
| 123 | DMX_INDEXING_MPEG2, |
| 124 | DMX_INDEXING_H264, |
| 125 | DMX_INDEXING_VC1 |
| 126 | }; |
| 127 | |
| 128 | /* Indexing: Supported video profiles */ |
| 129 | enum dmx_indexing_video_profile { |
| 130 | DMX_INDEXING_MPEG2_ANY, |
| 131 | DMX_INDEXING_H264_ANY, |
| 132 | DMX_INDEXING_VC1_ANY |
| 133 | }; |
| 134 | |
| 135 | /* Indexing: video configuration parameters */ |
| 136 | struct dmx_indexing_video_params { |
| 137 | enum dmx_indexing_video_standard standard; |
| 138 | enum dmx_indexing_video_profile profile; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | struct dmx_pes_filter_params |
| 142 | { |
| 143 | __u16 pid; |
| 144 | dmx_input_t input; |
| 145 | dmx_output_t output; |
| 146 | dmx_pes_type_t pes_type; |
| 147 | __u32 flags; |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 148 | |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame^] | 149 | /* |
| 150 | * The following configures when the event |
| 151 | * DMX_EVENT_NEW_REC_CHUNK will be triggered. |
| 152 | * When new recorded data is received with size |
| 153 | * equal or larger than this value a new event |
| 154 | * will be triggered. This is relevent when |
| 155 | * output is DMX_OUT_TS_TAP or DMX_OUT_TSDEMUX_TAP, |
| 156 | * size must be at least DMX_REC_BUFF_CHUNK_MIN_SIZE |
| 157 | * and smaller than buffer size. |
| 158 | */ |
| 159 | __u32 rec_chunk_size; |
| 160 | |
Liron Kuch | d4cc3b0 | 2012-05-17 16:31:58 +0300 | [diff] [blame] | 161 | struct dmx_indexing_video_params video_params; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 164 | struct dmx_buffer_status { |
| 165 | /* size of buffer in bytes */ |
| 166 | unsigned int size; |
| 167 | |
| 168 | /* fullness of buffer in bytes */ |
| 169 | unsigned int fullness; |
| 170 | |
| 171 | /* |
| 172 | * How many bytes are free |
| 173 | * It's the same as: size-fullness-1 |
| 174 | */ |
| 175 | unsigned int free_bytes; |
| 176 | |
| 177 | /* read pointer offset in bytes */ |
| 178 | unsigned int read_offset; |
| 179 | |
| 180 | /* write pointer offset in bytes */ |
| 181 | unsigned int write_offset; |
| 182 | |
| 183 | /* non-zero if data error occured */ |
| 184 | int error; |
| 185 | }; |
| 186 | |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame^] | 187 | /* Events associated with each demux filter */ |
| 188 | enum dmx_event { |
| 189 | /* New PES packet is ready to be consumed */ |
| 190 | DMX_EVENT_NEW_PES, |
| 191 | |
| 192 | /* New section is ready to be consumed */ |
| 193 | DMX_EVENT_NEW_SECTION, |
| 194 | |
| 195 | /* New recording chunk is ready to be consumed */ |
| 196 | DMX_EVENT_NEW_REC_CHUNK, |
| 197 | |
| 198 | /* New PCR value is ready */ |
| 199 | DMX_EVENT_NEW_PCR, |
| 200 | |
| 201 | /* Overflow */ |
| 202 | DMX_EVENT_BUFFER_OVERFLOW, |
| 203 | |
| 204 | /* Section was dropped due to CRC error */ |
| 205 | DMX_EVENT_SECTION_CRC_ERROR, |
| 206 | |
| 207 | /* End-of-stream, no more data from this filter */ |
| 208 | DMX_EVENT_EOS |
| 209 | }; |
| 210 | |
| 211 | /* Flags passed in filter events */ |
| 212 | |
| 213 | /* Continuity counter error was detected */ |
| 214 | #define DMX_FILTER_CC_ERROR 0x01 |
| 215 | |
| 216 | /* Discontinuity indicator was set */ |
| 217 | #define DMX_FILTER_DISCONTINUITY_INDEICATOR 0x02 |
| 218 | |
| 219 | /* PES legnth in PES header is not correct */ |
| 220 | #define DMX_FILTER_PES_LENGTH_ERROR 0x04 |
| 221 | |
| 222 | |
| 223 | /* PES info associated with DMX_EVENT_NEW_PES event */ |
| 224 | struct dmx_pes_event_info { |
| 225 | /* Offset at which PES information starts */ |
| 226 | __u32 base_offset; |
| 227 | |
| 228 | /* |
| 229 | * Start offset at which PES data |
| 230 | * from the stream starts. |
| 231 | * Equal to base_offset if PES data |
| 232 | * starts from the beginning. |
| 233 | */ |
| 234 | __u32 start_offset; |
| 235 | |
| 236 | /* Total length holding the PES information */ |
| 237 | __u32 total_length; |
| 238 | |
| 239 | /* Actual length holding the PES data */ |
| 240 | __u32 actual_length; |
| 241 | |
| 242 | /* Local receiver timestamp in 27MHz */ |
| 243 | __u64 stc; |
| 244 | |
| 245 | /* Flags passed in filter events */ |
| 246 | __u32 flags; |
| 247 | }; |
| 248 | |
| 249 | /* Section info associated with DMX_EVENT_NEW_SECTION event */ |
| 250 | struct dmx_section_event_info { |
| 251 | /* Offset at which section information starts */ |
| 252 | __u32 base_offset; |
| 253 | |
| 254 | /* |
| 255 | * Start offset at which section data |
| 256 | * from the stream starts. |
| 257 | * Equal to base_offset if section data |
| 258 | * starts from the beginning. |
| 259 | */ |
| 260 | __u32 start_offset; |
| 261 | |
| 262 | /* Total length holding the section information */ |
| 263 | __u32 total_length; |
| 264 | |
| 265 | /* Actual length holding the section data */ |
| 266 | __u32 actual_length; |
| 267 | |
| 268 | /* Flags passed in filter events */ |
| 269 | __u32 flags; |
| 270 | }; |
| 271 | |
| 272 | /* Recording info associated with DMX_EVENT_NEW_REC_CHUNK event */ |
| 273 | struct dmx_rec_chunk_event_info { |
| 274 | /* Offset at which recording chunk starts */ |
| 275 | __u32 offset; |
| 276 | |
| 277 | /* Size of recording chunk in bytes */ |
| 278 | __u32 size; |
| 279 | }; |
| 280 | |
| 281 | /* PCR info associated with DMX_EVENT_NEW_PCR event */ |
| 282 | struct dmx_pcr_event_info { |
| 283 | /* Local timestamp in 27MHz |
| 284 | * when PCR packet was received |
| 285 | */ |
| 286 | __u64 stc; |
| 287 | |
| 288 | /* PCR value in 27MHz */ |
| 289 | __u64 pcr; |
| 290 | |
| 291 | /* Flags passed in filter events */ |
| 292 | __u32 flags; |
| 293 | }; |
| 294 | |
| 295 | /* |
| 296 | * Filter's event returned through DMX_GET_EVENT. |
| 297 | * poll with POLLPRI would block until events are available. |
| 298 | */ |
| 299 | struct dmx_filter_event { |
| 300 | enum dmx_event type; |
| 301 | |
| 302 | union { |
| 303 | struct dmx_pes_event_info pes; |
| 304 | struct dmx_section_event_info section; |
| 305 | struct dmx_rec_chunk_event_info recording_chunk; |
| 306 | struct dmx_pcr_event_info pcr; |
| 307 | } params; |
| 308 | }; |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | typedef struct dmx_caps { |
| 311 | __u32 caps; |
Hamad Kadmany | d2c325e | 2012-05-28 13:52:49 +0300 | [diff] [blame] | 312 | |
| 313 | /* Indicates whether demux support playback from memory in pull mode */ |
| 314 | #define DMX_CAP_PULL_MODE 0x01 |
| 315 | |
| 316 | /* Indicates whether demux support indexing of recorded video stream */ |
| 317 | #define DMX_CAP_VIDEO_INDEXING 0x02 |
| 318 | |
| 319 | /* Indicates whether demux support sending data directly to video decoder */ |
| 320 | #define DMX_CAP_VIDEO_DECODER_DATA 0x04 |
| 321 | |
| 322 | /* Indicates whether demux support sending data directly to audio decoder */ |
| 323 | #define DMX_CAP_AUDIO_DECODER_DATA 0x08 |
| 324 | |
| 325 | /* Indicates whether demux support sending data directly to subtitle decoder */ |
| 326 | #define DMX_CAP_SUBTITLE_DECODER_DATA 0x10 |
| 327 | |
| 328 | /* Number of decoders demux can output data to */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | int num_decoders; |
Hamad Kadmany | d2c325e | 2012-05-28 13:52:49 +0300 | [diff] [blame] | 330 | |
| 331 | /* Number of demux devices */ |
| 332 | int num_demux_devices; |
| 333 | |
| 334 | /* Max number of PID filters */ |
| 335 | int num_pid_filters; |
| 336 | |
| 337 | /* Max number of section filters */ |
| 338 | int num_section_filters; |
| 339 | |
| 340 | /* |
| 341 | * Max number of section filters using same PID, |
| 342 | * 0 if not supported |
| 343 | */ |
| 344 | int num_section_filters_per_pid; |
| 345 | |
| 346 | /* |
| 347 | * Length of section filter, not including section |
| 348 | * length field (2 bytes). |
| 349 | */ |
| 350 | int section_filter_length; |
| 351 | |
| 352 | /* Max number of demod based input */ |
| 353 | int num_demod_inputs; |
| 354 | |
| 355 | /* Max number of memory based input */ |
| 356 | int num_memory_inputs; |
| 357 | |
| 358 | /* Overall bitrate from all inputs concurrently. Mbit/sec */ |
| 359 | int max_bitrate; |
| 360 | |
| 361 | /* Max bitrate from single demod input. Mbit/sec */ |
| 362 | int demod_input_max_bitrate; |
| 363 | |
| 364 | /* Max bitrate from single memory input. Mbit/sec */ |
| 365 | int memory_input_max_bitrate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } dmx_caps_t; |
| 367 | |
| 368 | typedef enum { |
| 369 | DMX_SOURCE_FRONT0 = 0, |
| 370 | DMX_SOURCE_FRONT1, |
| 371 | DMX_SOURCE_FRONT2, |
| 372 | DMX_SOURCE_FRONT3, |
| 373 | DMX_SOURCE_DVR0 = 16, |
| 374 | DMX_SOURCE_DVR1, |
| 375 | DMX_SOURCE_DVR2, |
| 376 | DMX_SOURCE_DVR3 |
| 377 | } dmx_source_t; |
| 378 | |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 379 | enum dmx_tsp_format_t { |
| 380 | DMX_TSP_FORMAT_188 = 0, |
| 381 | DMX_TSP_FORMAT_192_TAIL, |
| 382 | DMX_TSP_FORMAT_192_HEAD, |
| 383 | DMX_TSP_FORMAT_204, |
| 384 | }; |
| 385 | |
| 386 | enum dmx_playback_mode_t { |
| 387 | /* |
| 388 | * In push mode, if one of output buffers |
| 389 | * is full, the buffer would overflow |
| 390 | * and demux continue processing incoming stream. |
| 391 | * This is the default mode. When playing from frontend, |
| 392 | * this is the only mode that is allowed. |
| 393 | */ |
| 394 | DMX_PB_MODE_PUSH = 0, |
| 395 | |
| 396 | /* |
| 397 | * In pull mode, if one of output buffers |
| 398 | * is full, demux stalls waiting for free space, |
| 399 | * this would cause DVR input buffer fullness |
| 400 | * to accumulate. |
| 401 | * This mode is possible only when playing |
| 402 | * from DVR. |
| 403 | */ |
| 404 | DMX_PB_MODE_PULL, |
| 405 | }; |
| 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | struct dmx_stc { |
| 408 | unsigned int num; /* input : which STC? 0..N */ |
| 409 | unsigned int base; /* output: divisor for stc to get 90 kHz clock */ |
| 410 | __u64 stc; /* output: stc in 'base'*90 kHz units */ |
| 411 | }; |
| 412 | |
| 413 | |
| 414 | #define DMX_START _IO('o', 41) |
| 415 | #define DMX_STOP _IO('o', 42) |
| 416 | #define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params) |
| 417 | #define DMX_SET_PES_FILTER _IOW('o', 44, struct dmx_pes_filter_params) |
| 418 | #define DMX_SET_BUFFER_SIZE _IO('o', 45) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | #define DMX_GET_PES_PIDS _IOR('o', 47, __u16[5]) |
| 420 | #define DMX_GET_CAPS _IOR('o', 48, dmx_caps_t) |
| 421 | #define DMX_SET_SOURCE _IOW('o', 49, dmx_source_t) |
| 422 | #define DMX_GET_STC _IOWR('o', 50, struct dmx_stc) |
Andreas Oberritter | 1cb662a | 2009-07-14 20:28:50 -0300 | [diff] [blame] | 423 | #define DMX_ADD_PID _IOW('o', 51, __u16) |
| 424 | #define DMX_REMOVE_PID _IOW('o', 52, __u16) |
Hamad Kadmany | 32cb982 | 2012-05-10 08:47:44 +0300 | [diff] [blame] | 425 | #define DMX_SET_TS_PACKET_FORMAT _IOW('o', 53, enum dmx_tsp_format_t) |
| 426 | #define DMX_SET_TS_OUT_FORMAT _IOW('o', 54, enum dmx_tsp_format_t) |
| 427 | #define DMX_SET_DECODER_BUFFER_SIZE _IO('o', 55) |
| 428 | #define DMX_GET_BUFFER_STATUS _IOR('o', 56, struct dmx_buffer_status) |
| 429 | #define DMX_RELEASE_DATA _IO('o', 57) |
| 430 | #define DMX_FEED_DATA _IO('o', 58) |
| 431 | #define DMX_SET_PLAYBACK_MODE _IOW('o', 59, enum dmx_playback_mode_t) |
Hamad Kadmany | 4f87794 | 2012-07-15 15:06:01 +0300 | [diff] [blame^] | 432 | #define DMX_GET_EVENT _IOR('o', 60, struct dmx_filter_event) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | #endif /*_DVBDMX_H_*/ |