资源描述:
《解析TS流PAT和PMT 代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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流,并找出
2、PAT的PID和PAT的tablevoidparse_PAT(unsignedchar*buffer,intlen);//分析PAT,并找出所含频道的数目和PMT的PIDvoidpronum_pmtid_printf();//打印PMT的PIDunsignedchar*Find_PMT(unsignedshortpmt_pid);//找出PMT的tablevoidparse_PMT(unsignedchar*buffer,intlen,unsignedshortpmt_pid);//解析PMT,找出其中的
3、Video和Audio的PIDvoidprintf_program_list();//打印PMTtable中包含的stream的类型和PIDunsignedchar*Find_video_audio(unsignedshortprogram_pid,unsignedchartype);//找出Video或者Audio的tabletypedefstruct{unsignedshortprogram_num;//program'snumunsignedshortpmt_pid;//}PROGRAM;typed
4、efstruct{unsignedcharstream_type;unsignedshortelementary_pid;}PRO_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
5、流的指针unsignedintFileSize=0;intmain(){unsignedcharbuffer[188]={0};unsignedchar*pmt_buffer,*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_o
6、r_Audio_buffer=(unsignedchar*)malloc(sizeof(char)*188);memset(Video_or_Audio_buffer,0,sizeof(char)*188);file_handle=fopen(ts_path,"rb+");//以二进制方式打开TS文件if(NULL==file_handle)//判断是否打开文件{perror("fopen");printf("openfileerror!");return0;}elseprintf("openfile
7、success!");fseek(file_handle,0,SEEK_END);//指针file_handle将以SEEK_END位置偏移0个位置,即将指针移动到文件尾FileSize=ftell(file_handle);//计算file_handle到文件头的偏移字节数,即计算文件的大小printf("filesize=%d",FileSize);rewind(file_handle);//equivalent(void)feek(file_handle,0L,SEEK_SET)将file_
8、handle指针移动到文件头位置printf("findPATbegin-------->");for(i=0;i