![]() |
TSDuck v3.46-4965
MPEG Transport Stream Toolkit
|
#include <tsSectionFile.h>
Public Member Functions | |
| SectionFile (DuckContext &duck) | |
| void | add (const AbstractTablePtr &table) |
| void | add (const BinaryTablePtr &table) |
| void | add (const BinaryTablePtrVector &tables) |
| void | add (const SectionPtr §ion) |
| void | add (const SectionPtrVector §ions) |
| size_t | binarySize () const |
| void | clear () |
| void | getOrphanSections (SectionPtrVector §ions) const |
| void | getSections (SectionPtrVector §ions) const |
| void | getTables (BinaryTablePtrVector &tables) const |
| bool | load (const UString &file_name, SectionFormat type=SectionFormat::UNSPECIFIED, size_t max_nested=xml::DEFAULT_MAX_NESTED) |
| bool | load (std::istream &strm, SectionFormat type=SectionFormat::UNSPECIFIED, size_t max_nested=xml::DEFAULT_MAX_NESTED) |
| bool | loadBinary (const fs::path &file_name) |
| bool | loadBinary (std::istream &strm) |
| bool | loadBuffer (const ByteBlock &data, size_t start=0, size_t count=NPOS) |
| bool | loadBuffer (const void *data, size_t size) |
| bool | loadJSON (const UString &file_name, size_t max_nested=json::DEFAULT_MAX_NESTED) |
| bool | loadJSON (std::istream &strm, size_t max_nested=json::DEFAULT_MAX_NESTED) |
| bool | loadXML (const UString &file_name, size_t max_nested=xml::DEFAULT_MAX_NESTED) |
| bool | loadXML (std::istream &strm, size_t max_nested=xml::DEFAULT_MAX_NESTED) |
| const SectionPtrVector & | orphanSections () const |
| size_t | packOrphanSections () |
| bool | parseJSON (const UString &json_content, size_t max_nested=json::DEFAULT_MAX_NESTED) |
| bool | parseXML (const UString &xml_content, size_t max_nested=xml::DEFAULT_MAX_NESTED) |
| void | reorganizeEITs (const Time &reftime=Time(), EITOptions options=EITOptions::GEN_ALL) |
| bool | saveBinary (const fs::path &file_name) const |
| bool | saveBinary (std::ostream &strm) const |
| size_t | saveBuffer (ByteBlock &buffer) const |
| size_t | saveBuffer (void *buffer, size_t buffer_size) const |
| bool | saveJSON (const UString &file_name) |
| bool | saveXML (const UString &file_name) const |
| const SectionPtrVector & | sections () const |
| size_t | sectionsCount () const |
| void | setCRCValidation (CRC32::Validation crc_op) |
| void | setTweaks (const xml::Tweaks &tweaks) |
| const BinaryTablePtrVector & | tables () const |
| size_t | tablesCount () const |
| UString | toJSON () |
| UString | toXML () const |
Static Public Member Functions | |
| static bool | LoadModel (xml::Document &doc, bool load_extensions=true) |
Static Public Attributes | |
| static constexpr const UChar *const | XML_TABLES_MODEL = u"tsduck.tables.model.xml" |
A binary or XML file containing PSI/SI sections and tables.
A section file contains one or more sections. Short sections are also tables. Long sections need to be grouped to form a table. When a section file contains only complete valid tables, we also call it a table file.
When a section file is loaded, the application can indifferently access:
There are currently two storage formats for section files: binary and XML. By default, file names ending in .bin are considered as binary files while names ending in .xml are considered as XML files. To manipulate other file formats, the application must specify the file type.
A binary section file is simply the concatenation of complete sections, header and payload, without any encapsulation. Sections must be read from the beginning of the file. The length field in the section header shall be used to locate the next section, immediately after the current section.
Short sections are read and recognized as complete tables on their own. To get a valid table with long sections, all sections forming this table must be stored contiguously in the order of their section number.
The format of XML section files is documented in the TSDuck user guide. An informal template is given in file tsduck.tables.model.xml. This file is used to validate the content of XML section files.
Sample XML section file:
Each XML node describes a complete table. As a consequence, an XML section file contains complete tables only. There is no orphan section.
| ts::SectionFile::SectionFile | ( | DuckContext & | duck | ) |
Constructor.
| [in,out] | duck | TSDuck execution context. The reference is kept inside the demux. |
| void ts::SectionFile::clear | ( | ) |
Clear the list of loaded tables and sections.
| size_t ts::SectionFile::binarySize | ( | ) | const |
Get the size in bytes of all sections. This would be the size of the corresponding binary file.
|
inline |
Get the total number of sections in the file.
|
inline |
Get the total number of full tables in the file. Orphan sections are not included.
|
inline |
Set new parsing and formatting tweaks for XML files.
| [in] | tweaks | XML tweaks. |
|
inline |
| bool ts::SectionFile::load | ( | const UString & | file_name, |
| SectionFormat | type = SectionFormat::UNSPECIFIED, | ||
| size_t | max_nested = xml::DEFAULT_MAX_NESTED ) |
Load a binary or XML file. The loaded sections are added to the content of this object.
| [in] | file_name | XML file name. If the file name starts with "<?xml", this is considered as "inline XML content". If the file name is empty or "-", the standard input is used. |
| [in] | type | File type. If UNSPECIFIED, the file type is based on the file name. |
| [in] | max_nested | Specify the maximum number of nested levels of XML elements, when the file is XML. Higher numbers of nested levels may put pressure on the thread stack size. For JSON files, the maximum value is twice max_nested because of the XML<=>JSON conversion rules. This parameter is ignored for binary files. |
| bool ts::SectionFile::load | ( | std::istream & | strm, |
| SectionFormat | type = SectionFormat::UNSPECIFIED, | ||
| size_t | max_nested = xml::DEFAULT_MAX_NESTED ) |
Load a binary or XML file. The loaded sections are added to the content of this object.
| [in,out] | strm | A standard stream in input mode (binary mode for binary files). |
| [in] | type | File type. If UNSPECIFIED, return an error. |
| [in] | max_nested | Specify the maximum number of nested levels of XML elements, when the file is XML. Higher numbers of nested levels may put pressure on the thread stack size. For JSON files, the maximum value is twice max_nested because of the XML<=>JSON conversion rules. This parameter is ignored for binary files. |
| bool ts::SectionFile::loadXML | ( | const UString & | file_name, |
| size_t | max_nested = xml::DEFAULT_MAX_NESTED ) |
Load an XML file. The loaded tables are added to the content of this object.
| [in] | file_name | XML file name. If the file name starts with "<?xml", this is considered as "inline XML content". If the file name is empty or "-", the standard input is used. |
| [in] | max_nested | Specify the maximum number of nested levels of XML elements. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::loadXML | ( | std::istream & | strm, |
| size_t | max_nested = xml::DEFAULT_MAX_NESTED ) |
Load an XML file from an open text stream. The loaded sections are added to the content of this object.
| [in,out] | strm | A standard text stream in input mode. |
| [in] | max_nested | Specify the maximum number of nested levels of XML elements. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::parseXML | ( | const UString & | xml_content, |
| size_t | max_nested = xml::DEFAULT_MAX_NESTED ) |
Parse an XML content. The parsed tables are added to the content of this object.
| [in] | xml_content | XML file content in UTF-8. |
| [in] | max_nested | Specify the maximum number of nested levels of XML elements. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::loadJSON | ( | const UString & | file_name, |
| size_t | max_nested = json::DEFAULT_MAX_NESTED ) |
Load a JSON file. The JSON must have the format of a previous automated XML-to-JSON conversion. The loaded tables are added to the content of this object.
| [in] | file_name | JSON file name. If the file name starts with "{" or "[", this is considered as "inline JSON content". If the file name is empty or "-", the standard input is used. |
| [in] | max_nested | Specify the maximum number of nested levels of JSON objects. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::loadJSON | ( | std::istream & | strm, |
| size_t | max_nested = json::DEFAULT_MAX_NESTED ) |
Load a JSON file from an open text stream. The JSON must have the format of a previous automated XML-to-JSON conversion. The loaded sections are added to the content of this object.
| [in,out] | strm | A standard text stream in input mode. |
| [in] | max_nested | Specify the maximum number of nested levels of JSON objects. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::parseJSON | ( | const UString & | json_content, |
| size_t | max_nested = json::DEFAULT_MAX_NESTED ) |
Parse a JSON content. The JSON must have the format of a previous automated XML-to-JSON conversion. The parsed tables are added to the content of this object.
| [in] | json_content | JSON file content in UTF-8. |
| [in] | max_nested | Specify the maximum number of nested levels of JSON objects. Higher numbers of nested levels may put pressure on the thread stack size. |
| bool ts::SectionFile::saveXML | ( | const UString & | file_name | ) | const |
Save an XML file.
| [in] | file_name | XML file name. If the file name is empty or "-", the standard output is used. |
| bool ts::SectionFile::saveJSON | ( | const UString & | file_name | ) |
Save a JSON file after automated XML-to-JSON conversion.
| [in] | file_name | JSON file name. If the file name is empty or "-", the standard output is used. |
| UString ts::SectionFile::toXML | ( | ) | const |
Serialize as XML text.
| UString ts::SectionFile::toJSON | ( | ) |
Serialize as JSON text.
| bool ts::SectionFile::loadBinary | ( | std::istream & | strm | ) |
Load a binary section file from a stream. The loaded sections are added to the content of this object.
| [in,out] | strm | A standard stream in input mode (binary mode). |
| bool ts::SectionFile::loadBinary | ( | const fs::path & | file_name | ) |
Load a binary section file. The loaded sections are added to the content of this object.
| [in] | file_name | Binary file name. If the file name is empty or "-", the standard input is used. |
| bool ts::SectionFile::saveBinary | ( | std::ostream & | strm | ) | const |
Save a binary section file.
| [in,out] | strm | A standard stream in output mode (binary mode). |
| bool ts::SectionFile::saveBinary | ( | const fs::path & | file_name | ) | const |
Save a binary section file.
| [in] | file_name | Binary file name. If the file name is empty or "-", the standard output is used. |
| bool ts::SectionFile::loadBuffer | ( | const void * | data, |
| size_t | size ) |
Load a binary section file from a memory buffer. The loaded sections are added to the content of this object.
| [in] | data | Address of the memory buffer. |
| [in] | size | Size in bytes of the memory buffer. |
Load a binary section file from a memory buffer. The loaded sections are added to the content of this object.
| [in] | data | Byte block containing the binary data. |
| [in] | start | Starting index inside the byte buffer. |
| [in] | count | Size in bytes to read after start. If set to NPOS, use the rest of the buffer. |
| size_t ts::SectionFile::saveBuffer | ( | void * | buffer, |
| size_t | buffer_size ) const |
Save the section file into a memory buffer.
| [out] | buffer | Address of the memory buffer to write. |
| [in] | buffer_size | Size in bytes of the memory buffer. |
| size_t ts::SectionFile::saveBuffer | ( | ByteBlock & | buffer | ) | const |
Save the section file into a memory buffer.
| [in,out] | buffer | A byte block into which the sections are written. The sections are appended to the existing content of buffer. |
|
inline |
Fast access to the list of loaded tables.
|
inline |
Fast access to the list of loaded sections.
|
inline |
Fast access to the list of orphan sections, sections which are not part of a table.
|
inline |
Get a copy of the list of loaded tables.
| [out] | tables | The list of loaded tables. |
|
inline |
Get a copy of the list of loaded sections.
| [out] | sections | The list of loaded sections. |
|
inline |
Get a copy of the list of orphan sections.
| [out] | sections | The list of orphan sections. |
| void ts::SectionFile::add | ( | const BinaryTablePtr & | table | ) |
Add a binary table in the file. If the table is not complete (there are missing sections), the sections which are present are individually added.
| [in] | table | The binary table to add. |
| void ts::SectionFile::add | ( | const BinaryTablePtrVector & | tables | ) |
Add several binary tables in the file. If a table is not complete (there are missing sections), the sections which are present are individually added.
| [in] | tables | The binary tables to add. |
| void ts::SectionFile::add | ( | const AbstractTablePtr & | table | ) |
Add a typed table in the file. The table is serialized first. Then its sections are added in the file.
| [in] | table | The table to add. |
| void ts::SectionFile::add | ( | const SectionPtr & | section | ) |
Add a section in the file.
| [in] | section | The binary section to add. |
| void ts::SectionFile::add | ( | const SectionPtrVector & | sections | ) |
Add several sections in the file.
| [in] | sections | The binary sections to add. |
| size_t ts::SectionFile::packOrphanSections | ( | ) |
Pack all orphan sections. Consecutive sections from the same tables are packed: the sections are renumbered starting at zero. The result is a complete but potentially invalid section.
| void ts::SectionFile::reorganizeEITs | ( | const Time & | reftime = Time(), |
| EITOptions | options = EITOptions::GEN_ALL ) |
Reorganize all EIT sections according to ETSI TS 101 211.
Only one EITp/f subtable is kept per service. It is split in two sections if two events (present and following) are specified. All EIT schedule are kept. But they are completely reorganized. All events are extracted and spread over new EIT sections according to ETSI TS 101 211 rules.
| [in] | reftime | Reference time for EIT schedule. Only the date part is used. This is the "last midnight" according to which EIT segments are assigned. By default, the oldest event start time is used. |
| [in] | options | Generation options for EIT (p/f and/or schedule, actual and/or other). |
|
static |
This static method loads the XML model for tables and descriptors. It loads the main model and merges all extensions.
| [out] | doc | XML document which receives the model. |
| [out] | load_extensions | If true (the default), load model additions from all declared TSDuck extensions. |
|
staticconstexpr |
File name of the XML model file for tables.