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>Invalid argument, i.e. no filtering parameters provided via
559 the DMX_SET_FILTER or DMX_SET_PES_FILTER
567 <para>This error code indicates that there are conflicting
568 requests. There are active filters filtering data from
569 another input source. Make sure that these filters are
570 stopped before starting this filter.</para>
572 </row></tbody></tgroup></informaltable>
575 <section id="DMX_STOP">
576 <title>DMX_STOP</title>
579 <informaltable><tgroup cols="1"><tbody><row><entry
581 <para>This ioctl call is used to stop the actual filtering operation defined via the
582 ioctl calls DMX_SET_FILTER or DMX_SET_PES_FILTER and started via
583 the DMX_START command.</para>
585 </row></tbody></tgroup></informaltable>
588 <informaltable><tgroup cols="1"><tbody><row><entry
590 <para>int ioctl( int fd, int request = DMX_STOP);</para>
592 </row></tbody></tgroup></informaltable>
595 <informaltable><tgroup cols="2"><tbody><row><entry
600 <para>File descriptor returned by a previous call to open().</para>
604 <para>int request</para>
607 <para>Equals DMX_STOP for this command.</para>
609 </row></tbody></tgroup></informaltable>
613 <section id="DMX_SET_FILTER">
614 <title>DMX_SET_FILTER</title>
617 <informaltable><tgroup cols="1"><tbody><row><entry
619 <para>This ioctl call sets up a filter according to the filter and mask parameters
620 provided. A timeout may be defined stating number of seconds to wait for a
621 section to be loaded. A value of 0 means that no timeout should be applied.
622 Finally there is a flag field where it is possible to state whether a section should
623 be CRC-checked, whether the filter should be a ”one-shot” filter, i.e. if the
624 filtering operation should be stopped after the first section is received, and
625 whether the filtering operation should be started immediately (without waiting
626 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
627 be canceled, and the receive buffer will be flushed.</para>
629 </row></tbody></tgroup></informaltable>
632 <informaltable><tgroup cols="1"><tbody><row><entry
634 <para>int ioctl( int fd, int request = DMX_SET_FILTER,
635 struct dmx_sct_filter_params ⋆params);</para>
637 </row></tbody></tgroup></informaltable>
640 <informaltable><tgroup cols="2"><tbody><row><entry
645 <para>File descriptor returned by a previous call to open().</para>
649 <para>int request</para>
652 <para>Equals DMX_SET_FILTER for this command.</para>
657 dmx_sct_filter_params
661 <para>Pointer to structure containing filter parameters.</para>
663 </row></tbody></tgroup></informaltable>
667 <section id="DMX_SET_PES_FILTER">
668 <title>DMX_SET_PES_FILTER</title>
671 <informaltable><tgroup cols="1"><tbody><row><entry
673 <para>This ioctl call sets up a PES filter according to the parameters provided. By a
674 PES filter is meant a filter that is based just on the packet identifier (PID), i.e.
675 no PES header or payload filtering capability is supported.</para>
679 <para>The transport stream destination for the filtered output may be set. Also the
680 PES type may be stated in order to be able to e.g. direct a video stream directly
681 to the video decoder. Finally there is a flag field where it is possible to state
682 whether the filtering operation should be started immediately (without waiting
683 for a DMX_START ioctl call). If a filter was previously set-up, this filter will
684 be cancelled, and the receive buffer will be flushed.</para>
686 </row></tbody></tgroup></informaltable>
689 <informaltable><tgroup cols="1"><tbody><row><entry
691 <para>int ioctl( int fd, int request = DMX_SET_PES_FILTER,
692 struct dmx_pes_filter_params ⋆params);</para>
694 </row></tbody></tgroup></informaltable>
697 <informaltable><tgroup cols="2"><tbody><row><entry
702 <para>File descriptor returned by a previous call to open().</para>
706 <para>int request</para>
709 <para>Equals DMX_SET_PES_FILTER for this command.</para>
714 dmx_pes_filter_params
718 <para>Pointer to structure containing filter parameters.</para>
720 </row></tbody></tgroup></informaltable>
722 <informaltable><tgroup cols="2"><tbody><row><entry
727 <para>This error code indicates that there are conflicting
728 requests. There are active filters filtering data from
729 another input source. Make sure that these filters are
730 stopped before starting this filter.</para>
732 </row></tbody></tgroup></informaltable>
735 <section id="DMX_SET_BUFFER_SIZE">
736 <title>DMX_SET_BUFFER_SIZE</title>
739 <informaltable><tgroup cols="1"><tbody><row><entry
741 <para>This ioctl call is used to set the size of the circular buffer used for filtered data.
742 The default size is two maximum sized sections, i.e. if this function is not called
743 a buffer size of 2 * 4096 bytes will be used.</para>
745 </row></tbody></tgroup></informaltable>
748 <informaltable><tgroup cols="1"><tbody><row><entry
750 <para>int ioctl( int fd, int request =
751 DMX_SET_BUFFER_SIZE, unsigned long size);</para>
753 </row></tbody></tgroup></informaltable>
756 <informaltable><tgroup cols="2"><tbody><row><entry
761 <para>File descriptor returned by a previous call to open().</para>
765 <para>int request</para>
768 <para>Equals DMX_SET_BUFFER_SIZE for this command.</para>
772 <para>unsigned long size</para>
775 <para>Size of circular buffer.</para>
777 </row></tbody></tgroup></informaltable>
781 <section id="DMX_GET_EVENT">
782 <title>DMX_GET_EVENT</title>
785 <informaltable><tgroup cols="1"><tbody><row><entry
787 <para>This ioctl call returns an event if available. If an event is not available,
788 the behavior depends on whether the device is in blocking or non-blocking
789 mode. In the latter case, the call fails immediately with errno set to
790 EWOULDBLOCK. In the former case, the call blocks until an event becomes
795 <para>The standard Linux poll() and/or select() system calls can be used with the
796 device file descriptor to watch for new events. For select(), the file descriptor
797 should be included in the exceptfds argument, and for poll(), POLLPRI should
798 be specified as the wake-up condition. Only the latest event for each filter is
801 </row></tbody></tgroup></informaltable>
804 <informaltable><tgroup cols="1"><tbody><row><entry
806 <para>int ioctl( int fd, int request = DMX_GET_EVENT,
807 struct dmx_event ⋆ev);</para>
809 </row></tbody></tgroup></informaltable>
812 <informaltable><tgroup cols="2"><tbody><row><entry
817 <para>File descriptor returned by a previous call to open().</para>
821 <para>int request</para>
824 <para>Equals DMX_GET_EVENT for this command.</para>
828 <para>struct dmx_event *ev</para>
831 <para>Pointer to the location where the event is to be stored.</para>
833 </row></tbody></tgroup></informaltable>
835 <informaltable><tgroup cols="2"><tbody><row><entry
837 <para>EWOULDBLOCK</para>
840 <para>There is no event pending, and the device is in
841 non-blocking mode.</para>
843 </row></tbody></tgroup></informaltable>
846 <section id="DMX_GET_STC">
847 <title>DMX_GET_STC</title>
850 <informaltable><tgroup cols="1"><tbody><row><entry
852 <para>This ioctl call returns the current value of the system time counter (which is driven
853 by a PES filter of type DMX_PES_PCR). Some hardware supports more than one
854 STC, so you must specify which one by setting the num field of stc before the ioctl
855 (range 0...n). The result is returned in form of a ratio with a 64 bit numerator
856 and a 32 bit denominator, so the real 90kHz STC value is stc->stc /
860 </row></tbody></tgroup></informaltable>
863 <informaltable><tgroup cols="1"><tbody><row><entry
865 <para>int ioctl( int fd, int request = DMX_GET_STC, struct
866 dmx_stc ⋆stc);</para>
868 </row></tbody></tgroup></informaltable>
871 <informaltable><tgroup cols="2"><tbody><row><entry
876 <para>File descriptor returned by a previous call to open().</para>
880 <para>int request</para>
883 <para>Equals DMX_GET_STC for this command.</para>
887 <para>struct dmx_stc *stc</para>
890 <para>Pointer to the location where the stc is to be stored.</para>
892 </row></tbody></tgroup></informaltable>
894 <informaltable><tgroup cols="2"><tbody><row><entry
899 <para>Invalid stc number.</para>
901 </row></tbody></tgroup></informaltable>