1 <title>DVB Demux Device
</title>
3 <para>The DVB demux device controls the filters of the DVB hardware/software. It can be
4 accessed through
<emphasis role=
"tt">/dev/adapter0/demux0
</emphasis>. Data types and and ioctl definitions can be
5 accessed by including
<emphasis role=
"tt">linux/dvb/dmx.h
</emphasis> in your application.
7 <section id=
"dmx_types">
8 <title>Demux Data Types
</title>
10 <section id=
"dmx-output-t">
11 <title>dmx_output_t
</title>
15 DMX_OUT_DECODER, /
⋆ Streaming directly to decoder.
⋆/
16 DMX_OUT_TAP, /
⋆ Output going to a memory buffer
⋆/
17 /
⋆ (to be retrieved via the read command).
⋆/
18 DMX_OUT_TS_TAP, /
⋆ Output multiplexed into a new TS
⋆/
19 /
⋆ (to be retrieved by reading from the
⋆/
20 /
⋆ logical DVR device).
⋆/
21 DMX_OUT_TSDEMUX_TAP /
⋆ Like TS_TAP but retrieved from the DMX device
⋆/
24 <para><emphasis role=
"tt">DMX_OUT_TAP
</emphasis> delivers the stream output to the demux device on which the ioctl is
27 <para><emphasis role=
"tt">DMX_OUT_TS_TAP
</emphasis> routes output to the logical DVR device
<emphasis role=
"tt">/dev/dvb/adapter0/dvr0
</emphasis>,
28 which delivers a TS multiplexed from all filters for which
<emphasis role=
"tt">DMX_OUT_TS_TAP
</emphasis> was
33 <section id=
"dmx-input-t">
34 <title>dmx_input_t
</title>
38 DMX_IN_FRONTEND, /
⋆ Input from a front-end device.
⋆/
39 DMX_IN_DVR /
⋆ Input from the logical DVR device.
⋆/
44 <section id=
"dmx-pes-type-t">
45 <title>dmx_pes_type_t
</title>
78 <section id=
"dmx-filter">
79 <title>struct dmx_filter
</title>
81 typedef struct dmx_filter
83 __u8 filter[DMX_FILTER_SIZE];
84 __u8 mask[DMX_FILTER_SIZE];
85 __u8 mode[DMX_FILTER_SIZE];
90 <section id=
"dmx-sct-filter-params">
91 <title>struct dmx_sct_filter_params
</title>
93 struct dmx_sct_filter_params
99 #define DMX_CHECK_CRC
1
100 #define DMX_ONESHOT
2
101 #define DMX_IMMEDIATE_START
4
102 #define DMX_KERNEL_CLIENT
0x8000
107 <section id=
"dmx-pes-filter-params">
108 <title>struct dmx_pes_filter_params
</title>
110 struct dmx_pes_filter_params
115 dmx_pes_type_t pes_type;
121 <section id=
"dmx-event">
122 <title>struct dmx_event
</title>
130 dmx_scrambling_status_t scrambling;
136 <section id=
"dmx-stc">
137 <title>struct dmx_stc
</title>
140 unsigned int num; /
⋆ input : which STC?
0..N
⋆/
141 unsigned int base; /
⋆ output: divisor for stc to get
90 kHz clock
⋆/
142 __u64 stc; /
⋆ output: stc in 'base'
⋆90 kHz units
⋆/
149 <section id=
"dmx_fcalls">
150 <title>Demux Function Calls
</title>
152 <section id=
"dmx_fopen">
153 <title>open()
</title>
156 <informaltable><tgroup cols=
"1"><tbody><row><entry
158 <para>This system call, used with a device name of /dev/dvb/adapter0/demux0,
159 allocates a new filter and returns a handle which can be used for subsequent
160 control of that filter. This call has to be made for each filter to be used, i.e. every
161 returned file descriptor is a reference to a single filter. /dev/dvb/adapter0/dvr0
162 is a logical device to be used for retrieving Transport Streams for digital
163 video recording. When reading from this device a transport stream containing
164 the packets from all PES filters set in the corresponding demux device
165 (/dev/dvb/adapter0/demux0) having the output set to DMX_OUT_TS_TAP. A
166 recorded Transport Stream is replayed by writing to this device.
</para>
167 <para>The significance of blocking or non-blocking mode is described in the
168 documentation for functions where there is a difference. It does not affect the
169 semantics of the open() call itself. A device opened in blocking mode can later
170 be put into non-blocking mode (and vice versa) using the F_SETFL command
171 of the fcntl system call.
</para>
173 </row></tbody></tgroup></informaltable>
176 <informaltable><tgroup cols=
"1"><tbody><row><entry
178 <para>int open(const char
⋆deviceName, int flags);
</para>
180 </row></tbody></tgroup></informaltable>
183 <informaltable><tgroup cols=
"2"><tbody><row><entry
189 <para>Name of demux device.
</para>
193 <para>int flags
</para>
196 <para>A bit-wise OR of the following flags:
</para>
202 <para>O_RDWR read/write access
</para>
208 <para>O_NONBLOCK open in non-blocking mode
</para>
214 <para>(blocking mode is the default)
</para>
216 </row></tbody></tgroup></informaltable>
219 <informaltable><tgroup cols=
"2"><tbody><row><entry
224 <para>Device driver not loaded/available.
</para>
231 <para>Invalid argument.
</para>
238 <para>“Too many open files
”, i.e. no more filters available.
</para>
245 <para>The driver failed to allocate enough memory.
</para>
247 </row></tbody></tgroup></informaltable>
250 <section id=
"dmx_fclose">
251 <title>close()
</title>
254 <informaltable><tgroup cols=
"1"><tbody><row><entry
256 <para>This system call deactivates and deallocates a filter that was previously
257 allocated via the open() call.
</para>
259 </row></tbody></tgroup></informaltable>
262 <informaltable><tgroup cols=
"1"><tbody><row><entry
264 <para>int close(int fd);
</para>
266 </row></tbody></tgroup></informaltable>
269 <informaltable><tgroup cols=
"2"><tbody><row><entry
274 <para>File descriptor returned by a previous call to open().
</para>
276 </row></tbody></tgroup></informaltable>
279 <informaltable><tgroup cols=
"2"><tbody><row><entry
284 <para>fd is not a valid open file descriptor.
</para>
286 </row></tbody></tgroup></informaltable>
289 <section id=
"dmx_fread">
290 <title>read()
</title>
293 <informaltable><tgroup cols=
"1"><tbody><row><entry
295 <para>This system call returns filtered data, which might be section or PES data. The
296 filtered data is transferred from the driver
’s internal circular buffer to buf. The
297 maximum amount of data to be transferred is implied by count.
</para>
301 <para>When returning section data the driver always tries to return a complete single
302 section (even though buf would provide buffer space for more data). If the size
303 of the buffer is smaller than the section as much as possible will be returned,
304 and the remaining data will be provided in subsequent calls.
</para>
308 <para>The size of the internal buffer is
2 *
4096 bytes (the size of two maximum
309 sized sections) by default. The size of this buffer may be changed by using the
310 DMX_SET_BUFFER_SIZE function. If the buffer is not large enough, or if
311 the read operations are not performed fast enough, this may result in a buffer
312 overflow error. In this case EOVERFLOW will be returned, and the circular
313 buffer will be emptied. This call is blocking if there is no data to return, i.e. the
314 process will be put to sleep waiting for data, unless the O_NONBLOCK flag
319 <para>Note that in order to be able to read, the filtering process has to be started
320 by defining either a section or a PES filter by means of the ioctl functions,
321 and then starting the filtering process via the DMX_START ioctl function
322 or by setting the DMX_IMMEDIATE_START flag. If the reading is done
323 from a logical DVR demux device, the data will constitute a Transport Stream
324 including the packets from all PES filters in the corresponding demux device
325 /dev/dvb/adapter0/demux0 having the output set to DMX_OUT_TS_TAP.
</para>
327 </row></tbody></tgroup></informaltable>
330 <informaltable><tgroup cols=
"1"><tbody><row><entry
332 <para>size_t read(int fd, void
⋆buf, size_t count);
</para>
334 </row></tbody></tgroup></informaltable>
337 <informaltable><tgroup cols=
"2"><tbody><row><entry
342 <para>File descriptor returned by a previous call to open().
</para>
346 <para>void *buf
</para>
349 <para>Pointer to the buffer to be used for returned filtered data.
</para>
353 <para>size_t count
</para>
356 <para>Size of buf.
</para>
358 </row></tbody></tgroup></informaltable>
361 <informaltable><tgroup cols=
"2"><tbody><row><entry
363 <para>EWOULDBLOCK
</para>
366 <para>No data to return and O_NONBLOCK was specified.
</para>
373 <para>fd is not a valid open file descriptor.
</para>
380 <para>Last section had a CRC error - no data returned. The
381 buffer is flushed.
</para>
385 <para>EOVERFLOW
</para>
393 <para>The filtered data was not read from the buffer in due
394 time, resulting in non-read data being lost. The buffer is
399 <para>ETIMEDOUT
</para>
402 <para>The section was not loaded within the stated timeout
403 period. See ioctl DMX_SET_FILTER for how to set a
411 <para>The driver failed to write to the callers buffer due to an
412 invalid *buf pointer.
</para>
414 </row></tbody></tgroup></informaltable>
417 <section id=
"dmx_fwrite">
418 <title>write()
</title>
421 <informaltable><tgroup cols=
"1"><tbody><row><entry
423 <para>This system call is only provided by the logical device /dev/dvb/adapter0/dvr0,
424 associated with the physical demux device that provides the actual DVR
425 functionality. It is used for replay of a digitally recorded Transport Stream.
426 Matching filters have to be defined in the corresponding physical demux
427 device, /dev/dvb/adapter0/demux0. The amount of data to be transferred is
428 implied by count.
</para>
430 </row></tbody></tgroup></informaltable>
433 <informaltable><tgroup cols=
"1"><tbody><row><entry
435 <para>ssize_t write(int fd, const void
⋆buf, size_t
438 </row></tbody></tgroup></informaltable>
441 <informaltable><tgroup cols=
"2"><tbody><row><entry
446 <para>File descriptor returned by a previous call to open().
</para>
450 <para>void *buf
</para>
453 <para>Pointer to the buffer containing the Transport Stream.
</para>
457 <para>size_t count
</para>
460 <para>Size of buf.
</para>
462 </row></tbody></tgroup></informaltable>
465 <informaltable><tgroup cols=
"2"><tbody><row><entry
467 <para>EWOULDBLOCK
</para>
470 <para>No data was written. This
471 might happen if O_NONBLOCK was specified and there
472 is no more buffer space available (if O_NONBLOCK is
473 not specified the function will block until buffer space is
481 <para>This error code indicates that there are conflicting
482 requests. The corresponding demux device is setup to
483 receive data from the front- end. Make sure that these
484 filters are stopped and that the filters with input set to
485 DMX_IN_DVR are started.
</para>
492 <para>fd is not a valid open file descriptor.
</para>
494 </row></tbody></tgroup></informaltable>
497 <section id=
"DMX_START">
498 <title>DMX_START
</title>
501 <informaltable><tgroup cols=
"1"><tbody><row><entry
503 <para>This ioctl call is used to start the actual filtering operation defined via the ioctl
504 calls DMX_SET_FILTER or DMX_SET_PES_FILTER.
</para>
506 </row></tbody></tgroup></informaltable>
509 <informaltable><tgroup cols=
"1"><tbody><row><entry
511 <para>int ioctl( int fd, int request = DMX_START);
</para>
513 </row></tbody></tgroup></informaltable>
516 <informaltable><tgroup cols=
"2"><tbody><row><entry
521 <para>File descriptor returned by a previous call to open().
</para>
525 <para>int request
</para>
528 <para>Equals DMX_START for this command.
</para>
530 </row></tbody></tgroup></informaltable>
533 <informaltable><tgroup cols=
"2"><tbody><row><entry
538 <para>fd is not a valid file descriptor.
</para>
545 <para>Invalid argument, i.e. no filtering parameters provided via
546 the DMX_SET_FILTER or DMX_SET_PES_FILTER
554 <para>This error code indicates that there are conflicting
555 requests. There are active filters filtering data from
556 another input source. Make sure that these filters are
557 stopped before starting this filter.
</para>
559 </row></tbody></tgroup></informaltable>
562 <section id=
"DMX_STOP">
563 <title>DMX_STOP
</title>
566 <informaltable><tgroup cols=
"1"><tbody><row><entry
568 <para>This ioctl call is used to stop the actual filtering operation defined via the
569 ioctl calls DMX_SET_FILTER or DMX_SET_PES_FILTER and started via
570 the DMX_START command.
</para>
572 </row></tbody></tgroup></informaltable>
575 <informaltable><tgroup cols=
"1"><tbody><row><entry
577 <para>int ioctl( int fd, int request = DMX_STOP);
</para>
579 </row></tbody></tgroup></informaltable>
582 <informaltable><tgroup cols=
"2"><tbody><row><entry
587 <para>File descriptor returned by a previous call to open().
</para>
591 <para>int request
</para>
594 <para>Equals DMX_STOP for this command.
</para>
596 </row></tbody></tgroup></informaltable>
599 <informaltable><tgroup cols=
"2"><tbody><row><entry
604 <para>fd is not a valid file descriptor.
</para>
606 </row></tbody></tgroup></informaltable>
609 <section id=
"DMX_SET_FILTER">
610 <title>DMX_SET_FILTER
</title>
613 <informaltable><tgroup cols=
"1"><tbody><row><entry
615 <para>This ioctl call sets up a filter according to the filter and mask parameters
616 provided. A timeout may be defined stating number of seconds to wait for a
617 section to be loaded. A value of
0 means that no timeout should be applied.
618 Finally there is a flag field where it is possible to state whether a section should
619 be CRC-checked, whether the filter should be a
”one-shot
” filter, i.e. if the
620 filtering operation should be stopped after the first section is received, and
621 whether the filtering operation should be started immediately (without waiting
622 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
623 be canceled, and the receive buffer will be flushed.
</para>
625 </row></tbody></tgroup></informaltable>
628 <informaltable><tgroup cols=
"1"><tbody><row><entry
630 <para>int ioctl( int fd, int request = DMX_SET_FILTER,
631 struct dmx_sct_filter_params
⋆params);
</para>
633 </row></tbody></tgroup></informaltable>
636 <informaltable><tgroup cols=
"2"><tbody><row><entry
641 <para>File descriptor returned by a previous call to open().
</para>
645 <para>int request
</para>
648 <para>Equals DMX_SET_FILTER for this command.
</para>
653 dmx_sct_filter_params
657 <para>Pointer to structure containing filter parameters.
</para>
659 </row></tbody></tgroup></informaltable>
662 <informaltable><tgroup cols=
"2"><tbody><row><entry
667 <para>fd is not a valid file descriptor.
</para>
674 <para>Invalid argument.
</para>
676 </row></tbody></tgroup></informaltable>
679 <section id=
"DMX_SET_PES_FILTER">
680 <title>DMX_SET_PES_FILTER
</title>
683 <informaltable><tgroup cols=
"1"><tbody><row><entry
685 <para>This ioctl call sets up a PES filter according to the parameters provided. By a
686 PES filter is meant a filter that is based just on the packet identifier (PID), i.e.
687 no PES header or payload filtering capability is supported.
</para>
691 <para>The transport stream destination for the filtered output may be set. Also the
692 PES type may be stated in order to be able to e.g. direct a video stream directly
693 to the video decoder. Finally there is a flag field where it is possible to state
694 whether the filtering operation should be started immediately (without waiting
695 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
696 be cancelled, and the receive buffer will be flushed.
</para>
698 </row></tbody></tgroup></informaltable>
701 <informaltable><tgroup cols=
"1"><tbody><row><entry
703 <para>int ioctl( int fd, int request = DMX_SET_PES_FILTER,
704 struct dmx_pes_filter_params
⋆params);
</para>
706 </row></tbody></tgroup></informaltable>
709 <informaltable><tgroup cols=
"2"><tbody><row><entry
714 <para>File descriptor returned by a previous call to open().
</para>
718 <para>int request
</para>
721 <para>Equals DMX_SET_PES_FILTER for this command.
</para>
726 dmx_pes_filter_params
730 <para>Pointer to structure containing filter parameters.
</para>
732 </row></tbody></tgroup></informaltable>
735 <informaltable><tgroup cols=
"2"><tbody><row><entry
740 <para>fd is not a valid file descriptor.
</para>
747 <para>Invalid argument.
</para>
754 <para>This error code indicates that there are conflicting
755 requests. There are active filters filtering data from
756 another input source. Make sure that these filters are
757 stopped before starting this filter.
</para>
759 </row></tbody></tgroup></informaltable>
762 <section id=
"DMX_SET_BUFFER_SIZE">
763 <title>DMX_SET_BUFFER_SIZE
</title>
766 <informaltable><tgroup cols=
"1"><tbody><row><entry
768 <para>This ioctl call is used to set the size of the circular buffer used for filtered data.
769 The default size is two maximum sized sections, i.e. if this function is not called
770 a buffer size of
2 *
4096 bytes will be used.
</para>
772 </row></tbody></tgroup></informaltable>
775 <informaltable><tgroup cols=
"1"><tbody><row><entry
777 <para>int ioctl( int fd, int request =
778 DMX_SET_BUFFER_SIZE, unsigned long size);
</para>
780 </row></tbody></tgroup></informaltable>
783 <informaltable><tgroup cols=
"2"><tbody><row><entry
788 <para>File descriptor returned by a previous call to open().
</para>
792 <para>int request
</para>
795 <para>Equals DMX_SET_BUFFER_SIZE for this command.
</para>
799 <para>unsigned long size
</para>
802 <para>Size of circular buffer.
</para>
804 </row></tbody></tgroup></informaltable>
807 <informaltable><tgroup cols=
"2"><tbody><row><entry
812 <para>fd is not a valid file descriptor.
</para>
819 <para>The driver was not able to allocate a buffer of the
820 requested size.
</para>
822 </row></tbody></tgroup></informaltable>
825 <section id=
"DMX_GET_EVENT">
826 <title>DMX_GET_EVENT
</title>
829 <informaltable><tgroup cols=
"1"><tbody><row><entry
831 <para>This ioctl call returns an event if available. If an event is not available,
832 the behavior depends on whether the device is in blocking or non-blocking
833 mode. In the latter case, the call fails immediately with errno set to
834 EWOULDBLOCK. In the former case, the call blocks until an event becomes
839 <para>The standard Linux poll() and/or select() system calls can be used with the
840 device file descriptor to watch for new events. For select(), the file descriptor
841 should be included in the exceptfds argument, and for poll(), POLLPRI should
842 be specified as the wake-up condition. Only the latest event for each filter is
845 </row></tbody></tgroup></informaltable>
848 <informaltable><tgroup cols=
"1"><tbody><row><entry
850 <para>int ioctl( int fd, int request = DMX_GET_EVENT,
851 struct dmx_event
⋆ev);
</para>
853 </row></tbody></tgroup></informaltable>
856 <informaltable><tgroup cols=
"2"><tbody><row><entry
861 <para>File descriptor returned by a previous call to open().
</para>
865 <para>int request
</para>
868 <para>Equals DMX_GET_EVENT for this command.
</para>
872 <para>struct dmx_event *ev
</para>
875 <para>Pointer to the location where the event is to be stored.
</para>
877 </row></tbody></tgroup></informaltable>
880 <informaltable><tgroup cols=
"2"><tbody><row><entry
885 <para>fd is not a valid file descriptor.
</para>
892 <para>ev points to an invalid address.
</para>
896 <para>EWOULDBLOCK
</para>
899 <para>There is no event pending, and the device is in
900 non-blocking mode.
</para>
902 </row></tbody></tgroup></informaltable>
905 <section id=
"DMX_GET_STC">
906 <title>DMX_GET_STC
</title>
909 <informaltable><tgroup cols=
"1"><tbody><row><entry
911 <para>This ioctl call returns the current value of the system time counter (which is driven
912 by a PES filter of type DMX_PES_PCR). Some hardware supports more than one
913 STC, so you must specify which one by setting the num field of stc before the ioctl
914 (range
0...n). The result is returned in form of a ratio with a
64 bit numerator
915 and a
32 bit denominator, so the real
90kHz STC value is stc-
>stc /
919 </row></tbody></tgroup></informaltable>
922 <informaltable><tgroup cols=
"1"><tbody><row><entry
924 <para>int ioctl( int fd, int request = DMX_GET_STC, struct
925 dmx_stc
⋆stc);
</para>
927 </row></tbody></tgroup></informaltable>
930 <informaltable><tgroup cols=
"2"><tbody><row><entry
935 <para>File descriptor returned by a previous call to open().
</para>
939 <para>int request
</para>
942 <para>Equals DMX_GET_STC for this command.
</para>
946 <para>struct dmx_stc *stc
</para>
949 <para>Pointer to the location where the stc is to be stored.
</para>
951 </row></tbody></tgroup></informaltable>
954 <informaltable><tgroup cols=
"2"><tbody><row><entry
959 <para>fd is not a valid file descriptor.
</para>
966 <para>stc points to an invalid address.
</para>
973 <para>Invalid stc number.
</para>
975 </row></tbody></tgroup></informaltable>