TS流中从段解析出详细的表信息

        做了一个月左右的机顶盒开发,学到了点东西,希望记录下来以表明我在数字电视行业做过。
        PSI表和SI表我就不做太多详细的解释,百度下到处都是。现在以网络NIT表来做下各个字段的解释。

NIT表:
       网络信息表NIT传递了与通过一个给定的网络传输的复用流/TS流的物理结构相关的信息,以及与网络自身特性相关的信息。在本标准应用的范围内,original_network_id 和 transport_stream_id 两个标识符相结合唯一确定了网络中的TS流。各网络被分配独立的 network_id值作为网络的唯一识别码。这些码字的分配见ETR 162。当NIT表在生成TS流的网络上传输时,network_id和original_network_id将取同一值。

传输媒体边界间转换的业务信息处理指南见ETR 211。例如:从卫星系统到有线电视系统或SMATV(卫星公共天线电视)系统。

当转换频道时,为了使存取时间最小,IRD可以在非易失性存储器上存储NIT表信息。除现行网络外,也可以为其他网络传输NIT表信息。现行网络的NIT表与其他网络的NIT表使用不同的table_id值来区分(见表2)

按照表3的语法,NIT表被切分成网络信息段(network_information_section)。任何构成NIT表的段,都要由PID为0x10的TS包传输。描述现行网络(即包含NIT表的TS所在的网络)的NIT表的任何段的table_id值应为0x40,且具有相同的table_id_extension(network_id)。现行网络的network_id字段的值的分配见ETR 162。指向一个现行网络之外的其它网络的NIT表的任何段的table_id值应取0x41,network_id字段的值的分配见ETR 162。                                                            


网络信息段的意义:

        表标识符  table_id 见表2。

        段语法指示符  section_syntax_indicator 1位字段,应置“1”。

        段长度  section_length12位字段,前两位置“00”。它表示从该字段的下一个字节开始的本段的字节长度,并包含CRC。section_length不能超过1021,这样整个段的最大长度为1024字节。

        网络标识符  network_id:16位字段。NIT表所描述的传输系统的网络标识,用以区别其他的传输系统。本字段值的分配见ETR 162。

        版本号  version_number:5位字段。标识子表的版本号。当子表包含的信息发生变化时,version_number加1。当值增至31时,复位为0。                                                               当current_next_indicator置“1”时,则version_number为由table_id和network_id定义的当前使用的子表的版本号。当current_next_indicator置“0”时,则version_number为由table_id和network_id定义的下一个使用的子表的版本号。

        当前后续指示符  current_next_indicator:1位指示符。当被置“1”时,表示当前子表正被使用。当其置“0”时,表示所传子表尚未被使用,它是下一个将被使用的子表。

        段号  section_number: 8位字段,给出了段号。子表中的第一个段的section_number标为“0x00”。每增加一个具有相同的table_id和bouquet_id的段,section_number就加1。

        最后段号  last_section_number: 8位字段,表示所属的子表的最后一个段(即段号最大的段)的段号。

        网络描述符长度 network_descriptors_length:12位字段,给出了从本字段的下一个字节开始的网络描述符的总字节长度。

        传输流循环长度  transport_stream_loop_length:12位字段,定义了从本字段的下一个字节到第一个CRC-32字节之前的传输流循环的总字节长度。

        传输流标识符  transport_stream_id:16位字段,用于区别在同一个传输系统中,不同的复用码流。

        原始网络标识符 original_network_id:16位字段,给出原始传输系统的network_id。

        传输流描述符长度  transport_descriptors_length:12位字段,指出从本字段的下一个字节开始的TS描述符的总字节长度。

        CRC_32:32位字段。包含了CRC值,在处理完整个段之后,附录B定义的CRC解码器的寄存器输出为零。

        以上是摘抄自《数字视频广播中文业务信息规范》


       下面是从一个段中来解析出NIT表的详细信息代码实现:

#include<stdio.h>
#include<string.h>

//截取一个段的数据
unsigned char buff[] = {"\0"};// 实际截取的数据看代码最后面,可以用来验证程序是否正确

//网络描述结构体
typedef struct descriptoy
{
unsigned descriptor_tag          :8;
unsigned descriptor_length       :8;
unsigned frequency               :32;
unsigned reserved_future_use     :12;
unsigned FEC_outer               :4;
unsigned modulation              :8;
unsigned symbol_rate             :28;
unsigned FEC_inner               :4;
}Descriptor;

//第二个循环的结构体
typedef struct second_for
{
unsigned transport_stream_id             :16;
unsigned original_network_id             :16;
unsigned reserved_future_use              :4;
unsigned transport_descriptors_length    :12;
// Descriptor  descriptor                   :16;
}fLoop;

//整个NIT表的结构体
typedef struct NIT_Section
{
unsigned table_id                  :8;
unsigned section_syntax_indicator  :1;
unsigned reserved_future_use       :1;
unsigned reserved                  :2;
unsigned section_length            :12;
unsigned network_id                :16;
unsigned reserved_other            :2;
unsigned version_number            :5;
unsigned current_next_indicator    :1;
unsigned section_number            :8;
unsigned last_section_number       :8;
unsigned reserved_future_use_other :4;
unsigned network_descriptor_length :12;
unsigned reserved_future_use_two   :4;
unsigned transport_stream_loop_length       :12;
} NIT_S;

//定义全局变量
static int LEN = sizeof(buff);
static NIT_S NSection; 
static Descriptor descriptor;
static fLoop  floop;

int Descriptoy_Cx(int , int );

//调整有效字段,获取表字段信息
void adjust_NIT_Section()
{
   int i = 0;
   NSection.table_id = buff[i++];                                           // 8
   NSection.section_syntax_indicator = (buff[i] >> 7);             // 1
   NSection.reserved_future_use = ((buff[i] >> 6) & 0x01);     // 1
   NSection.reserved = ((buff[i] >> 4) & 0x3);                        // 2
   NSection.section_length = (((buff[i++] &0x0F) << 8 ) | buff[i+1]);  // 12
   i++;
   NSection.network_id = ((buff[i++] << 8) | buff[i+1]); // 16
   i++;
   NSection.reserved_other = buff[i] >> 6;                                          // 2
   NSection.version_number = ((buff[i] >> 1) | 0x1F);                         //  5
   NSection.current_next_indicator = (buff[i++] & 0x1);                         //  1
   NSection.section_number = buff[i++] ;                                            //   8
   NSection.last_section_number = buff[i++];                                       //   8
   NSection.reserved_future_use_other = (buff[i] >> 4);                       //   4
   NSection.network_descriptor_length  = (((buff[i++] & 0x0F) << 8) | buff[i+1] ); //12
   i++;

//打印段信息
   printf("\nNIT Section:=================\n");
   printf("table_id:0x%x\n",NSection.table_id);
   printf("section_syntax_indicator:0x%x\n",NSection.section_syntax_indicator);
   printf("reserved_future_use:0x%x\n",NSection.reserved_future_use);
   printf("reserved:0x%x\n",NSection.reserved);
   printf("section_lenth:0x%x\n",NSection.section_length);
   printf("network_id:0x%x\n",NSection.network_id);
   printf("reserved_other:0x%x\n",NSection.reserved_other);
   printf("version_number:0x%x\n",NSection.version_number);
   printf("current_next_indicator:0x%x\n",NSection.current_next_indicator);
   printf("section_number:0x%x\n",NSection.section_number);
   printf("last_section_number:0x%x\n",NSection.last_section_number);
   printf("reserved_future_use_other:0x%x\n",NSection.reserved_future_use_other);
   printf("network_descriptor_length:0x%x\n",NSection.network_descriptor_length);

   i = Descriptoy_Cx(i, NSection.network_descriptor_length);
  
   NSection.reserved_future_use_two = (buff[i] >> 4);    // 4
   printf("reserved_future_use_tw0:0x%x\n",NSection.reserved_future_use_two);
   NSection.transport_stream_loop_length = (((buff[i++] & 0xF) << 8) | buff[i+1]);   // 12 
   i++;
   printf("transport_stream_loop_length:0x%x\n",NSection.transport_stream_loop_length);

  i =  fLoop_descriptoy(i, NSection.transport_stream_loop_length);
  
  int CRC_32 = ( (buff[i] << 24) | (buff[i+1] << 16) | (buff[i+2] << 8) | buff[i+3] );
  printf("CRC_32:0x%x\n",CRC_32);
}

//第二个循环解析
int fLoop_descriptoy(int count,int length)
{
    printf("\nfL00p_descriptoy============================\n");
    while(0 < length)
    {
     floop.transport_stream_id = ((buff[count++] << 8) | buff[count+1]) ;// 16
     count++;
     floop.original_network_id =  ((buff[count++] << 8) | buff[count+1]);//16
     count++;
     floop.reserved_future_use = (buff[count] >> 4); // 4
     floop.transport_descriptors_length = (((buff[count++] & 0x0F) << 8) | buff[count+1]);
     count++;

     //打印流信息
     printf("transport_stream_id:0x%x\n",floop.transport_stream_id);
     printf("original_network_id:0x%x\n",floop.original_network_id);
     printf("reserved_future_use:0x%x\n",floop.reserved_future_use);
     printf("transport_descriptors_length:0x%x\n",floop.transport_descriptors_length);

     count = Descriptoy_Cx( count, floop.transport_descriptors_length);
     length = length - (6 + floop.transport_descriptors_length);
    }
   return count;
}

//网络描述
int Descriptoy_Cx(int count,int length)
{
    printf("\nDescriptoy====================\n");
    while(0 < length)
    {
     descriptor.descriptor_tag = buff[count++];
     descriptor.descriptor_length = buff[count++];
     printf("descriptor_tag:0x%x   descriptor_length:0x%x\n",descriptor.descriptor_tag,descriptor.descriptor_length);
     int tmp = descriptor.descriptor_length;
     while(descriptor.descriptor_length--)
     {
     printf("0x%x  ",buff[count++]);
     }
     printf("\n");
     length = length - (2+tmp);
    }
    return count;
}
int main(void)
{
adjust_NIT_Section();
return 0;
}

以上代码为原创,且测试通过了。


截取到的数据:

unsigned char buff[] = {  

  0x40,0xf3,0x03,0x00,0x01,0xcf,0x00,0x03,0xf0,0x76,0x40,0x0c,0x53,0x69,0x43,0x68,0x75,0x61,0x6e,0x43,0x61,0x62,

0x6c,0x65,0x5b,0x10,0x65,0x6e,0x67,0x0c,0x53,0x69,0x43,0x68,0x75,0x61,0x6e,0x43,0x61,0x62,0x6c,0x65,0x5f,0x04,

0x00,0x00,0x60,0x01,0x4a,0x1c,0x00,0x00,0x00,0x00,0x00,0x00,0xa0,0x64,0x00,0x00,0x00,0x71,0x02,0x02,0x00,0x03,

0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0xff,0xff,0x80,0xa1,0x23,0x01,0xcf,0x44,0x0b,0x03,0x15,0x00,0x00,

0x00,0x00,0x03,0x00,0x68,0x75,0x00,0x06,0x32,0x11,0x01,0x52,0x85,0x3f,0x00,0x02,0x80,0x05,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x4a,0x07,0xff,0xdc,0x00,0x01,0x00,0x63,0xa2,0x87,0x02,0x00,0x00,0xf2,0x80,0x00,0x01,

0x00,0x01,0xf0,0x2b,0x44,0x0b,0x03,0x15,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x03,0x15,0x00,

0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x03,0x15,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,

0x0f,0x00,0x02,0x00,0x02,0x00,0x01,0xf0,0x2b,0x44,0x0b,0x03,0x31,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,

0xe7,0x0d,0x03,0x31,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x03,0x31,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,

0x00,0x03,0x00,0x01,0xf0,0x2b,0x44,0x0b,0x02,0x43,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,  0x0d,0x02,0x43,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x02,0x43,0x00,0x00,

0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,0x00,0x04,0x00,0x01,0xf0,0x2b,0x44,0x0b,0x02,0x51,0x00,  0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x02,0x51,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,

0x00,0x01,0xe7,0x0d,0x02,0x51,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,0x00,0x05,0x00,  0x01,0xf0,0x58,0x44,0x0b,0x02,0x59,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x02,0x59,0x00,

0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x02,0x59,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,  0x0f,0x00,0x06,0xe7,0x0d,0x02,0x59,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x07,0xe7,0x0d,0x02,0x59,

0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x08,0xe7,0x0d,0x00,0x25,0x90,0x00,0xff,0xf2,0x03,0x00,0x68,  0x75,0x0f,0x00,0x09,0x00,0x06,0x00,0x01,0xf0,0x3a,0x44,0x0b,0x02,0x67,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,

0x0f,0xe7,0x0d,0x02,0x67,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x02,0x67,0x00,0x00,  0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,0xe7,0x0d,0x02,0x67,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,

0x00,0x06,0x00,0x07,0x00,0x01,0xf0,0x58,0x44,0x0b,0x02,0x75,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,

0x0d,0x02,0x75,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x02,0x75,0x00,0x00,0xff,0xf2,

0x03,0x00,0x68,0x75,0x0f,0x00,0x06,0xe7,0x0d,0x02,0x75,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x07,

0xe7,0x0d,0x02,0x75,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x08,0xe7,0x0d,0x02,0x75,0x00,0x00,0xff,

0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x09,0x00,0x08,0x00,0x01,0xf0,0x2b,0x44,0x0b,0x02,0x83,0x00,0x00,0xff,0xf2,

0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x02,0x83,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,

0x02,0x83,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,0x00,0x09,0x00,0x01,0xf0,0x2b,0x44,0x0b,0x02,

0x91,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x02,0x91,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,

0x0f,0x00,0x01,0xe7,0x0d,0x02,0x91,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x02,0x00,0x10,0x00,0x01,

0xf0,0x58,0x44,0x0b,0x02,0x99,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0xe7,0x0d,0x02,0x99,0x00,0x00,0xff,

0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x01,0xe7,0x0d,0x02,0x99,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,

0x06,0xe7,0x0d,0x02,0x99,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x07,0xe7,0x0d,0x02,0x99,0x00,0x00,

0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,0x00,0x08,0xe7,0x0d,0x02,0x99,0x00,0x00,0xff,0xf2,0x03,0x00,0x68,0x75,0x0f,

  0x00,0x09,0x4c,0xdb,0xef,0x25                    

};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值