


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#in clude#in clude#in clude/TS文件的绝对路径#defi ne ts_path /home/huohuo/hua ngwork/work/birds.ts int mai n()void Read_Ts_Packet(FILE *file_ha ndle, un sig ned char *packet_buf,i nt len); packetint parse_TS( un sig ned char *buffer,i nt FileSize);PAT 的 PID 和 PAT 的 tablevoid parse_PAT( un sig ned char *buf
2、fer,i nt len);出所含频道的数目和PMT的PID/读一个TS流的/分析TS流,并找出/分析PAT,并找void pronu m_pmtid_pri ntf();un sig ned char* Fin d_PMT( un sig ned short pmt_pid);void parse_PMT( un sig ned char *buffer,i nt len,un sig ned short pmt_pid); 的 Video 和 Audio 的 PID打印PMT的PID找出PMT的table/解析PMT,找出其中/打印PMT table中包含的void printf_prog
3、ram_list();stream的类型和PIDunsigned char* Find_video_audio(unsigned short program_pid,unsigned char type); / 找出 Video 或者 Audio 的 tabletypedef structun sig ned short program_ num; /programs numun sig ned short pmt_pid;/PROGRAM;typedef structun sig ned char stream_type;un sig ned short eleme ntary_pid;PR
4、O_LIST;PROGRAM programs10 = 0,0; un sig ned int num = 0; /total program/用来存储 PMT的PID和数量PRO_LIST programist10 = 0,0;PIDun sig ned int program_list_ num = 0;FILE *file_ha ndle;针un sig ned int FileSize = 0;用来存储PMT中stream的类型和指向TS流的指un sig ned char buffer188 = 0;un sig ned char *pmt_buffer, *Video_or_Aud
5、io_buffer;un sig ned int i=0,j=0,ret=0;pmt_buffer = (unsigned char*)malloc(sizeof(char)*188);给 buffer 分配空间memset(pmt_buffer,0,sizeof(char)*188);/清空 bufferVideo_or_Audio_buffer = (un sig ned char*)malloc(sizeof(char)*188); memset(Video_or_Audio_buffer,0,sizeof(char)*188);file_handle = fopen(ts_path,r
6、b+);/ 以二进制方式打开 TS 文件if(NULL = file_ha ndle)/判断是否打开文件perror(fope n);prin tf(ope n file error! n);return 0;elseprin tf(ope n file success! n);fseek(file_handle,0,SEEK_END);/指针 file_handle 将以 SEEK_END 位置偏移 0 个位置,即将指针移动到文件尾FileSize = ftell(file_handle); /计算file_handle到文件头的偏移字节数,即计算文件的大小prin tf(file size
7、 = %dn,FileSize);rewi nd(file_ha ndle); / equivale nt (void) feek(file_ha ndle,0L,SEEK_SET)将 file_ha ndle指针移动到文件头位置prin tf(fi nd PAT beginn);for(i=0;in);for(i=0;in);for(j=0;jn);for(i=0;in);for(j=0;j188;j+)printf(0x%x ,Video_or_Audio_bufferj);打印 elementarys tablememset(Video_or_Audio_buffer,0,sizeof(
8、char)*188); prin tf(n);free(pmt_buffer);free(Video_or_Audio_buffer);pmt_buffer = NULL;Video_or_Audio_buffer = NULL;fclose(file_ha ndle);prin tf(n);return 1;/* read one TS packets data* */void Read_Ts_Packet(FILE *file_ha ndle, un sig ned char *packet_buf,i nt len) fread(packet_buf,188,1,file_ha ndle
9、); int parse_TS( un sig ned char *buffer,i nt FileSize)un sig ned char *temp = buffer; short pat_pid;int i = 0;if(bufferO != 0x47)prin tf(its not a ts packet!n); return 0;while(temp buffer + FileSize)pat_pid = (temp1 & 0x1f)n);for(i=0;i=187;i+)prin tf(0x%x ,bufferi);prin tf(n);return 1;temp = temp +
10、 188;return 0; /* parse PAT table, get the PMTs PID* *void parse_PAT( un sig ned char *buffer,i nt len)un sig ned char *temp, *p;char adaptati on_con trol;int adaptati on_len gth,i=0;un sig ned short sect ion_len gth,prg_No,PMT_Pid;temp = buffer;adaptation_c ontrol = temp3 & 0x30;if(adaptati on_con
11、trol = 0x10)temp = buffer + 4 + 1;else if (adaptati on_con trol = 0x30)adaptati on_len gth = buffer4;temp = buffer + 4 + 1 +adaptati on_len gth + 1;elsereturn ;sectionen gth = (temp1&0x0f)8 | temp2;p = temp + 1 +secti on_len gth;temp = temp + 8;while(temp p - 4)prg_No = (temp08) | (temp1);if(prg_No
12、= 0)temp = temp + 4;con ti nue;elsePMT_Pid = (temp2&0x1f)8 | temp3; programs nu gram_ num = prg_No;programs nu m.pmt_pid = PMT_Pid;/prin tf(pmt_pid is ox%xn, PMT_Pid);num +;temp = temp + 4;void pronu m_pmtid_pri ntf()un sig ned int i;prin tf(PAT tables program_ num and PMTs PID:n);for(i=0;i nu
13、m;i+)prin tf(program_ num = 0x%x (%d),PMT_Pid = 0x%x (%d)n, gram_ nu m,gram_ num, programsi.pmt_pid,programsi.pmt_pid); void prin tf_programist()un sig ned int i;prin tf(AII PMT Tables program list: n);for(i=0;iprogramist_ nu m;i+)prin tf(stream_type=0x%x,eleme ntary_pid0x%
14、x n,program_listi.stream_type,program_listi.eleme ntary_pid);prin tf(n);un sig ned char* Fin d_PMT( un sig ned short pmt_pid)un sig ned int i=0,j=0;int pid;un sig ned char *buffer;buffer = (un sig ned char *)malloc(sizeof(char)*188); memset(buffer,0,sizeof(char)*188);rewi nd(file_ha ndle); for(j=0;j
15、FileSize/188;j+)Read_Ts_Packet(file_ha ndle,buffer,188); if(buffer0 != 0x47)prin tf(Its not TS packet !n);elsepid = (buffer1 & 0x1f) 8 | buffer2; if(pid = pmt_pid)prin tf(PMT Table already fin d!n); return buffer;elseprintf(fin di ng PMT tablen); un sig ned char* Fin d_video_audio (un sig ned short
16、program_pid, un sig ned char type) un sig ned int i = 0, j = 0 ;int pid;un sig ned char *buffer;buffer = (un sig ned char *)malloc(sizeof(char)*188);memset(buffer,0,sizeof(char)*188);rewin d(file_ha ndle);for(j=0;jFileSize/188;j+)Read_Ts_Packet(file_ha ndle,buffer,188);if(buffer0 != 0x47)prin tf(Its
17、 not TS packet !n); else pid = (buffer1 & 0x1f) 8 | buffer2;if(program_pid = pid)if(type = 0x02)printf(Find a program and this program is Video type! n); else if(type = 0x03)printf(Find a program and this program is Audio type! n); elseprintf(Find a program but this program is other type !n ”);retur
18、n buffer;elseprin tf(fi nding Video or Audio table.n );void parse_PMT( un sig ned char *buffer,i nt len,un sig ned short pmt_pid) un sig ned char *temp, *p;char adaptati on_con trol;int adaptati on_len gth,i=0;int program_i nfo_le ngth;int ES_in fo_le ngth;un sig ned short sect ion_len gth,pid; temp = buffer;adaptation_c ontrol = tem
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 四川省绵阳市三台中学2024-2025学年高二(上)期末生物试卷(含解析)
- 沟槽开挖支护施工方案
- 桥架钢结构施工方案
- 导管室装修施工方案
- 深圳灯光秀施工方案
- 反光涂料施工方案
- 防滑混凝土泳池施工方案
- 5以内的3个数加减混合题
- 等效电路模型、单颗粒模型、均质多孔模型、异构模型等
- 地暖加压泵换向阀工作原理
- 人教版PEP小学五年级英语下册全册教案(含计划)
- 《公路工程造价标准高海拔高寒地区补充规定》
- 2024-2030年中国工控机行业发展状况及营销战略研究报告
- 临床护理实践指南2024版
- 贵州省兽药经营质量管理规范实施细则
- 常规弱电系统施工单价表纯劳务
- 劳动合同(模版)4篇
- 2024-2025学年小学信息技术(信息科技)五年级下册人教版教学设计合集
- 2024年大学试题(林学)-森林经理学考试近5年真题集锦(频考类试题)带答案
- 医学教材 《妇产科学》第9版课件-胎儿异常与多胎妊娠
- 2025年国家公务员考试行测(地市级)行政职业能力测验试卷与参考答案
评论
0/150
提交评论