资源描述:
《解析TS流PAT和PMT代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.#include#include#include#definets_path"/home/huohuo/huangwork/work/birds.ts"//TS文件的绝对路径voidRead_Ts_Packet(FILE*file_handle,unsignedchar*packet_buf,intlen);//读一个TS流的packetintparse_TS(unsignedchar*buffer,intFileSize);//分析TS流,并找出PAT的PID和PAT的tablevoid
2、parse_PAT(unsignedchar*buffer,intlen);//分析PAT,并找出所含频道的数目和PMT的PIDvoidpronum_pmtid_printf();//打印PMT的PIDunsignedchar*Find_PMT(unsignedshortpmt_pid);//找出PMT的tablevoidparse_PMT(unsignedchar*buffer,intlen,unsignedshortpmt_pid);//解析PMT,找出其中的Video和Audio的PIDvoidprintf_program_list();//
3、打印PMTtable中包含的stream的类型和PIDunsignedchar*Find_video_audio(unsignedshortprogram_pid,unsignedchartype);//找出Video或者Audio的tabletypedefstruct{unsignedshortprogram_num;//program'snumunsignedshortpmt_pid;//}PROGRAM;typedefstruct{unsignedcharstream_type;unsignedshortelementary_pid;}PRO
4、_LIST;PROGRAMprograms[10]={{0,0}};//用来存储PMT的PID和数量unsignedintnum=0;//totalprogramPRO_LISTprogram_list[10]={{0,0}};//用来存储PMT中stream的类型和PIDunsignedintprogram_list_num=0;FILE*file_handle;//指向TS流的指针unsignedintFileSize=0;..intmain(){unsignedcharbuffer[188]={0};unsignedchar*pmt_buff
5、er,*Video_or_Audio_buffer;unsignedinti=0,j=0,ret=0;pmt_buffer=(unsignedchar*)malloc(sizeof(char)*188);//给buffer分配空间memset(pmt_buffer,0,sizeof(char)*188);//清空bufferVideo_or_Audio_buffer=(unsignedchar*)malloc(sizeof(char)*188);memset(Video_or_Audio_buffer,0,sizeof(char)*188);fil
6、e_handle=fopen(ts_path,"rb+");//以二进制方式打开TS文件if(NULL==file_handle)//判断是否打开文件{perror("fopen");printf("openfileerror!");return0;}elseprintf("openfilesuccess!");fseek(file_handle,0,SEEK_END);//指针file_handle将以SEEK_END位置偏移0个位置,即将指针移动到文件尾FileSize=ftell(file_handle);//计算file_handl
7、e到文件头的偏移字节数,即计算文件的大小printf("filesize=%d",FileSize);rewind(file_handle);//equivalent(void)feek(file_handle,0L,SEEK_SET)将file_handle指针移动到文件头位置printf("findPATbegin-------->");for(i=0;i8、et=parse_TS(buffer,188);//解析188个字节的TS'spacket,并打印找到的PAT’stabl