


版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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学年化学九上期末监测模拟试题含解析
- 河南职业技术学院《世界现代设计史》2023-2024学年第一学期期末试卷
- 公共卫生应急响应2025年资金申请与公共卫生舆情监控报告
- 陕西省西安市78中学2025届九年级化学第一学期期末达标检测模拟试题含解析
- 2024-2025学年湖南省长沙市长郡滨江中学七年级数学第一学期期末质量跟踪监视试题含解析
- 公路货运行业数字化转型效率提升的物流行业物流智能化技术应用报告
- 共享出行市场技术创新对行业格局的影响:2025年商业模式创新报告
- 能源设备环境监测技术培训与应用解析
- 西安美术学院《影视动画作品赏析》2023-2024学年第一学期期末试卷
- 油料运输使用管理办法
- 脊髓肿瘤的护理查房
- 2025年医师三基考试题及答案
- 中远海运招聘笔试题库2025
- 温州市2024-2025学年高一下学期6月期末-英语试卷及答案
- 2025至2030中国核应急机器人行业市场现状分析及竞争格局与投资发展报告
- 导管室护理管理制度
- 降低跌倒事件的发生率QC圈
- 深静脉血栓的试题及答案
- 2025年安徽省邮政行业职业技能大赛(快递员赛项)备赛试题库(含答案)
- 汽车产业链协同发展-洞察阐释
- 滴灌带造颗粒合同协议
评论
0/150
提交评论