Thursday, September 16, 2010

Format of a Transport Stream Packet

Each MPEG-2 TS packet carries 184 B of payload data prefixed by a 4 B (32 bit) header.


The header has the following fields:
The header starts with a well-known Synchronisation Byte (8 bits). This has the bit pattern 0x47 (0100 0111).
  1. A set of three flag bits are used to indicate how the payload should be processed.
    • The first flag indicates a transport error.
    • The second flag indicates the start of a payload (payload_unit_start_indicator)
    • The third flag indicates transport priority bit.
  2. The flags are followed by a 13 bit Packet Identifier (PID). This is used to uniquely identify the stream to which the packet belongs (e.g. PES packets corresponding to an ES) generated by the multiplexer. The PID allows the receiver to differentiate the stream to which each received packet belongs. Some PID values are predefined and are used to indicate various streams of control information. A packet with an unknown PID, or one with a PID which is not required by the receiver, is silently discarded. The particular PID value of 0x1FFF is reserved to indicate that the packet is a null packet (and is to be ignored by the receiver).
  3. two scrambling control bits, used by conditional access procedures to encrypted the payload of some TS packets.
  4. Two adaption field control bits, which may take four values:
    • 01 – no adaptation field, payload only
    • 10 – adaptation field only, no payload
    • 11 – adaptation field followed by payload
    • 00 - RESERVED for future use Finally there is a half byte Continuity Counter (4 bits)

Two options are possible for inserting PES data into the TS packet payload:
  1. The simplest option, from both the encoder and receiver viewpoints, is to send only one PES (or a part of single PES) in a TS packet. This allows the TS packet header to indicate the start of the PES, but since a PES packet may have an arbitrary length, also requires the remainder of the TS packet to be padded, ensuring correct alignment of the next PES to the start of a TS packet. In MPEG-2 the padding value is the hexadecimal byte 0xFF.
  2. In general a given PES packet spans several TS packets so that the majority of TS packets contain continuation data in their payloads. When a PES packet is starting, however, the payload_unit_start_indicator bit is set to ‘1’ which means the first byte of the TS payload contains the first byte of the PES packet header. Only one PES packet can start in any single TS packet. The TS header also contains the PID so that the receiver can accept or reject PES packets at a high level without burdening the receiver with too much processing. This has an impact on short PES packets

No comments: