How does the demux differenctiate between the 0x47 that is the sync byte and 0x47 as the data?
Asked Answered
B

2

6

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.

Belda answered 3/9, 2015 at 23:23 Comment(0)
P
6

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

Photokinesis answered 4/9, 2015 at 1:9 Comment(0)
S
1

At first, the parser should identify a proper packet boundary for the decoder to start decoding. The parser does this by:

  • Identifying 3 sync words (0x47) in a row.
  • The distance between 2 sync words is 188 bytes.

If above 2 conditions are achieved,the parser assumes a proper packet boundary then on.

Please correct or update.

Silken answered 14/12, 2015 at 6:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.