To the demux the input is a byte stream. Everything is just zero's and one's. Now how does the parser differentiate between 0x47 in the data and the 0x47 that is the sync byte of the Transport stream header?
For example, if the data that the demux receives is 0x47 0x56 0xef 0x47 ... How will it know which 0x47 is the sync byte?
Does it look for any additional bit after the sync byte to ensure that the 0x47 it read is indeed the start of the header? What is the mechanism?
The same holds true for any parser for that matter. The H.264 parser checks for the NAL start code. How does it differentiate between the actual start code and the start code in the data. Because for the parser everything is just bytes.
Thank You.
The sync bytes are sent exactly 188 bytes apart. If 0x47
is encountered, and 188 bytes later, there is not another 0x47
. It wasn't a sync byte. Next it waits for a PAT or PMT as these packets have checksums. So if the checksum matches, and there is a 0x47
every 188 bytes the stream is synced. The odds of the happening accidentally are astronomical. And if it does, eventually something else will go wrong while trying to decode the stream, and the process will start over.
In the case of h.264. the start code 000001
is not legal within the stream. If the encoder does produce this byte sequence, it is escaped to be 00000301
and the decoder knows to ignore a 03
after a 0000