TSDuck v3.40-4033
MPEG Transport Stream Toolkit
|
A binary or XML file containing PSI/SI sections and tables. More...
#include <tsSectionFile.h>
Public Member Functions | |
SectionFile (DuckContext &duck) | |
Constructor. | |
void | add (const AbstractTablePtr &table) |
Add a typed table in the file. | |
void | add (const BinaryTablePtr &table) |
Add a binary table in the file. | |
void | add (const BinaryTablePtrVector &tables) |
Add several binary tables in the file. | |
void | add (const SectionPtr §ion) |
Add a section in the file. | |
void | add (const SectionPtrVector §ions) |
Add several sections in the file. | |
size_t | binarySize () const |
Get the size in bytes of all sections. | |
void | clear () |
Clear the list of loaded tables and sections. | |
void | getOrphanSections (SectionPtrVector §ions) const |
Get a copy of the list of orphan sections. | |
void | getSections (SectionPtrVector §ions) const |
Get a copy of the list of loaded sections. | |
void | getTables (BinaryTablePtrVector &tables) const |
Get a copy of the list of loaded tables. | |
bool | load (const UString &file_name, SectionFormat type=SectionFormat::UNSPECIFIED) |
Load a binary or XML file. | |
bool | load (std::istream &strm, SectionFormat type=SectionFormat::UNSPECIFIED) |
Load a binary or XML file. | |
bool | loadBinary (const fs::path &file_name) |
Load a binary section file. | |
bool | loadBinary (std::istream &strm) |
Load a binary section file from a stream. | |
bool | loadBuffer (const ByteBlock &data, size_t start=0, size_t count=NPOS) |
Load a binary section file from a memory buffer. | |
bool | loadBuffer (const void *data, size_t size) |
Load a binary section file from a memory buffer. | |
bool | loadJSON (const UString &file_name) |
Load a JSON file. | |
bool | loadJSON (std::istream &strm) |
Load a JSON file from an open text stream. | |
bool | loadXML (const UString &file_name) |
Load an XML file. | |
bool | loadXML (std::istream &strm) |
Load an XML file from an open text stream. | |
const SectionPtrVector & | orphanSections () const |
Fast access to the list of orphan sections, sections which are not part of a table. | |
size_t | packOrphanSections () |
Pack all orphan sections. | |
bool | parseJSON (const UString &json_content) |
Parse a JSON content. | |
bool | parseXML (const UString &xml_content) |
Parse an XML content. | |
void | reorganizeEITs (const Time &reftime=Time(), EITOptions options=EITOptions::GEN_ALL) |
Reorganize all EIT sections according to ETSI TS 101 211. | |
bool | saveBinary (const fs::path &file_name) const |
Save a binary section file. | |
bool | saveBinary (std::ostream &strm) const |
Save a binary section file. | |
size_t | saveBuffer (ByteBlock &buffer) const |
Save the section file into a memory buffer. | |
size_t | saveBuffer (void *buffer, size_t buffer_size) const |
Save the section file into a memory buffer. | |
bool | saveJSON (const UString &file_name) |
Save a JSON file after automated XML-to-JSON conversion. | |
bool | saveXML (const UString &file_name) const |
Save an XML file. | |
const SectionPtrVector & | sections () const |
Fast access to the list of loaded sections. | |
size_t | sectionsCount () const |
Get the total number of sections in the file. | |
void | setCRCValidation (CRC32::Validation crc_op) |
Set the CRC32 processing mode when loading binary sections. | |
void | setTweaks (const xml::Tweaks &tweaks) |
Set new parsing and formatting tweaks for XML files. | |
const BinaryTablePtrVector & | tables () const |
Fast access to the list of loaded tables. | |
size_t | tablesCount () const |
Get the total number of full tables in the file. | |
UString | toJSON () |
Serialize as JSON text. | |
UString | toXML () const |
Serialize as XML text. | |
Static Public Member Functions | |
static bool | LoadModel (xml::Document &doc, bool load_extensions=true) |
This static method loads the XML model for tables and descriptors. | |
Static Public Attributes | |
static constexpr const UChar *const | XML_TABLES_MODEL = u"tsduck.tables.model.xml" |
File name of the XML model file for tables. | |
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's 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. |
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 |
||
) |
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. |
bool ts::SectionFile::load | ( | std::istream & | strm, |
SectionFormat | type = SectionFormat::UNSPECIFIED |
||
) |
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. |
bool ts::SectionFile::loadXML | ( | const UString & | file_name | ) |
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. |
bool ts::SectionFile::loadXML | ( | std::istream & | strm | ) |
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. |
bool ts::SectionFile::parseXML | ( | const UString & | xml_content | ) |
Parse an XML content.
The parsed tables are added to the content of this object.
[in] | xml_content | XML file content in UTF-8. |
bool ts::SectionFile::loadJSON | ( | const UString & | file_name | ) |
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. |
bool ts::SectionFile::loadJSON | ( | std::istream & | strm | ) |
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. |
bool ts::SectionFile::parseJSON | ( | const UString & | json_content | ) |
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. |
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.
|
inline |
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. |
|
inline |
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. |