winlin

fix bug of ts_info

... ... @@ -225,3 +225,55 @@ TS的第二个视频包数据如下:
0x60b3b0: 0xf3 0x99 0x45 0xee 0xce 0xc7 0x1f 0xeb
0x60b3b8: 0x43 0x37 0xfd 0x67 0x34 0x97 0xcc 0x8c
0x60b3c0: 0xc5 0xec 0x86 0xb0 0x57 0xb4 0x83 0xa9
3031个ts包是空包,解析有问题:
47 41 00 38 07 50 05 09 5A A6 7E 00 00 00 01 E0
00 00 80 C0 0A 31 28 53 60 81 11 28 53 42 F9 00
00 00 01 09 F0 00 00 00 01 67 64 00 28 AC D1 C0
50 05 BB FF 00 2D 00 22 10 00 00 03 00 10 00 00
03 03 08 F1 83 11 E0 00 00 00 01 68 E9 AB 2C 8B
00 00 01 65 88 84 00 42 BF 08 EE 00 02 B2 75 8D
9F C4 24 E5 BD 27 87 F1 E4 09 A0 51 2D 12 FC F5
6E 31 3D C4 0E 3F 51 47 07 BD D2 8C AB 72 1C 2D
D0 FA 2F 7D EF AA FB 17 C1 08 AD 36 8D F1 41 35
E0 20 AE E8 75 66 39 15 78 88 01 E8 2E 4E 8A 8B
F8 04 68 BF EC 82 59 86 DE E1 66 32 37 FA 78 6D
01 EF C0 2C 6B A6 E9 36 44 4B C8 37
Adaptation fields
Adaptation_field_length: 7
discontinuity_indicator: False
random_access_indicator: True
ES_priority_indicator: False
PCR_flag: True
OPCR_flag: False
splicing_point_flag: False
transport_private_data_flag: False
adaptation_field_extension_flag: False
PCR: 50699466000
PES header
stream_id: E0 (video stream 224)
PES_packet_length: 0 (undefined)
PES_scrambling: 0
PES_priority: False
data_alignment: False
copyright: False
original_or_copy: False
PTS_flag: True
DTS_flag: True
ESCR_flag: False
ES_rate_flag: False
DSM_trick_mode_flag: False
additional_copy_info_flag: False
PES_CRC_flag: False
PES_extension_flag: False
PES_header_data_length: 10
PTS: 169128000
DTS: 169124220
Video sequence
Sequence header code not found in this packet
AFD not found in this packet
\ No newline at end of file
... ...
... ... @@ -568,6 +568,7 @@ public:
*/
int pid_size;
TSPid* pids;
int64_t ts_packet_count;
std::map<int16_t, TSMessage*> msgs;
TSContext();
... ... @@ -583,6 +584,7 @@ public:
TSContext::TSContext()
{
pid_size = 0;
ts_packet_count = 0;
pids = NULL;
}
... ... @@ -1567,8 +1569,9 @@ int TSPacket::demux(TSContext* ctx, u_int8_t* start, u_int8_t* last, u_int8_t*&
trace("ts+header payload decoded.");
}
trace("ts+header parsed finished. parsed: %d left: %d header: %d payload: %d(%d+%d)",
(int)(p - start), (int)(last - p), header->get_size(), payload->size, payload->pointer_field_size,
ctx->ts_packet_count++;
trace("ts+header parsed %"PRId64" packets finished. parsed: %d left: %d header: %d payload: %d(%d+%d)",
ctx->ts_packet_count, (int)(p - start), (int)(last - p), header->get_size(), payload->size, payload->pointer_field_size,
payload->size - payload->pointer_field_size);
return finish();
... ... @@ -1692,22 +1695,11 @@ enum TSH264PicType
class TSH264Codec
{
public:
int8_t forbidden_zero_bit; //1bit
int8_t nal_ref_idc; //2bits
TSH264NalUnitType nal_unit_type; //5bits
// for nal_unit_type == TSH264NalUnitTypePictureDelimiter
TSH264PicType pic_type; //3bits
u_int8_t* raw_data;
int size;
TSH264Codec()
{
forbidden_zero_bit = 0;
nal_ref_idc = 0;
nal_unit_type = TSH264NalUnitTypeUnspecified;
pic_type = TSH264PicTypeI;
size = 0;
raw_data = NULL;
}
... ... @@ -1724,7 +1716,9 @@ public:
{
int ret = 0;
while (next_int(p, 3) != 0x000001) {
srs_assert(p);
while (next_start_code_prefix(p) != 0x000001) {
char ch = *p++;
if (ch != 0x00) {
trace("ts+h264 parse msg failed, "
... ... @@ -1741,45 +1735,25 @@ public:
// start_code_prefix_one_3bytes /* equal to 0x000001 */
p += 3;
if (p < last) {
raw_data = (u_int8_t*)p;
while (p < last) {
}
while (p < last - 3) {
if (match_start_code_prefix(p)) {
break;
}
p++;
}
size = (u_int8_t*)p - raw_data;
trace("ts+h264 parse msg finished");
return ret;
// nal_unit( NumBytesInNALunit ) specified in page 44.
// where f(1) specified in page 43.
int8_t _nal_unit_type = *p++;
forbidden_zero_bit = (_nal_unit_type >> 7) &0x01;
nal_ref_idc = (_nal_unit_type >> 5) &0x03;
_nal_unit_type &= 0x1f;
nal_unit_type = (TSH264NalUnitType)_nal_unit_type;
if (nal_unit_type == TSH264NalUnitTypePictureDelimiter) {
/**
* 7.3.2.4 Picture delimiter RBSP syntax
* pic_delimiter_rbsp(), in page 47
*/
} else if (nal_unit_type == TSH264NalUnitTypeSequenceParameterSet) {
/**
* 7.3.2.1 Sequence parameter set RBSP syntax
* seq_parameter_set_rbsp(), in page 45
*/
} else if (nal_unit_type == TSH264NalUnitTypePictureParameterSet) {
/**
* 7.3.2.2 Picture parameter set RBSP syntax
* pic_parameter_set_rbsp(), in page 46
*/
if (raw_data) {
size = (u_int8_t*)p - raw_data;
if (p == last - 3) {
size = (u_int8_t*)last - raw_data;
p = last;
}
}
trace("ts+h264 parse msg finished");
return ret;
}
... ... @@ -1788,16 +1762,14 @@ public:
return p[0] == 0x00 && p[1] == 0x00 && (p[2] == 0x00 || p[2] == 0x01);
}
int32_t next_int(char* p, int bytes)
int32_t next_start_code_prefix(char* p)
{
srs_assert(bytes <= sizeof(int32_t));
int32_t value = 0;
char* pp = (char*)&value;
for (int i = 0; i < bytes; i++) {
*(pp + bytes - 1 - i) = *(p + i);
}
pp[2] = p[0];
pp[1] = p[1];
pp[0] = p[2];
return value;
}
... ... @@ -1868,6 +1840,8 @@ public:
{
int ret = 0;
srs_assert(p);
char* start = p;
// adts_fixed_header
... ... @@ -1946,6 +1920,11 @@ int consume(TSMessage* msg)
int ret = 0;
char* p = msg->packet_data;
if (!p) {
trace("ts+aac+h264 ignore empty message.");
return ret;
}
char* last = msg->packet_data + msg->packet_data_size;
if (!msg->is_video()) {
... ...