[linux-dvb] Re: CA_ZAP/DVB libs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Random attempt at using libdvbsak#1:

Possible API for parsing a PAT table:

struct bitstream {
        union {
                struct {
                        unsigned char *buf;
                        size_t len;
                } mem;
        } u;
        enum {
                BITSTREAM_MEM,
        } type;
        unsigned int ptr;
        int error;
};

struct dvbsi_section {
        int pid;

        uint8_t table_id;
        int section_syntax_ind;
        /* if section_syntax_indicator == 1: */
        int table_id_ext;
        int version_nr;
        int current_next_ind;
        uint8_t section_nr;
        uint8_t last_section_nr;
        uint8_t crc32[4];

        struct bitstream contents;
};

struct dvbsi_table_pat {
        uint16_t transport_stream_id;
        uint16_t network_pid;
        int program_count;
};

struct dvbsi_table_pat_program {
        uint16_t number;
        uint16_t map_pid;
};

int dvbsi_decode_section_header(struct dvbsi_section* section, struct 
bitstream* bs);

int dvbsi_table_decode_pat(struct dvbsi_table_pat* pat, struct bitstream* bs);

int dvbsi_table_decode_pat_program(struct dvbsi_table_pat_program* program, 
struct bitstream* bs);

The return value is the number of bytes used, or a negative error code. The 
"struct bitstream" pointers are updated by the _caller_ using this value.

The idea is you decode the section header first with 
dvbsi_decode_section_header(), then you decode the PAT with 
dvbsi_table_decode_pat() if it was one. Since the PAT can have a variable 
number of programs, that only decodes the invariant parts, so you use 
dvbsi_table_decode_pat_program() to decode the programs themselves.


Descriptors are done similarily - you get a bitstream structure pointing at 
the start of them in an SI table structure.

You use the followings to get the ID and length of the descriptor.

int dvbsi_descriptor_id(struct bitstream* bs);
int dvbsi_descriptor_length(struct bitstream* bs);

if you like the descriptor, you decode it with the appropriate function.

int dvbsi_descriptor_decode_service(struct dvbsi_descriptor_service *srv, 
struct bitstream *bs);
....

Otherwise you just skip over the descriptor data to the next one.

This involves no mallocing whatsoever - and it leaves it entirely up to the 
application what to do with the extracted data. Sort of like a a SAX-style 
XML parser as opposed to a DOM style if you know what I mean.

Hmm, this idea reminds me of a certain other library now I think of it... 
anyway lemme know what you think. 



[Index of Archives]     [Linux Media]     [Video 4 Linux]     [Asterisk]     [Samba]     [Xorg]     [Xfree86]     [Linux USB]

  Powered by Linux