免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2007 | 回复: 0
打印 上一主题 下一主题

TS流解析之PMT表格解析 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-08-02 16:28 |只看该作者 |倒序浏览
[color="#000102"]typedef struct TS_PMT_Stream{ unsigned stream_type                    : 8; //指示特定PID的节目元素包的类型。该处PID由elementary PID指定 unsigned elementary_PID                    : 13; //该域指示TS包的PID值。这些TS包含有相关的节目元素 unsigned ES_info_length                    : 12; //前两位bit为00。该域指示跟随其后的描述相关节目元素的byte数 unsigned descriptor;}TS_PMT_Stream;
[color="#000102"]//PMT 表结构体typedef struct TS_PMT{    unsigned table_id                        : 8; //固定为0x02, 表示PMT表    unsigned section_syntax_indicator        : 1; //固定为0x01    unsigned zero                            : 1; //0x01    unsigned reserved_1                      : 2; //0x03    unsigned section_length                  : 12;//首先两位bit置为00,它指示段的byte数,由段长度域开始,包含CRC。    unsigned program_number                    : 16;// 指出该节目对应于可应用的Program map PID    unsigned reserved_2                        : 2; //0x03    unsigned version_number                    : 5; //指出TS流中Program map section的版本号    unsigned current_next_indicator            : 1; //当该位置1时,当前传送的Program map section可用;   //当该位置0时,指示当前传送的Program map section不可用,下一个TS流的Program map section有效。    unsigned section_number                    : 8; //固定为0x00    unsigned last_section_number            : 8; //固定为0x00    unsigned reserved_3                        : 3; //0x07    unsigned PCR_PID                        : 13; //指明TS包的PID值,该TS包含有PCR域,            //该PCR值对应于由节目号指定的对应节目。            //如果对于私有数据流的节目定义与PCR无关,这个域的值将为0x1FFF。    unsigned reserved_4                        : 4; //预留为0x0F    unsigned program_info_length            : 12; //前两位bit为00。该域指出跟随其后对节目信息的描述的byte数。     std::vector PMT_Stream;  //每个元素包含8位, 指示特定PID的节目元素包的类型。该处PID由elementary PID指定    unsigned reserved_5                        : 3; //0x07    unsigned reserved_6                        : 4; //0x0F    unsigned CRC_32                            : 32; } TS_PMT;
[color="#000102"]
[color="#000102"]解析代码为:
[color="#000102"]HRESULT CTS_Stream_Parse::adjust_PMT_table ( TS_PMT * packet, unsigned char * buffer ){     packet->table_id                            = buffer[0];    packet->section_syntax_indicator            = buffer[1] >> 7;    packet->zero                                = buffer[1] >> 6 & 0x01;     packet->reserved_1                            = buffer[1] >> 4 & 0x03;    packet->section_length                        = (buffer[1] & 0x0F)     packet->program_number                        = buffer[3]     packet->reserved_2                            = buffer[5] >> 6;    packet->version_number                        = buffer[5] >> 1 & 0x1F;    packet->current_next_indicator                = (buffer[5] > 7;    packet->section_number                        = buffer[6];    packet->last_section_number                    = buffer[7];    packet->reserved_3                            = buffer[8] >> 5;    packet->PCR_PID                                = ((buffer[8] [color="#000102"] PCRID = packet->PCR_PID;
[color="#000102"]    packet->reserved_4                            = buffer[10] >> 4;    packet->program_info_length                    = (buffer[10] & 0x0F)     // Get CRC_32 int len = 0;    len = packet->section_length + 3;        packet->CRC_32                = (buffer[len-4] & 0x000000FF)   | (buffer[len-3] & 0x000000FF)   | (buffer[len-2] & 0x000000FF)   | (buffer[len-1] & 0x000000FF);
[color="#000102"] int pos = 12;    // program info descriptor    if ( packet->program_info_length != 0 )        pos += packet->program_info_length;        // Get stream type and PID        for ( ; pos section_length + 2 ) -  4; )    {  TS_PMT_Stream pmt_stream;  pmt_stream.stream_type =  buffer[pos];  packet->reserved_5  =   buffer[pos+1] >> 5;  pmt_stream.elementary_PID =  ((buffer[pos+1]   packet->reserved_6     =   buffer[pos+3] >> 4;  pmt_stream.ES_info_length =   (buffer[pos+3] & 0x0F)     pmt_stream.descriptor = 0x00;  if (pmt_stream.ES_info_length != 0)  {   pmt_stream.descriptor = buffer[pos + 5];      for( int len = 2; len    {    pmt_stream.descriptor = pmt_stream.descriptor   }   pos += pmt_stream.ES_info_length;  }  pos += 5;  packet->PMT_Stream.push_back( pmt_stream );  TS_Stream_type.push_back( pmt_stream );    } return 0;}
[color="#000102"]举例如下:
[color="#000102"]0x47 0x43 0xe8 0x12[color="#000102"] [color="#000102"]0x00[color="#000102"] 0x02 0xb0 0x12 0x00 0x01 0xc1 0x00 0x00 0xe3 0xe9 0xf0 0x00[color="#000102"]  [color="#000102"]0x1b 0xe3 0xe9 0xf0 0x00 0xf0 0xaf 0xb4 0x4f 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff
[color="#000102"]TS[color="#000102"]头部
[color="#000102"]sync_byte   [color="#000102"]:[color="#000102"]0x47transport_error_indicator: 0x00payload_unit_start_indicator: 0x01transport_priority  : 0x00
[color="#000102"]  PID                     :0x03e8transport_scrambling_control  :0x00adaptation_field_control  :0x01                                    
[color="#000102"]continuity_counter   :0x02
[color="#000102"]
[color="#000102"]PMT[color="#000102"]数据[color="#000102"]         
[color="#000102"]table_id     :0x02                          // 8section_syntax_indicator  :0x01            //  1'0'                :0x00                   //  1reserved       :0x03                       //  2section_length :      0x012                 //  12program_number    :0x00 01                    //  16reserved               :0x03               //  2version_number    :0x00                    //  5current_next_indicator   0x01             //  1section_number      :0x00                  //  8last_section_number    :0x00               //  8 reserved                   0x07           //  3PCR_PID           :0x03 e9   // PCR([color="#000102"]节目参考时钟[color="#000102"])[color="#000102"]所在[color="#000102"]TS[color="#000102"]分组的[color="#000102"]PID          //  13reser[color="#000102"]ved[color="#000102"] [color="#000102"]      [color="#000102"]:0x0f[color="#000102"]                 [color="#000102"]//4program_info_length     :0x000              //  12stream_type       :0x1b                    //  8reserved            0x07                  //  3elementary_PID        :0x03 e9    //  13//[color="#000102"]该节目中包括的视频流,音频流等对应的[color="#000102"]TS[color="#000102"]分组的[color="#000102"]PIDreserved                    :0x0f          //  4ES_info_length         :0x000               //  12CRC[color="#000102"]        [color="#000102"]: 0xf0 af b4 4f
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/98222/showart_2015657.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP