ts_info.cpp 1.8 KB
/**
g++ -o ts_info ts_info.cpp -g -O0 -ansi
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/**
ISO/IEC 13818-1:2000(E)
Introduction
    Intro. 1 Transport Stream
        The Transport Stream system layer is divided into two sub-layers, one for multiplex-wide operations 
        (the Transport Stream packet layer), and one for stream-specific operations (the PES packet layer).
    Intro. 2 Program Stream
        The Program Stream system layer is divided into two sub-layers, one for multiplex-wide operations 
        (the pack layer), and one for stream-specific operations (the PES packet layer).
    Intro. 4 Packetized Elementary Stream
SECTION 2 ¨C TECHNICAL ELEMENTS
    2.4 Transport Stream bitstream requirements
    2.5 Program Stream bitstream requirements
    2.6 Program and program element descriptors
    2.7 Restrictions on the multiplexed stream semantics
Annex A ¨C CRC Decoder Model
*/

#define trace(msg, ...) printf(msg"\n", ##__VA_ARGS__);

int main(int /*argc*/, char** /*argv*/)
{
    const char* file = "livestream-1347.ts";
    int fd = open(file, O_RDONLY);
    
    trace("demuxer+read packet count offset P+0  P+1  P+2  P+x P+L2 P+L1 P+L0");
    for (int i = 0, offset = 0; ; i++) {
        unsigned char PES[188];
        memset(PES, 0, sizeof(PES));
        
        int ret = read(fd, PES, sizeof(PES));
        if (ret == 0) {
            trace("demuxer+read EOF, read completed, offset: %07d.", offset);
            break;
        }
        trace("demuxer+read packet %04d %07d 0x%02x 0x%02x 0x%02x ... 0x%02x 0x%02x 0x%02x", 
            i, offset, PES[0], PES[1], PES[2], PES[185], PES[186], PES[187]);
        
        
        offset += ret;
    }
    
    close(fd);
    return 0;
}