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 ⋆/
147 <section id="dmx-caps">
148 <title>struct dmx_caps</title>
150 typedef struct dmx_caps {
157 <section id="dmx-source-t">
158 <title>enum dmx_source_t</title>
161 DMX_SOURCE_FRONT0 = 0,
165 DMX_SOURCE_DVR0 = 16,
174 <section id="dmx_fcalls">
175 <title>Demux Function Calls</title>
177 <section id="dmx_fopen">
178 <title>open()</title>
181 <informaltable><tgroup cols="1"><tbody><row><entry
183 <para>This system call, used with a device name of /dev/dvb/adapter0/demux0,
184 allocates a new filter and returns a handle which can be used for subsequent
185 control of that filter. This call has to be made for each filter to be used, i.e. every
186 returned file descriptor is a reference to a single filter. /dev/dvb/adapter0/dvr0
187 is a logical device to be used for retrieving Transport Streams for digital
188 video recording. When reading from this device a transport stream containing
189 the packets from all PES filters set in the corresponding demux device
190 (/dev/dvb/adapter0/demux0) having the output set to DMX_OUT_TS_TAP. A
191 recorded Transport Stream is replayed by writing to this device. </para>
192 <para>The significance of blocking or non-blocking mode is described in the
193 documentation for functions where there is a difference. It does not affect the
194 semantics of the open() call itself. A device opened in blocking mode can later
195 be put into non-blocking mode (and vice versa) using the F_SETFL command
196 of the fcntl system call.</para>
198 </row></tbody></tgroup></informaltable>
201 <informaltable><tgroup cols="1"><tbody><row><entry
203 <para>int open(const char ⋆deviceName, int flags);</para>
205 </row></tbody></tgroup></informaltable>
208 <informaltable><tgroup cols="2"><tbody><row><entry
214 <para>Name of demux device.</para>
218 <para>int flags</para>
221 <para>A bit-wise OR of the following flags:</para>
227 <para>O_RDWR read/write access</para>
233 <para>O_NONBLOCK open in non-blocking mode</para>
239 <para>(blocking mode is the default)</para>
241 </row></tbody></tgroup></informaltable>
242 <para>RETURN VALUE</para>
243 <informaltable><tgroup cols="2"><tbody><row><entry
248 <para>Device driver not loaded/available.</para>
255 <para>Invalid argument.</para>
262 <para>“Too many open files”, i.e. no more filters available.</para>
269 <para>The driver failed to allocate enough memory.</para>
271 </row></tbody></tgroup></informaltable>
274 <section id="dmx_fclose">
275 <title>close()</title>
278 <informaltable><tgroup cols="1"><tbody><row><entry
280 <para>This system call deactivates and deallocates a filter that was previously
281 allocated via the open() call.</para>
283 </row></tbody></tgroup></informaltable>
286 <informaltable><tgroup cols="1"><tbody><row><entry
288 <para>int close(int fd);</para>
290 </row></tbody></tgroup></informaltable>
293 <informaltable><tgroup cols="2"><tbody><row><entry
298 <para>File descriptor returned by a previous call to open().</para>
300 </row></tbody></tgroup></informaltable>
301 <para>RETURN VALUE</para>
302 <informaltable><tgroup cols="2"><tbody><row><entry
307 <para>fd is not a valid open file descriptor.</para>
309 </row></tbody></tgroup></informaltable>
312 <section id="dmx_fread">
313 <title>read()</title>
316 <informaltable><tgroup cols="1"><tbody><row><entry
318 <para>This system call returns filtered data, which might be section or PES data. The
319 filtered data is transferred from the driver’s internal circular buffer to buf. The
320 maximum amount of data to be transferred is implied by count.</para>
324 <para>When returning section data the driver always tries to return a complete single
325 section (even though buf would provide buffer space for more data). If the size
326 of the buffer is smaller than the section as much as possible will be returned,
327 and the remaining data will be provided in subsequent calls.</para>
331 <para>The size of the internal buffer is 2 * 4096 bytes (the size of two maximum
332 sized sections) by default. The size of this buffer may be changed by using the
333 DMX_SET_BUFFER_SIZE function. If the buffer is not large enough, or if
334 the read operations are not performed fast enough, this may result in a buffer
335 overflow error. In this case EOVERFLOW will be returned, and the circular
336 buffer will be emptied. This call is blocking if there is no data to return, i.e. the
337 process will be put to sleep waiting for data, unless the O_NONBLOCK flag
342 <para>Note that in order to be able to read, the filtering process has to be started
343 by defining either a section or a PES filter by means of the ioctl functions,
344 and then starting the filtering process via the DMX_START ioctl function
345 or by setting the DMX_IMMEDIATE_START flag. If the reading is done
346 from a logical DVR demux device, the data will constitute a Transport Stream
347 including the packets from all PES filters in the corresponding demux device
348 /dev/dvb/adapter0/demux0 having the output set to DMX_OUT_TS_TAP.</para>
350 </row></tbody></tgroup></informaltable>
353 <informaltable><tgroup cols="1"><tbody><row><entry
355 <para>size_t read(int fd, void ⋆buf, size_t count);</para>
357 </row></tbody></tgroup></informaltable>
360 <informaltable><tgroup cols="2"><tbody><row><entry
365 <para>File descriptor returned by a previous call to open().</para>
369 <para>void *buf</para>
372 <para>Pointer to the buffer to be used for returned filtered data.</para>
376 <para>size_t count</para>
379 <para>Size of buf.</para>
381 </row></tbody></tgroup></informaltable>
382 <para>RETURN VALUE</para>
383 <informaltable><tgroup cols="2"><tbody><row><entry
385 <para>EWOULDBLOCK</para>
388 <para>No data to return and O_NONBLOCK was specified.</para>
395 <para>fd is not a valid open file descriptor.</para>
402 <para>Last section had a CRC error - no data returned. The
403 buffer is flushed.</para>
407 <para>EOVERFLOW</para>
415 <para>The filtered data was not read from the buffer in due
416 time, resulting in non-read data being lost. The buffer is
421 <para>ETIMEDOUT</para>
424 <para>The section was not loaded within the stated timeout
425 period. See ioctl DMX_SET_FILTER for how to set a
433 <para>The driver failed to write to the callers buffer due to an
434 invalid *buf pointer.</para>
436 </row></tbody></tgroup></informaltable>
439 <section id="dmx_fwrite">
440 <title>write()</title>
443 <informaltable><tgroup cols="1"><tbody><row><entry
445 <para>This system call is only provided by the logical device /dev/dvb/adapter0/dvr0,
446 associated with the physical demux device that provides the actual DVR
447 functionality. It is used for replay of a digitally recorded Transport Stream.
448 Matching filters have to be defined in the corresponding physical demux
449 device, /dev/dvb/adapter0/demux0. The amount of data to be transferred is
450 implied by count.</para>
452 </row></tbody></tgroup></informaltable>
455 <informaltable><tgroup cols="1"><tbody><row><entry
457 <para>ssize_t write(int fd, const void ⋆buf, size_t
460 </row></tbody></tgroup></informaltable>
463 <informaltable><tgroup cols="2"><tbody><row><entry
468 <para>File descriptor returned by a previous call to open().</para>
472 <para>void *buf</para>
475 <para>Pointer to the buffer containing the Transport Stream.</para>
479 <para>size_t count</para>
482 <para>Size of buf.</para>
484 </row></tbody></tgroup></informaltable>
485 <para>RETURN VALUE</para>
486 <informaltable><tgroup cols="2"><tbody><row><entry
488 <para>EWOULDBLOCK</para>
491 <para>No data was written. This
492 might happen if O_NONBLOCK was specified and there
493 is no more buffer space available (if O_NONBLOCK is
494 not specified the function will block until buffer space is
502 <para>This error code indicates that there are conflicting
503 requests. The corresponding demux device is setup to
504 receive data from the front- end. Make sure that these
505 filters are stopped and that the filters with input set to
506 DMX_IN_DVR are started.</para>
513 <para>fd is not a valid open file descriptor.</para>
515 </row></tbody></tgroup></informaltable>
518 <section id="DMX_START">
519 <title>DMX_START</title>
522 <informaltable><tgroup cols="1"><tbody><row><entry
524 <para>This ioctl call is used to start the actual filtering operation defined via the ioctl
525 calls DMX_SET_FILTER or DMX_SET_PES_FILTER.</para>
527 </row></tbody></tgroup></informaltable>
530 <informaltable><tgroup cols="1"><tbody><row><entry
532 <para>int ioctl( int fd, int request = DMX_START);</para>
534 </row></tbody></tgroup></informaltable>
537 <informaltable><tgroup cols="2"><tbody><row><entry
542 <para>File descriptor returned by a previous call to open().</para>
546 <para>int request</para>
549 <para>Equals DMX_START for this command.</para>
551 </row></tbody></tgroup></informaltable>
553 <informaltable><tgroup cols="2"><tbody><row><entry
558 <para>fd is not a valid file descriptor.</para>
565 <para>Invalid argument, i.e. no filtering parameters provided via
566 the DMX_SET_FILTER or DMX_SET_PES_FILTER
574 <para>This error code indicates that there are conflicting
575 requests. There are active filters filtering data from
576 another input source. Make sure that these filters are
577 stopped before starting this filter.</para>
579 </row></tbody></tgroup></informaltable>
582 <section id="DMX_STOP">
583 <title>DMX_STOP</title>
586 <informaltable><tgroup cols="1"><tbody><row><entry
588 <para>This ioctl call is used to stop the actual filtering operation defined via the
589 ioctl calls DMX_SET_FILTER or DMX_SET_PES_FILTER and started via
590 the DMX_START command.</para>
592 </row></tbody></tgroup></informaltable>
595 <informaltable><tgroup cols="1"><tbody><row><entry
597 <para>int ioctl( int fd, int request = DMX_STOP);</para>
599 </row></tbody></tgroup></informaltable>
602 <informaltable><tgroup cols="2"><tbody><row><entry
607 <para>File descriptor returned by a previous call to open().</para>
611 <para>int request</para>
614 <para>Equals DMX_STOP for this command.</para>
616 </row></tbody></tgroup></informaltable>
618 <informaltable><tgroup cols="2"><tbody><row><entry
623 <para>fd is not a valid file descriptor.</para>
625 </row></tbody></tgroup></informaltable>
628 <section id="DMX_SET_FILTER">
629 <title>DMX_SET_FILTER</title>
632 <informaltable><tgroup cols="1"><tbody><row><entry
634 <para>This ioctl call sets up a filter according to the filter and mask parameters
635 provided. A timeout may be defined stating number of seconds to wait for a
636 section to be loaded. A value of 0 means that no timeout should be applied.
637 Finally there is a flag field where it is possible to state whether a section should
638 be CRC-checked, whether the filter should be a ”one-shot” filter, i.e. if the
639 filtering operation should be stopped after the first section is received, and
640 whether the filtering operation should be started immediately (without waiting
641 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
642 be canceled, and the receive buffer will be flushed.</para>
644 </row></tbody></tgroup></informaltable>
647 <informaltable><tgroup cols="1"><tbody><row><entry
649 <para>int ioctl( int fd, int request = DMX_SET_FILTER,
650 struct dmx_sct_filter_params ⋆params);</para>
652 </row></tbody></tgroup></informaltable>
655 <informaltable><tgroup cols="2"><tbody><row><entry
660 <para>File descriptor returned by a previous call to open().</para>
664 <para>int request</para>
667 <para>Equals DMX_SET_FILTER for this command.</para>
672 dmx_sct_filter_params
676 <para>Pointer to structure containing filter parameters.</para>
678 </row></tbody></tgroup></informaltable>
680 <informaltable><tgroup cols="2"><tbody><row><entry
685 <para>fd is not a valid file descriptor.</para>
692 <para>Invalid argument.</para>
694 </row></tbody></tgroup></informaltable>
697 <section id="DMX_SET_PES_FILTER">
698 <title>DMX_SET_PES_FILTER</title>
701 <informaltable><tgroup cols="1"><tbody><row><entry
703 <para>This ioctl call sets up a PES filter according to the parameters provided. By a
704 PES filter is meant a filter that is based just on the packet identifier (PID), i.e.
705 no PES header or payload filtering capability is supported.</para>
709 <para>The transport stream destination for the filtered output may be set. Also the
710 PES type may be stated in order to be able to e.g. direct a video stream directly
711 to the video decoder. Finally there is a flag field where it is possible to state
712 whether the filtering operation should be started immediately (without waiting
713 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
714 be cancelled, and the receive buffer will be flushed.</para>
716 </row></tbody></tgroup></informaltable>
719 <informaltable><tgroup cols="1"><tbody><row><entry
721 <para>int ioctl( int fd, int request = DMX_SET_PES_FILTER,
722 struct dmx_pes_filter_params ⋆params);</para>
724 </row></tbody></tgroup></informaltable>
727 <informaltable><tgroup cols="2"><tbody><row><entry
732 <para>File descriptor returned by a previous call to open().</para>
736 <para>int request</para>
739 <para>Equals DMX_SET_PES_FILTER for this command.</para>
744 dmx_pes_filter_params
748 <para>Pointer to structure containing filter parameters.</para>
750 </row></tbody></tgroup></informaltable>
752 <informaltable><tgroup cols="2"><tbody><row><entry
757 <para>fd is not a valid file descriptor.</para>
764 <para>Invalid argument.</para>
771 <para>This error code indicates that there are conflicting
772 requests. There are active filters filtering data from
773 another input source. Make sure that these filters are
774 stopped before starting this filter.</para>
776 </row></tbody></tgroup></informaltable>
779 <section id="DMX_SET_BUFFER_SIZE">
780 <title>DMX_SET_BUFFER_SIZE</title>
783 <informaltable><tgroup cols="1"><tbody><row><entry
785 <para>This ioctl call is used to set the size of the circular buffer used for filtered data.
786 The default size is two maximum sized sections, i.e. if this function is not called
787 a buffer size of 2 * 4096 bytes will be used.</para>
789 </row></tbody></tgroup></informaltable>
792 <informaltable><tgroup cols="1"><tbody><row><entry
794 <para>int ioctl( int fd, int request =
795 DMX_SET_BUFFER_SIZE, unsigned long size);</para>
797 </row></tbody></tgroup></informaltable>
800 <informaltable><tgroup cols="2"><tbody><row><entry
805 <para>File descriptor returned by a previous call to open().</para>
809 <para>int request</para>
812 <para>Equals DMX_SET_BUFFER_SIZE for this command.</para>
816 <para>unsigned long size</para>
819 <para>Size of circular buffer.</para>
821 </row></tbody></tgroup></informaltable>
823 <informaltable><tgroup cols="2"><tbody><row><entry
828 <para>fd is not a valid file descriptor.</para>
835 <para>The driver was not able to allocate a buffer of the
836 requested size.</para>
838 </row></tbody></tgroup></informaltable>
841 <section id="DMX_GET_EVENT">
842 <title>DMX_GET_EVENT</title>
845 <informaltable><tgroup cols="1"><tbody><row><entry
847 <para>This ioctl call returns an event if available. If an event is not available,
848 the behavior depends on whether the device is in blocking or non-blocking
849 mode. In the latter case, the call fails immediately with errno set to
850 EWOULDBLOCK. In the former case, the call blocks until an event becomes
855 <para>The standard Linux poll() and/or select() system calls can be used with the
856 device file descriptor to watch for new events. For select(), the file descriptor
857 should be included in the exceptfds argument, and for poll(), POLLPRI should
858 be specified as the wake-up condition. Only the latest event for each filter is
861 </row></tbody></tgroup></informaltable>
864 <informaltable><tgroup cols="1"><tbody><row><entry
866 <para>int ioctl( int fd, int request = DMX_GET_EVENT,
867 struct dmx_event ⋆ev);</para>
869 </row></tbody></tgroup></informaltable>
872 <informaltable><tgroup cols="2"><tbody><row><entry
877 <para>File descriptor returned by a previous call to open().</para>
881 <para>int request</para>
884 <para>Equals DMX_GET_EVENT for this command.</para>
888 <para>struct dmx_event *ev</para>
891 <para>Pointer to the location where the event is to be stored.</para>
893 </row></tbody></tgroup></informaltable>
895 <informaltable><tgroup cols="2"><tbody><row><entry
900 <para>fd is not a valid file descriptor.</para>
907 <para>ev points to an invalid address.</para>
911 <para>EWOULDBLOCK</para>
914 <para>There is no event pending, and the device is in
915 non-blocking mode.</para>
917 </row></tbody></tgroup></informaltable>
920 <section id="DMX_GET_STC">
921 <title>DMX_GET_STC</title>
924 <informaltable><tgroup cols="1"><tbody><row><entry
926 <para>This ioctl call returns the current value of the system time counter (which is driven
927 by a PES filter of type DMX_PES_PCR). Some hardware supports more than one
928 STC, so you must specify which one by setting the num field of stc before the ioctl
929 (range 0...n). The result is returned in form of a ratio with a 64 bit numerator
930 and a 32 bit denominator, so the real 90kHz STC value is stc->stc /
934 </row></tbody></tgroup></informaltable>
937 <informaltable><tgroup cols="1"><tbody><row><entry
939 <para>int ioctl( int fd, int request = DMX_GET_STC, struct
940 dmx_stc ⋆stc);</para>
942 </row></tbody></tgroup></informaltable>
945 <informaltable><tgroup cols="2"><tbody><row><entry
950 <para>File descriptor returned by a previous call to open().</para>
954 <para>int request</para>
957 <para>Equals DMX_GET_STC for this command.</para>
961 <para>struct dmx_stc *stc</para>
964 <para>Pointer to the location where the stc is to be stored.</para>
966 </row></tbody></tgroup></informaltable>
968 <informaltable><tgroup cols="2"><tbody><row><entry
973 <para>fd is not a valid file descriptor.</para>
980 <para>stc points to an invalid address.</para>
987 <para>Invalid stc number.</para>
989 </row></tbody></tgroup></informaltable>