blob: 257e0697bacae118282dcc1be0cc4fb46ef34853 [file] [log] [blame]
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -08001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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 Kadmany32cb9822012-05-10 08:47:44 +03008 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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 Rajputc86629c2009-01-30 19:55:32 +053029#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#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 Kadmany4f877942012-07-15 15:06:01 +030039/* Min recording chunk upon which event is generated */
40#define DMX_REC_BUFF_CHUNK_MIN_SIZE (100*188)
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042typedef enum
43{
44 DMX_OUT_DECODER, /* Streaming directly to decoder. */
45 DMX_OUT_TAP, /* Output going to a memory buffer */
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -080046 /* (to be retrieved via the read command).*/
Peter Hartleyb01cd932008-04-22 14:45:36 -030047 DMX_OUT_TS_TAP, /* Output multiplexed into a new TS */
Mauro Carvalho Chehab674434c2005-12-12 00:37:28 -080048 /* (to be retrieved by reading from the */
49 /* logical DVR device). */
Peter Hartleyb01cd932008-04-22 14:45:36 -030050 DMX_OUT_TSDEMUX_TAP /* Like TS_TAP but retrieved from the DMX device */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051} dmx_output_t;
52
53
54typedef 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
61typedef enum
62{
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080063 DMX_PES_AUDIO0,
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 DMX_PES_VIDEO0,
65 DMX_PES_TELETEXT0,
66 DMX_PES_SUBTITLE0,
67 DMX_PES_PCR0,
68
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080069 DMX_PES_AUDIO1,
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 DMX_PES_VIDEO1,
71 DMX_PES_TELETEXT1,
72 DMX_PES_SUBTITLE1,
73 DMX_PES_PCR1,
74
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080075 DMX_PES_AUDIO2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 DMX_PES_VIDEO2,
77 DMX_PES_TELETEXT2,
78 DMX_PES_SUBTITLE2,
79 DMX_PES_PCR2,
80
Mauro Carvalho Chehabafd1a0c2005-12-12 00:37:27 -080081 DMX_PES_AUDIO3,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 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 Torvalds1da177e2005-04-16 15:20:36 -070097typedef 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 Kuchd4cc3b02012-05-17 16:31:58 +0300105/* 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 Torvalds1da177e2005-04-16 15:20:36 -0700112struct dmx_sct_filter_params
113{
114 __u16 pid;
115 dmx_filter_t filter;
116 __u32 timeout;
117 __u32 flags;
Liron Kuchd4cc3b02012-05-17 16:31:58 +0300118};
119
120
121/* Indexing: supported video standards */
122enum dmx_indexing_video_standard {
123 DMX_INDEXING_MPEG2,
124 DMX_INDEXING_H264,
125 DMX_INDEXING_VC1
126};
127
128/* Indexing: Supported video profiles */
129enum 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 */
136struct dmx_indexing_video_params {
137 enum dmx_indexing_video_standard standard;
138 enum dmx_indexing_video_profile profile;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139};
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141struct 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 Kuchd4cc3b02012-05-17 16:31:58 +0300148
Hamad Kadmany4f877942012-07-15 15:06:01 +0300149 /*
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 Kuchd4cc3b02012-05-17 16:31:58 +0300161 struct dmx_indexing_video_params video_params;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162};
163
Hamad Kadmany32cb9822012-05-10 08:47:44 +0300164struct 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 Kadmany4f877942012-07-15 15:06:01 +0300187/* Events associated with each demux filter */
188enum 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 */
224struct 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 */
250struct 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 */
273struct 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 */
282struct 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 */
299struct 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
Hamad Kadmanyec6202d2012-09-20 07:58:57 +0300310/* Filter's buffer requirement returned in dmx_caps */
311struct dmx_buffer_requirement {
312 /* Buffer size alignment, 0 means no special requirement */
313 __u32 size_alignment;
314
315 /* Maximum buffer size allowed */
316 __u32 max_size;
317 __u32 flags;
318
319/* Buffer allocated as physically contiguous memory */
320#define DMX_BUFFER_CONTIGEOUS_MEM 0x1
321
322/* If the filter's data is decrypted, the buffer should be secured one */
323#define DMX_BUFFER_SECURED_IF_DECRYPTED 0x2
324};
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326typedef struct dmx_caps {
327 __u32 caps;
Hamad Kadmanyd2c325e2012-05-28 13:52:49 +0300328
329/* Indicates whether demux support playback from memory in pull mode */
330#define DMX_CAP_PULL_MODE 0x01
331
332/* Indicates whether demux support indexing of recorded video stream */
333#define DMX_CAP_VIDEO_INDEXING 0x02
334
335/* Indicates whether demux support sending data directly to video decoder */
336#define DMX_CAP_VIDEO_DECODER_DATA 0x04
337
338/* Indicates whether demux support sending data directly to audio decoder */
339#define DMX_CAP_AUDIO_DECODER_DATA 0x08
340
341/* Indicates whether demux support sending data directly to subtitle decoder */
342#define DMX_CAP_SUBTITLE_DECODER_DATA 0x10
343
344 /* Number of decoders demux can output data to */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 int num_decoders;
Hamad Kadmanyd2c325e2012-05-28 13:52:49 +0300346
347 /* Number of demux devices */
348 int num_demux_devices;
349
350 /* Max number of PID filters */
351 int num_pid_filters;
352
353 /* Max number of section filters */
354 int num_section_filters;
355
356 /*
357 * Max number of section filters using same PID,
358 * 0 if not supported
359 */
360 int num_section_filters_per_pid;
361
362 /*
363 * Length of section filter, not including section
364 * length field (2 bytes).
365 */
366 int section_filter_length;
367
368 /* Max number of demod based input */
369 int num_demod_inputs;
370
371 /* Max number of memory based input */
372 int num_memory_inputs;
373
374 /* Overall bitrate from all inputs concurrently. Mbit/sec */
375 int max_bitrate;
376
377 /* Max bitrate from single demod input. Mbit/sec */
378 int demod_input_max_bitrate;
379
380 /* Max bitrate from single memory input. Mbit/sec */
381 int memory_input_max_bitrate;
Hamad Kadmanyec6202d2012-09-20 07:58:57 +0300382
383 struct dmx_buffer_requirement section;
384
385 /* For PES not sent to decoder */
386 struct dmx_buffer_requirement pes;
387
388 /* Recording buffer for recording of 188 bytes packets */
389 struct dmx_buffer_requirement recording_188_tsp;
390
391 /* Recording buffer for recording of 192 bytes packets */
392 struct dmx_buffer_requirement recording_192_tsp;
393
394 /* DVR input buffer for playback of 188 bytes packets */
395 struct dmx_buffer_requirement playback_188_tsp;
396
397 /* DVR input buffer for playback of 192 bytes packets */
398 struct dmx_buffer_requirement playback_192_tsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399} dmx_caps_t;
400
401typedef enum {
402 DMX_SOURCE_FRONT0 = 0,
403 DMX_SOURCE_FRONT1,
404 DMX_SOURCE_FRONT2,
405 DMX_SOURCE_FRONT3,
406 DMX_SOURCE_DVR0 = 16,
407 DMX_SOURCE_DVR1,
408 DMX_SOURCE_DVR2,
409 DMX_SOURCE_DVR3
410} dmx_source_t;
411
Hamad Kadmany32cb9822012-05-10 08:47:44 +0300412enum dmx_tsp_format_t {
413 DMX_TSP_FORMAT_188 = 0,
414 DMX_TSP_FORMAT_192_TAIL,
415 DMX_TSP_FORMAT_192_HEAD,
416 DMX_TSP_FORMAT_204,
417};
418
419enum dmx_playback_mode_t {
420 /*
421 * In push mode, if one of output buffers
422 * is full, the buffer would overflow
423 * and demux continue processing incoming stream.
424 * This is the default mode. When playing from frontend,
425 * this is the only mode that is allowed.
426 */
427 DMX_PB_MODE_PUSH = 0,
428
429 /*
430 * In pull mode, if one of output buffers
431 * is full, demux stalls waiting for free space,
432 * this would cause DVR input buffer fullness
433 * to accumulate.
434 * This mode is possible only when playing
435 * from DVR.
436 */
437 DMX_PB_MODE_PULL,
438};
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440struct dmx_stc {
441 unsigned int num; /* input : which STC? 0..N */
442 unsigned int base; /* output: divisor for stc to get 90 kHz clock */
443 __u64 stc; /* output: stc in 'base'*90 kHz units */
444};
445
Hamad Kadmanyec6202d2012-09-20 07:58:57 +0300446enum dmx_buffer_mode {
447 /*
448 * demux buffers are allocated internally
449 * by the demux driver. This is the default mode.
450 * DMX_SET_BUFFER_SIZE can be used to set the size of
451 * this buffer.
452 */
453 DMX_BUFFER_MODE_INTERNAL,
454
455 /*
456 * demux buffers are allocated externally and provided
457 * to demux through DMX_SET_BUFFER.
458 * When this mode is used DMX_SET_BUFFER_SIZE and
459 * mmap are prohibited.
460 */
461 DMX_BUFFER_MODE_EXTERNAL,
462};
463
464struct dmx_buffer {
465 unsigned int size;
466 int handle;
467};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469#define DMX_START _IO('o', 41)
470#define DMX_STOP _IO('o', 42)
471#define DMX_SET_FILTER _IOW('o', 43, struct dmx_sct_filter_params)
472#define DMX_SET_PES_FILTER _IOW('o', 44, struct dmx_pes_filter_params)
473#define DMX_SET_BUFFER_SIZE _IO('o', 45)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474#define DMX_GET_PES_PIDS _IOR('o', 47, __u16[5])
475#define DMX_GET_CAPS _IOR('o', 48, dmx_caps_t)
476#define DMX_SET_SOURCE _IOW('o', 49, dmx_source_t)
477#define DMX_GET_STC _IOWR('o', 50, struct dmx_stc)
Andreas Oberritter1cb662a2009-07-14 20:28:50 -0300478#define DMX_ADD_PID _IOW('o', 51, __u16)
479#define DMX_REMOVE_PID _IOW('o', 52, __u16)
Hamad Kadmany32cb9822012-05-10 08:47:44 +0300480#define DMX_SET_TS_PACKET_FORMAT _IOW('o', 53, enum dmx_tsp_format_t)
481#define DMX_SET_TS_OUT_FORMAT _IOW('o', 54, enum dmx_tsp_format_t)
482#define DMX_SET_DECODER_BUFFER_SIZE _IO('o', 55)
483#define DMX_GET_BUFFER_STATUS _IOR('o', 56, struct dmx_buffer_status)
484#define DMX_RELEASE_DATA _IO('o', 57)
485#define DMX_FEED_DATA _IO('o', 58)
486#define DMX_SET_PLAYBACK_MODE _IOW('o', 59, enum dmx_playback_mode_t)
Hamad Kadmany4f877942012-07-15 15:06:01 +0300487#define DMX_GET_EVENT _IOR('o', 60, struct dmx_filter_event)
Hamad Kadmanyec6202d2012-09-20 07:58:57 +0300488#define DMX_SET_BUFFER_MODE _IOW('o', 61, enum dmx_buffer_mode)
489#define DMX_SET_BUFFER _IOW('o', 62, struct dmx_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491#endif /*_DVBDMX_H_*/