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>
20 <para><emphasis role="tt">DMX_OUT_TAP</emphasis> delivers the stream output to the demux device on which the ioctl is
23 <para><emphasis role="tt">DMX_OUT_TS_TAP</emphasis> routes output to the logical DVR device <emphasis role="tt">/dev/dvb/adapter0/dvr0</emphasis>,
24 which delivers a TS multiplexed from all filters for which <emphasis role="tt">DMX_OUT_TS_TAP</emphasis> was
29 <section id="dmx_input_t">
30 <title>dmx_input_t</title>
40 <section id="dmx_pes_type_t">
41 <title>dmx_pes_type_t</title>
55 <section id="dmx_event_t">
56 <title>dmx_event_t</title>
66 <section id="dmx_scrambling_status_t">
67 <title>dmx_scrambling_status_t</title>
73 } dmx_scrambling_status_t;
77 <section id="dmx_filter">
78 <title>struct dmx_filter</title>
80 typedef struct dmx_filter
82 uint8_t filter[DMX_FILTER_SIZE];
83 uint8_t mask[DMX_FILTER_SIZE];
88 <section id="dmx_sct_filter_params">
89 <title>struct dmx_sct_filter_params</title>
91 struct dmx_sct_filter_params
97 #define DMX_CHECK_CRC 1
99 #define DMX_IMMEDIATE_START 4
104 <section id="dmx_pes_filter_params">
105 <title>struct dmx_pes_filter_params</title>
107 struct dmx_pes_filter_params
112 dmx_pes_type_t pes_type;
118 <section id="dmx_event">
119 <title>struct dmx_event</title>
127 dmx_scrambling_status_t scrambling;
133 <section id="dmx_stc">
134 <title>struct dmx_stc</title>
137 unsigned int num; /⋆ input : which STC? 0..N ⋆/
138 unsigned int base; /⋆ output: divisor for stc to get 90 kHz clock ⋆/
139 uint64_t stc; /⋆ output: stc in 'base'⋆90 kHz units ⋆/
146 <section id="dmx_fcalls">
147 <title>Demux Function Calls</title>
149 <section id="dmx_fopen">
150 <title>open()</title>
153 <informaltable><tgroup cols="1"><tbody><row><entry
155 <para>This system call, used with a device name of /dev/dvb/adapter0/demux0,
156 allocates a new filter and returns a handle which can be used for subsequent
157 control of that filter. This call has to be made for each filter to be used, i.e. every
158 returned file descriptor is a reference to a single filter. /dev/dvb/adapter0/dvr0
159 is a logical device to be used for retrieving Transport Streams for digital
160 video recording. When reading from this device a transport stream containing
161 the packets from all PES filters set in the corresponding demux device
162 (/dev/dvb/adapter0/demux0) having the output set to DMX_OUT_TS_TAP. A
163 recorded Transport Stream is replayed by writing to this device. </para>
164 <para>The significance of blocking or non-blocking mode is described in the
165 documentation for functions where there is a difference. It does not affect the
166 semantics of the open() call itself. A device opened in blocking mode can later
167 be put into non-blocking mode (and vice versa) using the F_SETFL command
168 of the fcntl system call.</para>
170 </row></tbody></tgroup></informaltable>
173 <informaltable><tgroup cols="1"><tbody><row><entry
175 <para>int open(const char ⋆deviceName, int flags);</para>
177 </row></tbody></tgroup></informaltable>
180 <informaltable><tgroup cols="2"><tbody><row><entry
186 <para>Name of demux device.</para>
190 <para>int flags</para>
193 <para>A bit-wise OR of the following flags:</para>
199 <para>O_RDWR read/write access</para>
205 <para>O_NONBLOCK open in non-blocking mode</para>
211 <para>(blocking mode is the default)</para>
213 </row></tbody></tgroup></informaltable>
216 <informaltable><tgroup cols="2"><tbody><row><entry
221 <para>Device driver not loaded/available.</para>
228 <para>Invalid argument.</para>
235 <para>“Too many open files”, i.e. no more filters available.</para>
242 <para>The driver failed to allocate enough memory.</para>
244 </row></tbody></tgroup></informaltable>
247 <section id="dmx_fclose">
248 <title>close()</title>
251 <informaltable><tgroup cols="1"><tbody><row><entry
253 <para>This system call deactivates and deallocates a filter that was previously
254 allocated via the open() call.</para>
256 </row></tbody></tgroup></informaltable>
259 <informaltable><tgroup cols="1"><tbody><row><entry
261 <para>int close(int fd);</para>
263 </row></tbody></tgroup></informaltable>
266 <informaltable><tgroup cols="2"><tbody><row><entry
271 <para>File descriptor returned by a previous call to open().</para>
273 </row></tbody></tgroup></informaltable>
276 <informaltable><tgroup cols="2"><tbody><row><entry
281 <para>fd is not a valid open file descriptor.</para>
283 </row></tbody></tgroup></informaltable>
286 <section id="dmx_fread">
287 <title>read()</title>
290 <informaltable><tgroup cols="1"><tbody><row><entry
292 <para>This system call returns filtered data, which might be section or PES data. The
293 filtered data is transferred from the driver’s internal circular buffer to buf. The
294 maximum amount of data to be transferred is implied by count.</para>
298 <para>When returning section data the driver always tries to return a complete single
299 section (even though buf would provide buffer space for more data). If the size
300 of the buffer is smaller than the section as much as possible will be returned,
301 and the remaining data will be provided in subsequent calls.</para>
305 <para>The size of the internal buffer is 2 * 4096 bytes (the size of two maximum
306 sized sections) by default. The size of this buffer may be changed by using the
307 DMX_SET_BUFFER_SIZE function. If the buffer is not large enough, or if
308 the read operations are not performed fast enough, this may result in a buffer
309 overflow error. In this case EOVERFLOW will be returned, and the circular
310 buffer will be emptied. This call is blocking if there is no data to return, i.e. the
311 process will be put to sleep waiting for data, unless the O_NONBLOCK flag
316 <para>Note that in order to be able to read, the filtering process has to be started
317 by defining either a section or a PES filter by means of the ioctl functions,
318 and then starting the filtering process via the DMX_START ioctl function
319 or by setting the DMX_IMMEDIATE_START flag. If the reading is done
320 from a logical DVR demux device, the data will constitute a Transport Stream
321 including the packets from all PES filters in the corresponding demux device
322 /dev/dvb/adapter0/demux0 having the output set to DMX_OUT_TS_TAP.</para>
324 </row></tbody></tgroup></informaltable>
327 <informaltable><tgroup cols="1"><tbody><row><entry
329 <para>size_t read(int fd, void ⋆buf, size_t count);</para>
331 </row></tbody></tgroup></informaltable>
334 <informaltable><tgroup cols="2"><tbody><row><entry
339 <para>File descriptor returned by a previous call to open().</para>
343 <para>void *buf</para>
346 <para>Pointer to the buffer to be used for returned filtered data.</para>
350 <para>size_t count</para>
353 <para>Size of buf.</para>
355 </row></tbody></tgroup></informaltable>
358 <informaltable><tgroup cols="2"><tbody><row><entry
360 <para>EWOULDBLOCK</para>
363 <para>No data to return and O_NONBLOCK was specified.</para>
370 <para>fd is not a valid open file descriptor.</para>
377 <para>Last section had a CRC error - no data returned. The
378 buffer is flushed.</para>
382 <para>EOVERFLOW</para>
390 <para>The filtered data was not read from the buffer in due
391 time, resulting in non-read data being lost. The buffer is
396 <para>ETIMEDOUT</para>
399 <para>The section was not loaded within the stated timeout
400 period. See ioctl DMX_SET_FILTER for how to set a
408 <para>The driver failed to write to the callers buffer due to an
409 invalid *buf pointer.</para>
411 </row></tbody></tgroup></informaltable>
414 <section id="dmx_fwrite">
415 <title>write()</title>
418 <informaltable><tgroup cols="1"><tbody><row><entry
420 <para>This system call is only provided by the logical device /dev/dvb/adapter0/dvr0,
421 associated with the physical demux device that provides the actual DVR
422 functionality. It is used for replay of a digitally recorded Transport Stream.
423 Matching filters have to be defined in the corresponding physical demux
424 device, /dev/dvb/adapter0/demux0. The amount of data to be transferred is
425 implied by count.</para>
427 </row></tbody></tgroup></informaltable>
430 <informaltable><tgroup cols="1"><tbody><row><entry
432 <para>ssize_t write(int fd, const void ⋆buf, size_t
435 </row></tbody></tgroup></informaltable>
438 <informaltable><tgroup cols="2"><tbody><row><entry
443 <para>File descriptor returned by a previous call to open().</para>
447 <para>void *buf</para>
450 <para>Pointer to the buffer containing the Transport Stream.</para>
454 <para>size_t count</para>
457 <para>Size of buf.</para>
459 </row></tbody></tgroup></informaltable>
462 <informaltable><tgroup cols="2"><tbody><row><entry
464 <para>EWOULDBLOCK</para>
467 <para>No data was written. This
468 might happen if O_NONBLOCK was specified and there
469 is no more buffer space available (if O_NONBLOCK is
470 not specified the function will block until buffer space is
478 <para>This error code indicates that there are conflicting
479 requests. The corresponding demux device is setup to
480 receive data from the front- end. Make sure that these
481 filters are stopped and that the filters with input set to
482 DMX_IN_DVR are started.</para>
489 <para>fd is not a valid open file descriptor.</para>
491 </row></tbody></tgroup></informaltable>
494 <section id="dmx_start">
495 <title>DMX_START</title>
498 <informaltable><tgroup cols="1"><tbody><row><entry
500 <para>This ioctl call is used to start the actual filtering operation defined via the ioctl
501 calls DMX_SET_FILTER or DMX_SET_PES_FILTER.</para>
503 </row></tbody></tgroup></informaltable>
506 <informaltable><tgroup cols="1"><tbody><row><entry
508 <para>int ioctl( int fd, int request = DMX_START);</para>
510 </row></tbody></tgroup></informaltable>
513 <informaltable><tgroup cols="2"><tbody><row><entry
518 <para>File descriptor returned by a previous call to open().</para>
522 <para>int request</para>
525 <para>Equals DMX_START for this command.</para>
527 </row></tbody></tgroup></informaltable>
530 <informaltable><tgroup cols="2"><tbody><row><entry
535 <para>fd is not a valid file descriptor.</para>
542 <para>Invalid argument, i.e. no filtering parameters provided via
543 the DMX_SET_FILTER or DMX_SET_PES_FILTER
551 <para>This error code indicates that there are conflicting
552 requests. There are active filters filtering data from
553 another input source. Make sure that these filters are
554 stopped before starting this filter.</para>
556 </row></tbody></tgroup></informaltable>
559 <section id="dmx_stop">
560 <title>DMX_STOP</title>
563 <informaltable><tgroup cols="1"><tbody><row><entry
565 <para>This ioctl call is used to stop the actual filtering operation defined via the
566 ioctl calls DMX_SET_FILTER or DMX_SET_PES_FILTER and started via
567 the DMX_START command.</para>
569 </row></tbody></tgroup></informaltable>
572 <informaltable><tgroup cols="1"><tbody><row><entry
574 <para>int ioctl( int fd, int request = DMX_STOP);</para>
576 </row></tbody></tgroup></informaltable>
579 <informaltable><tgroup cols="2"><tbody><row><entry
584 <para>File descriptor returned by a previous call to open().</para>
588 <para>int request</para>
591 <para>Equals DMX_STOP for this command.</para>
593 </row></tbody></tgroup></informaltable>
596 <informaltable><tgroup cols="2"><tbody><row><entry
601 <para>fd is not a valid file descriptor.</para>
603 </row></tbody></tgroup></informaltable>
606 <section id="dmx_set_filter">
607 <title>DMX_SET_FILTER</title>
610 <informaltable><tgroup cols="1"><tbody><row><entry
612 <para>This ioctl call sets up a filter according to the filter and mask parameters
613 provided. A timeout may be defined stating number of seconds to wait for a
614 section to be loaded. A value of 0 means that no timeout should be applied.
615 Finally there is a flag field where it is possible to state whether a section should
616 be CRC-checked, whether the filter should be a ”one-shot” filter, i.e. if the
617 filtering operation should be stopped after the first section is received, and
618 whether the filtering operation should be started immediately (without waiting
619 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
620 be canceled, and the receive buffer will be flushed.</para>
622 </row></tbody></tgroup></informaltable>
625 <informaltable><tgroup cols="1"><tbody><row><entry
627 <para>int ioctl( int fd, int request = DMX_SET_FILTER,
628 struct dmx_sct_filter_params ⋆params);</para>
630 </row></tbody></tgroup></informaltable>
633 <informaltable><tgroup cols="2"><tbody><row><entry
638 <para>File descriptor returned by a previous call to open().</para>
642 <para>int request</para>
645 <para>Equals DMX_SET_FILTER for this command.</para>
650 dmx_sct_filter_params
654 <para>Pointer to structure containing filter parameters.</para>
656 </row></tbody></tgroup></informaltable>
659 <informaltable><tgroup cols="2"><tbody><row><entry
664 <para>fd is not a valid file descriptor.</para>
671 <para>Invalid argument.</para>
673 </row></tbody></tgroup></informaltable>
676 <section id="dmx_set_pes_filter">
677 <title>DMX_SET_PES_FILTER</title>
680 <informaltable><tgroup cols="1"><tbody><row><entry
682 <para>This ioctl call sets up a PES filter according to the parameters provided. By a
683 PES filter is meant a filter that is based just on the packet identifier (PID), i.e.
684 no PES header or payload filtering capability is supported.</para>
688 <para>The transport stream destination for the filtered output may be set. Also the
689 PES type may be stated in order to be able to e.g. direct a video stream directly
690 to the video decoder. Finally there is a flag field where it is possible to state
691 whether the filtering operation should be started immediately (without waiting
692 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
693 be cancelled, and the receive buffer will be flushed.</para>
695 </row></tbody></tgroup></informaltable>
698 <informaltable><tgroup cols="1"><tbody><row><entry
700 <para>int ioctl( int fd, int request = DMX_SET_PES_FILTER,
701 struct dmx_pes_filter_params ⋆params);</para>
703 </row></tbody></tgroup></informaltable>
706 <informaltable><tgroup cols="2"><tbody><row><entry
711 <para>File descriptor returned by a previous call to open().</para>
715 <para>int request</para>
718 <para>Equals DMX_SET_PES_FILTER for this command.</para>
723 dmx_pes_filter_params
727 <para>Pointer to structure containing filter parameters.</para>
729 </row></tbody></tgroup></informaltable>
732 <informaltable><tgroup cols="2"><tbody><row><entry
737 <para>fd is not a valid file descriptor.</para>
744 <para>Invalid argument.</para>
751 <para>This error code indicates that there are conflicting
752 requests. There are active filters filtering data from
753 another input source. Make sure that these filters are
754 stopped before starting this filter.</para>
756 </row></tbody></tgroup></informaltable>
759 <section id="dms_set_buffer_size">
760 <title>DMX_SET_BUFFER_SIZE</title>
763 <informaltable><tgroup cols="1"><tbody><row><entry
765 <para>This ioctl call is used to set the size of the circular buffer used for filtered data.
766 The default size is two maximum sized sections, i.e. if this function is not called
767 a buffer size of 2 * 4096 bytes will be used.</para>
769 </row></tbody></tgroup></informaltable>
772 <informaltable><tgroup cols="1"><tbody><row><entry
774 <para>int ioctl( int fd, int request =
775 DMX_SET_BUFFER_SIZE, unsigned long size);</para>
777 </row></tbody></tgroup></informaltable>
780 <informaltable><tgroup cols="2"><tbody><row><entry
785 <para>File descriptor returned by a previous call to open().</para>
789 <para>int request</para>
792 <para>Equals DMX_SET_BUFFER_SIZE for this command.</para>
796 <para>unsigned long size</para>
799 <para>Size of circular buffer.</para>
801 </row></tbody></tgroup></informaltable>
804 <informaltable><tgroup cols="2"><tbody><row><entry
809 <para>fd is not a valid file descriptor.</para>
816 <para>The driver was not able to allocate a buffer of the
817 requested size.</para>
819 </row></tbody></tgroup></informaltable>
822 <section id="dmx_get_event">
823 <title>DMX_GET_EVENT</title>
826 <informaltable><tgroup cols="1"><tbody><row><entry
828 <para>This ioctl call returns an event if available. If an event is not available,
829 the behavior depends on whether the device is in blocking or non-blocking
830 mode. In the latter case, the call fails immediately with errno set to
831 EWOULDBLOCK. In the former case, the call blocks until an event becomes
836 <para>The standard Linux poll() and/or select() system calls can be used with the
837 device file descriptor to watch for new events. For select(), the file descriptor
838 should be included in the exceptfds argument, and for poll(), POLLPRI should
839 be specified as the wake-up condition. Only the latest event for each filter is
842 </row></tbody></tgroup></informaltable>
845 <informaltable><tgroup cols="1"><tbody><row><entry
847 <para>int ioctl( int fd, int request = DMX_GET_EVENT,
848 struct dmx_event ⋆ev);</para>
850 </row></tbody></tgroup></informaltable>
853 <informaltable><tgroup cols="2"><tbody><row><entry
858 <para>File descriptor returned by a previous call to open().</para>
862 <para>int request</para>
865 <para>Equals DMX_GET_EVENT for this command.</para>
869 <para>struct dmx_event *ev</para>
872 <para>Pointer to the location where the event is to be stored.</para>
874 </row></tbody></tgroup></informaltable>
877 <informaltable><tgroup cols="2"><tbody><row><entry
882 <para>fd is not a valid file descriptor.</para>
889 <para>ev points to an invalid address.</para>
893 <para>EWOULDBLOCK</para>
896 <para>There is no event pending, and the device is in
897 non-blocking mode.</para>
899 </row></tbody></tgroup></informaltable>
902 <section id="dmx_get_stc">
903 <title>DMX_GET_STC</title>
906 <informaltable><tgroup cols="1"><tbody><row><entry
908 <para>This ioctl call returns the current value of the system time counter (which is driven
909 by a PES filter of type DMX_PES_PCR). Some hardware supports more than one
910 STC, so you must specify which one by setting the num field of stc before the ioctl
911 (range 0...n). The result is returned in form of a ratio with a 64 bit numerator
912 and a 32 bit denominator, so the real 90kHz STC value is stc->stc /
916 </row></tbody></tgroup></informaltable>
919 <informaltable><tgroup cols="1"><tbody><row><entry
921 <para>int ioctl( int fd, int request = DMX_GET_STC, struct
922 dmx_stc ⋆stc);</para>
924 </row></tbody></tgroup></informaltable>
927 <informaltable><tgroup cols="2"><tbody><row><entry
932 <para>File descriptor returned by a previous call to open().</para>
936 <para>int request</para>
939 <para>Equals DMX_GET_STC for this command.</para>
943 <para>struct dmx_stc *stc</para>
946 <para>Pointer to the location where the stc is to be stored.</para>
948 </row></tbody></tgroup></informaltable>
951 <informaltable><tgroup cols="2"><tbody><row><entry
956 <para>fd is not a valid file descriptor.</para>
963 <para>stc points to an invalid address.</para>
970 <para>Invalid stc number.</para>
972 </row></tbody></tgroup></informaltable>