|
libclosedcaption 1.0.3
ISDB-Tb/SBTVD (Brazilian DTV) closed caption extraction from MPEG-TS
|
Reading MPEG-TS files, packet by packet. More...
#include "caption-common.h"

Go to the source code of this file.
Macros | |
| #define | TS_PACKET_SIZE 188 |
| #define | TS_SYNC_BYTE 0x47 |
Typedefs | |
| typedef struct TsReader_s | TsReader_t |
Enumerations | |
| enum | TsReaderError_t { TS_READER_OK = 0 , TS_READER_ERROR_OPEN , TS_READER_ERROR_FORMAT , TS_READER_ERROR_MEMORY } |
Functions | |
| bool | ts_detect_packet_format (const uint8_t *buf, size_t len, size_t *packet_size, size_t *offset) |
| TsReader_t * | ts_reader_open (const char *filename, TsReaderError_t *error) |
| const uint8_t * | ts_reader_next (TsReader_t *reader) |
| size_t | ts_reader_get_packet_size (const TsReader_t *reader) |
| void | ts_reader_close (TsReader_t *reader) |
Reading MPEG-TS files, packet by packet.
The reader detects the file format by itself and always hands over packets of TS_PACKET_SIZE bytes, ready for ts_demux_push().
Accepted formats:
When sync is lost (the TS_SYNC_BYTE byte is out of place), the reader looks for the next TS_SYNC_BYTE and keeps going from there.
Example:
Definition in file ts-reader.h.
| #define TS_PACKET_SIZE 188 |
Size of an MPEG-TS packet, without the extra timecode or Reed-Solomon bytes.
Definition at line 39 of file ts-reader.h.
| #define TS_SYNC_BYTE 0x47 |
Sync byte that starts every MPEG-TS packet.
Definition at line 42 of file ts-reader.h.
| typedef struct TsReader_s TsReader_t |
MPEG-TS file reader. Opaque struct, created by ts_reader_open().
Definition at line 57 of file ts-reader.h.
| enum TsReaderError_t |
Errors returned by ts_reader_open().
Definition at line 47 of file ts-reader.h.
| bool ts_detect_packet_format | ( | const uint8_t * | buf, |
| size_t | len, | ||
| size_t * | packet_size, | ||
| size_t * | offset | ||
| ) |
Detects the packet format from the start of a buffer.
It needs at least 3 consecutive packets with the sync byte in the right place for the format to be recognized.
| buf | Start of the file content. |
| len | Number of bytes in buf (recommended: 1024 or more). |
| packet_size | Receives the packet size: 188, 192 or 204. |
| offset | Receives the position of the TS_SYNC_BYTE inside the packet (4 for M2TS, 0 for the others). |
| TsReader_t * ts_reader_open | ( | const char * | filename, |
| TsReaderError_t * | error | ||
| ) |
Opens an MPEG-TS file for reading.
| filename | File path. |
| error | Optional (can be NULL). Receives the reason of the failure. |
| const uint8_t * ts_reader_next | ( | TsReader_t * | reader | ) |
Reads the next packet of the file.
| reader | Reader created by ts_reader_open(). |
| size_t ts_reader_get_packet_size | ( | const TsReader_t * | reader | ) |
Tells the packet size in the file.
| reader | Reader created by ts_reader_open(). |
| void ts_reader_close | ( | TsReader_t * | reader | ) |
Closes the file and frees the reader.
| reader | Reader created by ts_reader_open(). NULL is fine. |