winlin

update ts_info, parse the PES packet dts/pts.

... ... @@ -2,6 +2,12 @@
g++ -o ts_info ts_info.cpp -g -O0 -ansi
*/
#if 1
// for int64_t print using PRId64 format.
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <inttypes.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
... ... @@ -361,6 +367,45 @@ public:
int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p);
};
/**
* Table 2-18 – Stream_id assignments. page 52.
*/
enum TSPESStreamId
{
PES_program_stream_map = 0b10111100,
PES_private_stream_1 = 0b10111101,
PES_padding_stream = 0b10111110,
PES_private_stream_2 = 0b10111111,
// 110x xxxx
// ISO/IEC 13818-3 or ISO/IEC 11172-3 or ISO/IEC 13818-7 or ISO/IEC
// 14496-3 audio stream number x xxxx
// (stream_id>>5)&0x07 == PES_audio_prefix
PES_audio_prefix = 0b110,
// 1110 xxxx
// ITU-T Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 11172-2 or ISO/IEC
// 14496-2 video stream number xxxx
// (stream_id>>5)&0x07 == PES_audio_prefix
PES_video_prefix = 0b1110,
PES_ECM_stream = 0b11110000,
PES_EMM_stream = 0b11110001,
PES_DSMCC_stream = 0b11110010,
PES_13522_stream = 0b11110011,
PES_H_222_1_type_A = 0b11110100,
PES_H_222_1_type_B = 0b11110101,
PES_H_222_1_type_C = 0b11110110,
PES_H_222_1_type_D = 0b11110111,
PES_H_222_1_type_E = 0b11111000,
PES_ancillary_stream = 0b11111001,
PES_SL_packetized_stream = 0b11111010,
PES_FlexMux_stream = 0b11111011,
// reserved data stream
// 1111 1100 … 1111 1110
PES_program_stream_directory= 0b11111111,
};
/**
* 2.4.3.7 Semantic definition of fields in PES packet. page 49.
... ... @@ -375,6 +420,33 @@ public:
// 2B
u_int16_t PES_packet_length; //16bits
// 1B
// 2bits const '10'
int8_t PES_scrambling_control; //2bits
int8_t PES_priority; //1bit
int8_t data_alignment_indicator; //1bit
int8_t copyright; //1bit
int8_t original_or_copy; //1bit
// 1B
int8_t PTS_DTS_flags; //2bits
int8_t ESCR_flag; //1bit
int8_t ES_rate_flag; //1bit
int8_t DSM_trick_mode_flag; //1bit
int8_t additional_copy_info_flag; //1bit
int8_t PES_CRC_flag; //1bit
int8_t PES_extension_flag; //1bit
// 1B
u_int8_t PES_header_data_length; //8bits
/**
* logic data.
*/
// generated by PTS_DTS_flags
int64_t pts; // 33bits
int64_t dts; // 33bits
TSPayloadPES();
virtual ~TSPayloadPES();
int demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t* last, u_int8_t*& p);
... ... @@ -832,6 +904,7 @@ int TSPayloadPMT::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t
TSPayloadPES::TSPayloadPES()
{
pts = dts = 0;
}
TSPayloadPES::~TSPayloadPES()
... ... @@ -855,6 +928,131 @@ int TSPayloadPES::demux(TSContext* ctx, TSPacket* pkt, u_int8_t* start, u_int8_t
pp[1] = *p++;
pp[0] = *p++;
if (stream_id != PES_program_stream_map
&& stream_id != PES_padding_stream
&& stream_id != PES_private_stream_2
&& stream_id != PES_ECM_stream
&& stream_id != PES_EMM_stream
&& stream_id != PES_program_stream_directory
&& stream_id != PES_DSMCC_stream
&& stream_id != PES_H_222_1_type_E
) {
original_or_copy = *p++;
//int8_t const2bits = (original_or_copy >> 6) & 0x03;
PES_scrambling_control = (original_or_copy >> 4) & 0x03;
PES_priority = (original_or_copy >> 3) & 0x01;
data_alignment_indicator = (original_or_copy >> 2) & 0x01;
copyright = (original_or_copy >> 1) & 0x01;
original_or_copy &= 0x01;
PES_extension_flag = *p++;
PTS_DTS_flags = (PES_extension_flag >> 6) & 0x03;
ESCR_flag = (PES_extension_flag >> 5) & 0x01;
ES_rate_flag = (PES_extension_flag >> 4) & 0x01;
DSM_trick_mode_flag = (PES_extension_flag >> 3) & 0x01;
additional_copy_info_flag = (PES_extension_flag >> 2) & 0x01;
PES_CRC_flag = (PES_extension_flag >> 1) & 0x01;
PES_extension_flag &= 0x01;
PES_header_data_length = *p++;
if (PTS_DTS_flags == 0x2) {
int64_t temp = 0;
pp = (char*)&temp;
pp[4] = *p++;
pp[3] = *p++;
pp[2] = *p++;
pp[1] = *p++;
pp[0] = *p++;
// marker_bit 1bit
temp = temp >> 1;
// PTS [14..0] 15bits
pts |= temp & 0x3FFF;
// marker_bit 1bit
temp = temp >> 1;
// PTS [29..15] 15bits
pts |= temp & 0x3fff8000;
// marker_bit 1bit
temp = temp >> 1;
// PTS [32..30] 3bits
pts |= temp & 0x1c0000000;
// '0010' 4bits
//int8_t const4bits = (temp >> 32) & 0x0F;
}
if (PTS_DTS_flags == 0x3) {
int64_t temp = 0;
pp = (char*)&temp;
pp[4] = *p++;
pp[3] = *p++;
pp[2] = *p++;
pp[1] = *p++;
pp[0] = *p++;
// marker_bit 1bit
temp = temp >> 1;
// PTS [14..0] 15bits
pts |= temp & 0x3FFF;
// marker_bit 1bit
temp = temp >> 1;
// PTS [29..15] 15bits
pts |= temp & 0x3fff8000;
// marker_bit 1bit
temp = temp >> 1;
// PTS [32..30] 3bits
pts |= temp & 0x1c0000000;
// '0010' 4bits
//int8_t const4bits = (temp >> 32) & 0x0F;
pp = (char*)&temp;
pp[4] = *p++;
pp[3] = *p++;
pp[2] = *p++;
pp[1] = *p++;
pp[0] = *p++;
// marker_bit 1bit
temp = temp >> 1;
// PTS [14..0] 15bits
dts |= temp & 0x3FFF;
// marker_bit 1bit
temp = temp >> 1;
// PTS [29..15] 15bits
dts |= temp & 0x3fff8000;
// marker_bit 1bit
temp = temp >> 1;
// PTS [32..30] 3bits
dts |= temp & 0x1c0000000;
// '0010' 4bits
//int8_t const4bits = (temp >> 32) & 0x0F;
}
if (ESCR_flag) {
}
} else if (stream_id == PES_program_stream_map
|| stream_id == PES_private_stream_2
|| stream_id == PES_ECM_stream
|| stream_id == PES_EMM_stream
|| stream_id == PES_program_stream_directory
|| stream_id == PES_DSMCC_stream
|| stream_id == PES_H_222_1_type_E
) {
// for (i = 0; i < PES_packet_length; i++) {
// PES_packet_data_byte
// }
} else if (stream_id != PES_padding_stream) {
// for (i = 0; i < PES_packet_length; i++) {
// padding_byte
// }
}
trace("ts+pes stream_id: %d size: %d pts: %"PRId64" dts: %"PRId64"",
stream_id, PES_packet_length, pts, dts);
return ret;
}
... ...