1 <title>Kernel Demux API</title>
2 <para>The kernel demux API defines a driver-internal interface for registering low-level,
3 hardware specific driver to a hardware independent demux layer. It is only of interest for
4 DVB device driver writers. The header file for this API is named <emphasis role="tt">demux.h</emphasis> and located in
5 <emphasis role="tt">drivers/media/dvb/dvb-core</emphasis>.
7 <para>Maintainer note: This section must be reviewed. It is probably out of date.
10 <section id="kernel_demux_data_types">
11 <title>Kernel Demux Data Types</title>
14 <section id="dmx_success_t">
15 <title>dmx_success_t</title>
18 DMX_OK = 0, /⋆ Received Ok ⋆/
19 DMX_LENGTH_ERROR, /⋆ Incorrect length ⋆/
20 DMX_OVERRUN_ERROR, /⋆ Receiver ring buffer overrun ⋆/
21 DMX_CRC_ERROR, /⋆ Incorrect CRC ⋆/
22 DMX_FRAME_ERROR, /⋆ Frame alignment error ⋆/
23 DMX_FIFO_ERROR, /⋆ Receiver FIFO overrun ⋆/
24 DMX_MISSED_ERROR /⋆ Receiver missed packet ⋆/
29 <section id="ts_filter_types">
30 <title>TS filter types</title>
32 /⋆--------------------------------------------------------------------------⋆/
33 /⋆ TS packet reception ⋆/
34 /⋆--------------------------------------------------------------------------⋆/
36 /⋆ TS filter type for set_type() ⋆/
38 #define TS_PACKET 1 /⋆ send TS packets (188 bytes) to callback (default) ⋆/
39 #define TS_PAYLOAD_ONLY 2 /⋆ in case TS_PACKET is set, only send the TS
40 payload (<=184 bytes per packet) to callback ⋆/
41 #define TS_DECODER 4 /⋆ send stream to built-in decoder (if present) ⋆/
45 <section id="dmx_ts_pes_t">
46 <title>dmx_ts_pes_t</title>
52 DMX_TS_PES_AUDIO, /⋆ also send packets to audio decoder (if it exists) ⋆/
53 DMX_TS_PES_VIDEO, /⋆ ... ⋆/
60 <para>describes the PES type for filters which write to a built-in decoder. The correspond (and
61 should be kept identical) to the types in the demux device.
64 struct dmx_ts_feed_s {
65 int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/
66 struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/
67 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
68 int (⋆set) (struct dmx_ts_feed_s⋆ feed,
70 size_t callback_length,
71 size_t circular_buffer_size,
73 struct timespec timeout);
74 int (⋆start_filtering) (struct dmx_ts_feed_s⋆ feed);
75 int (⋆stop_filtering) (struct dmx_ts_feed_s⋆ feed);
76 int (⋆set_type) (struct dmx_ts_feed_s⋆ feed,
78 dmx_ts_pes_t pes_type);
81 typedef struct dmx_ts_feed_s dmx_ts_feed_t;
84 /⋆--------------------------------------------------------------------------⋆/
85 /⋆ PES packet reception (not supported yet) ⋆/
86 /⋆--------------------------------------------------------------------------⋆/
88 typedef struct dmx_pes_filter_s {
89 struct dmx_pes_s⋆ parent; /⋆ Back-pointer ⋆/
90 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
94 typedef struct dmx_pes_feed_s {
95 int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/
96 struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/
97 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
98 int (⋆set) (struct dmx_pes_feed_s⋆ feed,
100 size_t circular_buffer_size,
102 struct timespec timeout);
103 int (⋆start_filtering) (struct dmx_pes_feed_s⋆ feed);
104 int (⋆stop_filtering) (struct dmx_pes_feed_s⋆ feed);
105 int (⋆allocate_filter) (struct dmx_pes_feed_s⋆ feed,
106 dmx_pes_filter_t⋆⋆ filter);
107 int (⋆release_filter) (struct dmx_pes_feed_s⋆ feed,
108 dmx_pes_filter_t⋆ filter);
113 __u8 filter_value [DMX_MAX_FILTER_SIZE];
114 __u8 filter_mask [DMX_MAX_FILTER_SIZE];
115 struct dmx_section_feed_s⋆ parent; /⋆ Back-pointer ⋆/
116 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
117 } dmx_section_filter_t;
120 struct dmx_section_feed_s {
121 int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/
122 struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/
123 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
124 int (⋆set) (struct dmx_section_feed_s⋆ feed,
126 size_t circular_buffer_size,
129 int (⋆allocate_filter) (struct dmx_section_feed_s⋆ feed,
130 dmx_section_filter_t⋆⋆ filter);
131 int (⋆release_filter) (struct dmx_section_feed_s⋆ feed,
132 dmx_section_filter_t⋆ filter);
133 int (⋆start_filtering) (struct dmx_section_feed_s⋆ feed);
134 int (⋆stop_filtering) (struct dmx_section_feed_s⋆ feed);
136 typedef struct dmx_section_feed_s dmx_section_feed_t;
138 /⋆--------------------------------------------------------------------------⋆/
139 /⋆ Callback functions ⋆/
140 /⋆--------------------------------------------------------------------------⋆/
142 typedef int (⋆dmx_ts_cb) ( __u8 ⋆ buffer1,
143 size_t buffer1_length,
144 __u8 ⋆ buffer2,
145 size_t buffer2_length,
146 dmx_ts_feed_t⋆ source,
147 dmx_success_t success);
149 typedef int (⋆dmx_section_cb) ( __u8 ⋆ buffer1,
151 __u8 ⋆ buffer2,
153 dmx_section_filter_t ⋆ source,
154 dmx_success_t success);
156 typedef int (⋆dmx_pes_cb) ( __u8 ⋆ buffer1,
158 __u8 ⋆ buffer2,
160 dmx_pes_filter_t⋆ source,
161 dmx_success_t success);
163 /⋆--------------------------------------------------------------------------⋆/
164 /⋆ DVB Front-End ⋆/
165 /⋆--------------------------------------------------------------------------⋆/
173 DMX_ASI_FE, /⋆ DVB-ASI interface ⋆/
175 } dmx_frontend_source_t;
178 /⋆ The following char⋆ fields point to NULL terminated strings ⋆/
179 char⋆ id; /⋆ Unique front-end identifier ⋆/
180 char⋆ vendor; /⋆ Name of the front-end vendor ⋆/
181 char⋆ model; /⋆ Name of the front-end model ⋆/
182 struct list_head connectivity_list; /⋆ List of front-ends that can
183 be connected to a particular
185 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
186 dmx_frontend_source_t source;
189 /⋆--------------------------------------------------------------------------⋆/
190 /⋆ MPEG-2 TS Demux ⋆/
191 /⋆--------------------------------------------------------------------------⋆/
194 ⋆ Flags OR'ed in the capabilites field of struct dmx_demux_s.
197 #define DMX_TS_FILTERING 1
198 #define DMX_PES_FILTERING 2
199 #define DMX_SECTION_FILTERING 4
200 #define DMX_MEMORY_BASED_FILTERING 8 /⋆ write() available ⋆/
201 #define DMX_CRC_CHECKING 16
202 #define DMX_TS_DESCRAMBLING 32
203 #define DMX_SECTION_PAYLOAD_DESCRAMBLING 64
204 #define DMX_MAC_ADDRESS_DESCRAMBLING 128
208 <section id="demux_demux_t">
209 <title>demux_demux_t</title>
212 ⋆ DMX_FE_ENTRY(): Casts elements in the list of registered
213 ⋆ front-ends from the generic type struct list_head
214 ⋆ to the type ⋆ dmx_frontend_t
218 #define DMX_FE_ENTRY(list) list_entry(list, dmx_frontend_t, connectivity_list)
221 /⋆ The following char⋆ fields point to NULL terminated strings ⋆/
222 char⋆ id; /⋆ Unique demux identifier ⋆/
223 char⋆ vendor; /⋆ Name of the demux vendor ⋆/
224 char⋆ model; /⋆ Name of the demux model ⋆/
225 __u32 capabilities; /⋆ Bitfield of capability flags ⋆/
226 dmx_frontend_t⋆ frontend; /⋆ Front-end connected to the demux ⋆/
227 struct list_head reg_list; /⋆ List of registered demuxes ⋆/
228 void⋆ priv; /⋆ Pointer to private data of the API client ⋆/
229 int users; /⋆ Number of users ⋆/
230 int (⋆open) (struct dmx_demux_s⋆ demux);
231 int (⋆close) (struct dmx_demux_s⋆ demux);
232 int (⋆write) (struct dmx_demux_s⋆ demux, const char⋆ buf, size_t count);
233 int (⋆allocate_ts_feed) (struct dmx_demux_s⋆ demux,
234 dmx_ts_feed_t⋆⋆ feed,
236 int (⋆release_ts_feed) (struct dmx_demux_s⋆ demux,
237 dmx_ts_feed_t⋆ feed);
238 int (⋆allocate_pes_feed) (struct dmx_demux_s⋆ demux,
239 dmx_pes_feed_t⋆⋆ feed,
240 dmx_pes_cb callback);
241 int (⋆release_pes_feed) (struct dmx_demux_s⋆ demux,
242 dmx_pes_feed_t⋆ feed);
243 int (⋆allocate_section_feed) (struct dmx_demux_s⋆ demux,
244 dmx_section_feed_t⋆⋆ feed,
245 dmx_section_cb callback);
246 int (⋆release_section_feed) (struct dmx_demux_s⋆ demux,
247 dmx_section_feed_t⋆ feed);
248 int (⋆descramble_mac_address) (struct dmx_demux_s⋆ demux,
249 __u8⋆ buffer1,
250 size_t buffer1_length,
251 __u8⋆ buffer2,
252 size_t buffer2_length,
254 int (⋆descramble_section_payload) (struct dmx_demux_s⋆ demux,
255 __u8⋆ buffer1,
256 size_t buffer1_length,
257 __u8⋆ buffer2, size_t buffer2_length,
259 int (⋆add_frontend) (struct dmx_demux_s⋆ demux,
260 dmx_frontend_t⋆ frontend);
261 int (⋆remove_frontend) (struct dmx_demux_s⋆ demux,
262 dmx_frontend_t⋆ frontend);
263 struct list_head⋆ (⋆get_frontends) (struct dmx_demux_s⋆ demux);
264 int (⋆connect_frontend) (struct dmx_demux_s⋆ demux,
265 dmx_frontend_t⋆ frontend);
266 int (⋆disconnect_frontend) (struct dmx_demux_s⋆ demux);
269 /⋆ added because js cannot keep track of these himself ⋆/
270 int (⋆get_pes_pids) (struct dmx_demux_s⋆ demux, __u16 ⋆pids);
272 typedef struct dmx_demux_s dmx_demux_t;
276 <section id="demux_directory">
277 <title>Demux directory</title>
280 ⋆ DMX_DIR_ENTRY(): Casts elements in the list of registered
281 ⋆ demuxes from the generic type struct list_head⋆ to the type dmx_demux_t
285 #define DMX_DIR_ENTRY(list) list_entry(list, dmx_demux_t, reg_list)
287 int dmx_register_demux (dmx_demux_t⋆ demux);
288 int dmx_unregister_demux (dmx_demux_t⋆ demux);
289 struct list_head⋆ dmx_get_demuxes (void);
292 <section id="demux_directory_api">
293 <title>Demux Directory API</title>
294 <para>The demux directory is a Linux kernel-wide facility for registering and accessing the
295 MPEG-2 TS demuxes in the system. Run-time registering and unregistering of demux drivers
296 is possible using this API.
298 <para>All demux drivers in the directory implement the abstract interface dmx_demux_t.
302 role="subsection"><title>dmx_register_demux()</title>
305 <informaltable><tgroup cols="1"><tbody><row><entry
307 <para>This function makes a demux driver interface available to the Linux kernel. It is
308 usually called by the init_module() function of the kernel module that contains
309 the demux driver. The caller of this function is responsible for allocating
310 dynamic or static memory for the demux structure and for initializing its fields
311 before calling this function. The memory allocated for the demux structure
312 must not be freed before calling dmx_unregister_demux(),</para>
314 </row></tbody></tgroup></informaltable>
317 <informaltable><tgroup cols="1"><tbody><row><entry
319 <para>int dmx_register_demux ( dmx_demux_t ⋆demux )</para>
321 </row></tbody></tgroup></informaltable>
324 <informaltable><tgroup cols="2"><tbody><row><entry
330 <para>Pointer to the demux structure.</para>
332 </row></tbody></tgroup></informaltable>
335 <informaltable><tgroup cols="2"><tbody><row><entry
340 <para>The function was completed without errors.</para>
347 <para>A demux with the same value of the id field already stored
348 in the directory.</para>
355 <para>No space left in the directory.</para>
357 </row></tbody></tgroup></informaltable>
360 role="subsection"><title>dmx_unregister_demux()</title>
363 <informaltable><tgroup cols="1"><tbody><row><entry
365 <para>This function is called to indicate that the given demux interface is no
366 longer available. The caller of this function is responsible for freeing the
367 memory of the demux structure, if it was dynamically allocated before calling
368 dmx_register_demux(). The cleanup_module() function of the kernel module
369 that contains the demux driver should call this function. Note that this function
370 fails if the demux is currently in use, i.e., release_demux() has not been called
371 for the interface.</para>
373 </row></tbody></tgroup></informaltable>
376 <informaltable><tgroup cols="1"><tbody><row><entry
378 <para>int dmx_unregister_demux ( dmx_demux_t ⋆demux )</para>
380 </row></tbody></tgroup></informaltable>
383 <informaltable><tgroup cols="2"><tbody><row><entry
389 <para>Pointer to the demux structure which is to be
392 </row></tbody></tgroup></informaltable>
395 <informaltable><tgroup cols="2"><tbody><row><entry
400 <para>The function was completed without errors.</para>
407 <para>The specified demux is not registered in the demux
415 <para>The specified demux is currently in use.</para>
417 </row></tbody></tgroup></informaltable>
420 role="subsection"><title>dmx_get_demuxes()</title>
423 <informaltable><tgroup cols="1"><tbody><row><entry
425 <para>Provides the caller with the list of registered demux interfaces, using the
426 standard list structure defined in the include file linux/list.h. The include file
427 demux.h defines the macro DMX_DIR_ENTRY() for converting an element of
428 the generic type struct list_head* to the type dmx_demux_t*. The caller must
429 not free the memory of any of the elements obtained via this function call.</para>
431 </row></tbody></tgroup></informaltable>
434 <informaltable><tgroup cols="1"><tbody><row><entry
436 <para>struct list_head ⋆dmx_get_demuxes ()</para>
438 </row></tbody></tgroup></informaltable>
441 <informaltable><tgroup cols="2"><tbody><row><entry
445 </row></tbody></tgroup></informaltable>
448 <informaltable><tgroup cols="2"><tbody><row><entry
450 <para>struct list_head *</para>
453 <para>A list of demux interfaces, or NULL in the case of an
456 </row></tbody></tgroup></informaltable>
458 <section id="demux_api">
459 <title>Demux API</title>
460 <para>The demux API should be implemented for each demux in the system. It is used to select
461 the TS source of a demux and to manage the demux resources. When the demux
462 client allocates a resource via the demux API, it receives a pointer to the API of that
465 <para>Each demux receives its TS input from a DVB front-end or from memory, as set via the
466 demux API. In a system with more than one front-end, the API can be used to select one of
467 the DVB front-ends as a TS source for a demux, unless this is fixed in the HW platform. The
468 demux API only controls front-ends regarding their connections with demuxes; the APIs
469 used to set the other front-end parameters, such as tuning, are not defined in this
472 <para>The functions that implement the abstract interface demux should be defined static or
473 module private and registered to the Demux Directory for external access. It is not necessary
474 to implement every function in the demux_t struct, however (for example, a demux interface
475 might support Section filtering, but not TS or PES filtering). The API client is expected to
476 check the value of any function pointer before calling the function: the value of NULL means
477 “function not available”.
479 <para>Whenever the functions of the demux API modify shared data, the possibilities of lost
480 update and race condition problems should be addressed, e.g. by protecting parts of code with
481 mutexes. This is especially important on multi-processor hosts.
483 <para>Note that functions called from a bottom half context must not sleep, at least in the 2.2.x
484 kernels. Even a simple memory allocation can result in a kernel thread being put to sleep if
485 swapping is needed. For example, the Linux kernel calls the functions of a network device
486 interface from a bottom half context. Thus, if a demux API function is called from network
487 device code, the function must not sleep.
491 <section id="kdapi_fopen">
492 <title>open()</title>
495 <informaltable><tgroup cols="1"><tbody><row><entry
497 <para>This function reserves the demux for use by the caller and, if necessary,
498 initializes the demux. When the demux is no longer needed, the function close()
499 should be called. It should be possible for multiple clients to access the demux
500 at the same time. Thus, the function implementation should increment the
501 demux usage count when open() is called and decrement it when close() is
504 </row></tbody></tgroup></informaltable>
507 <informaltable><tgroup cols="1"><tbody><row><entry
509 <para>int open ( demux_t⋆ demux );</para>
511 </row></tbody></tgroup></informaltable>
514 <informaltable><tgroup cols="2"><tbody><row><entry
516 <para>demux_t* demux</para>
519 <para>Pointer to the demux API and instance data.</para>
521 </row></tbody></tgroup></informaltable>
524 <informaltable><tgroup cols="2"><tbody><row><entry
529 <para>The function was completed without errors.</para>
536 <para>Maximum usage count reached.</para>
543 <para>Bad parameter.</para>
545 </row></tbody></tgroup></informaltable>
548 <section id="kdapi_fclose">
549 <title>close()</title>
552 <informaltable><tgroup cols="1"><tbody><row><entry
554 <para>This function reserves the demux for use by the caller and, if necessary,
555 initializes the demux. When the demux is no longer needed, the function close()
556 should be called. It should be possible for multiple clients to access the demux
557 at the same time. Thus, the function implementation should increment the
558 demux usage count when open() is called and decrement it when close() is
561 </row></tbody></tgroup></informaltable>
564 <informaltable><tgroup cols="1"><tbody><row><entry
566 <para>int close(demux_t⋆ demux);</para>
568 </row></tbody></tgroup></informaltable>
571 <informaltable><tgroup cols="2"><tbody><row><entry
573 <para>demux_t* demux</para>
576 <para>Pointer to the demux API and instance data.</para>
578 </row></tbody></tgroup></informaltable>
581 <informaltable><tgroup cols="2"><tbody><row><entry
586 <para>The function was completed without errors.</para>
593 <para>The demux was not in use.</para>
600 <para>Bad parameter.</para>
602 </row></tbody></tgroup></informaltable>
605 <section id="kdapi_fwrite">
606 <title>write()</title>
609 <informaltable><tgroup cols="1"><tbody><row><entry
611 <para>This function provides the demux driver with a memory buffer containing TS
612 packets. Instead of receiving TS packets from the DVB front-end, the demux
613 driver software will read packets from memory. Any clients of this demux
614 with active TS, PES or Section filters will receive filtered data via the Demux
615 callback API (see 0). The function returns when all the data in the buffer has
616 been consumed by the demux. Demux hardware typically cannot read TS from
617 memory. If this is the case, memory-based filtering has to be implemented
618 entirely in software.</para>
620 </row></tbody></tgroup></informaltable>
623 <informaltable><tgroup cols="1"><tbody><row><entry
625 <para>int write(demux_t⋆ demux, const char⋆ buf, size_t
628 </row></tbody></tgroup></informaltable>
631 <informaltable><tgroup cols="2"><tbody><row><entry
633 <para>demux_t* demux</para>
636 <para>Pointer to the demux API and instance data.</para>
640 <para>const char* buf</para>
643 <para>Pointer to the TS data in kernel-space memory.</para>
647 <para>size_t length</para>
650 <para>Length of the TS data.</para>
652 </row></tbody></tgroup></informaltable>
655 <informaltable><tgroup cols="2"><tbody><row><entry
660 <para>The function was completed without errors.</para>
667 <para>The command is not implemented.</para>
674 <para>Bad parameter.</para>
676 </row></tbody></tgroup></informaltable>
679 role="subsection"><title>allocate_ts_feed()</title>
682 <informaltable><tgroup cols="1"><tbody><row><entry
684 <para>Allocates a new TS feed, which is used to filter the TS packets carrying a
685 certain PID. The TS feed normally corresponds to a hardware PID filter on the
688 </row></tbody></tgroup></informaltable>
691 <informaltable><tgroup cols="1"><tbody><row><entry
693 <para>int allocate_ts_feed(dmx_demux_t⋆ demux,
694 dmx_ts_feed_t⋆⋆ feed, dmx_ts_cb callback);</para>
696 </row></tbody></tgroup></informaltable>
699 <informaltable><tgroup cols="2"><tbody><row><entry
701 <para>demux_t* demux</para>
704 <para>Pointer to the demux API and instance data.</para>
708 <para>dmx_ts_feed_t**
712 <para>Pointer to the TS feed API and instance data.</para>
716 <para>dmx_ts_cb callback</para>
719 <para>Pointer to the callback function for passing received TS
722 </row></tbody></tgroup></informaltable>
725 <informaltable><tgroup cols="2"><tbody><row><entry
730 <para>The function was completed without errors.</para>
737 <para>No more TS feeds available.</para>
744 <para>The command is not implemented.</para>
751 <para>Bad parameter.</para>
753 </row></tbody></tgroup></informaltable>
756 role="subsection"><title>release_ts_feed()</title>
759 <informaltable><tgroup cols="1"><tbody><row><entry
761 <para>Releases the resources allocated with allocate_ts_feed(). Any filtering in
762 progress on the TS feed should be stopped before calling this function.</para>
764 </row></tbody></tgroup></informaltable>
767 <informaltable><tgroup cols="1"><tbody><row><entry
769 <para>int release_ts_feed(dmx_demux_t⋆ demux,
770 dmx_ts_feed_t⋆ feed);</para>
772 </row></tbody></tgroup></informaltable>
775 <informaltable><tgroup cols="2"><tbody><row><entry
777 <para>demux_t* demux</para>
780 <para>Pointer to the demux API and instance data.</para>
784 <para>dmx_ts_feed_t* feed</para>
787 <para>Pointer to the TS feed API and instance data.</para>
789 </row></tbody></tgroup></informaltable>
792 <informaltable><tgroup cols="2"><tbody><row><entry
797 <para>The function was completed without errors.</para>
804 <para>Bad parameter.</para>
806 </row></tbody></tgroup></informaltable>
809 role="subsection"><title>allocate_section_feed()</title>
812 <informaltable><tgroup cols="1"><tbody><row><entry
814 <para>Allocates a new section feed, i.e. a demux resource for filtering and receiving
815 sections. On platforms with hardware support for section filtering, a section
816 feed is directly mapped to the demux HW. On other platforms, TS packets are
817 first PID filtered in hardware and a hardware section filter then emulated in
818 software. The caller obtains an API pointer of type dmx_section_feed_t as an
819 out parameter. Using this API the caller can set filtering parameters and start
820 receiving sections.</para>
822 </row></tbody></tgroup></informaltable>
825 <informaltable><tgroup cols="1"><tbody><row><entry
827 <para>int allocate_section_feed(dmx_demux_t⋆ demux,
828 dmx_section_feed_t ⋆⋆feed, dmx_section_cb callback);</para>
830 </row></tbody></tgroup></informaltable>
833 <informaltable><tgroup cols="2"><tbody><row><entry
835 <para>demux_t *demux</para>
838 <para>Pointer to the demux API and instance data.</para>
842 <para>dmx_section_feed_t
846 <para>Pointer to the section feed API and instance data.</para>
854 <para>Pointer to the callback function for passing received
857 </row></tbody></tgroup></informaltable>
860 <informaltable><tgroup cols="2"><tbody><row><entry
865 <para>The function was completed without errors.</para>
872 <para>No more section feeds available.</para>
879 <para>The command is not implemented.</para>
886 <para>Bad parameter.</para>
888 </row></tbody></tgroup></informaltable>
891 role="subsection"><title>release_section_feed()</title>
894 <informaltable><tgroup cols="1"><tbody><row><entry
896 <para>Releases the resources allocated with allocate_section_feed(), including
897 allocated filters. Any filtering in progress on the section feed should be stopped
898 before calling this function.</para>
900 </row></tbody></tgroup></informaltable>
903 <informaltable><tgroup cols="1"><tbody><row><entry
905 <para>int release_section_feed(dmx_demux_t⋆ demux,
906 dmx_section_feed_t ⋆feed);</para>
908 </row></tbody></tgroup></informaltable>
911 <informaltable><tgroup cols="2"><tbody><row><entry
913 <para>demux_t *demux</para>
916 <para>Pointer to the demux API and instance data.</para>
920 <para>dmx_section_feed_t
924 <para>Pointer to the section feed API and instance data.</para>
926 </row></tbody></tgroup></informaltable>
929 <informaltable><tgroup cols="2"><tbody><row><entry
934 <para>The function was completed without errors.</para>
941 <para>Bad parameter.</para>
943 </row></tbody></tgroup></informaltable>
946 role="subsection"><title>descramble_mac_address()</title>
949 <informaltable><tgroup cols="1"><tbody><row><entry
951 <para>This function runs a descrambling algorithm on the destination MAC
952 address field of a DVB Datagram Section, replacing the original address
953 with its un-encrypted version. Otherwise, the description on the function
954 descramble_section_payload() applies also to this function.</para>
956 </row></tbody></tgroup></informaltable>
959 <informaltable><tgroup cols="1"><tbody><row><entry
961 <para>int descramble_mac_address(dmx_demux_t⋆ demux, __u8
962 ⋆buffer1, size_t buffer1_length, __u8 ⋆buffer2,
963 size_t buffer2_length, __u16 pid);</para>
965 </row></tbody></tgroup></informaltable>
968 <informaltable><tgroup cols="2"><tbody><row><entry
974 <para>Pointer to the demux API and instance data.</para>
978 <para>__u8 *buffer1</para>
981 <para>Pointer to the first byte of the section.</para>
985 <para>size_t buffer1_length</para>
988 <para>Length of the section data, including headers and CRC,
993 <para>__u8* buffer2</para>
996 <para>Pointer to the tail of the section data, or NULL. The
997 pointer has a non-NULL value if the section wraps past
998 the end of a circular buffer.</para>
1002 <para>size_t buffer2_length</para>
1005 <para>Length of the section data, including headers and CRC,
1010 <para>__u16 pid</para>
1013 <para>The PID on which the section was received. Useful
1014 for obtaining the descrambling key, e.g. from a DVB
1015 Common Access facility.</para>
1017 </row></tbody></tgroup></informaltable>
1020 <informaltable><tgroup cols="2"><tbody><row><entry
1025 <para>The function was completed without errors.</para>
1029 <para>-ENOSYS</para>
1032 <para>No descrambling facility available.</para>
1036 <para>-EINVAL</para>
1039 <para>Bad parameter.</para>
1041 </row></tbody></tgroup></informaltable>
1044 role="subsection"><title>descramble_section_payload()</title>
1047 <informaltable><tgroup cols="1"><tbody><row><entry
1049 <para>This function runs a descrambling algorithm on the payload of a DVB
1050 Datagram Section, replacing the original payload with its un-encrypted
1051 version. The function will be called from the demux API implementation;
1052 the API client need not call this function directly. Section-level scrambling
1053 algorithms are currently standardized only for DVB-RCC (return channel
1054 over 2-directional cable TV network) systems. For all other DVB networks,
1055 encryption schemes are likely to be proprietary to each data broadcaster. Thus,
1056 it is expected that this function pointer will have the value of NULL (i.e.,
1057 function not available) in most demux API implementations. Nevertheless, it
1058 should be possible to use the function pointer as a hook for dynamically adding
1059 a “plug-in” descrambling facility to a demux driver.</para>
1063 <para>While this function is not needed with hardware-based section descrambling,
1064 the descramble_section_payload function pointer can be used to override the
1065 default hardware-based descrambling algorithm: if the function pointer has a
1066 non-NULL value, the corresponding function should be used instead of any
1067 descrambling hardware.</para>
1069 </row></tbody></tgroup></informaltable>
1072 <informaltable><tgroup cols="1"><tbody><row><entry
1074 <para>int descramble_section_payload(dmx_demux_t⋆ demux,
1075 __u8 ⋆buffer1, size_t buffer1_length, __u8 ⋆buffer2,
1076 size_t buffer2_length, __u16 pid);</para>
1078 </row></tbody></tgroup></informaltable>
1081 <informaltable><tgroup cols="2"><tbody><row><entry
1087 <para>Pointer to the demux API and instance data.</para>
1091 <para>__u8 *buffer1</para>
1094 <para>Pointer to the first byte of the section.</para>
1098 <para>size_t buffer1_length</para>
1101 <para>Length of the section data, including headers and CRC,
1106 <para>__u8 *buffer2</para>
1109 <para>Pointer to the tail of the section data, or NULL. The
1110 pointer has a non-NULL value if the section wraps past
1111 the end of a circular buffer.</para>
1115 <para>size_t buffer2_length</para>
1118 <para>Length of the section data, including headers and CRC,
1123 <para>__u16 pid</para>
1126 <para>The PID on which the section was received. Useful
1127 for obtaining the descrambling key, e.g. from a DVB
1128 Common Access facility.</para>
1130 </row></tbody></tgroup></informaltable>
1133 <informaltable><tgroup cols="2"><tbody><row><entry
1138 <para>The function was completed without errors.</para>
1142 <para>-ENOSYS</para>
1145 <para>No descrambling facility available.</para>
1149 <para>-EINVAL</para>
1152 <para>Bad parameter.</para>
1154 </row></tbody></tgroup></informaltable>
1157 role="subsection"><title>add_frontend()</title>
1160 <informaltable><tgroup cols="1"><tbody><row><entry
1162 <para>Registers a connectivity between a demux and a front-end, i.e., indicates that
1163 the demux can be connected via a call to connect_frontend() to use the given
1164 front-end as a TS source. The client of this function has to allocate dynamic or
1165 static memory for the frontend structure and initialize its fields before calling
1166 this function. This function is normally called during the driver initialization.
1167 The caller must not free the memory of the frontend struct before successfully
1168 calling remove_frontend().</para>
1170 </row></tbody></tgroup></informaltable>
1173 <informaltable><tgroup cols="1"><tbody><row><entry
1175 <para>int add_frontend(dmx_demux_t ⋆demux, dmx_frontend_t
1176 ⋆frontend);</para>
1178 </row></tbody></tgroup></informaltable>
1181 <informaltable><tgroup cols="2"><tbody><row><entry
1187 <para>Pointer to the demux API and instance data.</para>
1191 <para>dmx_frontend_t*
1195 <para>Pointer to the front-end instance data.</para>
1197 </row></tbody></tgroup></informaltable>
1200 <informaltable><tgroup cols="2"><tbody><row><entry
1205 <para>The function was completed without errors.</para>
1209 <para>-EEXIST</para>
1212 <para>A front-end with the same value of the id field already
1217 <para>-EINUSE</para>
1220 <para>The demux is in use.</para>
1224 <para>-ENOMEM</para>
1227 <para>No more front-ends can be added.</para>
1231 <para>-EINVAL</para>
1234 <para>Bad parameter.</para>
1236 </row></tbody></tgroup></informaltable>
1239 role="subsection"><title>remove_frontend()</title>
1242 <informaltable><tgroup cols="1"><tbody><row><entry
1244 <para>Indicates that the given front-end, registered by a call to add_frontend(), can
1245 no longer be connected as a TS source by this demux. The function should be
1246 called when a front-end driver or a demux driver is removed from the system.
1247 If the front-end is in use, the function fails with the return value of -EBUSY.
1248 After successfully calling this function, the caller can free the memory of
1249 the frontend struct if it was dynamically allocated before the add_frontend()
1252 </row></tbody></tgroup></informaltable>
1255 <informaltable><tgroup cols="1"><tbody><row><entry
1257 <para>int remove_frontend(dmx_demux_t⋆ demux,
1258 dmx_frontend_t⋆ frontend);</para>
1260 </row></tbody></tgroup></informaltable>
1263 <informaltable><tgroup cols="2"><tbody><row><entry
1269 <para>Pointer to the demux API and instance data.</para>
1273 <para>dmx_frontend_t*
1277 <para>Pointer to the front-end instance data.</para>
1279 </row></tbody></tgroup></informaltable>
1282 <informaltable><tgroup cols="2"><tbody><row><entry
1287 <para>The function was completed without errors.</para>
1291 <para>-EINVAL</para>
1294 <para>Bad parameter.</para>
1301 <para>The front-end is in use, i.e. a call to connect_frontend()
1302 has not been followed by a call to disconnect_frontend().</para>
1304 </row></tbody></tgroup></informaltable>
1307 role="subsection"><title>get_frontends()</title>
1310 <informaltable><tgroup cols="1"><tbody><row><entry
1312 <para>Provides the APIs of the front-ends that have been registered for this demux.
1313 Any of the front-ends obtained with this call can be used as a parameter for
1314 connect_frontend().</para>
1318 <para>The include file demux.h contains the macro DMX_FE_ENTRY() for
1319 converting an element of the generic type struct list_head* to the type
1320 dmx_frontend_t*. The caller must not free the memory of any of the elements
1321 obtained via this function call.</para>
1323 </row></tbody></tgroup></informaltable>
1326 <informaltable><tgroup cols="1"><tbody><row><entry
1328 <para>struct list_head⋆ get_frontends(dmx_demux_t⋆ demux);</para>
1330 </row></tbody></tgroup></informaltable>
1333 <informaltable><tgroup cols="2"><tbody><row><entry
1339 <para>Pointer to the demux API and instance data.</para>
1341 </row></tbody></tgroup></informaltable>
1344 <informaltable><tgroup cols="2"><tbody><row><entry
1346 <para>dmx_demux_t*</para>
1349 <para>A list of front-end interfaces, or NULL in the case of an
1352 </row></tbody></tgroup></informaltable>
1355 role="subsection"><title>connect_frontend()</title>
1358 <informaltable><tgroup cols="1"><tbody><row><entry
1360 <para>Connects the TS output of the front-end to the input of the demux. A demux
1361 can only be connected to a front-end registered to the demux with the function
1362 add_frontend().</para>
1366 <para>It may or may not be possible to connect multiple demuxes to the same
1367 front-end, depending on the capabilities of the HW platform. When not used,
1368 the front-end should be released by calling disconnect_frontend().</para>
1370 </row></tbody></tgroup></informaltable>
1373 <informaltable><tgroup cols="1"><tbody><row><entry
1375 <para>int connect_frontend(dmx_demux_t⋆ demux,
1376 dmx_frontend_t⋆ frontend);</para>
1378 </row></tbody></tgroup></informaltable>
1381 <informaltable><tgroup cols="2"><tbody><row><entry
1387 <para>Pointer to the demux API and instance data.</para>
1391 <para>dmx_frontend_t*
1395 <para>Pointer to the front-end instance data.</para>
1397 </row></tbody></tgroup></informaltable>
1400 <informaltable><tgroup cols="2"><tbody><row><entry
1405 <para>The function was completed without errors.</para>
1409 <para>-EINVAL</para>
1412 <para>Bad parameter.</para>
1419 <para>The front-end is in use.</para>
1421 </row></tbody></tgroup></informaltable>
1424 role="subsection"><title>disconnect_frontend()</title>
1427 <informaltable><tgroup cols="1"><tbody><row><entry
1429 <para>Disconnects the demux and a front-end previously connected by a
1430 connect_frontend() call.</para>
1432 </row></tbody></tgroup></informaltable>
1435 <informaltable><tgroup cols="1"><tbody><row><entry
1437 <para>int disconnect_frontend(dmx_demux_t⋆ demux);</para>
1439 </row></tbody></tgroup></informaltable>
1442 <informaltable><tgroup cols="2"><tbody><row><entry
1448 <para>Pointer to the demux API and instance data.</para>
1450 </row></tbody></tgroup></informaltable>
1453 <informaltable><tgroup cols="2"><tbody><row><entry
1458 <para>The function was completed without errors.</para>
1462 <para>-EINVAL</para>
1465 <para>Bad parameter.</para>
1467 </row></tbody></tgroup></informaltable>
1468 </section></section>
1469 <section id="demux_callback_api">
1470 <title>Demux Callback API</title>
1471 <para>This kernel-space API comprises the callback functions that deliver filtered data to the
1472 demux client. Unlike the other APIs, these API functions are provided by the client and called
1473 from the demux code.
1475 <para>The function pointers of this abstract interface are not packed into a structure as in the
1476 other demux APIs, because the callback functions are registered and used independent
1477 of each other. As an example, it is possible for the API client to provide several
1478 callback functions for receiving TS packets and no callbacks for PES packets or
1481 <para>The functions that implement the callback API need not be re-entrant: when a demux
1482 driver calls one of these functions, the driver is not allowed to call the function again before
1483 the original call returns. If a callback is triggered by a hardware interrupt, it is recommended
1484 to use the Linux “bottom half” mechanism or start a tasklet instead of making the callback
1485 function call directly from a hardware interrupt.
1489 role="subsection"><title>dmx_ts_cb()</title>
1492 <informaltable><tgroup cols="1"><tbody><row><entry
1494 <para>This function, provided by the client of the demux API, is called from the
1495 demux code. The function is only called when filtering on this TS feed has
1496 been enabled using the start_filtering() function.</para>
1500 <para>Any TS packets that match the filter settings are copied to a circular buffer. The
1501 filtered TS packets are delivered to the client using this callback function. The
1502 size of the circular buffer is controlled by the circular_buffer_size parameter
1503 of the set() function in the TS Feed API. It is expected that the buffer1 and
1504 buffer2 callback parameters point to addresses within the circular buffer, but
1505 other implementations are also possible. Note that the called party should not
1506 try to free the memory the buffer1 and buffer2 parameters point to.</para>
1510 <para>When this function is called, the buffer1 parameter typically points to the
1511 start of the first undelivered TS packet within a circular buffer. The buffer2
1512 buffer parameter is normally NULL, except when the received TS packets have
1513 crossed the last address of the circular buffer and ”wrapped” to the beginning
1514 of the buffer. In the latter case the buffer1 parameter would contain an address
1515 within the circular buffer, while the buffer2 parameter would contain the first
1516 address of the circular buffer.</para>
1520 <para>The number of bytes delivered with this function (i.e. buffer1_length +
1521 buffer2_length) is usually equal to the value of callback_length parameter
1522 given in the set() function, with one exception: if a timeout occurs before
1523 receiving callback_length bytes of TS data, any undelivered packets are
1524 immediately delivered to the client by calling this function. The timeout
1525 duration is controlled by the set() function in the TS Feed API.</para>
1529 <para>If a TS packet is received with errors that could not be fixed by the TS-level
1530 forward error correction (FEC), the Transport_error_indicator flag of the TS
1531 packet header should be set. The TS packet should not be discarded, as
1532 the error can possibly be corrected by a higher layer protocol. If the called
1533 party is slow in processing the callback, it is possible that the circular buffer
1534 eventually fills up. If this happens, the demux driver should discard any TS
1535 packets received while the buffer is full. The error should be indicated to the
1536 client on the next callback by setting the success parameter to the value of
1537 DMX_OVERRUN_ERROR.</para>
1541 <para>The type of data returned to the callback can be selected by the new
1542 function int (*set_type) (struct dmx_ts_feed_s* feed, int type, dmx_ts_pes_t
1543 pes_type) which is part of the dmx_ts_feed_s struct (also cf. to the
1544 include file ost/demux.h) The type parameter decides if the raw TS packet
1545 (TS_PACKET) or just the payload (TS_PACKET—TS_PAYLOAD_ONLY)
1546 should be returned. If additionally the TS_DECODER bit is set the stream
1547 will also be sent to the hardware MPEG decoder. In this case, the second
1548 flag decides as what kind of data the stream should be interpreted. The
1549 possible choices are one of DMX_TS_PES_AUDIO, DMX_TS_PES_VIDEO,
1550 DMX_TS_PES_TELETEXT, DMX_TS_PES_SUBTITLE,
1551 DMX_TS_PES_PCR, or DMX_TS_PES_OTHER.</para>
1553 </row></tbody></tgroup></informaltable>
1556 <informaltable><tgroup cols="1"><tbody><row><entry
1558 <para>int dmx_ts_cb(__u8⋆ buffer1, size_t buffer1_length,
1559 __u8⋆ buffer2, size_t buffer2_length, dmx_ts_feed_t⋆
1560 source, dmx_success_t success);</para>
1562 </row></tbody></tgroup></informaltable>
1565 <informaltable><tgroup cols="2"><tbody><row><entry
1567 <para>__u8* buffer1</para>
1570 <para>Pointer to the start of the filtered TS packets.</para>
1574 <para>size_t buffer1_length</para>
1577 <para>Length of the TS data in buffer1.</para>
1581 <para>__u8* buffer2</para>
1584 <para>Pointer to the tail of the filtered TS packets, or NULL.</para>
1588 <para>size_t buffer2_length</para>
1591 <para>Length of the TS data in buffer2.</para>
1595 <para>dmx_ts_feed_t*
1599 <para>Indicates which TS feed is the source of the callback.</para>
1607 <para>Indicates if there was an error in TS reception.</para>
1609 </row></tbody></tgroup></informaltable>
1612 <informaltable><tgroup cols="2"><tbody><row><entry
1617 <para>Continue filtering.</para>
1624 <para>Stop filtering - has the same effect as a call to
1625 stop_filtering() on the TS Feed API.</para>
1627 </row></tbody></tgroup></informaltable>
1630 role="subsection"><title>dmx_section_cb()</title>
1633 <informaltable><tgroup cols="1"><tbody><row><entry
1635 <para>This function, provided by the client of the demux API, is called from the
1636 demux code. The function is only called when filtering of sections has been
1637 enabled using the function start_filtering() of the section feed API. When the
1638 demux driver has received a complete section that matches at least one section
1639 filter, the client is notified via this callback function. Normally this function is
1640 called for each received section; however, it is also possible to deliver multiple
1641 sections with one callback, for example when the system load is high. If an
1642 error occurs while receiving a section, this function should be called with
1643 the corresponding error type set in the success field, whether or not there is
1644 data to deliver. The Section Feed implementation should maintain a circular
1645 buffer for received sections. However, this is not necessary if the Section Feed
1646 API is implemented as a client of the TS Feed API, because the TS Feed
1647 implementation then buffers the received data. The size of the circular buffer
1648 can be configured using the set() function in the Section Feed API. If there
1649 is no room in the circular buffer when a new section is received, the section
1650 must be discarded. If this happens, the value of the success parameter should
1651 be DMX_OVERRUN_ERROR on the next callback.</para>
1653 </row></tbody></tgroup></informaltable>
1656 <informaltable><tgroup cols="1"><tbody><row><entry
1658 <para>int dmx_section_cb(__u8⋆ buffer1, size_t
1659 buffer1_length, __u8⋆ buffer2, size_t
1660 buffer2_length, dmx_section_filter_t⋆ source,
1661 dmx_success_t success);</para>
1663 </row></tbody></tgroup></informaltable>
1666 <informaltable><tgroup cols="2"><tbody><row><entry
1668 <para>__u8* buffer1</para>
1671 <para>Pointer to the start of the filtered section, e.g. within the
1672 circular buffer of the demux driver.</para>
1676 <para>size_t buffer1_length</para>
1679 <para>Length of the filtered section data in buffer1, including
1680 headers and CRC.</para>
1684 <para>__u8* buffer2</para>
1687 <para>Pointer to the tail of the filtered section data, or NULL.
1688 Useful to handle the wrapping of a circular buffer.</para>
1692 <para>size_t buffer2_length</para>
1695 <para>Length of the filtered section data in buffer2, including
1696 headers and CRC.</para>
1700 <para>dmx_section_filter_t*
1704 <para>Indicates the filter that triggered the callback.</para>
1712 <para>Indicates if there was an error in section reception.</para>
1714 </row></tbody></tgroup></informaltable>
1717 <informaltable><tgroup cols="2"><tbody><row><entry
1722 <para>Continue filtering.</para>
1729 <para>Stop filtering - has the same effect as a call to
1730 stop_filtering() on the Section Feed API.</para>
1732 </row></tbody></tgroup></informaltable>
1733 </section></section>
1734 <section id="ts_feed_api">
1735 <title>TS Feed API</title>
1736 <para>A TS feed is typically mapped to a hardware PID filter on the demux chip.
1737 Using this API, the client can set the filtering properties to start/stop filtering TS
1738 packets on a particular TS feed. The API is defined as an abstract interface of the type
1741 <para>The functions that implement the interface should be defined static or module private. The
1742 client can get the handle of a TS feed API by calling the function allocate_ts_feed() in the
1747 role="subsection"><title>set()</title>
1750 <informaltable><tgroup cols="1"><tbody><row><entry
1752 <para>This function sets the parameters of a TS feed. Any filtering in progress on the
1753 TS feed must be stopped before calling this function.</para>
1755 </row></tbody></tgroup></informaltable>
1758 <informaltable><tgroup cols="1"><tbody><row><entry
1760 <para>int set ( dmx_ts_feed_t⋆ feed, __u16 pid, size_t
1761 callback_length, size_t circular_buffer_size, int
1762 descramble, struct timespec timeout);</para>
1764 </row></tbody></tgroup></informaltable>
1767 <informaltable><tgroup cols="2"><tbody><row><entry
1769 <para>dmx_ts_feed_t* feed</para>
1772 <para>Pointer to the TS feed API and instance data.</para>
1776 <para>__u16 pid</para>
1779 <para>PID value to filter. Only the TS packets carrying the
1780 specified PID will be passed to the API client.</para>
1785 callback_length</para>
1788 <para>Number of bytes to deliver with each call to the
1789 dmx_ts_cb() callback function. The value of this
1790 parameter should be a multiple of 188.</para>
1795 circular_buffer_size</para>
1798 <para>Size of the circular buffer for the filtered TS packets.</para>
1802 <para>int descramble</para>
1805 <para>If non-zero, descramble the filtered TS packets.</para>
1809 <para>struct timespec
1813 <para>Maximum time to wait before delivering received TS
1814 packets to the client.</para>
1816 </row></tbody></tgroup></informaltable>
1819 <informaltable><tgroup cols="2"><tbody><row><entry
1824 <para>The function was completed without errors.</para>
1828 <para>-ENOMEM</para>
1831 <para>Not enough memory for the requested buffer size.</para>
1835 <para>-ENOSYS</para>
1838 <para>No descrambling facility available for TS.</para>
1842 <para>-EINVAL</para>
1845 <para>Bad parameter.</para>
1847 </row></tbody></tgroup></informaltable>
1850 role="subsection"><title>start_filtering()</title>
1853 <informaltable><tgroup cols="1"><tbody><row><entry
1855 <para>Starts filtering TS packets on this TS feed, according to its settings. The PID
1856 value to filter can be set by the API client. All matching TS packets are
1857 delivered asynchronously to the client, using the callback function registered
1858 with allocate_ts_feed().</para>
1860 </row></tbody></tgroup></informaltable>
1863 <informaltable><tgroup cols="1"><tbody><row><entry
1865 <para>int start_filtering(dmx_ts_feed_t⋆ feed);</para>
1867 </row></tbody></tgroup></informaltable>
1870 <informaltable><tgroup cols="2"><tbody><row><entry
1872 <para>dmx_ts_feed_t* feed</para>
1875 <para>Pointer to the TS feed API and instance data.</para>
1877 </row></tbody></tgroup></informaltable>
1880 <informaltable><tgroup cols="2"><tbody><row><entry
1885 <para>The function was completed without errors.</para>
1889 <para>-EINVAL</para>
1892 <para>Bad parameter.</para>
1894 </row></tbody></tgroup></informaltable>
1897 role="subsection"><title>stop_filtering()</title>
1900 <informaltable><tgroup cols="1"><tbody><row><entry
1902 <para>Stops filtering TS packets on this TS feed.</para>
1904 </row></tbody></tgroup></informaltable>
1907 <informaltable><tgroup cols="1"><tbody><row><entry
1909 <para>int stop_filtering(dmx_ts_feed_t⋆ feed);</para>
1911 </row></tbody></tgroup></informaltable>
1914 <informaltable><tgroup cols="2"><tbody><row><entry
1916 <para>dmx_ts_feed_t* feed</para>
1919 <para>Pointer to the TS feed API and instance data.</para>
1921 </row></tbody></tgroup></informaltable>
1924 <informaltable><tgroup cols="2"><tbody><row><entry
1929 <para>The function was completed without errors.</para>
1933 <para>-EINVAL</para>
1936 <para>Bad parameter.</para>
1938 </row></tbody></tgroup></informaltable>
1939 </section></section>
1940 <section id="section_feed_api">
1941 <title>Section Feed API</title>
1942 <para>A section feed is a resource consisting of a PID filter and a set of section filters. Using this
1943 API, the client can set the properties of a section feed and to start/stop filtering. The API is
1944 defined as an abstract interface of the type dmx_section_feed_t. The functions that implement
1945 the interface should be defined static or module private. The client can get the handle of
1946 a section feed API by calling the function allocate_section_feed() in the demux
1949 <para>On demux platforms that provide section filtering in hardware, the Section Feed API
1950 implementation provides a software wrapper for the demux hardware. Other platforms may
1951 support only PID filtering in hardware, requiring that TS packets are converted to sections in
1952 software. In the latter case the Section Feed API implementation can be a client of the TS
1957 <section id="kdapi_set">
1958 <title>set()</title>
1961 <informaltable><tgroup cols="1"><tbody><row><entry
1963 <para>This function sets the parameters of a section feed. Any filtering in progress on
1964 the section feed must be stopped before calling this function. If descrambling
1965 is enabled, the payload_scrambling_control and address_scrambling_control
1966 fields of received DVB datagram sections should be observed. If either one is
1967 non-zero, the section should be descrambled either in hardware or using the
1968 functions descramble_mac_address() and descramble_section_payload() of the
1969 demux API. Note that according to the MPEG-2 Systems specification, only
1970 the payloads of private sections can be scrambled while the rest of the section
1971 data must be sent in the clear.</para>
1973 </row></tbody></tgroup></informaltable>
1976 <informaltable><tgroup cols="1"><tbody><row><entry
1978 <para>int set(dmx_section_feed_t⋆ feed, __u16 pid, size_t
1979 circular_buffer_size, int descramble, int
1982 </row></tbody></tgroup></informaltable>
1985 <informaltable><tgroup cols="2"><tbody><row><entry
1987 <para>dmx_section_feed_t*
1991 <para>Pointer to the section feed API and instance data.</para>
1995 <para>__u16 pid</para>
1998 <para>PID value to filter; only the TS packets carrying the
1999 specified PID will be accepted.</para>
2004 circular_buffer_size</para>
2007 <para>Size of the circular buffer for filtered sections.</para>
2011 <para>int descramble</para>
2014 <para>If non-zero, descramble any sections that are scrambled.</para>
2018 <para>int check_crc</para>
2021 <para>If non-zero, check the CRC values of filtered sections.</para>
2023 </row></tbody></tgroup></informaltable>
2026 <informaltable><tgroup cols="2"><tbody><row><entry
2031 <para>The function was completed without errors.</para>
2035 <para>-ENOMEM</para>
2038 <para>Not enough memory for the requested buffer size.</para>
2042 <para>-ENOSYS</para>
2045 <para>No descrambling facility available for sections.</para>
2049 <para>-EINVAL</para>
2052 <para>Bad parameters.</para>
2054 </row></tbody></tgroup></informaltable>
2057 role="subsection"><title>allocate_filter()</title>
2060 <informaltable><tgroup cols="1"><tbody><row><entry
2062 <para>This function is used to allocate a section filter on the demux. It should only be
2063 called when no filtering is in progress on this section feed. If a filter cannot be
2064 allocated, the function fails with -ENOSPC. See in section ?? for the format of
2065 the section filter.</para>
2069 <para>The bitfields filter_mask and filter_value should only be modified when no
2070 filtering is in progress on this section feed. filter_mask controls which bits of
2071 filter_value are compared with the section headers/payload. On a binary value
2072 of 1 in filter_mask, the corresponding bits are compared. The filter only accepts
2073 sections that are equal to filter_value in all the tested bit positions. Any changes
2074 to the values of filter_mask and filter_value are guaranteed to take effect only
2075 when the start_filtering() function is called next time. The parent pointer in
2076 the struct is initialized by the API implementation to the value of the feed
2077 parameter. The priv pointer is not used by the API implementation, and can
2078 thus be freely utilized by the caller of this function. Any data pointed to by the
2079 priv pointer is available to the recipient of the dmx_section_cb() function call.</para>
2083 <para>While the maximum section filter length (DMX_MAX_FILTER_SIZE) is
2084 currently set at 16 bytes, hardware filters of that size are not available on all
2085 platforms. Therefore, section filtering will often take place first in hardware,
2086 followed by filtering in software for the header bytes that were not covered
2087 by a hardware filter. The filter_mask field can be checked to determine how
2088 many bytes of the section filter are actually used, and if the hardware filter will
2089 suffice. Additionally, software-only section filters can optionally be allocated
2090 to clients when all hardware section filters are in use. Note that on most demux
2091 hardware it is not possible to filter on the section_length field of the section
2092 header – thus this field is ignored, even though it is included in filter_value and
2093 filter_mask fields.</para>
2095 </row></tbody></tgroup></informaltable>
2098 <informaltable><tgroup cols="1"><tbody><row><entry
2100 <para>int allocate_filter(dmx_section_feed_t⋆ feed,
2101 dmx_section_filter_t⋆⋆ filter);</para>
2103 </row></tbody></tgroup></informaltable>
2106 <informaltable><tgroup cols="2"><tbody><row><entry
2108 <para>dmx_section_feed_t*
2112 <para>Pointer to the section feed API and instance data.</para>
2116 <para>dmx_section_filter_t**
2120 <para>Pointer to the allocated filter.</para>
2122 </row></tbody></tgroup></informaltable>
2125 <informaltable><tgroup cols="2"><tbody><row><entry
2130 <para>The function was completed without errors.</para>
2134 <para>-ENOSPC</para>
2137 <para>No filters of given type and length available.</para>
2141 <para>-EINVAL</para>
2144 <para>Bad parameters.</para>
2146 </row></tbody></tgroup></informaltable>
2149 role="subsection"><title>release_filter()</title>
2152 <informaltable><tgroup cols="1"><tbody><row><entry
2154 <para>This function releases all the resources of a previously allocated section filter.
2155 The function should not be called while filtering is in progress on this section
2156 feed. After calling this function, the caller should not try to dereference the
2157 filter pointer.</para>
2159 </row></tbody></tgroup></informaltable>
2162 <informaltable><tgroup cols="1"><tbody><row><entry
2164 <para>int release_filter ( dmx_section_feed_t⋆ feed,
2165 dmx_section_filter_t⋆ filter);</para>
2167 </row></tbody></tgroup></informaltable>
2170 <informaltable><tgroup cols="2"><tbody><row><entry
2172 <para>dmx_section_feed_t*
2176 <para>Pointer to the section feed API and instance data.</para>
2180 <para>dmx_section_filter_t*
2184 <para>I/O Pointer to the instance data of a section filter.</para>
2186 </row></tbody></tgroup></informaltable>
2189 <informaltable><tgroup cols="2"><tbody><row><entry
2194 <para>The function was completed without errors.</para>
2198 <para>-ENODEV</para>
2201 <para>No such filter allocated.</para>
2205 <para>-EINVAL</para>
2208 <para>Bad parameter.</para>
2210 </row></tbody></tgroup></informaltable>
2213 role="subsection"><title>start_filtering()</title>
2216 <informaltable><tgroup cols="1"><tbody><row><entry
2218 <para>Starts filtering sections on this section feed, according to its settings. Sections
2219 are first filtered based on their PID and then matched with the section
2220 filters allocated for this feed. If the section matches the PID filter and
2221 at least one section filter, it is delivered to the API client. The section
2222 is delivered asynchronously using the callback function registered with
2223 allocate_section_feed().</para>
2225 </row></tbody></tgroup></informaltable>
2228 <informaltable><tgroup cols="1"><tbody><row><entry
2230 <para>int start_filtering ( dmx_section_feed_t⋆ feed );</para>
2232 </row></tbody></tgroup></informaltable>
2235 <informaltable><tgroup cols="2"><tbody><row><entry
2237 <para>dmx_section_feed_t*
2241 <para>Pointer to the section feed API and instance data.</para>
2243 </row></tbody></tgroup></informaltable>
2246 <informaltable><tgroup cols="2"><tbody><row><entry
2251 <para>The function was completed without errors.</para>
2255 <para>-EINVAL</para>
2258 <para>Bad parameter.</para>
2260 </row></tbody></tgroup></informaltable>
2263 role="subsection"><title>stop_filtering()</title>
2266 <informaltable><tgroup cols="1"><tbody><row><entry
2268 <para>Stops filtering sections on this section feed. Note that any changes to the
2269 filtering parameters (filter_value, filter_mask, etc.) should only be made when
2270 filtering is stopped.</para>
2272 </row></tbody></tgroup></informaltable>
2275 <informaltable><tgroup cols="1"><tbody><row><entry
2277 <para>int stop_filtering ( dmx_section_feed_t⋆ feed );</para>
2279 </row></tbody></tgroup></informaltable>
2282 <informaltable><tgroup cols="2"><tbody><row><entry
2284 <para>dmx_section_feed_t*
2288 <para>Pointer to the section feed API and instance data.</para>
2290 </row></tbody></tgroup></informaltable>
2293 <informaltable><tgroup cols="2"><tbody><row><entry
2298 <para>The function was completed without errors.</para>
2302 <para>-EINVAL</para>
2305 <para>Bad parameter.</para>
2307 </row></tbody></tgroup></informaltable>