winlin

fix bug of ts_info

@@ -225,3 +225,55 @@ TS的第二个视频包数据如下: @@ -225,3 +225,55 @@ TS的第二个视频包数据如下:
225 0x60b3b0: 0xf3 0x99 0x45 0xee 0xce 0xc7 0x1f 0xeb 225 0x60b3b0: 0xf3 0x99 0x45 0xee 0xce 0xc7 0x1f 0xeb
226 0x60b3b8: 0x43 0x37 0xfd 0x67 0x34 0x97 0xcc 0x8c 226 0x60b3b8: 0x43 0x37 0xfd 0x67 0x34 0x97 0xcc 0x8c
227 0x60b3c0: 0xc5 0xec 0x86 0xb0 0x57 0xb4 0x83 0xa9 227 0x60b3c0: 0xc5 0xec 0x86 0xb0 0x57 0xb4 0x83 0xa9
  228 +
  229 +
  230 +
  231 +3031个ts包是空包,解析有问题:
  232 +47 41 00 38 07 50 05 09 5A A6 7E 00 00 00 01 E0
  233 +00 00 80 C0 0A 31 28 53 60 81 11 28 53 42 F9 00
  234 +00 00 01 09 F0 00 00 00 01 67 64 00 28 AC D1 C0
  235 +50 05 BB FF 00 2D 00 22 10 00 00 03 00 10 00 00
  236 +03 03 08 F1 83 11 E0 00 00 00 01 68 E9 AB 2C 8B
  237 +00 00 01 65 88 84 00 42 BF 08 EE 00 02 B2 75 8D
  238 +9F C4 24 E5 BD 27 87 F1 E4 09 A0 51 2D 12 FC F5
  239 +6E 31 3D C4 0E 3F 51 47 07 BD D2 8C AB 72 1C 2D
  240 +D0 FA 2F 7D EF AA FB 17 C1 08 AD 36 8D F1 41 35
  241 +E0 20 AE E8 75 66 39 15 78 88 01 E8 2E 4E 8A 8B
  242 +F8 04 68 BF EC 82 59 86 DE E1 66 32 37 FA 78 6D
  243 +01 EF C0 2C 6B A6 E9 36 44 4B C8 37
  244 +
  245 +Adaptation fields
  246 + Adaptation_field_length: 7
  247 + discontinuity_indicator: False
  248 + random_access_indicator: True
  249 + ES_priority_indicator: False
  250 + PCR_flag: True
  251 + OPCR_flag: False
  252 + splicing_point_flag: False
  253 + transport_private_data_flag: False
  254 + adaptation_field_extension_flag: False
  255 + PCR: 50699466000
  256 +
  257 +PES header
  258 + stream_id: E0 (video stream 224)
  259 + PES_packet_length: 0 (undefined)
  260 + PES_scrambling: 0
  261 + PES_priority: False
  262 + data_alignment: False
  263 + copyright: False
  264 + original_or_copy: False
  265 + PTS_flag: True
  266 + DTS_flag: True
  267 + ESCR_flag: False
  268 + ES_rate_flag: False
  269 + DSM_trick_mode_flag: False
  270 + additional_copy_info_flag: False
  271 + PES_CRC_flag: False
  272 + PES_extension_flag: False
  273 + PES_header_data_length: 10
  274 + PTS: 169128000
  275 + DTS: 169124220
  276 +
  277 +Video sequence
  278 +Sequence header code not found in this packet
  279 +AFD not found in this packet
@@ -568,6 +568,7 @@ public: @@ -568,6 +568,7 @@ public:
568 */ 568 */
569 int pid_size; 569 int pid_size;
570 TSPid* pids; 570 TSPid* pids;
  571 + int64_t ts_packet_count;
571 std::map<int16_t, TSMessage*> msgs; 572 std::map<int16_t, TSMessage*> msgs;
572 573
573 TSContext(); 574 TSContext();
@@ -583,6 +584,7 @@ public: @@ -583,6 +584,7 @@ public:
583 TSContext::TSContext() 584 TSContext::TSContext()
584 { 585 {
585 pid_size = 0; 586 pid_size = 0;
  587 + ts_packet_count = 0;
586 pids = NULL; 588 pids = NULL;
587 } 589 }
588 590
@@ -1567,8 +1569,9 @@ int TSPacket::demux(TSContext* ctx, u_int8_t* start, u_int8_t* last, u_int8_t*& @@ -1567,8 +1569,9 @@ int TSPacket::demux(TSContext* ctx, u_int8_t* start, u_int8_t* last, u_int8_t*&
1567 trace("ts+header payload decoded."); 1569 trace("ts+header payload decoded.");
1568 } 1570 }
1569 1571
1570 - trace("ts+header parsed finished. parsed: %d left: %d header: %d payload: %d(%d+%d)",  
1571 - (int)(p - start), (int)(last - p), header->get_size(), payload->size, payload->pointer_field_size, 1572 + ctx->ts_packet_count++;
  1573 + trace("ts+header parsed %"PRId64" packets finished. parsed: %d left: %d header: %d payload: %d(%d+%d)",
  1574 + ctx->ts_packet_count, (int)(p - start), (int)(last - p), header->get_size(), payload->size, payload->pointer_field_size,
1572 payload->size - payload->pointer_field_size); 1575 payload->size - payload->pointer_field_size);
1573 1576
1574 return finish(); 1577 return finish();
@@ -1692,22 +1695,11 @@ enum TSH264PicType @@ -1692,22 +1695,11 @@ enum TSH264PicType
1692 class TSH264Codec 1695 class TSH264Codec
1693 { 1696 {
1694 public: 1697 public:
1695 - int8_t forbidden_zero_bit; //1bit  
1696 - int8_t nal_ref_idc; //2bits  
1697 - TSH264NalUnitType nal_unit_type; //5bits  
1698 -  
1699 - // for nal_unit_type == TSH264NalUnitTypePictureDelimiter  
1700 - TSH264PicType pic_type; //3bits  
1701 -  
1702 u_int8_t* raw_data; 1698 u_int8_t* raw_data;
1703 int size; 1699 int size;
1704 1700
1705 TSH264Codec() 1701 TSH264Codec()
1706 { 1702 {
1707 - forbidden_zero_bit = 0;  
1708 - nal_ref_idc = 0;  
1709 - nal_unit_type = TSH264NalUnitTypeUnspecified;  
1710 - pic_type = TSH264PicTypeI;  
1711 size = 0; 1703 size = 0;
1712 raw_data = NULL; 1704 raw_data = NULL;
1713 } 1705 }
@@ -1724,7 +1716,9 @@ public: @@ -1724,7 +1716,9 @@ public:
1724 { 1716 {
1725 int ret = 0; 1717 int ret = 0;
1726 1718
1727 - while (next_int(p, 3) != 0x000001) { 1719 + srs_assert(p);
  1720 +
  1721 + while (next_start_code_prefix(p) != 0x000001) {
1728 char ch = *p++; 1722 char ch = *p++;
1729 if (ch != 0x00) { 1723 if (ch != 0x00) {
1730 trace("ts+h264 parse msg failed, " 1724 trace("ts+h264 parse msg failed, "
@@ -1741,45 +1735,25 @@ public: @@ -1741,45 +1735,25 @@ public:
1741 // start_code_prefix_one_3bytes /* equal to 0x000001 */ 1735 // start_code_prefix_one_3bytes /* equal to 0x000001 */
1742 p += 3; 1736 p += 3;
1743 1737
  1738 + if (p < last) {
1744 raw_data = (u_int8_t*)p; 1739 raw_data = (u_int8_t*)p;
1745 - while (p < last) { 1740 + }
  1741 + while (p < last - 3) {
1746 if (match_start_code_prefix(p)) { 1742 if (match_start_code_prefix(p)) {
1747 break; 1743 break;
1748 } 1744 }
1749 p++; 1745 p++;
1750 } 1746 }
1751 - size = (u_int8_t*)p - raw_data;  
1752 -  
1753 - trace("ts+h264 parse msg finished");  
1754 - return ret;  
1755 1747
1756 - // nal_unit( NumBytesInNALunit ) specified in page 44.  
1757 - // where f(1) specified in page 43.  
1758 - int8_t _nal_unit_type = *p++;  
1759 -  
1760 - forbidden_zero_bit = (_nal_unit_type >> 7) &0x01;  
1761 - nal_ref_idc = (_nal_unit_type >> 5) &0x03;  
1762 - _nal_unit_type &= 0x1f;  
1763 -  
1764 - nal_unit_type = (TSH264NalUnitType)_nal_unit_type;  
1765 -  
1766 - if (nal_unit_type == TSH264NalUnitTypePictureDelimiter) {  
1767 - /**  
1768 - * 7.3.2.4 Picture delimiter RBSP syntax  
1769 - * pic_delimiter_rbsp(), in page 47  
1770 - */  
1771 - } else if (nal_unit_type == TSH264NalUnitTypeSequenceParameterSet) {  
1772 - /**  
1773 - * 7.3.2.1 Sequence parameter set RBSP syntax  
1774 - * seq_parameter_set_rbsp(), in page 45  
1775 - */  
1776 - } else if (nal_unit_type == TSH264NalUnitTypePictureParameterSet) {  
1777 - /**  
1778 - * 7.3.2.2 Picture parameter set RBSP syntax  
1779 - * pic_parameter_set_rbsp(), in page 46  
1780 - */ 1748 + if (raw_data) {
  1749 + size = (u_int8_t*)p - raw_data;
  1750 + if (p == last - 3) {
  1751 + size = (u_int8_t*)last - raw_data;
  1752 + p = last;
  1753 + }
1781 } 1754 }
1782 1755
  1756 + trace("ts+h264 parse msg finished");
1783 return ret; 1757 return ret;
1784 } 1758 }
1785 1759
@@ -1788,16 +1762,14 @@ public: @@ -1788,16 +1762,14 @@ public:
1788 return p[0] == 0x00 && p[1] == 0x00 && (p[2] == 0x00 || p[2] == 0x01); 1762 return p[0] == 0x00 && p[1] == 0x00 && (p[2] == 0x00 || p[2] == 0x01);
1789 } 1763 }
1790 1764
1791 - int32_t next_int(char* p, int bytes) 1765 + int32_t next_start_code_prefix(char* p)
1792 { 1766 {
1793 - srs_assert(bytes <= sizeof(int32_t));  
1794 -  
1795 int32_t value = 0; 1767 int32_t value = 0;
1796 char* pp = (char*)&value; 1768 char* pp = (char*)&value;
1797 1769
1798 - for (int i = 0; i < bytes; i++) {  
1799 - *(pp + bytes - 1 - i) = *(p + i);  
1800 - } 1770 + pp[2] = p[0];
  1771 + pp[1] = p[1];
  1772 + pp[0] = p[2];
1801 1773
1802 return value; 1774 return value;
1803 } 1775 }
@@ -1868,6 +1840,8 @@ public: @@ -1868,6 +1840,8 @@ public:
1868 { 1840 {
1869 int ret = 0; 1841 int ret = 0;
1870 1842
  1843 + srs_assert(p);
  1844 +
1871 char* start = p; 1845 char* start = p;
1872 1846
1873 // adts_fixed_header 1847 // adts_fixed_header
@@ -1946,6 +1920,11 @@ int consume(TSMessage* msg) @@ -1946,6 +1920,11 @@ int consume(TSMessage* msg)
1946 int ret = 0; 1920 int ret = 0;
1947 1921
1948 char* p = msg->packet_data; 1922 char* p = msg->packet_data;
  1923 + if (!p) {
  1924 + trace("ts+aac+h264 ignore empty message.");
  1925 + return ret;
  1926 + }
  1927 +
1949 char* last = msg->packet_data + msg->packet_data_size; 1928 char* last = msg->packet_data + msg->packet_data_size;
1950 1929
1951 if (!msg->is_video()) { 1930 if (!msg->is_video()) {