<commit_before>C++ Si Generation Library 2.6.6
===============================

A C++ [MPG PSI](https://en.wikipedia.org/wiki/Program-specific_information) and
[DVB SI](https://en.wikipedia.org/wiki/Digital_Video_Broadcasting)
table generation library. The library has support most (if not all) tables: CAT,
PAT, PMT, NIT, SDT, BAT, TDT, TOT and their descriptors.

I wrote the initial version of this library ca. 1999-2000 and updated
it around 2003 with a few minor tweaks done since then. It was used in
production but nobody had since been maintaining it so I was given
permission to open the source so I could make changes to it if
needed.

This is very legacy so now it's mainly a C++ feature playground. Also,
some of the logic could definitely be re-thought.


Building
========

```
  autoreconf -i
  ./configure
  make
```

Sample Usage
============

See tests/*.cc for more thorough examples of building various tables. Here's a snippet:

```c++

    // some dummy data
    const ui16 network_pid = 0x20;
    const ui16 xport_stream_id = 0x10;
    const int num_services = 10;

    // the binary table data will be written to a TStream
    TStream t;

    // Create an MPG Program Association Table
    PAT pat( xport_stream_id, 0x01 );

    // override the default maximum section length.. (optional)
    pat.setMaxSectionLen( 900 );

    // add the services (programs).. first, set the network pid (required for
    // some systems)
    pat.addNetworkPid( network_pid );

    for (int i = 0; i < num_services; i++)
    {
	    // each service has an id and pmt pid associated with it..
        ui16 service_id = 100 + i;
        ui16 pmt_pid = 200 + i;

        pat.addProgram( service_id, pmt_pid );
    }

    // for debug output
    DUMP(pat);

    // this builds the binary section data onto the TStream object
    pat.buildSections(t);

    //
    // create a DVB Time and Date Table with the current time
    TDT tdt;
    DUMP(tdt);     // debug output to stderr to see table data

    // write table data onto the TStream
    tdt.buildSections(t);

    //
    // we now have a TStream that holds a list<Section *>..

    DUMP(t);       // debug - dump the contents of the TStream binary data

    // each Section holds an ui8[] with the data. we can write it to an
    // ostream (file, etc) by using the write method defined by
    // Section. Alternatively, you can have direct access to the binary
    // data by invoking getBinaryData().. regardless, iterate throguh
    // the list and do whatever you need like so:
    for (const Section& section : t.section_list)
    {
       // const ui8* sec_data = section.getBinaryData();
    }

```

Program output:


```
- - PAT Dump - -
Table id            : 0
Section syn. ind.   : 0x1
rsvrd. future use   : 0
reserved            : 0x3
Table length        : 49 (0x31)
Xport stream id     : 16 (0x10)
reserved            : 0x3
Version number      : 0x1
Current next ind.   : 0x1

 Program number      : 0 (0)
 reserved            : 0x7<commit_msg>Corrected minor error in README<commit_after>C++ Si Generation Library 2.6.6
===============================

A C++ [MPG PSI](https://en.wikipedia.org/wiki/Program-specific_information) and
[DVB SI](https://en.wikipedia.org/wiki/Digital_Video_Broadcasting)
table generation library. The library has support most (if not all) tables: CAT,
PAT, PMT, NIT, SDT, BAT, TDT, TOT and their descriptors.

I wrote the initial version of this library ca. 1999-2000 and updated
it around 2003 with a few minor tweaks done since then. It was used in
production but nobody had since been maintaining it so I was given
permission to open the source so I could make changes to it if
needed.

This is very legacy so now it's mainly a C++ feature playground. Also,
some of the logic could definitely be re-thought.


Building
========

```
  autoreconf -i
  ./configure
  make
```

Sample Usage
============

See tests/*.cc for more thorough examples of building various tables. Here's a snippet:

```c++

    // some dummy data
    const ui16 network_pid = 0x20;
    const ui16 xport_stream_id = 0x10;
    const int num_services = 10;

    // the binary table data will be written to a TStream
    TStream t;

    // Create an MPG Program Association Table
    PAT pat( xport_stream_id, 0x01 );

    // override the default maximum section length.. (optional)
    pat.setMaxSectionLen( 900 );

    // add the services (programs).. first, set the network pid (required for
    // some systems)
    pat.addNetworkPid( network_pid );

    for (int i = 0; i < num_services; i++)
    {
        // each service has an id and pmt pid associated with it..
        ui16 service_id = 100 + i;
        ui16 pmt_pid = 200 + i;

        pat.addProgram( service_id, pmt_pid );
    }

    // for debug output
    DUMP(pat);

    // this builds the binary section data onto the TStream object
    pat.buildSections(t);

    //
    // create a DVB Time and Date Table with the current time
    TDT tdt;
    DUMP(tdt);     // debug output to stderr to see table data

    // write table data onto the TStream
    tdt.buildSections(t);

    //
    // we now have a TStream that holds a list<Section *>..

    DUMP(t);       // debug - dump the contents of the TStream binary data

    // each Section holds an ui8[] with the data. we can write it to an
    // ostream (file, etc) by using the write method defined by
    // Section. Alternatively, you can have direct access to the binary
    // data by invoking getBinaryData().. regardless, iterate throguh
    // the list and do whatever you need like so:
    for (const Section* section : t.section_list)
    {
       // const ui8* sec_data = section.getBinaryData();
    }

```

Program output:


```
- - PAT Dump - -
Table id            : 0
Section syn. ind.   : 0x1
rsvrd. future use   : 0
reserved            : 0x3
Table length        : 49 (0x31)
Xport stream id     : 16 (0x10)
reserved            : 0x3
Version number      : 0x1
Current next ind.   : 0x1

 Program number      : 0 (0)
 reserved            : 0x7
{'fraction_non_alphanumeric': 0.10117374772689701, 'fraction_numerical': 0.023805587700446353, 'mean_word_length': 2.5421545667447307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '273575', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1768, 'n_words': 769}