資源描述:
《解析匯報(bào)TS流PAT和PMT代碼》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、實(shí)用標(biāo)準(zhǔn)文案#include#include#include#definets_path"/home/huohuo/huangwork/work/birds.ts"http://TS文件的絕對(duì)路徑voidRead_Ts_Packet(FILE*file_handle,unsignedchar*packet_buf,intlen);//讀一個(gè)TS流的packetintparse_TS(unsignedchar*buffer,intFileSize);//分析TS流,并找出PAT的PID和PAT的tablevoidparse_P
2、AT(unsignedchar*buffer,intlen);//分析PAT,并找出所含頻道的數(shù)目和PMT的PIDvoidpronum_pmtid_printf();//打印PMT的PIDunsignedchar*Find_PMT(unsignedshortpmt_pid);//找出PMT的tablevoidparse_PMT(unsignedchar*buffer,intlen,unsignedshortpmt_pid);//解析PMT,找出其中的Video和Audio的PIDvoidprintf_program_list();//打印PMTtable中包含的strea
3、m的類型和PIDunsignedchar*Find_video_audio(unsignedshortprogram_pid,unsignedchartype);//找出Video或者Audio的tabletypedefstruct{unsignedshortprogram_num;//program'snumunsignedshortpmt_pid;//}PROGRAM;typedefstruct{unsignedcharstream_type;unsignedshortelementary_pid;}PRO_LIST;PROGRAMprograms[10]={{0,0
4、}};//用來存儲(chǔ)PMT的PID和數(shù)量unsignedintnum=0;//totalprogramPRO_LISTprogram_list[10]={{0,0}};//用來存儲(chǔ)PMT中stream的類型和PIDunsignedintprogram_list_num=0;FILE*file_handle;//指向TS流的指針unsignedintFileSize=0;文檔大全實(shí)用標(biāo)準(zhǔn)文案intmain(){unsignedcharbuffer[188]={0};unsignedchar*pmt_buffer,*Video_or_Audio_buffer;unsignedi
5、nti=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);file_handle=fopen(ts_path,"rb+");//以二進(jìn)制方式打開TS文件if(
6、NULL==file_handle)//判斷是否打開文件{perror("fopen");printf("openfileerror!");return0;}elseprintf("openfilesuccess!");fseek(file_handle,0,SEEK_END);//指針file_handle將以SEEK_END位置偏移0個(gè)位置,即將指針移動(dòng)到文件尾FileSize=ftell(file_handle);//計(jì)算file_handle到文件頭的偏移字節(jié)數(shù),即計(jì)算文件的大小printf("filesize=%d",FileSize);rewind
7、(file_handle);//equivalent(void)feek(file_handle,0L,SEEK_SET)將file_handle指針移動(dòng)到文件頭位置printf("findPATbegin-------->");for(i=0;i