winlin

for #250, parse the PES ts packet payload.

... ... @@ -408,6 +408,12 @@ SrsTsContext::SrsTsContext()
SrsTsContext::~SrsTsContext()
{
std::map<int, SrsTsChannel*>::iterator it;
for (it = pids.begin(); it != pids.end(); ++it) {
SrsTsChannel* channel = it->second;
srs_freep(channel);
}
pids.clear();
}
int SrsTsContext::decode(SrsStream* stream)
... ... @@ -429,17 +435,28 @@ int SrsTsContext::decode(SrsStream* stream)
return ret;
}
SrsTsPidApply SrsTsContext::get(int pid)
SrsTsChannel* SrsTsContext::get(int pid)
{
if (pids.find(pid) == pids.end()) {
return SrsTsPidApplyReserved;
return NULL;
}
return pids[pid];
}
void SrsTsContext::set(int pid, SrsTsPidApply apply_pid)
void SrsTsContext::set(int pid, SrsTsPidApply apply_pid, SrsTsStream stream)
{
pids[pid] = apply_pid;
SrsTsChannel* channel = NULL;
if (pids.find(pid) == pids.end()) {
channel = new SrsTsChannel();
pids[pid] = channel;
} else {
channel = pids[pid];
}
channel->pid = pid;
channel->apply = apply_pid;
channel->stream = stream;
}
SrsTsPacket::SrsTsPacket(SrsTsContext* c)
... ... @@ -523,11 +540,15 @@ int SrsTsPacket::decode(SrsStream* stream)
srs_freep(payload);
payload = new SrsTsPayloadPAT(this);
} else {
SrsTsPidApply apply_pid = context->get(pid);
if (apply_pid == SrsTsPidApplyPMT) {
SrsTsChannel* channel = context->get(pid);
if (channel && channel->apply == SrsTsPidApplyPMT) {
// 2.4.4.8 Program Map Table
srs_freep(payload);
payload = new SrsTsPayloadPMT(this);
} else if (channel && (channel->apply == SrsTsPidApplyVideo || channel->apply == SrsTsPidApplyAudio)) {
// 2.4.3.6 PES packet
srs_freep(payload);
payload = new SrsTsPayloadPES(this);
} else {
// left bytes as reserved.
stream->skip(nb_payload);
... ... @@ -793,6 +814,31 @@ SrsTsPayload::~SrsTsPayload()
{
}
SrsTsPayloadPES::SrsTsPayloadPES(SrsTsPacket* p) : SrsTsPayload(p)
{
PES_private_data = NULL;
pack_field = NULL;
PES_extension_field = NULL;
nb_stuffings = 0;
nb_bytes = 0;
bytes = NULL;
nb_paddings = 0;
}
SrsTsPayloadPES::~SrsTsPayloadPES()
{
srs_freep(PES_private_data);
srs_freep(pack_field);
srs_freep(PES_extension_field);
srs_freep(bytes);
}
int SrsTsPayloadPES::decode(SrsStream* stream)
{
int ret = ERROR_SUCCESS;
return ret;
}
SrsTsPayloadPSI::SrsTsPayloadPSI(SrsTsPacket* p) : SrsTsPayload(p)
{
pointer_field = 0;
... ... @@ -879,7 +925,19 @@ int SrsTsPayloadPSI::decode(SrsStream* stream)
// consume left stuffings
if (!stream->empty()) {
stream->skip(stream->size() - stream->pos());
int nb_stuffings = stream->size() - stream->pos();
char* stuffing = stream->data() + stream->pos();
// all stuffing must be 0xff.
// TODO: FIXME: maybe need to remove the following.
for (int i = 0; i < nb_stuffings; i++) {
if ((u_int8_t)stuffing[i] != 0xff) {
srs_warn("ts: stuff is not 0xff, actual=%#x", stuffing[i]);
break;
}
}
stream->skip(nb_stuffings);
}
return ret;
... ... @@ -1049,7 +1107,7 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* stream)
return ret;
}
info->stream_type = stream->read_1bytes();
info->stream_type = (SrsTsStream)stream->read_1bytes();
info->elementary_PID = stream->read_2bytes();
info->ES_info_length = stream->read_2bytes();
... ... @@ -1066,6 +1124,23 @@ int SrsTsPayloadPMT::psi_decode(SrsStream* stream)
info->ES_info = new char[info->ES_info_length];
stream->read_bytes(info->ES_info, info->ES_info_length);
}
// update the apply pid table
switch (info->stream_type) {
case SrsTsStreamVideoH264:
case SrsTsStreamVideoMpeg4:
packet->context->set(info->elementary_PID, SrsTsPidApplyVideo, info->stream_type);
break;
case SrsTsStreamAudioAAC:
case SrsTsStreamAudioAC3:
case SrsTsStreamAudioDTS:
case SrsTsStreamAudioMp3:
packet->context->set(info->elementary_PID, SrsTsPidApplyAudio, info->stream_type);
break;
default:
srs_warn("ts: drop pid=%#x, stream=%#x", info->elementary_PID, info->stream_type);
break;
}
}
// update the apply pid table.
... ...
... ... @@ -65,8 +65,8 @@ public:
/**
* the pid of ts packet,
* Table 2-3 ¨C PID table, hls-mpeg-ts-iso13818-1.pdf, page 37
* NOTE ¨C The transport packets with PID values 0x0000, 0x0001, and 0x0010-0x1FFE are allowed to carry a PCR.
* Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37
* NOTE - The transport packets with PID values 0x0000, 0x0001, and 0x0010-0x1FFE are allowed to carry a PCR.
*/
enum SrsTsPid
{
... ... @@ -88,7 +88,7 @@ enum SrsTsPid
/**
* the transport_scrambling_control of ts packet,
* Table 2-4 ¨C Scrambling control values, hls-mpeg-ts-iso13818-1.pdf, page 38
* Table 2-4 - Scrambling control values, hls-mpeg-ts-iso13818-1.pdf, page 38
*/
enum SrsTsScrambled
{
... ... @@ -104,7 +104,7 @@ enum SrsTsScrambled
/**
* the adaption_field_control of ts packet,
* Table 2-5 ¨C Adaptation field control values, hls-mpeg-ts-iso13818-1.pdf, page 38
* Table 2-5 - Adaptation field control values, hls-mpeg-ts-iso13818-1.pdf, page 38
*/
enum SrsTsAdaptationFieldType
{
... ... @@ -134,12 +134,61 @@ enum SrsTsPidApply
};
/**
* Table 2-29 - Stream type assignments
*/
enum SrsTsStream
{
// ITU-T | ISO/IEC Reserved
SrsTsStreamReserved = 0x00,
// ISO/IEC 11172 Video
// ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream
// ISO/IEC 11172 Audio
// ISO/IEC 13818-3 Audio
SrsTsStreamAudioMp3 = 0x04,
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data
// ISO/IEC 13522 MHEG
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Annex A DSM-CC
// ITU-T Rec. H.222.1
// ISO/IEC 13818-6 type A
// ISO/IEC 13818-6 type B
// ISO/IEC 13818-6 type C
// ISO/IEC 13818-6 type D
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 auxiliary
// ISO/IEC 13818-7 Audio with ADTS transport syntax
SrsTsStreamAudioAAC = 0x0f,
// ISO/IEC 14496-2 Visual
SrsTsStreamVideoMpeg4 = 0x10,
// ISO/IEC 14496-3 Audio with the LATM transport syntax as defined in ISO/IEC 14496-3 / AMD 1
// ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in PES packets
// ISO/IEC 14496-1 SL-packetized stream or FlexMux stream carried in ISO/IEC14496_sections.
// ISO/IEC 13818-6 Synchronized Download Protocol
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 Reserved
// 0x15-0x7F
SrsTsStreamVideoH264 = 0x1b,
// User Private
// 0x80-0xFF
SrsTsStreamAudioAC3 = 0x81,
SrsTsStreamAudioDTS = 0x8a,
};
/**
* the ts channel.
*/
struct SrsTsChannel
{
int pid;
SrsTsPidApply apply;
SrsTsStream stream;
};
/**
* the context of ts, to decode the ts stream.
*/
class SrsTsContext
{
private:
std::map<int, SrsTsPidApply> pids;
std::map<int, SrsTsChannel*> pids;
public:
SrsTsContext();
virtual ~SrsTsContext();
... ... @@ -152,13 +201,13 @@ public:
public:
/**
* get the pid apply, the parsed pid.
* @return the apply pid; SrsTsPidApplyReserved for invalid.
* @return the apply channel; NULL for invalid.
*/
virtual SrsTsPidApply get(int pid);
virtual SrsTsChannel* get(int pid);
/**
* set the pid apply, the parsed pid.
*/
virtual void set(int pid, SrsTsPidApply apply_pid);
virtual void set(int pid, SrsTsPidApply apply_pid, SrsTsStream stream = SrsTsStreamReserved);
};
/**
... ... @@ -216,7 +265,7 @@ public:
/**
* The PID is a 13-bit field, indicating the type of the data stored in the packet payload. PID value 0x0000 is
* reserved for the Program Association Table (see Table 2-25). PID value 0x0001 is reserved for the Conditional Access
* Table (see Table 2-27). PID values 0x0002 ¨C 0x000F are reserved. PID value 0x1FFF is reserved for null packets (see
* Table (see Table 2-27). PID values 0x0002 - 0x000F are reserved. PID value 0x1FFF is reserved for null packets (see
* Table 2-3).
*/
SrsTsPid pid; //13bits
... ... @@ -269,7 +318,7 @@ public:
/**
* the adaption field of ts packet.
* 2.4.3.5 Semantic definition of fields in adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 39
* Table 2-6 ¨C Transport Stream adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 40
* Table 2-6 - Transport Stream adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 40
*/
class SrsTsAdaptationField
{
... ... @@ -329,8 +378,8 @@ public:
* same PID.
*
* For the purpose of this clause, an elementary stream access point is defined as follows:
* Video ¨C The first byte of a video sequence header.
* Audio ¨C The first byte of an audio frame.
* Video - The first byte of a video sequence header.
* Audio - The first byte of an audio frame.
*
* After a continuity counter discontinuity in a Transport packet which is designated as containing elementary stream data,
* the first byte of elementary stream data in a Transport Stream packet of the same PID shall be the first byte of an
... ... @@ -454,8 +503,8 @@ public:
* being excluded).
*
* For the purposes of this subclause, an access point is defined as follows:
* Video ¨C The first byte of a video_sequence_header.
* Audio ¨C The first byte of an audio frame.
* Video - The first byte of a video_sequence_header.
* Audio - The first byte of an audio frame.
*/
int8_t splice_countdown; //8bits
... ... @@ -497,15 +546,15 @@ public:
//5bits reserved
// if ltw_flag, 2B
/**
* (legal time window_valid_flag) ¨C This is a 1-bit field which when set to '1' indicates that the value of the
* (legal time window_valid_flag) - This is a 1-bit field which when set to '1' indicates that the value of the
* ltw_offset shall be valid. A value of '0' indicates that the value in the ltw_offset field is undefined.
*/
int8_t ltw_valid_flag; //1bit
/**
* (legal time window offset) ¨C This is a 15-bit field, the value of which is defined only if the ltw_valid flag has
* (legal time window offset) - This is a 15-bit field, the value of which is defined only if the ltw_valid flag has
* a value of '1'. When defined, the legal time window offset is in units of (300/fs) seconds, where fs is the system clock
* frequency of the program that this PID belongs to, and fulfils:
* offset = t1(i) ¨C t(i)
* offset = t1(i) - t(i)
* ltw_offset = offset//1
* where i is the index of the first byte of this Transport Stream packet, offset is the value encoded in this field, t(i) is the
* arrival time of byte i in the T-STD, and t1(i) is the upper bound in time of a time interval called the Legal Time Window
... ... @@ -532,7 +581,7 @@ public:
*/
int8_t splice_type; //4bits
/**
* (decoding time stamp next access unit) ¨C This is a 33-bit field, coded in three parts. In the case of
* (decoding time stamp next access unit) - This is a 33-bit field, coded in three parts. In the case of
* continuous and periodic decoding through this splicing point it indicates the decoding time of the first access unit
* following the splicing point. This decoding time is expressed in the time base which is valid in the Transport Stream
* packet in which the splice_countdown reaches zero. From the first occurrence of this field onwards, it shall have the
... ... @@ -613,6 +662,312 @@ public:
};
/**
* the PES payload of ts packet.
* 2.4.3.6 PES packet, hls-mpeg-ts-iso13818-1.pdf, page 49
*/
class SrsTsPayloadPES : public SrsTsPayload
{
public:
// 3B
/**
* The packet_start_code_prefix is a 24-bit code. Together with the stream_id that follows it
* constitutes a packet start code that identifies the beginning of a packet. The packet_start_code_prefix is the bit string
* '0000 0000 0000 0000 0000 0001' (0x000001).
*/
int32_t packet_start_code_prefix; //24bits
// 1B
/**
* In Program Streams, the stream_id specifies the type and number of the elementary stream as defined by the
* stream_id Table 2-18. In Transport Streams, the stream_id may be set to any valid value which correctly describes the
* elementary stream type as defined in Table 2-18. In Transport Streams, the elementary stream type is specified in the
* Program Specific Information as specified in 2.4.4.
*/
u_int8_t stream_id; //8bits
// 2B
/**
* A 16-bit field specifying the number of bytes in the PES packet following the last byte of the
* field. A value of 0 indicates that the PES packet length is neither specified nor bounded and is allowed only in
* PES packets whose payload consists of bytes from a video elementary stream contained in Transport Stream packets.
*/
u_int16_t PES_packet_length; //16bits
// 1B
// 2bits const '10'
/**
* The 2-bit PES_scrambling_control field indicates the scrambling mode of the PES packet
* payload. When scrambling is performed at the PES level, the PES packet header, including the optional fields when
* present, shall not be scrambled (see Table 2-19).
*/
int8_t PES_scrambling_control; //2bits
/**
* This is a 1-bit field indicating the priority of the payload in this PES packet. A '1' indicates a higher
* priority of the payload of the PES packet payload than a PES packet payload with this field set to '0'. A multiplexor can
* use the PES_priority bit to prioritize its data within an elementary stream. This field shall not be changed by the transport
* mechanism.
*/
int8_t PES_priority; //1bit
/**
* This is a 1-bit flag. When set to a value of '1' it indicates that the PES packet header is
* immediately followed by the video start code or audio syncword indicated in the data_stream_alignment_descriptor
* in 2.6.10 if this descriptor is present. If set to a value of '1' and the descriptor is not present, alignment as indicated in
* alignment_type '01' in Table 2-47 and Table 2-48 is required. When set to a value of '0' it is not defined whether any such
* alignment occurs or not.
*/
int8_t data_alignment_indicator; //1bit
/**
* This is a 1-bit field. When set to '1' it indicates that the material of the associated PES packet payload is
* protected by copyright. When set to '0' it is not defined whether the material is protected by copyright. A copyright
* descriptor described in 2.6.24 is associated with the elementary stream which contains this PES packet and the copyright
* flag is set to '1' if the descriptor applies to the material contained in this PES packet
*/
int8_t copyright; //1bit
/**
* This is a 1-bit field. When set to '1' the contents of the associated PES packet payload is an original.
* When set to '0' it indicates that the contents of the associated PES packet payload is a copy.
*/
int8_t original_or_copy; //1bit
// 1B
/**
* This is a 2-bit field. When the PTS_DTS_flags field is set to '10', the PTS fields shall be present in
* the PES packet header. When the PTS_DTS_flags field is set to '11', both the PTS fields and DTS fields shall be present
* in the PES packet header. When the PTS_DTS_flags field is set to '00' no PTS or DTS fields shall be present in the PES
* packet header. The value '01' is forbidden.
*/
int8_t PTS_DTS_flags; //2bits
/**
* A 1-bit flag, which when set to '1' indicates that ESCR base and extension fields are present in the PES
* packet header. When set to '0' it indicates that no ESCR fields are present.
*/
int8_t ESCR_flag; //1bit
/**
* A 1-bit flag, which when set to '1' indicates that the ES_rate field is present in the PES packet header.
* When set to '0' it indicates that no ES_rate field is present.
*/
int8_t ES_rate_flag; //1bit
/**
* A 1-bit flag, which when set to '1' it indicates the presence of an 8-bit trick mode field. When
* set to '0' it indicates that this field is not present.
*/
int8_t DSM_trick_mode_flag; //1bit
/**
* A 1-bit flag, which when set to '1' indicates the presence of the additional_copy_info field.
* When set to '0' it indicates that this field is not present.
*/
int8_t additional_copy_info_flag; //1bit
/**
* A 1-bit flag, which when set to '1' indicates that a CRC field is present in the PES packet. When set to
* '0' it indicates that this field is not present.
*/
int8_t PES_CRC_flag; //1bit
/**
* A 1-bit flag, which when set to '1' indicates that an extension field exists in this PES packet
* header. When set to '0' it indicates that this field is not present.
*/
int8_t PES_extension_flag; //1bit
// 1B
/**
* An 8-bit field specifying the total number of bytes occupied by the optional fields and any
* stuffing bytes contained in this PES packet header. The presence of optional fields is indicated in the byte that precedes
* the PES_header_data_length field.
*/
u_int8_t PES_header_data_length; //8bits
// 8B
/**
* Presentation times shall be related to decoding times as follows: The PTS is a 33-bit
* number coded in three separate fields. It indicates the time of presentation, tp n (k), in the system target decoder of a
* presentation unit k of elementary stream n. The value of PTS is specified in units of the period of the system clock
* frequency divided by 300 (yielding 90 kHz). The presentation time is derived from the PTS according to equation 2-11
* below. Refer to 2.7.4 for constraints on the frequency of coding presentation timestamps.
*/
int64_t pts; // 33bits
/**
* The DTS is a 33-bit number coded in three separate fields. It indicates the decoding time,
* td n (j), in the system target decoder of an access unit j of elementary stream n. The value of DTS is specified in units of
* the period of the system clock frequency divided by 300 (yielding 90 kHz).
*/
int64_t dts; // 33bits
// 8B
/**
* The elementary stream clock reference is a 42-bit field coded in two parts. The first
* part, ESCR_base, is a 33-bit field whose value is given by ESCR_base(i), as given in equation 2-14. The second part,
* ESCR_ext, is a 9-bit field whose value is given by ESCR_ext(i), as given in equation 2-15. The ESCR field indicates the
* intended time of arrival of the byte containing the last bit of the ESCR_base at the input of the PES-STD for PES streams
* (refer to 2.5.2.4).
*/
int16_t ESCR_extension; //9bits
int64_t ESCR_base; //33bits
/**
* The ES_rate field is a 22-bit unsigned integer specifying the rate at which the
* system target decoder receives bytes of the PES packet in the case of a PES stream. The ES_rate is valid in the PES
* packet in which it is included and in subsequent PES packets of the same PES stream until a new ES_rate field is
* encountered. The value of the ES_rate is measured in units of 50 bytes/second. The value 0 is forbidden. The value of the
* ES_rate is used to define the time of arrival of bytes at the input of a P-STD for PES streams defined in 2.5.2.4. The
* value encoded in the ES_rate field may vary from PES_packet to PES_packet.
*/
int32_t ES_rate; //22bits
// 1B
/**
* A 3-bit field that indicates which trick mode is applied to the associated video stream. In cases of
* other types of elementary streams, the meanings of this field and those defined by the following five bits are undefined.
* For the definition of trick_mode status, refer to the trick mode section of 2.4.2.3.
*/
int8_t trick_mode_control; //3bits
int8_t trick_mode_value; //5bits
// 1B
// 1bit const '1'
/**
* This 7-bit field contains private data relating to copyright information.
*/
int8_t additional_copy_info; //7bits
// 2B
/**
* The previous_PES_packet_CRC is a 16-bit field that contains the CRC value that yields
* a zero output of the 16 registers in the decoder similar to the one defined in Annex A,
*/
int16_t previous_PES_packet_CRC; //16bits
// 1B
/**
* A 1-bit flag which when set to '1' indicates that the PES packet header contains private data.
* When set to a value of '0' it indicates that private data is not present in the PES header.
*/
int8_t PES_private_data_flag; //1bit
/**
* A 1-bit flag which when set to '1' indicates that an ISO/IEC 11172-1 pack header or a
* Program Stream pack header is stored in this PES packet header. If this field is in a PES packet that is contained in a
* Program Stream, then this field shall be set to '0'. In a Transport Stream, when set to the value '0' it indicates that no pack
* header is present in the PES header.
*/
int8_t pack_header_field_flag; //1bit
/**
* A 1-bit flag which when set to '1' indicates that the
* program_packet_sequence_counter, MPEG1_MPEG2_identifier, and original_stuff_length fields are present in this
* PES packet. When set to a value of '0' it indicates that these fields are not present in the PES header.
*/
int8_t program_packet_sequence_counter_flag; //1bit
/**
* A 1-bit flag which when set to '1' indicates that the P-STD_buffer_scale and P-STD_buffer_size
* are present in the PES packet header. When set to a value of '0' it indicates that these fields are not present in the
* PES header.
*/
int8_t P_STD_buffer_flag; //1bit
// reserved 3bits
/**
* A 1-bit field which when set to '1' indicates the presence of the PES_extension_field_length
* field and associated fields. When set to a value of '0' this indicates that the PES_extension_field_length field and any
* associated fields are not present.
*/
int8_t PES_extension_flag_2; //1bit
// 16B
/**
* This is a 16-byte field which contains private data. This data, combined with the fields before and
* after, shall not emulate the packet_start_code_prefix (0x000001).
*/
char* PES_private_data; //128bits
// (1+x)B
/**
* This is an 8-bit field which indicates the length, in bytes, of the pack_header_field().
*/
int8_t pack_field_length; //8bits
char* pack_field; //[pack_field_length] bytes
// 2B
// 1bit const '1'
/**
* The program_packet_sequence_counter field is a 7-bit field. It is an optional
* counter that increments with each successive PES packet from a Program Stream or from an ISO/IEC 11172-1 Stream or
* the PES packets associated with a single program definition in a Transport Stream, providing functionality similar to a
* continuity counter (refer to 2.4.3.2). This allows an application to retrieve the original PES packet sequence of a Program
* Stream or the original packet sequence of the original ISO/IEC 11172-1 stream. The counter will wrap around to 0 after
* its maximum value. Repetition of PES packets shall not occur. Consequently, no two consecutive PES packets in the
* program multiplex shall have identical program_packet_sequence_counter values.
*/
int8_t program_packet_sequence_counter; //7bits
// 1bit const '1'
/**
* A 1-bit flag which when set to '1' indicates that this PES packet carries information from
* an ISO/IEC 11172-1 stream. When set to '0' it indicates that this PES packet carries information from a Program Stream.
*/
int8_t MPEG1_MPEG2_identifier; //1bit
/**
* This 6-bit field specifies the number of stuffing bytes used in the original ITU-T
* Rec. H.222.0 | ISO/IEC 13818-1 PES packet header or in the original ISO/IEC 11172-1 packet header.
*/
int8_t original_stuff_length; //6bits
// 2B
// 2bits const '01'
/**
* The P-STD_buffer_scale is a 1-bit field, the meaning of which is only defined if this PES packet
* is contained in a Program Stream. It indicates the scaling factor used to interpret the subsequent P-STD_buffer_size field.
* If the preceding stream_id indicates an audio stream, P-STD_buffer_scale shall have the value '0'. If the preceding
* stream_id indicates a video stream, P-STD_buffer_scale shall have the value '1'. For all other stream types, the value
* may be either '1' or '0'.
*/
int8_t P_STD_buffer_scale; //1bit
/**
* The P-STD_buffer_size is a 13-bit unsigned integer, the meaning of which is only defined if this
* PES packet is contained in a Program Stream. It defines the size of the input buffer, BS n , in the P-STD. If
* P-STD_buffer_scale has the value '0', then the P-STD_buffer_size measures the buffer size in units of 128 bytes. If
* P-STD_buffer_scale has the value '1', then the P-STD_buffer_size measures the buffer size in units of 1024 bytes.
*/
int16_t P_STD_buffer_size; //13bits
// (1+x)B
// 1bit const '1'
/**
* This is a 7-bit field which specifies the length, in bytes, of the data following this field in
* the PES extension field up to and including any reserved bytes.
*/
int8_t PES_extension_field_length; //7bits
char* PES_extension_field; //[PES_extension_field_length] bytes
// NB
/**
* This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder, for example to meet
* the requirements of the channel. It is discarded by the decoder. No more than 32 stuffing bytes shall be present in one
* PES packet header.
*/
int nb_stuffings;
// NB
/**
* PES_packet_data_bytes shall be contiguous bytes of data from the elementary stream
* indicated by the packet’s stream_id or PID. When the elementary stream data conforms to ITU-T
* Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 13818-3, the PES_packet_data_bytes shall be byte aligned to the bytes of this
* Recommendation | International Standard. The byte-order of the elementary stream shall be preserved. The number of
* PES_packet_data_bytes, N, is specified by the PES_packet_length field. N shall be equal to the value indicated in the
* PES_packet_length minus the number of bytes between the last byte of the PES_packet_length field and the first
* PES_packet_data_byte.
*
* In the case of a private_stream_1, private_stream_2, ECM_stream, or EMM_stream, the contents of the
* PES_packet_data_byte field are user definable and will not be specified by ITU-T | ISO/IEC in the future.
*/
int nb_bytes;
char* bytes;
// NB
/**
* This is a fixed 8-bit value equal to '1111 1111'. It is discarded by the decoder.
*/
int nb_paddings;
public:
SrsTsPayloadPES(SrsTsPacket* p);
virtual ~SrsTsPayloadPES();
public:
virtual int decode(SrsStream* stream);
};
/**
* the PSI payload of ts packet.
* 2.4.4 Program specific information, hls-mpeg-ts-iso13818-1.pdf, page 59
*/
... ... @@ -687,7 +1042,7 @@ public:
// reserved 3bits
/**
* program_map_PID/network_PID 13bits
* network_PID ¨C The network_PID is a 13-bit field, which is used only in conjunction with the value of the
* network_PID - The network_PID is a 13-bit field, which is used only in conjunction with the value of the
* program_number set to 0x0000, specifies the PID of the Transport Stream packets which shall contain the Network
* Information Table. The value of the network_PID field is defined by the user, but shall only take values as specified in
* Table 2-3. The presence of the network_PID is optional.
... ... @@ -767,7 +1122,7 @@ public:
* This is an 8-bit field specifying the type of program element carried within the packets with the PID
* whose value is specified by the elementary_PID. The values of stream_type are specified in Table 2-29.
*/
u_int8_t stream_type; //8bits
SrsTsStream stream_type; //8bits
// 2B
// 3bits reserved
... ...