···11-<title>Kernel Demux API</title>22-<para>The kernel demux API defines a driver-internal interface for registering low-level,33-hardware specific driver to a hardware independent demux layer. It is only of interest for44-DVB device driver writers. The header file for this API is named <constant>demux.h</constant> and located in55-<constant>">drivers/media/dvb-core</constant>.66-</para>77-<para>Maintainer note: This section must be reviewed. It is probably out of date.88-</para>99-1010-<section id="kernel_demux_data_types">1111-<title>Kernel Demux Data Types</title>1212-1313-1414-</section>1515-<section id="ts_filter_types">1616-<title>TS filter types</title>1717- <programlisting>1818- /⋆--------------------------------------------------------------------------⋆/1919- /⋆ TS packet reception ⋆/2020- /⋆--------------------------------------------------------------------------⋆/2121-2222- /⋆ TS filter type for set_type() ⋆/2323-2424- #define TS_PACKET 1 /⋆ send TS packets (188 bytes) to callback (default) ⋆/2525- #define TS_PAYLOAD_ONLY 2 /⋆ in case TS_PACKET is set, only send the TS2626- payload (<=184 bytes per packet) to callback ⋆/2727- #define TS_DECODER 4 /⋆ send stream to built-in decoder (if present) ⋆/2828-</programlisting>2929-3030-</section>3131-<section id="dmx_ts_pes_t">3232-<title>dmx_ts_pes_t</title>3333-<para>The structure3434-</para>3535-<programlisting>3636- typedef enum3737- {3838- DMX_TS_PES_AUDIO, /⋆ also send packets to audio decoder (if it exists) ⋆/3939- DMX_TS_PES_VIDEO, /⋆ ... ⋆/4040- DMX_TS_PES_TELETEXT,4141- DMX_TS_PES_SUBTITLE,4242- DMX_TS_PES_PCR,4343- DMX_TS_PES_OTHER,4444- } dmx_ts_pes_t;4545-</programlisting>4646-<para>describes the PES type for filters which write to a built-in decoder. The correspond (and4747-should be kept identical) to the types in the demux device.4848-</para>4949-<programlisting>5050- struct dmx_ts_feed_s {5151- int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/5252- struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/5353- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/5454- int (⋆set) (struct dmx_ts_feed_s⋆ feed,5555- __u16 pid,5656- size_t callback_length,5757- size_t circular_buffer_size,5858- int descramble,5959- struct timespec timeout);6060- int (⋆start_filtering) (struct dmx_ts_feed_s⋆ feed);6161- int (⋆stop_filtering) (struct dmx_ts_feed_s⋆ feed);6262- int (⋆set_type) (struct dmx_ts_feed_s⋆ feed,6363- int type,6464- dmx_ts_pes_t pes_type);6565- };6666-6767- typedef struct dmx_ts_feed_s dmx_ts_feed_t;6868-</programlisting>6969- <programlisting>7070- /⋆--------------------------------------------------------------------------⋆/7171- /⋆ PES packet reception (not supported yet) ⋆/7272- /⋆--------------------------------------------------------------------------⋆/7373-7474- typedef struct dmx_pes_filter_s {7575- struct dmx_pes_s⋆ parent; /⋆ Back-pointer ⋆/7676- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/7777- } dmx_pes_filter_t;7878-</programlisting>7979- <programlisting>8080- typedef struct dmx_pes_feed_s {8181- int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/8282- struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/8383- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/8484- int (⋆set) (struct dmx_pes_feed_s⋆ feed,8585- __u16 pid,8686- size_t circular_buffer_size,8787- int descramble,8888- struct timespec timeout);8989- int (⋆start_filtering) (struct dmx_pes_feed_s⋆ feed);9090- int (⋆stop_filtering) (struct dmx_pes_feed_s⋆ feed);9191- int (⋆allocate_filter) (struct dmx_pes_feed_s⋆ feed,9292- dmx_pes_filter_t⋆⋆ filter);9393- int (⋆release_filter) (struct dmx_pes_feed_s⋆ feed,9494- dmx_pes_filter_t⋆ filter);9595- } dmx_pes_feed_t;9696-</programlisting>9797- <programlisting>9898- typedef struct {9999- __u8 filter_value [DMX_MAX_FILTER_SIZE];100100- __u8 filter_mask [DMX_MAX_FILTER_SIZE];101101- struct dmx_section_feed_s⋆ parent; /⋆ Back-pointer ⋆/102102- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/103103- } dmx_section_filter_t;104104-</programlisting>105105- <programlisting>106106- struct dmx_section_feed_s {107107- int is_filtering; /⋆ Set to non-zero when filtering in progress ⋆/108108- struct dmx_demux_s⋆ parent; /⋆ Back-pointer ⋆/109109- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/110110- int (⋆set) (struct dmx_section_feed_s⋆ feed,111111- __u16 pid,112112- size_t circular_buffer_size,113113- int descramble,114114- int check_crc);115115- int (⋆allocate_filter) (struct dmx_section_feed_s⋆ feed,116116- dmx_section_filter_t⋆⋆ filter);117117- int (⋆release_filter) (struct dmx_section_feed_s⋆ feed,118118- dmx_section_filter_t⋆ filter);119119- int (⋆start_filtering) (struct dmx_section_feed_s⋆ feed);120120- int (⋆stop_filtering) (struct dmx_section_feed_s⋆ feed);121121- };122122- typedef struct dmx_section_feed_s dmx_section_feed_t;123123-124124- /⋆--------------------------------------------------------------------------⋆/125125- /⋆ Callback functions ⋆/126126- /⋆--------------------------------------------------------------------------⋆/127127-128128- typedef int (⋆dmx_ts_cb) ( __u8 ⋆ buffer1,129129- size_t buffer1_length,130130- __u8 ⋆ buffer2,131131- size_t buffer2_length,132132- dmx_ts_feed_t⋆ source)133133-134134- typedef int (⋆dmx_section_cb) ( __u8 ⋆ buffer1,135135- size_t buffer1_len,136136- __u8 ⋆ buffer2,137137- size_t buffer2_len,138138- dmx_section_filter_t ⋆ source);139139-140140- typedef int (⋆dmx_pes_cb) ( __u8 ⋆ buffer1,141141- size_t buffer1_len,142142- __u8 ⋆ buffer2,143143- size_t buffer2_len,144144- dmx_pes_filter_t⋆ source);145145-146146- /⋆--------------------------------------------------------------------------⋆/147147- /⋆ DVB Front-End ⋆/148148- /⋆--------------------------------------------------------------------------⋆/149149-150150- typedef enum {151151- DMX_MEMORY_FE,152152- DMX_FRONTEND_0,153153- } dmx_frontend_source;154154-155155- typedef struct {156156- /⋆ The following char⋆ fields point to NULL terminated strings ⋆/157157- char⋆ id; /⋆ Unique front-end identifier ⋆/158158- char⋆ vendor; /⋆ Name of the front-end vendor ⋆/159159- char⋆ model; /⋆ Name of the front-end model ⋆/160160- struct list_head connectivity_list; /⋆ List of front-ends that can161161- be connected to a particular162162- demux ⋆/163163- void⋆ priv; /⋆ Pointer to private data of the API client ⋆/164164- dmx_frontend_source source;165165- } dmx_frontend_t;166166-167167- /⋆--------------------------------------------------------------------------⋆/168168- /⋆ MPEG-2 TS Demux ⋆/169169- /⋆--------------------------------------------------------------------------⋆/170170-171171- /⋆172172- ⋆ Flags OR'ed in the capabilites field of struct dmx_demux_s.173173- ⋆/174174-175175- #define DMX_TS_FILTERING 1176176- #define DMX_PES_FILTERING 2177177- #define DMX_SECTION_FILTERING 4178178- #define DMX_MEMORY_BASED_FILTERING 8 /⋆ write() available ⋆/179179- #define DMX_CRC_CHECKING 16180180- #define DMX_TS_DESCRAMBLING 32181181- #define DMX_SECTION_PAYLOAD_DESCRAMBLING 64182182- #define DMX_MAC_ADDRESS_DESCRAMBLING 128183183-</programlisting>184184-185185-</section>186186-<section id="demux_demux_t">187187-<title>demux_demux_t</title>188188- <programlisting>189189- /⋆190190- ⋆ DMX_FE_ENTRY(): Casts elements in the list of registered191191- ⋆ front-ends from the generic type struct list_head192192- ⋆ to the type ⋆ dmx_frontend_t193193- ⋆.194194- ⋆/195195-</programlisting>196196-197197-</section>198198-<section id="demux_directory">199199-<title>Demux directory</title>200200- <programlisting>201201- /⋆202202- ⋆ DMX_DIR_ENTRY(): Casts elements in the list of registered203203- ⋆ demuxes from the generic type struct list_head⋆ to the type dmx_demux_t204204- ⋆.205205- ⋆/206206-207207- #define DMX_DIR_ENTRY(list) list_entry(list, dmx_demux_t, reg_list)208208-209209- int dmx_register_demux (dmx_demux_t⋆ demux);210210- int dmx_unregister_demux (dmx_demux_t⋆ demux);211211- struct list_head⋆ dmx_get_demuxes (void);212212-</programlisting>213213- </section></section>214214-<section id="demux_directory_api">215215-<title>Demux Directory API</title>216216-<para>The demux directory is a Linux kernel-wide facility for registering and accessing the217217-MPEG-2 TS demuxes in the system. Run-time registering and unregistering of demux drivers218218-is possible using this API.219219-</para>220220-<para>All demux drivers in the directory implement the abstract interface dmx_demux_t.221221-</para>222222-223223-<section224224-role="subsection"><title>dmx_register_demux()</title>225225-<para>DESCRIPTION226226-</para>227227-<informaltable><tgroup cols="1"><tbody><row><entry228228- align="char">229229-<para>This function makes a demux driver interface available to the Linux kernel. It is230230- usually called by the init_module() function of the kernel module that contains231231- the demux driver. The caller of this function is responsible for allocating232232- dynamic or static memory for the demux structure and for initializing its fields233233- before calling this function. The memory allocated for the demux structure234234- must not be freed before calling dmx_unregister_demux(),</para>235235-</entry>236236- </row></tbody></tgroup></informaltable>237237-<para>SYNOPSIS238238-</para>239239-<informaltable><tgroup cols="1"><tbody><row><entry240240- align="char">241241-<para>int dmx_register_demux ( dmx_demux_t ⋆demux )</para>242242-</entry>243243- </row></tbody></tgroup></informaltable>244244-<para>PARAMETERS245245-</para>246246-<informaltable><tgroup cols="2"><tbody><row><entry247247- align="char">248248-<para>dmx_demux_t*249249- demux</para>250250-</entry><entry251251- align="char">252252-<para>Pointer to the demux structure.</para>253253-</entry>254254- </row></tbody></tgroup></informaltable>255255-<para>RETURNS256256-</para>257257-<informaltable><tgroup cols="2"><tbody><row><entry258258- align="char">259259-<para>0</para>260260-</entry><entry261261- align="char">262262-<para>The function was completed without errors.</para>263263-</entry>264264- </row><row><entry265265- align="char">266266-<para>-EEXIST</para>267267-</entry><entry268268- align="char">269269-<para>A demux with the same value of the id field already stored270270- in the directory.</para>271271-</entry>272272- </row><row><entry273273- align="char">274274-<para>-ENOSPC</para>275275-</entry><entry276276- align="char">277277-<para>No space left in the directory.</para>278278-</entry>279279- </row></tbody></tgroup></informaltable>280280-281281-</section><section282282-role="subsection"><title>dmx_unregister_demux()</title>283283-<para>DESCRIPTION284284-</para>285285-<informaltable><tgroup cols="1"><tbody><row><entry286286- align="char">287287-<para>This function is called to indicate that the given demux interface is no288288- longer available. The caller of this function is responsible for freeing the289289- memory of the demux structure, if it was dynamically allocated before calling290290- dmx_register_demux(). The cleanup_module() function of the kernel module291291- that contains the demux driver should call this function. Note that this function292292- fails if the demux is currently in use, i.e., release_demux() has not been called293293- for the interface.</para>294294-</entry>295295- </row></tbody></tgroup></informaltable>296296-<para>SYNOPSIS297297-</para>298298-<informaltable><tgroup cols="1"><tbody><row><entry299299- align="char">300300-<para>int dmx_unregister_demux ( dmx_demux_t ⋆demux )</para>301301-</entry>302302- </row></tbody></tgroup></informaltable>303303-<para>PARAMETERS304304-</para>305305-<informaltable><tgroup cols="2"><tbody><row><entry306306- align="char">307307-<para>dmx_demux_t*308308- demux</para>309309-</entry><entry310310- align="char">311311-<para>Pointer to the demux structure which is to be312312- unregistered.</para>313313-</entry>314314- </row></tbody></tgroup></informaltable>315315-<para>RETURNS316316-</para>317317-<informaltable><tgroup cols="2"><tbody><row><entry318318- align="char">319319-<para>0</para>320320-</entry><entry321321- align="char">322322-<para>The function was completed without errors.</para>323323-</entry>324324- </row><row><entry325325- align="char">326326-<para>ENODEV</para>327327-</entry><entry328328- align="char">329329-<para>The specified demux is not registered in the demux330330- directory.</para>331331-</entry>332332- </row><row><entry333333- align="char">334334-<para>EBUSY</para>335335-</entry><entry336336- align="char">337337-<para>The specified demux is currently in use.</para>338338-</entry>339339- </row></tbody></tgroup></informaltable>340340-341341-</section><section342342-role="subsection"><title>dmx_get_demuxes()</title>343343-<para>DESCRIPTION344344-</para>345345-<informaltable><tgroup cols="1"><tbody><row><entry346346- align="char">347347-<para>Provides the caller with the list of registered demux interfaces, using the348348- standard list structure defined in the include file linux/list.h. The include file349349- demux.h defines the macro DMX_DIR_ENTRY() for converting an element of350350- the generic type struct list_head* to the type dmx_demux_t*. The caller must351351- not free the memory of any of the elements obtained via this function call.</para>352352-</entry>353353- </row></tbody></tgroup></informaltable>354354-<para>SYNOPSIS355355-</para>356356-<informaltable><tgroup cols="1"><tbody><row><entry357357- align="char">358358-<para>struct list_head ⋆dmx_get_demuxes ()</para>359359-</entry>360360- </row></tbody></tgroup></informaltable>361361-<para>PARAMETERS362362-</para>363363-<informaltable><tgroup cols="2"><tbody><row><entry364364- align="char">365365-<para>none</para>366366-</entry>367367- </row></tbody></tgroup></informaltable>368368-<para>RETURNS369369-</para>370370-<informaltable><tgroup cols="2"><tbody><row><entry371371- align="char">372372-<para>struct list_head *</para>373373-</entry><entry374374- align="char">375375-<para>A list of demux interfaces, or NULL in the case of an376376- empty list.</para>377377-</entry>378378- </row></tbody></tgroup></informaltable>379379- </section></section>380380-<section id="demux_api">381381-<title>Demux API</title>382382-<para>The demux API should be implemented for each demux in the system. It is used to select383383-the TS source of a demux and to manage the demux resources. When the demux384384-client allocates a resource via the demux API, it receives a pointer to the API of that385385-resource.386386-</para>387387-<para>Each demux receives its TS input from a DVB front-end or from memory, as set via the388388-demux API. In a system with more than one front-end, the API can be used to select one of389389-the DVB front-ends as a TS source for a demux, unless this is fixed in the HW platform. The390390-demux API only controls front-ends regarding their connections with demuxes; the APIs391391-used to set the other front-end parameters, such as tuning, are not defined in this392392-document.393393-</para>394394-<para>The functions that implement the abstract interface demux should be defined static or395395-module private and registered to the Demux Directory for external access. It is not necessary396396-to implement every function in the demux_t struct, however (for example, a demux interface397397-might support Section filtering, but not TS or PES filtering). The API client is expected to398398-check the value of any function pointer before calling the function: the value of NULL means399399-“function not available”.400400-</para>401401-<para>Whenever the functions of the demux API modify shared data, the possibilities of lost402402-update and race condition problems should be addressed, e.g. by protecting parts of code with403403-mutexes. This is especially important on multi-processor hosts.404404-</para>405405-<para>Note that functions called from a bottom half context must not sleep, at least in the 2.2.x406406-kernels. Even a simple memory allocation can result in a kernel thread being put to sleep if407407-swapping is needed. For example, the Linux kernel calls the functions of a network device408408-interface from a bottom half context. Thus, if a demux API function is called from network409409-device code, the function must not sleep.410410-</para>411411-412412-</section>413413-<section id="demux_callback_api">414414-<title>Demux Callback API</title>415415-<para>This kernel-space API comprises the callback functions that deliver filtered data to the416416-demux client. Unlike the other APIs, these API functions are provided by the client and called417417-from the demux code.418418-</para>419419-<para>The function pointers of this abstract interface are not packed into a structure as in the420420-other demux APIs, because the callback functions are registered and used independent421421-of each other. As an example, it is possible for the API client to provide several422422-callback functions for receiving TS packets and no callbacks for PES packets or423423-sections.424424-</para>425425-<para>The functions that implement the callback API need not be re-entrant: when a demux426426-driver calls one of these functions, the driver is not allowed to call the function again before427427-the original call returns. If a callback is triggered by a hardware interrupt, it is recommended428428-to use the Linux “bottom half” mechanism or start a tasklet instead of making the callback429429-function call directly from a hardware interrupt.430430-</para>431431-432432-<section433433-role="subsection"><title>dmx_ts_cb()</title>434434-<para>DESCRIPTION435435-</para>436436-<informaltable><tgroup cols="1"><tbody><row><entry437437- align="char">438438-<para>This function, provided by the client of the demux API, is called from the439439- demux code. The function is only called when filtering on this TS feed has440440- been enabled using the start_filtering() function.</para>441441-</entry>442442- </row><row><entry443443- align="char">444444-<para>Any TS packets that match the filter settings are copied to a circular buffer. The445445- filtered TS packets are delivered to the client using this callback function. The446446- size of the circular buffer is controlled by the circular_buffer_size parameter447447- of the set() function in the TS Feed API. It is expected that the buffer1 and448448- buffer2 callback parameters point to addresses within the circular buffer, but449449- other implementations are also possible. Note that the called party should not450450- try to free the memory the buffer1 and buffer2 parameters point to.</para>451451-</entry>452452- </row><row><entry453453- align="char">454454-<para>When this function is called, the buffer1 parameter typically points to the455455- start of the first undelivered TS packet within a circular buffer. The buffer2456456- buffer parameter is normally NULL, except when the received TS packets have457457- crossed the last address of the circular buffer and ”wrapped” to the beginning458458- of the buffer. In the latter case the buffer1 parameter would contain an address459459- within the circular buffer, while the buffer2 parameter would contain the first460460- address of the circular buffer.</para>461461-</entry>462462- </row><row><entry463463- align="char">464464-<para>The number of bytes delivered with this function (i.e. buffer1_length +465465- buffer2_length) is usually equal to the value of callback_length parameter466466- given in the set() function, with one exception: if a timeout occurs before467467- receiving callback_length bytes of TS data, any undelivered packets are468468- immediately delivered to the client by calling this function. The timeout469469- duration is controlled by the set() function in the TS Feed API.</para>470470-</entry>471471- </row><row><entry472472- align="char">473473-<para>If a TS packet is received with errors that could not be fixed by the TS-level474474- forward error correction (FEC), the Transport_error_indicator flag of the TS475475- packet header should be set. The TS packet should not be discarded, as476476- the error can possibly be corrected by a higher layer protocol. If the called477477- party is slow in processing the callback, it is possible that the circular buffer478478- eventually fills up. If this happens, the demux driver should discard any TS479479- packets received while the buffer is full. The error should be indicated to the480480- client on the next callback by setting the success parameter to the value of481481- DMX_OVERRUN_ERROR.</para>482482-</entry>483483- </row><row><entry484484- align="char">485485-<para>The type of data returned to the callback can be selected by the new486486- function int (*set_type) (struct dmx_ts_feed_s* feed, int type, dmx_ts_pes_t487487- pes_type) which is part of the dmx_ts_feed_s struct (also cf. to the488488- include file ost/demux.h) The type parameter decides if the raw TS packet489489- (TS_PACKET) or just the payload (TS_PACKET—TS_PAYLOAD_ONLY)490490- should be returned. If additionally the TS_DECODER bit is set the stream491491- will also be sent to the hardware MPEG decoder. In this case, the second492492- flag decides as what kind of data the stream should be interpreted. The493493- possible choices are one of DMX_TS_PES_AUDIO, DMX_TS_PES_VIDEO,494494- DMX_TS_PES_TELETEXT, DMX_TS_PES_SUBTITLE,495495- DMX_TS_PES_PCR, or DMX_TS_PES_OTHER.</para>496496-</entry>497497- </row></tbody></tgroup></informaltable>498498-<para>SYNOPSIS499499-</para>500500-<informaltable><tgroup cols="1"><tbody><row><entry501501- align="char">502502-<para>int dmx_ts_cb(__u8⋆ buffer1, size_t buffer1_length,503503- __u8⋆ buffer2, size_t buffer2_length, dmx_ts_feed_t⋆504504- source);</para>505505-</entry>506506- </row></tbody></tgroup></informaltable>507507-<para>PARAMETERS508508-</para>509509-<informaltable><tgroup cols="2"><tbody><row><entry510510- align="char">511511-<para>__u8* buffer1</para>512512-</entry><entry513513- align="char">514514-<para>Pointer to the start of the filtered TS packets.</para>515515-</entry>516516- </row><row><entry517517- align="char">518518-<para>size_t buffer1_length</para>519519-</entry><entry520520- align="char">521521-<para>Length of the TS data in buffer1.</para>522522-</entry>523523- </row><row><entry524524- align="char">525525-<para>__u8* buffer2</para>526526-</entry><entry527527- align="char">528528-<para>Pointer to the tail of the filtered TS packets, or NULL.</para>529529-</entry>530530- </row><row><entry531531- align="char">532532-<para>size_t buffer2_length</para>533533-</entry><entry534534- align="char">535535-<para>Length of the TS data in buffer2.</para>536536-</entry>537537- </row><row><entry538538- align="char">539539-<para>dmx_ts_feed_t*540540- source</para>541541-</entry><entry542542- align="char">543543-<para>Indicates which TS feed is the source of the callback.</para>544544-</entry>545545- </row></tbody></tgroup></informaltable>546546-<para>RETURNS547547-</para>548548-<informaltable><tgroup cols="2"><tbody><row><entry549549- align="char">550550-<para>0</para>551551-</entry><entry552552- align="char">553553-<para>Continue filtering.</para>554554-</entry>555555- </row><row><entry556556- align="char">557557-<para>-1</para>558558-</entry><entry559559- align="char">560560-<para>Stop filtering - has the same effect as a call to561561- stop_filtering() on the TS Feed API.</para>562562-</entry>563563- </row></tbody></tgroup></informaltable>564564-565565-</section><section566566-role="subsection"><title>dmx_section_cb()</title>567567-<para>DESCRIPTION568568-</para>569569-<informaltable><tgroup cols="1"><tbody><row><entry570570- align="char">571571-<para>This function, provided by the client of the demux API, is called from the572572- demux code. The function is only called when filtering of sections has been573573- enabled using the function start_filtering() of the section feed API. When the574574- demux driver has received a complete section that matches at least one section575575- filter, the client is notified via this callback function. Normally this function is576576- called for each received section; however, it is also possible to deliver multiple577577- sections with one callback, for example when the system load is high. If an578578- error occurs while receiving a section, this function should be called with579579- the corresponding error type set in the success field, whether or not there is580580- data to deliver. The Section Feed implementation should maintain a circular581581- buffer for received sections. However, this is not necessary if the Section Feed582582- API is implemented as a client of the TS Feed API, because the TS Feed583583- implementation then buffers the received data. The size of the circular buffer584584- can be configured using the set() function in the Section Feed API. If there585585- is no room in the circular buffer when a new section is received, the section586586- must be discarded. If this happens, the value of the success parameter should587587- be DMX_OVERRUN_ERROR on the next callback.</para>588588-</entry>589589- </row></tbody></tgroup></informaltable>590590-<para>SYNOPSIS591591-</para>592592-<informaltable><tgroup cols="1"><tbody><row><entry593593- align="char">594594-<para>int dmx_section_cb(__u8⋆ buffer1, size_t595595- buffer1_length, __u8⋆ buffer2, size_t596596- buffer2_length, dmx_section_filter_t⋆ source);</para>597597-</entry>598598- </row></tbody></tgroup></informaltable>599599-<para>PARAMETERS600600-</para>601601-<informaltable><tgroup cols="2"><tbody><row><entry602602- align="char">603603-<para>__u8* buffer1</para>604604-</entry><entry605605- align="char">606606-<para>Pointer to the start of the filtered section, e.g. within the607607- circular buffer of the demux driver.</para>608608-</entry>609609- </row><row><entry610610- align="char">611611-<para>size_t buffer1_length</para>612612-</entry><entry613613- align="char">614614-<para>Length of the filtered section data in buffer1, including615615- headers and CRC.</para>616616-</entry>617617- </row><row><entry618618- align="char">619619-<para>__u8* buffer2</para>620620-</entry><entry621621- align="char">622622-<para>Pointer to the tail of the filtered section data, or NULL.623623- Useful to handle the wrapping of a circular buffer.</para>624624-</entry>625625- </row><row><entry626626- align="char">627627-<para>size_t buffer2_length</para>628628-</entry><entry629629- align="char">630630-<para>Length of the filtered section data in buffer2, including631631- headers and CRC.</para>632632-</entry>633633- </row><row><entry634634- align="char">635635-<para>dmx_section_filter_t*636636- filter</para>637637-</entry><entry638638- align="char">639639-<para>Indicates the filter that triggered the callback.</para>640640-</entry>641641- </row></tbody></tgroup></informaltable>642642-<para>RETURNS643643-</para>644644-<informaltable><tgroup cols="2"><tbody><row><entry645645- align="char">646646-<para>0</para>647647-</entry><entry648648- align="char">649649-<para>Continue filtering.</para>650650-</entry>651651- </row><row><entry652652- align="char">653653-<para>-1</para>654654-</entry><entry655655- align="char">656656-<para>Stop filtering - has the same effect as a call to657657- stop_filtering() on the Section Feed API.</para>658658-</entry>659659- </row></tbody></tgroup></informaltable>660660- </section></section>661661-<section id="ts_feed_api">662662-<title>TS Feed API</title>663663-<para>A TS feed is typically mapped to a hardware PID filter on the demux chip.664664-Using this API, the client can set the filtering properties to start/stop filtering TS665665-packets on a particular TS feed. The API is defined as an abstract interface of the type666666-dmx_ts_feed_t.667667-</para>668668-<para>The functions that implement the interface should be defined static or module private. The669669-client can get the handle of a TS feed API by calling the function allocate_ts_feed() in the670670-demux API.671671-</para>672672-673673-<section674674-role="subsection"><title>set()</title>675675-<para>DESCRIPTION676676-</para>677677-<informaltable><tgroup cols="1"><tbody><row><entry678678- align="char">679679-<para>This function sets the parameters of a TS feed. Any filtering in progress on the680680- TS feed must be stopped before calling this function.</para>681681-</entry>682682- </row></tbody></tgroup></informaltable>683683-<para>SYNOPSIS684684-</para>685685-<informaltable><tgroup cols="1"><tbody><row><entry686686- align="char">687687-<para>int set ( dmx_ts_feed_t⋆ feed, __u16 pid, size_t688688- callback_length, size_t circular_buffer_size, int689689- descramble, struct timespec timeout);</para>690690-</entry>691691- </row></tbody></tgroup></informaltable>692692-<para>PARAMETERS693693-</para>694694-<informaltable><tgroup cols="2"><tbody><row><entry695695- align="char">696696-<para>dmx_ts_feed_t* feed</para>697697-</entry><entry698698- align="char">699699-<para>Pointer to the TS feed API and instance data.</para>700700-</entry>701701- </row><row><entry702702- align="char">703703-<para>__u16 pid</para>704704-</entry><entry705705- align="char">706706-<para>PID value to filter. Only the TS packets carrying the707707- specified PID will be passed to the API client.</para>708708-</entry>709709- </row><row><entry710710- align="char">711711-<para>size_t712712- callback_length</para>713713-</entry><entry714714- align="char">715715-<para>Number of bytes to deliver with each call to the716716- dmx_ts_cb() callback function. The value of this717717- parameter should be a multiple of 188.</para>718718-</entry>719719- </row><row><entry720720- align="char">721721-<para>size_t722722- circular_buffer_size</para>723723-</entry><entry724724- align="char">725725-<para>Size of the circular buffer for the filtered TS packets.</para>726726-</entry>727727- </row><row><entry728728- align="char">729729-<para>int descramble</para>730730-</entry><entry731731- align="char">732732-<para>If non-zero, descramble the filtered TS packets.</para>733733-</entry>734734- </row><row><entry735735- align="char">736736-<para>struct timespec737737- timeout</para>738738-</entry><entry739739- align="char">740740-<para>Maximum time to wait before delivering received TS741741- packets to the client.</para>742742-</entry>743743- </row></tbody></tgroup></informaltable>744744-<para>RETURNS745745-</para>746746-<informaltable><tgroup cols="2"><tbody><row><entry747747- align="char">748748-<para>0</para>749749-</entry><entry750750- align="char">751751-<para>The function was completed without errors.</para>752752-</entry>753753- </row><row><entry754754- align="char">755755-<para>-ENOMEM</para>756756-</entry><entry757757- align="char">758758-<para>Not enough memory for the requested buffer size.</para>759759-</entry>760760- </row><row><entry761761- align="char">762762-<para>-ENOSYS</para>763763-</entry><entry764764- align="char">765765-<para>No descrambling facility available for TS.</para>766766-</entry>767767- </row><row><entry768768- align="char">769769-<para>-EINVAL</para>770770-</entry><entry771771- align="char">772772-<para>Bad parameter.</para>773773-</entry>774774- </row></tbody></tgroup></informaltable>775775-776776-</section><section777777-role="subsection"><title>start_filtering()</title>778778-<para>DESCRIPTION779779-</para>780780-<informaltable><tgroup cols="1"><tbody><row><entry781781- align="char">782782-<para>Starts filtering TS packets on this TS feed, according to its settings. The PID783783- value to filter can be set by the API client. All matching TS packets are784784- delivered asynchronously to the client, using the callback function registered785785- with allocate_ts_feed().</para>786786-</entry>787787- </row></tbody></tgroup></informaltable>788788-<para>SYNOPSIS789789-</para>790790-<informaltable><tgroup cols="1"><tbody><row><entry791791- align="char">792792-<para>int start_filtering(dmx_ts_feed_t⋆ feed);</para>793793-</entry>794794- </row></tbody></tgroup></informaltable>795795-<para>PARAMETERS796796-</para>797797-<informaltable><tgroup cols="2"><tbody><row><entry798798- align="char">799799-<para>dmx_ts_feed_t* feed</para>800800-</entry><entry801801- align="char">802802-<para>Pointer to the TS feed API and instance data.</para>803803-</entry>804804- </row></tbody></tgroup></informaltable>805805-<para>RETURNS806806-</para>807807-<informaltable><tgroup cols="2"><tbody><row><entry808808- align="char">809809-<para>0</para>810810-</entry><entry811811- align="char">812812-<para>The function was completed without errors.</para>813813-</entry>814814- </row><row><entry815815- align="char">816816-<para>-EINVAL</para>817817-</entry><entry818818- align="char">819819-<para>Bad parameter.</para>820820-</entry>821821- </row></tbody></tgroup></informaltable>822822-823823-</section><section824824-role="subsection"><title>stop_filtering()</title>825825-<para>DESCRIPTION826826-</para>827827-<informaltable><tgroup cols="1"><tbody><row><entry828828- align="char">829829-<para>Stops filtering TS packets on this TS feed.</para>830830-</entry>831831- </row></tbody></tgroup></informaltable>832832-<para>SYNOPSIS833833-</para>834834-<informaltable><tgroup cols="1"><tbody><row><entry835835- align="char">836836-<para>int stop_filtering(dmx_ts_feed_t⋆ feed);</para>837837-</entry>838838- </row></tbody></tgroup></informaltable>839839-<para>PARAMETERS840840-</para>841841-<informaltable><tgroup cols="2"><tbody><row><entry842842- align="char">843843-<para>dmx_ts_feed_t* feed</para>844844-</entry><entry845845- align="char">846846-<para>Pointer to the TS feed API and instance data.</para>847847-</entry>848848- </row></tbody></tgroup></informaltable>849849-<para>RETURNS850850-</para>851851-<informaltable><tgroup cols="2"><tbody><row><entry852852- align="char">853853-<para>0</para>854854-</entry><entry855855- align="char">856856-<para>The function was completed without errors.</para>857857-</entry>858858- </row><row><entry859859- align="char">860860-<para>-EINVAL</para>861861-</entry><entry862862- align="char">863863-<para>Bad parameter.</para>864864-</entry>865865- </row></tbody></tgroup></informaltable>866866- </section></section>867867-<section id="section_feed_api">868868-<title>Section Feed API</title>869869-<para>A section feed is a resource consisting of a PID filter and a set of section filters. Using this870870-API, the client can set the properties of a section feed and to start/stop filtering. The API is871871-defined as an abstract interface of the type dmx_section_feed_t. The functions that implement872872-the interface should be defined static or module private. The client can get the handle of873873-a section feed API by calling the function allocate_section_feed() in the demux874874-API.875875-</para>876876-<para>On demux platforms that provide section filtering in hardware, the Section Feed API877877-implementation provides a software wrapper for the demux hardware. Other platforms may878878-support only PID filtering in hardware, requiring that TS packets are converted to sections in879879-software. In the latter case the Section Feed API implementation can be a client of the TS880880-Feed API.881881-</para>882882-883883-</section>884884-<section id="kdapi_set">885885-<title>set()</title>886886-<para>DESCRIPTION887887-</para>888888-<informaltable><tgroup cols="1"><tbody><row><entry889889- align="char">890890-<para>This function sets the parameters of a section feed. Any filtering in progress on891891- the section feed must be stopped before calling this function. If descrambling892892- is enabled, the payload_scrambling_control and address_scrambling_control893893- fields of received DVB datagram sections should be observed. If either one is894894- non-zero, the section should be descrambled either in hardware or using the895895- functions descramble_mac_address() and descramble_section_payload() of the896896- demux API. Note that according to the MPEG-2 Systems specification, only897897- the payloads of private sections can be scrambled while the rest of the section898898- data must be sent in the clear.</para>899899-</entry>900900- </row></tbody></tgroup></informaltable>901901-<para>SYNOPSIS902902-</para>903903-<informaltable><tgroup cols="1"><tbody><row><entry904904- align="char">905905-<para>int set(dmx_section_feed_t⋆ feed, __u16 pid, size_t906906- circular_buffer_size, int descramble, int907907- check_crc);</para>908908-</entry>909909- </row></tbody></tgroup></informaltable>910910-<para>PARAMETERS911911-</para>912912-<informaltable><tgroup cols="2"><tbody><row><entry913913- align="char">914914-<para>dmx_section_feed_t*915915- feed</para>916916-</entry><entry917917- align="char">918918-<para>Pointer to the section feed API and instance data.</para>919919-</entry>920920- </row><row><entry921921- align="char">922922-<para>__u16 pid</para>923923-</entry><entry924924- align="char">925925-<para>PID value to filter; only the TS packets carrying the926926- specified PID will be accepted.</para>927927-</entry>928928- </row><row><entry929929- align="char">930930-<para>size_t931931- circular_buffer_size</para>932932-</entry><entry933933- align="char">934934-<para>Size of the circular buffer for filtered sections.</para>935935-</entry>936936- </row><row><entry937937- align="char">938938-<para>int descramble</para>939939-</entry><entry940940- align="char">941941-<para>If non-zero, descramble any sections that are scrambled.</para>942942-</entry>943943- </row><row><entry944944- align="char">945945-<para>int check_crc</para>946946-</entry><entry947947- align="char">948948-<para>If non-zero, check the CRC values of filtered sections.</para>949949-</entry>950950- </row></tbody></tgroup></informaltable>951951-<para>RETURNS952952-</para>953953-<informaltable><tgroup cols="2"><tbody><row><entry954954- align="char">955955-<para>0</para>956956-</entry><entry957957- align="char">958958-<para>The function was completed without errors.</para>959959-</entry>960960- </row><row><entry961961- align="char">962962-<para>-ENOMEM</para>963963-</entry><entry964964- align="char">965965-<para>Not enough memory for the requested buffer size.</para>966966-</entry>967967- </row><row><entry968968- align="char">969969-<para>-ENOSYS</para>970970-</entry><entry971971- align="char">972972-<para>No descrambling facility available for sections.</para>973973-</entry>974974- </row><row><entry975975- align="char">976976-<para>-EINVAL</para>977977-</entry><entry978978- align="char">979979-<para>Bad parameters.</para>980980-</entry>981981- </row></tbody></tgroup></informaltable>982982-983983-</section><section984984-role="subsection"><title>allocate_filter()</title>985985-<para>DESCRIPTION986986-</para>987987-<informaltable><tgroup cols="1"><tbody><row><entry988988- align="char">989989-<para>This function is used to allocate a section filter on the demux. It should only be990990- called when no filtering is in progress on this section feed. If a filter cannot be991991- allocated, the function fails with -ENOSPC. See in section ?? for the format of992992- the section filter.</para>993993-</entry>994994- </row><row><entry995995- align="char">996996-<para>The bitfields filter_mask and filter_value should only be modified when no997997- filtering is in progress on this section feed. filter_mask controls which bits of998998- filter_value are compared with the section headers/payload. On a binary value999999- of 1 in filter_mask, the corresponding bits are compared. The filter only accepts10001000- sections that are equal to filter_value in all the tested bit positions. Any changes10011001- to the values of filter_mask and filter_value are guaranteed to take effect only10021002- when the start_filtering() function is called next time. The parent pointer in10031003- the struct is initialized by the API implementation to the value of the feed10041004- parameter. The priv pointer is not used by the API implementation, and can10051005- thus be freely utilized by the caller of this function. Any data pointed to by the10061006- priv pointer is available to the recipient of the dmx_section_cb() function call.</para>10071007-</entry>10081008- </row><row><entry10091009- align="char">10101010-<para>While the maximum section filter length (DMX_MAX_FILTER_SIZE) is10111011- currently set at 16 bytes, hardware filters of that size are not available on all10121012- platforms. Therefore, section filtering will often take place first in hardware,10131013- followed by filtering in software for the header bytes that were not covered10141014- by a hardware filter. The filter_mask field can be checked to determine how10151015- many bytes of the section filter are actually used, and if the hardware filter will10161016- suffice. Additionally, software-only section filters can optionally be allocated10171017- to clients when all hardware section filters are in use. Note that on most demux10181018- hardware it is not possible to filter on the section_length field of the section10191019- header – thus this field is ignored, even though it is included in filter_value and10201020- filter_mask fields.</para>10211021-</entry>10221022- </row></tbody></tgroup></informaltable>10231023-<para>SYNOPSIS10241024-</para>10251025-<informaltable><tgroup cols="1"><tbody><row><entry10261026- align="char">10271027-<para>int allocate_filter(dmx_section_feed_t⋆ feed,10281028- dmx_section_filter_t⋆⋆ filter);</para>10291029-</entry>10301030- </row></tbody></tgroup></informaltable>10311031-<para>PARAMETERS10321032-</para>10331033-<informaltable><tgroup cols="2"><tbody><row><entry10341034- align="char">10351035-<para>dmx_section_feed_t*10361036- feed</para>10371037-</entry><entry10381038- align="char">10391039-<para>Pointer to the section feed API and instance data.</para>10401040-</entry>10411041- </row><row><entry10421042- align="char">10431043-<para>dmx_section_filter_t**10441044- filter</para>10451045-</entry><entry10461046- align="char">10471047-<para>Pointer to the allocated filter.</para>10481048-</entry>10491049- </row></tbody></tgroup></informaltable>10501050-<para>RETURNS10511051-</para>10521052-<informaltable><tgroup cols="2"><tbody><row><entry10531053- align="char">10541054-<para>0</para>10551055-</entry><entry10561056- align="char">10571057-<para>The function was completed without errors.</para>10581058-</entry>10591059- </row><row><entry10601060- align="char">10611061-<para>-ENOSPC</para>10621062-</entry><entry10631063- align="char">10641064-<para>No filters of given type and length available.</para>10651065-</entry>10661066- </row><row><entry10671067- align="char">10681068-<para>-EINVAL</para>10691069-</entry><entry10701070- align="char">10711071-<para>Bad parameters.</para>10721072-</entry>10731073- </row></tbody></tgroup></informaltable>10741074-10751075-</section><section10761076-role="subsection"><title>release_filter()</title>10771077-<para>DESCRIPTION10781078-</para>10791079-<informaltable><tgroup cols="1"><tbody><row><entry10801080- align="char">10811081-<para>This function releases all the resources of a previously allocated section filter.10821082- The function should not be called while filtering is in progress on this section10831083- feed. After calling this function, the caller should not try to dereference the10841084- filter pointer.</para>10851085-</entry>10861086- </row></tbody></tgroup></informaltable>10871087-<para>SYNOPSIS10881088-</para>10891089-<informaltable><tgroup cols="1"><tbody><row><entry10901090- align="char">10911091-<para>int release_filter ( dmx_section_feed_t⋆ feed,10921092- dmx_section_filter_t⋆ filter);</para>10931093-</entry>10941094- </row></tbody></tgroup></informaltable>10951095-<para>PARAMETERS10961096-</para>10971097-<informaltable><tgroup cols="2"><tbody><row><entry10981098- align="char">10991099-<para>dmx_section_feed_t*11001100- feed</para>11011101-</entry><entry11021102- align="char">11031103-<para>Pointer to the section feed API and instance data.</para>11041104-</entry>11051105- </row><row><entry11061106- align="char">11071107-<para>dmx_section_filter_t*11081108- filter</para>11091109-</entry><entry11101110- align="char">11111111-<para>I/O Pointer to the instance data of a section filter.</para>11121112-</entry>11131113- </row></tbody></tgroup></informaltable>11141114-<para>RETURNS11151115-</para>11161116-<informaltable><tgroup cols="2"><tbody><row><entry11171117- align="char">11181118-<para>0</para>11191119-</entry><entry11201120- align="char">11211121-<para>The function was completed without errors.</para>11221122-</entry>11231123- </row><row><entry11241124- align="char">11251125-<para>-ENODEV</para>11261126-</entry><entry11271127- align="char">11281128-<para>No such filter allocated.</para>11291129-</entry>11301130- </row><row><entry11311131- align="char">11321132-<para>-EINVAL</para>11331133-</entry><entry11341134- align="char">11351135-<para>Bad parameter.</para>11361136-</entry>11371137- </row></tbody></tgroup></informaltable>11381138-11391139-</section><section11401140-role="subsection"><title>start_filtering()</title>11411141-<para>DESCRIPTION11421142-</para>11431143-<informaltable><tgroup cols="1"><tbody><row><entry11441144- align="char">11451145-<para>Starts filtering sections on this section feed, according to its settings. Sections11461146- are first filtered based on their PID and then matched with the section11471147- filters allocated for this feed. If the section matches the PID filter and11481148- at least one section filter, it is delivered to the API client. The section11491149- is delivered asynchronously using the callback function registered with11501150- allocate_section_feed().</para>11511151-</entry>11521152- </row></tbody></tgroup></informaltable>11531153-<para>SYNOPSIS11541154-</para>11551155-<informaltable><tgroup cols="1"><tbody><row><entry11561156- align="char">11571157-<para>int start_filtering ( dmx_section_feed_t⋆ feed );</para>11581158-</entry>11591159- </row></tbody></tgroup></informaltable>11601160-<para>PARAMETERS11611161-</para>11621162-<informaltable><tgroup cols="2"><tbody><row><entry11631163- align="char">11641164-<para>dmx_section_feed_t*11651165- feed</para>11661166-</entry><entry11671167- align="char">11681168-<para>Pointer to the section feed API and instance data.</para>11691169-</entry>11701170- </row></tbody></tgroup></informaltable>11711171-<para>RETURNS11721172-</para>11731173-<informaltable><tgroup cols="2"><tbody><row><entry11741174- align="char">11751175-<para>0</para>11761176-</entry><entry11771177- align="char">11781178-<para>The function was completed without errors.</para>11791179-</entry>11801180- </row><row><entry11811181- align="char">11821182-<para>-EINVAL</para>11831183-</entry><entry11841184- align="char">11851185-<para>Bad parameter.</para>11861186-</entry>11871187- </row></tbody></tgroup></informaltable>11881188-11891189-</section><section11901190-role="subsection"><title>stop_filtering()</title>11911191-<para>DESCRIPTION11921192-</para>11931193-<informaltable><tgroup cols="1"><tbody><row><entry11941194- align="char">11951195-<para>Stops filtering sections on this section feed. Note that any changes to the11961196- filtering parameters (filter_value, filter_mask, etc.) should only be made when11971197- filtering is stopped.</para>11981198-</entry>11991199- </row></tbody></tgroup></informaltable>12001200-<para>SYNOPSIS12011201-</para>12021202-<informaltable><tgroup cols="1"><tbody><row><entry12031203- align="char">12041204-<para>int stop_filtering ( dmx_section_feed_t⋆ feed );</para>12051205-</entry>12061206- </row></tbody></tgroup></informaltable>12071207-<para>PARAMETERS12081208-</para>12091209-<informaltable><tgroup cols="2"><tbody><row><entry12101210- align="char">12111211-<para>dmx_section_feed_t*12121212- feed</para>12131213-</entry><entry12141214- align="char">12151215-<para>Pointer to the section feed API and instance data.</para>12161216-</entry>12171217- </row></tbody></tgroup></informaltable>12181218-<para>RETURNS12191219-</para>12201220-<informaltable><tgroup cols="2"><tbody><row><entry12211221- align="char">12221222-<para>0</para>12231223-</entry><entry12241224- align="char">12251225-<para>The function was completed without errors.</para>12261226-</entry>12271227- </row><row><entry12281228- align="char">12291229-<para>-EINVAL</para>12301230-</entry><entry12311231- align="char">12321232-<para>Bad parameter.</para>12331233-</entry>12341234- </row></tbody></tgroup></informaltable>12351235-12361236-</section>