Mercurial > mplayer.hg
comparison libmpdemux/demux_ts.c @ 29263:0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
author | diego |
---|---|
date | Wed, 13 May 2009 02:58:57 +0000 |
parents | c4dc4cf9347b |
children | 5f45df619c7c |
comparison
equal
deleted
inserted
replaced
29262:7d545a6b8aff | 29263:0f1b5b68af32 |
---|---|
145 uint8_t random_accesspoint_only; | 145 uint8_t random_accesspoint_only; |
146 uint8_t padding; | 146 uint8_t padding; |
147 uint8_t use_ts; | 147 uint8_t use_ts; |
148 uint8_t idle; | 148 uint8_t idle; |
149 uint8_t duration; | 149 uint8_t duration; |
150 | 150 |
151 uint32_t ts_resolution, ocr_resolution; | 151 uint32_t ts_resolution, ocr_resolution; |
152 uint8_t ts_len, ocr_len, au_len, instant_bitrate_len, degr_len, au_seqnum_len, packet_seqnum_len; | 152 uint8_t ts_len, ocr_len, au_len, instant_bitrate_len, degr_len, au_seqnum_len, packet_seqnum_len; |
153 uint32_t timescale; | 153 uint32_t timescale; |
154 uint16_t au_duration, cts_duration; | 154 uint16_t au_duration, cts_duration; |
155 uint64_t ocr, dts, cts; | 155 uint64_t ocr, dts, cts; |
567 128, 160, 192, 224, 256, 320, 384, 448, | 567 128, 160, 192, 224, 256, 320, 384, 448, |
568 512, 576, 640 | 568 512, 576, 640 |
569 }; | 569 }; |
570 uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}; | 570 uint8_t halfrate[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3}; |
571 int frmsizecod, bitrate, half; | 571 int frmsizecod, bitrate, half; |
572 | 572 |
573 if((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */ | 573 if((buf[0] != 0x0b) || (buf[1] != 0x77)) /* syncword */ |
574 return 0; | 574 return 0; |
575 | 575 |
576 if(buf[5] >= 0x60) /* bsid >= 12 */ | 576 if(buf[5] >= 0x60) /* bsid >= 12 */ |
577 return 0; | 577 return 0; |
578 | 578 |
579 half = halfrate[buf[5] >> 3]; | 579 half = halfrate[buf[5] >> 3]; |
580 | 580 |
581 frmsizecod = buf[4] & 63; | 581 frmsizecod = buf[4] & 63; |
582 if(frmsizecod >= 38) | 582 if(frmsizecod >= 38) |
583 return 0; | 583 return 0; |
584 | 584 |
585 bitrate = rate[frmsizecod >> 1]; | 585 bitrate = rate[frmsizecod >> 1]; |
586 | 586 |
587 switch(buf[4] & 0xc0) | 587 switch(buf[4] & 0xc0) |
588 { | 588 { |
589 case 0: /* 48 KHz */ | 589 case 0: /* 48 KHz */ |
590 *srate = 48000 >> half; | 590 *srate = 48000 >> half; |
591 return 4 * bitrate; | 591 return 4 * bitrate; |
592 case 0x40: /* 44.1 KHz */ | 592 case 0x40: /* 44.1 KHz */ |
594 return 2 * (320 * bitrate / 147 + (frmsizecod & 1)); | 594 return 2 * (320 * bitrate / 147 + (frmsizecod & 1)); |
595 case 0x80: /* 32 KHz */ | 595 case 0x80: /* 32 KHz */ |
596 *srate = 32000 >> half; | 596 *srate = 32000 >> half; |
597 return 6 * bitrate; | 597 return 6 * bitrate; |
598 } | 598 } |
599 | 599 |
600 return 0; | 600 return 0; |
601 } | 601 } |
602 | 602 |
603 //second stage: returns the count of A52 syncwords found | 603 //second stage: returns the count of A52 syncwords found |
604 static int a52_check(char *buf, int len) | 604 static int a52_check(char *buf, int len) |
605 { | 605 { |
606 int cnt, frame_length, ok, srate; | 606 int cnt, frame_length, ok, srate; |
607 | 607 |
608 cnt = ok = 0; | 608 cnt = ok = 0; |
609 if(len < 8) | 609 if(len < 8) |
610 return 0; | 610 return 0; |
611 | 611 |
612 while(cnt < len - 7) | 612 while(cnt < len - 7) |
613 { | 613 { |
614 if(buf[cnt] == 0x0B && buf[cnt+1] == 0x77) | 614 if(buf[cnt] == 0x0B && buf[cnt+1] == 0x77) |
615 { | 615 { |
616 frame_length = mp_a52_framesize(&buf[cnt], &srate); | 616 frame_length = mp_a52_framesize(&buf[cnt], &srate); |
617 if(frame_length>=7 && frame_length<=3840) | 617 if(frame_length>=7 && frame_length<=3840) |
624 } | 624 } |
625 else | 625 else |
626 cnt++; | 626 cnt++; |
627 } | 627 } |
628 | 628 |
629 mp_msg(MSGT_DEMUXER, MSGL_V, "A52_CHECK(%d input bytes), found %d frame syncwords of %d bytes length\n", len, ok, frame_length); | 629 mp_msg(MSGT_DEMUXER, MSGL_V, "A52_CHECK(%d input bytes), found %d frame syncwords of %d bytes length\n", len, ok, frame_length); |
630 return ok; | 630 return ok; |
631 } | 631 } |
632 | 632 |
633 | 633 |
634 static off_t ts_detect_streams(demuxer_t *demuxer, tsdemux_init_t *param) | 634 static off_t ts_detect_streams(demuxer_t *demuxer, tsdemux_init_t *param) |
685 es.type = AUDIO_A52; | 685 es.type = AUDIO_A52; |
686 } | 686 } |
687 } | 687 } |
688 } | 688 } |
689 } | 689 } |
690 | 690 |
691 is_audio = IS_AUDIO(es.type) || ((es.type==SL_PES_STREAM) && IS_AUDIO(es.subtype)); | 691 is_audio = IS_AUDIO(es.type) || ((es.type==SL_PES_STREAM) && IS_AUDIO(es.subtype)); |
692 is_video = IS_VIDEO(es.type) || ((es.type==SL_PES_STREAM) && IS_VIDEO(es.subtype)); | 692 is_video = IS_VIDEO(es.type) || ((es.type==SL_PES_STREAM) && IS_VIDEO(es.subtype)); |
693 is_sub = ((es.type == SPU_DVD) || (es.type == SPU_DVB)); | 693 is_sub = ((es.type == SPU_DVD) || (es.type == SPU_DVB)); |
694 | 694 |
695 | 695 |
836 free(pes_priv1[i].buf); | 836 free(pes_priv1[i].buf); |
837 pes_priv1[i].buf = NULL; | 837 pes_priv1[i].buf = NULL; |
838 pes_priv1[i].pos = 0; | 838 pes_priv1[i].pos = 0; |
839 } | 839 } |
840 } | 840 } |
841 | 841 |
842 if(video_found) | 842 if(video_found) |
843 { | 843 { |
844 if(param->vtype == VIDEO_MPEG1) | 844 if(param->vtype == VIDEO_MPEG1) |
845 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG1(pid=%d) ", param->vpid); | 845 mp_msg(MSGT_DEMUXER, MSGL_INFO, "VIDEO MPEG1(pid=%d) ", param->vpid); |
846 else if(param->vtype == VIDEO_MPEG2) | 846 else if(param->vtype == VIDEO_MPEG2) |
919 } | 919 } |
920 | 920 |
921 static int parse_avc_sps(uint8_t *buf, int len, int *w, int *h) | 921 static int parse_avc_sps(uint8_t *buf, int len, int *w, int *h) |
922 { | 922 { |
923 int sps, sps_len; | 923 int sps, sps_len; |
924 unsigned char *ptr; | 924 unsigned char *ptr; |
925 mp_mpeg_header_t picture; | 925 mp_mpeg_header_t picture; |
926 if(len < 6) | 926 if(len < 6) |
927 return 0; | 927 return 0; |
928 sps = buf[5] & 0x1f; | 928 sps = buf[5] & 0x1f; |
929 if(!sps) | 929 if(!sps) |
1033 demuxer->video->sh = sh_video; | 1033 demuxer->video->sh = sh_video; |
1034 } | 1034 } |
1035 | 1035 |
1036 if(params.atype != UNKNOWN) | 1036 if(params.atype != UNKNOWN) |
1037 { | 1037 { |
1038 ES_stream_t *es = priv->ts.pids[params.apid]; | 1038 ES_stream_t *es = priv->ts.pids[params.apid]; |
1039 | 1039 |
1040 if(!IS_AUDIO(es->type) && !IS_AUDIO(es->subtype) && IS_AUDIO(params.atype)) es->subtype = params.atype; | 1040 if(!IS_AUDIO(es->type) && !IS_AUDIO(es->subtype) && IS_AUDIO(params.atype)) es->subtype = params.atype; |
1041 ts_add_stream(demuxer, priv->ts.pids[params.apid]); | 1041 ts_add_stream(demuxer, priv->ts.pids[params.apid]); |
1042 sh_audio = priv->ts.streams[params.apid].sh; | 1042 sh_audio = priv->ts.streams[params.apid].sh; |
1043 demuxer->audio->id = priv->ts.streams[params.apid].id; | 1043 demuxer->audio->id = priv->ts.streams[params.apid].id; |
1044 sh_audio->ds = demuxer->audio; | 1044 sh_audio->ds = demuxer->audio; |
1073 priv->fifo[2].buffer_size = 32767; | 1073 priv->fifo[2].buffer_size = 32767; |
1074 | 1074 |
1075 priv->pat.section.buffer_len = 0; | 1075 priv->pat.section.buffer_len = 0; |
1076 for(i = 0; i < priv->pmt_cnt; i++) | 1076 for(i = 0; i < priv->pmt_cnt; i++) |
1077 priv->pmt[i].section.buffer_len = 0; | 1077 priv->pmt[i].section.buffer_len = 0; |
1078 | 1078 |
1079 demuxer->filepos = stream_tell(demuxer->stream); | 1079 demuxer->filepos = stream_tell(demuxer->stream); |
1080 return demuxer; | 1080 return demuxer; |
1081 } | 1081 } |
1082 | 1082 |
1083 static void demux_close_ts(demuxer_t * demuxer) | 1083 static void demux_close_ts(demuxer_t * demuxer) |
1084 { | 1084 { |
1085 uint16_t i; | 1085 uint16_t i; |
1086 ts_priv_t *priv = (ts_priv_t*) demuxer->priv; | 1086 ts_priv_t *priv = (ts_priv_t*) demuxer->priv; |
1087 | 1087 |
1088 if(priv) | 1088 if(priv) |
1089 { | 1089 { |
1090 if(priv->pat.section.buffer) | 1090 if(priv->pat.section.buffer) |
1091 free(priv->pat.section.buffer); | 1091 free(priv->pat.section.buffer); |
1092 if(priv->pat.progs) | 1092 if(priv->pat.progs) |
1093 free(priv->pat.progs); | 1093 free(priv->pat.progs); |
1094 | 1094 |
1095 if(priv->pmt) | 1095 if(priv->pmt) |
1096 { | 1096 { |
1097 for(i = 0; i < priv->pmt_cnt; i++) | 1097 for(i = 0; i < priv->pmt_cnt; i++) |
1098 { | 1098 { |
1099 if(priv->pmt[i].section.buffer) | 1099 if(priv->pmt[i].section.buffer) |
1100 free(priv->pmt[i].section.buffer); | 1100 free(priv->pmt[i].section.buffer); |
1101 if(priv->pmt[i].es) | 1101 if(priv->pmt[i].es) |
1114 | 1114 |
1115 static int mp4_parse_sl_packet(pmt_t *pmt, uint8_t *buf, uint16_t packet_len, int pid, ES_stream_t *pes_es) | 1115 static int mp4_parse_sl_packet(pmt_t *pmt, uint8_t *buf, uint16_t packet_len, int pid, ES_stream_t *pes_es) |
1116 { | 1116 { |
1117 int i, n, m, mp4_es_id = -1; | 1117 int i, n, m, mp4_es_id = -1; |
1118 uint64_t v = 0; | 1118 uint64_t v = 0; |
1119 uint32_t pl_size = 0; | 1119 uint32_t pl_size = 0; |
1120 int deg_flag = 0; | 1120 int deg_flag = 0; |
1121 mp4_es_descr_t *es = NULL; | 1121 mp4_es_descr_t *es = NULL; |
1122 mp4_sl_config_t *sl = NULL; | 1122 mp4_sl_config_t *sl = NULL; |
1123 uint8_t au_start = 0, au_end = 0, rap_flag = 0, ocr_flag = 0, padding = 0, padding_bits = 0, idle = 0; | 1123 uint8_t au_start = 0, au_end = 0, rap_flag = 0, ocr_flag = 0, padding = 0, padding_bits = 0, idle = 0; |
1124 | 1124 |
1125 pes_es->is_synced = 0; | 1125 pes_es->is_synced = 0; |
1126 mp_msg(MSGT_DEMUXER,MSGL_V, "mp4_parse_sl_packet, pid: %d, pmt: %pm, packet_len: %d\n", pid, pmt, packet_len); | 1126 mp_msg(MSGT_DEMUXER,MSGL_V, "mp4_parse_sl_packet, pid: %d, pmt: %pm, packet_len: %d\n", pid, pmt, packet_len); |
1127 if(! pmt || !packet_len) | 1127 if(! pmt || !packet_len) |
1128 return 0; | 1128 return 0; |
1129 | 1129 |
1130 for(i = 0; i < pmt->es_cnt; i++) | 1130 for(i = 0; i < pmt->es_cnt; i++) |
1131 { | 1131 { |
1132 if(pmt->es[i].pid == pid) | 1132 if(pmt->es[i].pid == pid) |
1133 mp4_es_id = pmt->es[i].mp4_es_id; | 1133 mp4_es_id = pmt->es[i].mp4_es_id; |
1134 } | 1134 } |
1135 if(mp4_es_id < 0) | 1135 if(mp4_es_id < 0) |
1136 return -1; | 1136 return -1; |
1137 | 1137 |
1138 for(i = 0; i < pmt->mp4es_cnt; i++) | 1138 for(i = 0; i < pmt->mp4es_cnt; i++) |
1139 { | 1139 { |
1140 if(pmt->mp4es[i].id == mp4_es_id) | 1140 if(pmt->mp4es[i].id == mp4_es_id) |
1141 es = &(pmt->mp4es[i]); | 1141 es = &(pmt->mp4es[i]); |
1142 } | 1142 } |
1143 if(! es) | 1143 if(! es) |
1144 return -1; | 1144 return -1; |
1145 | 1145 |
1146 pes_es->subtype = es->decoder.object_type; | 1146 pes_es->subtype = es->decoder.object_type; |
1147 | 1147 |
1148 sl = &(es->sl); | 1148 sl = &(es->sl); |
1149 if(!sl) | 1149 if(!sl) |
1150 return -1; | 1150 return -1; |
1151 | 1151 |
1152 //now es is the complete es_descriptor of out mp4 ES stream | 1152 //now es is the complete es_descriptor of out mp4 ES stream |
1153 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "ID: %d, FLAGS: 0x%x, subtype: %x\n", es->id, sl->flags, pes_es->subtype); | 1153 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "ID: %d, FLAGS: 0x%x, subtype: %x\n", es->id, sl->flags, pes_es->subtype); |
1154 | 1154 |
1155 n = 0; | 1155 n = 0; |
1156 if(sl->au_start) | 1156 if(sl->au_start) |
1157 pes_es->sl.au_start = au_start = getbits(buf, n++, 1); | 1157 pes_es->sl.au_start = au_start = getbits(buf, n++, 1); |
1158 else | 1158 else |
1159 pes_es->sl.au_start = (pes_es->sl.last_au_end ? 1 : 0); | 1159 pes_es->sl.au_start = (pes_es->sl.last_au_end ? 1 : 0); |
1160 if(sl->au_end) | 1160 if(sl->au_end) |
1161 pes_es->sl.au_end = au_end = getbits(buf, n++, 1); | 1161 pes_es->sl.au_end = au_end = getbits(buf, n++, 1); |
1162 | 1162 |
1163 if(!sl->au_start && !sl->au_end) | 1163 if(!sl->au_start && !sl->au_end) |
1164 { | 1164 { |
1165 pes_es->sl.au_start = pes_es->sl.au_end = au_start = au_end = 1; | 1165 pes_es->sl.au_start = pes_es->sl.au_end = au_start = au_end = 1; |
1166 } | 1166 } |
1167 pes_es->sl.last_au_end = pes_es->sl.au_end; | 1167 pes_es->sl.last_au_end = pes_es->sl.au_end; |
1168 | 1168 |
1169 | 1169 |
1170 if(sl->ocr_len > 0) | 1170 if(sl->ocr_len > 0) |
1171 ocr_flag = getbits(buf, n++, 1); | 1171 ocr_flag = getbits(buf, n++, 1); |
1172 if(sl->idle) | 1172 if(sl->idle) |
1173 idle = getbits(buf, n++, 1); | 1173 idle = getbits(buf, n++, 1); |
1174 if(sl->padding) | 1174 if(sl->padding) |
1176 if(padding) | 1176 if(padding) |
1177 { | 1177 { |
1178 padding_bits = getbits(buf, n, 3); | 1178 padding_bits = getbits(buf, n, 3); |
1179 n += 3; | 1179 n += 3; |
1180 } | 1180 } |
1181 | 1181 |
1182 if(idle || (padding && !padding_bits)) | 1182 if(idle || (padding && !padding_bits)) |
1183 { | 1183 { |
1184 pes_es->payload_size = 0; | 1184 pes_es->payload_size = 0; |
1185 return -1; | 1185 return -1; |
1186 } | 1186 } |
1187 | 1187 |
1188 //(! idle && (!padding || padding_bits != 0)) is true | 1188 //(! idle && (!padding || padding_bits != 0)) is true |
1189 n += sl->packet_seqnum_len; | 1189 n += sl->packet_seqnum_len; |
1190 if(sl->degr_len) | 1190 if(sl->degr_len) |
1191 deg_flag = getbits(buf, n++, 1); | 1191 deg_flag = getbits(buf, n++, 1); |
1192 if(deg_flag) | 1192 if(deg_flag) |
1193 n += sl->degr_len; | 1193 n += sl->degr_len; |
1194 | 1194 |
1195 if(ocr_flag) | 1195 if(ocr_flag) |
1196 { | 1196 { |
1197 n += sl->ocr_len; | 1197 n += sl->ocr_len; |
1198 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "OCR: %d bits\n", sl->ocr_len); | 1198 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "OCR: %d bits\n", sl->ocr_len); |
1199 } | 1199 } |
1200 | 1200 |
1201 if(packet_len * 8 <= n) | 1201 if(packet_len * 8 <= n) |
1202 return -1; | 1202 return -1; |
1203 | 1203 |
1204 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "\nAU_START: %d, AU_END: %d\n", au_start, au_end); | 1204 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "\nAU_START: %d, AU_END: %d\n", au_start, au_end); |
1205 if(au_start) | 1205 if(au_start) |
1206 { | 1206 { |
1207 int dts_flag = 0, cts_flag = 0, ib_flag = 0; | 1207 int dts_flag = 0, cts_flag = 0, ib_flag = 0; |
1208 | 1208 |
1209 if(sl->random_accesspoint) | 1209 if(sl->random_accesspoint) |
1210 rap_flag = getbits(buf, n++, 1); | 1210 rap_flag = getbits(buf, n++, 1); |
1211 | 1211 |
1212 //check commented because it seems it's rarely used, and we need this flag set in case of au_start | 1212 //check commented because it seems it's rarely used, and we need this flag set in case of au_start |
1213 //the decoder will eventually discard the payload if it can't decode it | 1213 //the decoder will eventually discard the payload if it can't decode it |
1214 //if(rap_flag || sl->random_accesspoint_only) | 1214 //if(rap_flag || sl->random_accesspoint_only) |
1215 pes_es->is_synced = 1; | 1215 pes_es->is_synced = 1; |
1216 | 1216 |
1217 n += sl->au_seqnum_len; | 1217 n += sl->au_seqnum_len; |
1218 if(packet_len * 8 <= n+8) | 1218 if(packet_len * 8 <= n+8) |
1219 return -1; | 1219 return -1; |
1220 if(sl->use_ts) | 1220 if(sl->use_ts) |
1221 { | 1221 { |
1234 if(packet_len * 8 <= n+8) | 1234 if(packet_len * 8 <= n+8) |
1235 return -1; | 1235 return -1; |
1236 if(cts_flag && (sl->ts_len > 0)) | 1236 if(cts_flag && (sl->ts_len > 0)) |
1237 { | 1237 { |
1238 int i = 0, m; | 1238 int i = 0, m; |
1239 | 1239 |
1240 while(i < sl->ts_len) | 1240 while(i < sl->ts_len) |
1241 { | 1241 { |
1242 m = FFMIN(8, sl->ts_len - i); | 1242 m = FFMIN(8, sl->ts_len - i); |
1243 v |= getbits(buf, n, m); | 1243 v |= getbits(buf, n, m); |
1244 if(sl->ts_len - i > 8) | 1244 if(sl->ts_len - i > 8) |
1246 i += m; | 1246 i += m; |
1247 n += m; | 1247 n += m; |
1248 if(packet_len * 8 <= n+8) | 1248 if(packet_len * 8 <= n+8) |
1249 return -1; | 1249 return -1; |
1250 } | 1250 } |
1251 | 1251 |
1252 pes_es->pts = (float) v / (float) sl->ts_resolution; | 1252 pes_es->pts = (float) v / (float) sl->ts_resolution; |
1253 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "CTS: %d bits, value: %"PRIu64"/%d = %.3f\n", sl->ts_len, v, sl->ts_resolution, pes_es->pts); | 1253 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "CTS: %d bits, value: %"PRIu64"/%d = %.3f\n", sl->ts_len, v, sl->ts_resolution, pes_es->pts); |
1254 } | 1254 } |
1255 | 1255 |
1256 | 1256 |
1257 i = 0; | 1257 i = 0; |
1258 pl_size = 0; | 1258 pl_size = 0; |
1259 while(i < sl->au_len) | 1259 while(i < sl->au_len) |
1260 { | 1260 { |
1261 m = FFMIN(8, sl->au_len - i); | 1261 m = FFMIN(8, sl->au_len - i); |
1269 } | 1269 } |
1270 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "AU_LEN: %u (%d bits)\n", pl_size, sl->au_len); | 1270 mp_msg(MSGT_DEMUXER,MSGL_DBG2, "AU_LEN: %u (%d bits)\n", pl_size, sl->au_len); |
1271 if(ib_flag) | 1271 if(ib_flag) |
1272 n += sl->instant_bitrate_len; | 1272 n += sl->instant_bitrate_len; |
1273 } | 1273 } |
1274 | 1274 |
1275 m = (n+7)/8; | 1275 m = (n+7)/8; |
1276 if(0 < pl_size && pl_size < pes_es->payload_size) | 1276 if(0 < pl_size && pl_size < pes_es->payload_size) |
1277 pes_es->payload_size = pl_size; | 1277 pes_es->payload_size = pl_size; |
1278 | 1278 |
1279 mp_msg(MSGT_DEMUXER,MSGL_V, "mp4_parse_sl_packet, n=%d, m=%d, size from pes hdr: %u, sl hdr size: %u, RAP FLAGS: %d/%d\n", | 1279 mp_msg(MSGT_DEMUXER,MSGL_V, "mp4_parse_sl_packet, n=%d, m=%d, size from pes hdr: %u, sl hdr size: %u, RAP FLAGS: %d/%d\n", |
1280 n, m, pes_es->payload_size, pl_size, (int) rap_flag, (int) sl->random_accesspoint_only); | 1280 n, m, pes_es->payload_size, pl_size, (int) rap_flag, (int) sl->random_accesspoint_only); |
1281 | 1281 |
1282 return m; | 1282 return m; |
1283 } | 1283 } |
1284 | 1284 |
1285 //this function parses the extension fields in the PES header and returns the substream_id, or -1 in case of errors | 1285 //this function parses the extension fields in the PES header and returns the substream_id, or -1 in case of errors |
1286 static int parse_pes_extension_fields(unsigned char *p, int pkt_len) | 1286 static int parse_pes_extension_fields(unsigned char *p, int pkt_len) |
1287 { | 1287 { |
1288 int skip; | 1288 int skip; |
1289 unsigned char flags; | 1289 unsigned char flags; |
1290 | 1290 |
1291 if(!(p[7] & 0x1)) //no extension_field | 1291 if(!(p[7] & 0x1)) //no extension_field |
1292 return -1; | 1292 return -1; |
1293 skip = 9; | 1293 skip = 9; |
1294 if(p[7] & 0x80) | 1294 if(p[7] & 0x80) |
1295 { | 1295 { |
1337 int ssid = p[skip]; | 1337 int ssid = p[skip]; |
1338 mp_msg(MSGT_IDENTIFY, MSGL_V, "SUBSTREAM_ID=%d (0x%02X)\n", ssid, ssid); | 1338 mp_msg(MSGT_IDENTIFY, MSGL_V, "SUBSTREAM_ID=%d (0x%02X)\n", ssid, ssid); |
1339 return ssid; | 1339 return ssid; |
1340 } | 1340 } |
1341 } | 1341 } |
1342 | 1342 |
1343 return -1; | 1343 return -1; |
1344 } | 1344 } |
1345 | 1345 |
1346 static int pes_parse2(unsigned char *buf, uint16_t packet_len, ES_stream_t *es, int32_t type_from_pmt, pmt_t *pmt, int pid) | 1346 static int pes_parse2(unsigned char *buf, uint16_t packet_len, ES_stream_t *es, int32_t type_from_pmt, pmt_t *pmt, int pid) |
1347 { | 1347 { |
1404 if (header_len + 9 > pkt_len) //9 are the bytes read up to the header_length field | 1404 if (header_len + 9 > pkt_len) //9 are the bytes read up to the header_length field |
1405 { | 1405 { |
1406 mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_ts: illegal value for PES_header_data_length (0x%02x)\n", header_len); | 1406 mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_ts: illegal value for PES_header_data_length (0x%02x)\n", header_len); |
1407 return 0; | 1407 return 0; |
1408 } | 1408 } |
1409 | 1409 |
1410 if(stream_id==0xfd) | 1410 if(stream_id==0xfd) |
1411 { | 1411 { |
1412 int ssid = parse_pes_extension_fields(p, pkt_len); | 1412 int ssid = parse_pes_extension_fields(p, pkt_len); |
1413 if((audio_substream_id!=-1) && (ssid != audio_substream_id)) | 1413 if((audio_substream_id!=-1) && (ssid != audio_substream_id)) |
1414 return 0; | 1414 return 0; |
1525 return 1; | 1525 return 1; |
1526 } | 1526 } |
1527 else if ((stream_id == 0xfa)) | 1527 else if ((stream_id == 0xfa)) |
1528 { | 1528 { |
1529 int l; | 1529 int l; |
1530 | 1530 |
1531 es->is_synced = 0; | 1531 es->is_synced = 0; |
1532 if(type_from_pmt != UNKNOWN) //MP4 A/V or SL | 1532 if(type_from_pmt != UNKNOWN) //MP4 A/V or SL |
1533 { | 1533 { |
1534 es->start = p; | 1534 es->start = p; |
1535 es->size = packet_len; | 1535 es->size = packet_len; |
1536 es->type = type_from_pmt; | 1536 es->type = type_from_pmt; |
1537 | 1537 |
1538 if(type_from_pmt == SL_PES_STREAM) | 1538 if(type_from_pmt == SL_PES_STREAM) |
1539 { | 1539 { |
1540 //if(pes_is_aligned) | 1540 //if(pes_is_aligned) |
1541 //{ | 1541 //{ |
1542 l = mp4_parse_sl_packet(pmt, p, packet_len, pid, es); | 1542 l = mp4_parse_sl_packet(pmt, p, packet_len, pid, es); |
1545 { | 1545 { |
1546 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: couldn't parse SL header, passing along full PES payload\n"); | 1546 mp_msg(MSGT_DEMUX, MSGL_DBG2, "pes_parse2: couldn't parse SL header, passing along full PES payload\n"); |
1547 l = 0; | 1547 l = 0; |
1548 } | 1548 } |
1549 //} | 1549 //} |
1550 | 1550 |
1551 es->start += l; | 1551 es->start += l; |
1552 es->size -= l; | 1552 es->size -= l; |
1553 } | 1553 } |
1554 | 1554 |
1555 if(es->payload_size) | 1555 if(es->payload_size) |
1660 static int collect_section(ts_section_t *section, int is_start, unsigned char *buff, int size) | 1660 static int collect_section(ts_section_t *section, int is_start, unsigned char *buff, int size) |
1661 { | 1661 { |
1662 uint8_t *ptr; | 1662 uint8_t *ptr; |
1663 uint16_t tlen; | 1663 uint16_t tlen; |
1664 int skip, tid; | 1664 int skip, tid; |
1665 | 1665 |
1666 mp_msg(MSGT_DEMUX, MSGL_V, "COLLECT_SECTION, start: %d, size: %d, collected: %d\n", is_start, size, section->buffer_len); | 1666 mp_msg(MSGT_DEMUX, MSGL_V, "COLLECT_SECTION, start: %d, size: %d, collected: %d\n", is_start, size, section->buffer_len); |
1667 if(! is_start && !section->buffer_len) | 1667 if(! is_start && !section->buffer_len) |
1668 return 0; | 1668 return 0; |
1669 | 1669 |
1670 if(is_start) | 1670 if(is_start) |
1671 { | 1671 { |
1672 if(! section->buffer) | 1672 if(! section->buffer) |
1673 { | 1673 { |
1674 section->buffer = (uint8_t*) malloc(4096+256); | 1674 section->buffer = (uint8_t*) malloc(4096+256); |
1675 if(section->buffer == NULL) | 1675 if(section->buffer == NULL) |
1676 return 0; | 1676 return 0; |
1677 } | 1677 } |
1678 section->buffer_len = 0; | 1678 section->buffer_len = 0; |
1679 } | 1679 } |
1680 | 1680 |
1681 if(size + section->buffer_len > 4096+256) | 1681 if(size + section->buffer_len > 4096+256) |
1682 { | 1682 { |
1683 mp_msg(MSGT_DEMUX, MSGL_V, "COLLECT_SECTION, excessive len: %d + %d\n", section->buffer_len, size); | 1683 mp_msg(MSGT_DEMUX, MSGL_V, "COLLECT_SECTION, excessive len: %d + %d\n", section->buffer_len, size); |
1684 return 0; | 1684 return 0; |
1685 } | 1685 } |
1686 | 1686 |
1687 memcpy(&(section->buffer[section->buffer_len]), buff, size); | 1687 memcpy(&(section->buffer[section->buffer_len]), buff, size); |
1688 section->buffer_len += size; | 1688 section->buffer_len += size; |
1689 | 1689 |
1690 if(section->buffer_len < 3) | 1690 if(section->buffer_len < 3) |
1691 return 0; | 1691 return 0; |
1692 | 1692 |
1693 skip = section->buffer[0]; | 1693 skip = section->buffer[0]; |
1694 if(skip + 4 > section->buffer_len) | 1694 if(skip + 4 > section->buffer_len) |
1695 return 0; | 1695 return 0; |
1696 | 1696 |
1697 ptr = &(section->buffer[skip + 1]); | 1697 ptr = &(section->buffer[skip + 1]); |
1698 tid = ptr[0]; | 1698 tid = ptr[0]; |
1699 tlen = ((ptr[1] & 0x0f) << 8) | ptr[2]; | 1699 tlen = ((ptr[1] & 0x0f) << 8) | ptr[2]; |
1700 mp_msg(MSGT_DEMUX, MSGL_V, "SKIP: %d+1, TID: %d, TLEN: %d, COLLECTED: %d\n", skip, tid, tlen, section->buffer_len); | 1700 mp_msg(MSGT_DEMUX, MSGL_V, "SKIP: %d+1, TID: %d, TLEN: %d, COLLECTED: %d\n", skip, tid, tlen, section->buffer_len); |
1701 if(section->buffer_len < (skip+1+3+tlen)) | 1701 if(section->buffer_len < (skip+1+3+tlen)) |
1702 { | 1702 { |
1703 mp_msg(MSGT_DEMUX, MSGL_DBG2, "DATA IS NOT ENOUGH, NEXT TIME\n"); | 1703 mp_msg(MSGT_DEMUX, MSGL_DBG2, "DATA IS NOT ENOUGH, NEXT TIME\n"); |
1704 return 0; | 1704 return 0; |
1705 } | 1705 } |
1706 | 1706 |
1707 return skip+1; | 1707 return skip+1; |
1708 } | 1708 } |
1709 | 1709 |
1710 static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int size) | 1710 static int parse_pat(ts_priv_t * priv, int is_start, unsigned char *buff, int size) |
1711 { | 1711 { |
1719 | 1719 |
1720 section = &(priv->pat.section); | 1720 section = &(priv->pat.section); |
1721 skip = collect_section(section, is_start, buff, size); | 1721 skip = collect_section(section, is_start, buff, size); |
1722 if(! skip) | 1722 if(! skip) |
1723 return 0; | 1723 return 0; |
1724 | 1724 |
1725 ptr = &(section->buffer[skip]); | 1725 ptr = &(section->buffer[skip]); |
1726 //PARSING | 1726 //PARSING |
1727 priv->pat.table_id = ptr[0]; | 1727 priv->pat.table_id = ptr[0]; |
1728 if(priv->pat.table_id != 0) | 1728 if(priv->pat.table_id != 0) |
1729 return 0; | 1729 return 0; |
1793 | 1793 |
1794 static uint16_t get_mp4_desc_len(uint8_t *buf, int *len) | 1794 static uint16_t get_mp4_desc_len(uint8_t *buf, int *len) |
1795 { | 1795 { |
1796 //uint16_t i = 0, size = 0; | 1796 //uint16_t i = 0, size = 0; |
1797 int i = 0, j, size = 0; | 1797 int i = 0, j, size = 0; |
1798 | 1798 |
1799 mp_msg(MSGT_DEMUX, MSGL_DBG2, "PARSE_MP4_DESC_LEN(%d), bytes: ", *len); | 1799 mp_msg(MSGT_DEMUX, MSGL_DBG2, "PARSE_MP4_DESC_LEN(%d), bytes: ", *len); |
1800 j = FFMIN(*len, 4); | 1800 j = FFMIN(*len, 4); |
1801 while(i < j) | 1801 while(i < j) |
1802 { | 1802 { |
1803 mp_msg(MSGT_DEMUX, MSGL_DBG2, " %x ", buf[i]); | 1803 mp_msg(MSGT_DEMUX, MSGL_DBG2, " %x ", buf[i]); |
1806 break; | 1806 break; |
1807 size <<= 7; | 1807 size <<= 7; |
1808 i++; | 1808 i++; |
1809 } | 1809 } |
1810 mp_msg(MSGT_DEMUX, MSGL_DBG2, ", SIZE=%d\n", size); | 1810 mp_msg(MSGT_DEMUX, MSGL_DBG2, ", SIZE=%d\n", size); |
1811 | 1811 |
1812 *len = i+1; | 1812 *len = i+1; |
1813 return size; | 1813 return size; |
1814 } | 1814 } |
1815 | 1815 |
1816 | 1816 |
1817 static uint16_t parse_mp4_slconfig_descriptor(uint8_t *buf, int len, void *elem) | 1817 static uint16_t parse_mp4_slconfig_descriptor(uint8_t *buf, int len, void *elem) |
1818 { | 1818 { |
1819 int i = 0; | 1819 int i = 0; |
1820 mp4_es_descr_t *es; | 1820 mp4_es_descr_t *es; |
1821 mp4_sl_config_t *sl; | 1821 mp4_sl_config_t *sl; |
1822 | 1822 |
1823 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_SLCONFIG_DESCRIPTOR(%d)\n", len); | 1823 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_SLCONFIG_DESCRIPTOR(%d)\n", len); |
1824 es = (mp4_es_descr_t *) elem; | 1824 es = (mp4_es_descr_t *) elem; |
1825 if(!es) | 1825 if(!es) |
1826 { | 1826 { |
1827 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); | 1827 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); |
1829 } | 1829 } |
1830 sl = &(es->sl); | 1830 sl = &(es->sl); |
1831 | 1831 |
1832 sl->ts_len = sl->ocr_len = sl->au_len = sl->instant_bitrate_len = sl->degr_len = sl->au_seqnum_len = sl->packet_seqnum_len = 0; | 1832 sl->ts_len = sl->ocr_len = sl->au_len = sl->instant_bitrate_len = sl->degr_len = sl->au_seqnum_len = sl->packet_seqnum_len = 0; |
1833 sl->ocr = sl->dts = sl->cts = 0; | 1833 sl->ocr = sl->dts = sl->cts = 0; |
1834 | 1834 |
1835 if(buf[0] == 0) | 1835 if(buf[0] == 0) |
1836 { | 1836 { |
1837 i++; | 1837 i++; |
1838 sl->flags = buf[i]; | 1838 sl->flags = buf[i]; |
1839 i++; | 1839 i++; |
1852 sl->degr_len = (buf[i] >> 4) & 0x0f; | 1852 sl->degr_len = (buf[i] >> 4) & 0x0f; |
1853 sl->au_seqnum_len = ((buf[i] & 0x0f) << 1) | ((buf[i+1] >> 7) & 0x01); | 1853 sl->au_seqnum_len = ((buf[i] & 0x0f) << 1) | ((buf[i+1] >> 7) & 0x01); |
1854 i++; | 1854 i++; |
1855 sl->packet_seqnum_len = ((buf[i] >> 2) & 0x1f); | 1855 sl->packet_seqnum_len = ((buf[i] >> 2) & 0x1f); |
1856 i++; | 1856 i++; |
1857 | 1857 |
1858 } | 1858 } |
1859 else if(buf[0] == 1) | 1859 else if(buf[0] == 1) |
1860 { | 1860 { |
1861 sl->flags = 0; | 1861 sl->flags = 0; |
1862 sl->ts_resolution = 1000; | 1862 sl->ts_resolution = 1000; |
1866 else if(buf[0] == 2) | 1866 else if(buf[0] == 2) |
1867 { | 1867 { |
1868 sl->flags = 4; | 1868 sl->flags = 4; |
1869 i++; | 1869 i++; |
1870 } | 1870 } |
1871 else | 1871 else |
1872 { | 1872 { |
1873 sl->flags = 0; | 1873 sl->flags = 0; |
1874 i++; | 1874 i++; |
1875 } | 1875 } |
1876 | 1876 |
1877 sl->au_start = (sl->flags >> 7) & 0x1; | 1877 sl->au_start = (sl->flags >> 7) & 0x1; |
1878 sl->au_end = (sl->flags >> 6) & 0x1; | 1878 sl->au_end = (sl->flags >> 6) & 0x1; |
1879 sl->random_accesspoint = (sl->flags >> 5) & 0x1; | 1879 sl->random_accesspoint = (sl->flags >> 5) & 0x1; |
1880 sl->random_accesspoint_only = (sl->flags >> 4) & 0x1; | 1880 sl->random_accesspoint_only = (sl->flags >> 4) & 0x1; |
1881 sl->padding = (sl->flags >> 3) & 0x1; | 1881 sl->padding = (sl->flags >> 3) & 0x1; |
1882 sl->use_ts = (sl->flags >> 2) & 0x1; | 1882 sl->use_ts = (sl->flags >> 2) & 0x1; |
1883 sl->idle = (sl->flags >> 1) & 0x1; | 1883 sl->idle = (sl->flags >> 1) & 0x1; |
1884 sl->duration = sl->flags & 0x1; | 1884 sl->duration = sl->flags & 0x1; |
1885 | 1885 |
1886 if(sl->duration) | 1886 if(sl->duration) |
1887 { | 1887 { |
1888 sl->timescale = (buf[i] << 24) | (buf[i+1] << 16) | (buf[i+2] << 8) | buf[i+3]; | 1888 sl->timescale = (buf[i] << 24) | (buf[i+1] << 16) | (buf[i+2] << 8) | buf[i+3]; |
1889 i += 4; | 1889 i += 4; |
1890 sl->au_duration = (buf[i] << 8) | buf[i+1]; | 1890 sl->au_duration = (buf[i] << 8) | buf[i+1]; |
1891 i += 2; | 1891 i += 2; |
1892 sl->cts_duration = (buf[i] << 8) | buf[i+1]; | 1892 sl->cts_duration = (buf[i] << 8) | buf[i+1]; |
1893 i += 2; | 1893 i += 2; |
1894 } | 1894 } |
1895 else //no support for fixed durations atm | 1895 else //no support for fixed durations atm |
1896 sl->timescale = sl->au_duration = sl->cts_duration = 0; | 1896 sl->timescale = sl->au_duration = sl->cts_duration = 0; |
1897 | 1897 |
1898 mp_msg(MSGT_DEMUX, MSGL_V, "MP4SLCONFIG(len=0x%x), predef: %d, flags: %x, use_ts: %d, tslen: %d, timescale: %d, dts: %"PRIu64", cts: %"PRIu64"\n", | 1898 mp_msg(MSGT_DEMUX, MSGL_V, "MP4SLCONFIG(len=0x%x), predef: %d, flags: %x, use_ts: %d, tslen: %d, timescale: %d, dts: %"PRIu64", cts: %"PRIu64"\n", |
1899 len, buf[0], sl->flags, sl->use_ts, sl->ts_len, sl->timescale, (uint64_t) sl->dts, (uint64_t) sl->cts); | 1899 len, buf[0], sl->flags, sl->use_ts, sl->ts_len, sl->timescale, (uint64_t) sl->dts, (uint64_t) sl->cts); |
1900 | 1900 |
1901 return len; | 1901 return len; |
1902 } | 1902 } |
1903 | 1903 |
1904 static int parse_mp4_descriptors(pmt_t *pmt, uint8_t *buf, int len, void *elem); | 1904 static int parse_mp4_descriptors(pmt_t *pmt, uint8_t *buf, int len, void *elem); |
1905 | 1905 |
1906 static uint16_t parse_mp4_decoder_config_descriptor(pmt_t *pmt, uint8_t *buf, int len, void *elem) | 1906 static uint16_t parse_mp4_decoder_config_descriptor(pmt_t *pmt, uint8_t *buf, int len, void *elem) |
1907 { | 1907 { |
1908 int i = 0, j; | 1908 int i = 0, j; |
1909 mp4_es_descr_t *es; | 1909 mp4_es_descr_t *es; |
1910 mp4_decoder_config_t *dec; | 1910 mp4_decoder_config_t *dec; |
1911 | 1911 |
1912 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DECODER_CONFIG_DESCRIPTOR(%d)\n", len); | 1912 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DECODER_CONFIG_DESCRIPTOR(%d)\n", len); |
1913 es = (mp4_es_descr_t *) elem; | 1913 es = (mp4_es_descr_t *) elem; |
1914 if(!es) | 1914 if(!es) |
1915 { | 1915 { |
1916 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); | 1916 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); |
1917 return len; | 1917 return len; |
1918 } | 1918 } |
1919 dec = (mp4_decoder_config_t*) &(es->decoder); | 1919 dec = (mp4_decoder_config_t*) &(es->decoder); |
1920 | 1920 |
1921 dec->object_type = buf[i]; | 1921 dec->object_type = buf[i]; |
1922 dec->stream_type = (buf[i+1]>>2) & 0x3f; | 1922 dec->stream_type = (buf[i+1]>>2) & 0x3f; |
1923 | 1923 |
1924 if(dec->object_type == 1 && dec->stream_type == 1) | 1924 if(dec->object_type == 1 && dec->stream_type == 1) |
1925 { | 1925 { |
1926 dec->object_type = MP4_OD; | 1926 dec->object_type = MP4_OD; |
1927 dec->stream_type = MP4_OD; | 1927 dec->stream_type = MP4_OD; |
1928 } | 1928 } |
1951 else | 1951 else |
1952 dec->object_type = UNKNOWN; | 1952 dec->object_type = UNKNOWN; |
1953 } | 1953 } |
1954 else | 1954 else |
1955 dec->object_type = dec->stream_type = UNKNOWN; | 1955 dec->object_type = dec->stream_type = UNKNOWN; |
1956 | 1956 |
1957 if(dec->object_type != UNKNOWN) | 1957 if(dec->object_type != UNKNOWN) |
1958 { | 1958 { |
1959 //update the type of the current stream | 1959 //update the type of the current stream |
1960 for(j = 0; j < pmt->es_cnt; j++) | 1960 for(j = 0; j < pmt->es_cnt; j++) |
1961 { | 1961 { |
1963 { | 1963 { |
1964 pmt->es[j].type = SL_PES_STREAM; | 1964 pmt->es[j].type = SL_PES_STREAM; |
1965 } | 1965 } |
1966 } | 1966 } |
1967 } | 1967 } |
1968 | 1968 |
1969 if(len > 13) | 1969 if(len > 13) |
1970 parse_mp4_descriptors(pmt, &buf[13], len-13, dec); | 1970 parse_mp4_descriptors(pmt, &buf[13], len-13, dec); |
1971 | 1971 |
1972 mp_msg(MSGT_DEMUX, MSGL_V, "MP4DECODER(0x%x), object_type: 0x%x, stream_type: 0x%x\n", len, dec->object_type, dec->stream_type); | 1972 mp_msg(MSGT_DEMUX, MSGL_V, "MP4DECODER(0x%x), object_type: 0x%x, stream_type: 0x%x\n", len, dec->object_type, dec->stream_type); |
1973 | 1973 |
1974 return len; | 1974 return len; |
1975 } | 1975 } |
1976 | 1976 |
1977 static uint16_t parse_mp4_decoder_specific_descriptor(uint8_t *buf, int len, void *elem) | 1977 static uint16_t parse_mp4_decoder_specific_descriptor(uint8_t *buf, int len, void *elem) |
1978 { | 1978 { |
1979 int i; | 1979 int i; |
1980 mp4_decoder_config_t *dec; | 1980 mp4_decoder_config_t *dec; |
1981 | 1981 |
1982 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DECODER_SPECIFIC_DESCRIPTOR(%d)\n", len); | 1982 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DECODER_SPECIFIC_DESCRIPTOR(%d)\n", len); |
1983 dec = (mp4_decoder_config_t *) elem; | 1983 dec = (mp4_decoder_config_t *) elem; |
1984 if(!dec) | 1984 if(!dec) |
1985 { | 1985 { |
1986 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); | 1986 mp_msg(MSGT_DEMUX, MSGL_V, "argh! NULL elem passed, skip\n"); |
1987 return len; | 1987 return len; |
1988 } | 1988 } |
1989 | 1989 |
1990 mp_msg(MSGT_DEMUX, MSGL_DBG2, "MP4 SPECIFIC INFO BYTES: \n"); | 1990 mp_msg(MSGT_DEMUX, MSGL_DBG2, "MP4 SPECIFIC INFO BYTES: \n"); |
1991 for(i=0; i<len; i++) | 1991 for(i=0; i<len; i++) |
1992 mp_msg(MSGT_DEMUX, MSGL_DBG2, "%02x ", buf[i]); | 1992 mp_msg(MSGT_DEMUX, MSGL_DBG2, "%02x ", buf[i]); |
1993 mp_msg(MSGT_DEMUX, MSGL_DBG2, "\n"); | 1993 mp_msg(MSGT_DEMUX, MSGL_DBG2, "\n"); |
1994 | 1994 |
1997 mp_msg(MSGT_DEMUX, MSGL_ERR, "DEMUX_TS, EXTRADATA SUSPICIOUSLY BIG: %d, REFUSED\r\n", len); | 1997 mp_msg(MSGT_DEMUX, MSGL_ERR, "DEMUX_TS, EXTRADATA SUSPICIOUSLY BIG: %d, REFUSED\r\n", len); |
1998 return len; | 1998 return len; |
1999 } | 1999 } |
2000 memcpy(dec->buf, buf, len); | 2000 memcpy(dec->buf, buf, len); |
2001 dec->buf_size = len; | 2001 dec->buf_size = len; |
2002 | 2002 |
2003 return len; | 2003 return len; |
2004 } | 2004 } |
2005 | 2005 |
2006 static uint16_t parse_mp4_es_descriptor(pmt_t *pmt, uint8_t *buf, int len) | 2006 static uint16_t parse_mp4_es_descriptor(pmt_t *pmt, uint8_t *buf, int len) |
2007 { | 2007 { |
2008 int i = 0, j = 0, k, found; | 2008 int i = 0, j = 0, k, found; |
2009 uint8_t flag; | 2009 uint8_t flag; |
2010 mp4_es_descr_t es, *target_es = NULL, *tmp; | 2010 mp4_es_descr_t es, *target_es = NULL, *tmp; |
2011 | 2011 |
2012 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4ES: len=%d\n", len); | 2012 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4ES: len=%d\n", len); |
2013 memset(&es, 0, sizeof(mp4_es_descr_t)); | 2013 memset(&es, 0, sizeof(mp4_es_descr_t)); |
2014 while(i < len) | 2014 while(i < len) |
2015 { | 2015 { |
2016 es.id = (buf[i] << 8) | buf[i+1]; | 2016 es.id = (buf[i] << 8) | buf[i+1]; |
2022 i += 2; | 2022 i += 2; |
2023 if(flag & 0x40) | 2023 if(flag & 0x40) |
2024 i += buf[i]+1; | 2024 i += buf[i]+1; |
2025 if(flag & 0x20) //OCR, maybe we need it | 2025 if(flag & 0x20) //OCR, maybe we need it |
2026 i += 2; | 2026 i += 2; |
2027 | 2027 |
2028 j = parse_mp4_descriptors(pmt, &buf[i], len-i, &es); | 2028 j = parse_mp4_descriptors(pmt, &buf[i], len-i, &es); |
2029 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4ES, types after parse_mp4_descriptors: 0x%x, 0x%x\n", es.decoder.object_type, es.decoder.stream_type); | 2029 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4ES, types after parse_mp4_descriptors: 0x%x, 0x%x\n", es.decoder.object_type, es.decoder.stream_type); |
2030 if(es.decoder.object_type != UNKNOWN && es.decoder.stream_type != UNKNOWN) | 2030 if(es.decoder.object_type != UNKNOWN && es.decoder.stream_type != UNKNOWN) |
2031 { | 2031 { |
2032 found = 0; | 2032 found = 0; |
2037 { | 2037 { |
2038 target_es = &(pmt->mp4es[k]); | 2038 target_es = &(pmt->mp4es[k]); |
2039 found = 1; | 2039 found = 1; |
2040 } | 2040 } |
2041 } | 2041 } |
2042 | 2042 |
2043 if(! found) | 2043 if(! found) |
2044 { | 2044 { |
2045 tmp = realloc_struct(pmt->mp4es, pmt->mp4es_cnt+1, sizeof(mp4_es_descr_t)); | 2045 tmp = realloc_struct(pmt->mp4es, pmt->mp4es_cnt+1, sizeof(mp4_es_descr_t)); |
2046 if(tmp == NULL) | 2046 if(tmp == NULL) |
2047 { | 2047 { |
2056 mp_msg(MSGT_DEMUX, MSGL_V, "MP4ES_CNT: %d, ID=%d\n", pmt->mp4es_cnt, target_es->id); | 2056 mp_msg(MSGT_DEMUX, MSGL_V, "MP4ES_CNT: %d, ID=%d\n", pmt->mp4es_cnt, target_es->id); |
2057 } | 2057 } |
2058 | 2058 |
2059 i += j; | 2059 i += j; |
2060 } | 2060 } |
2061 | 2061 |
2062 return len; | 2062 return len; |
2063 } | 2063 } |
2064 | 2064 |
2065 static void parse_mp4_object_descriptor(pmt_t *pmt, uint8_t *buf, int len, void *elem) | 2065 static void parse_mp4_object_descriptor(pmt_t *pmt, uint8_t *buf, int len, void *elem) |
2066 { | 2066 { |
2067 int i, j = 0, id; | 2067 int i, j = 0, id; |
2068 | 2068 |
2069 i=0; | 2069 i=0; |
2070 id = (buf[0] << 2) | ((buf[1] & 0xc0) >> 6); | 2070 id = (buf[0] << 2) | ((buf[1] & 0xc0) >> 6); |
2071 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_OBJECT_DESCRIPTOR: len=%d, OD_ID=%d\n", len, id); | 2071 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_OBJECT_DESCRIPTOR: len=%d, OD_ID=%d\n", len, id); |
2072 if(buf[1] & 0x20) | 2072 if(buf[1] & 0x20) |
2073 { | 2073 { |
2075 mp_msg(MSGT_DEMUX, MSGL_V, "URL\n"); | 2075 mp_msg(MSGT_DEMUX, MSGL_V, "URL\n"); |
2076 } | 2076 } |
2077 else | 2077 else |
2078 { | 2078 { |
2079 i = 2; | 2079 i = 2; |
2080 | 2080 |
2081 while(i < len) | 2081 while(i < len) |
2082 { | 2082 { |
2083 j = parse_mp4_descriptors(pmt, &(buf[i]), len-i, elem); | 2083 j = parse_mp4_descriptors(pmt, &(buf[i]), len-i, elem); |
2084 mp_msg(MSGT_DEMUX, MSGL_V, "OBJD, NOW i = %d, j=%d, LEN=%d\n", i, j, len); | 2084 mp_msg(MSGT_DEMUX, MSGL_V, "OBJD, NOW i = %d, j=%d, LEN=%d\n", i, j, len); |
2085 i += j; | 2085 i += j; |
2090 | 2090 |
2091 static void parse_mp4_iod(pmt_t *pmt, uint8_t *buf, int len, void *elem) | 2091 static void parse_mp4_iod(pmt_t *pmt, uint8_t *buf, int len, void *elem) |
2092 { | 2092 { |
2093 int i, j = 0; | 2093 int i, j = 0; |
2094 mp4_od_t *iod = &(pmt->iod); | 2094 mp4_od_t *iod = &(pmt->iod); |
2095 | 2095 |
2096 iod->id = (buf[0] << 2) | ((buf[1] & 0xc0) >> 6); | 2096 iod->id = (buf[0] << 2) | ((buf[1] & 0xc0) >> 6); |
2097 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_IOD: len=%d, IOD_ID=%d\n", len, iod->id); | 2097 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_IOD: len=%d, IOD_ID=%d\n", len, iod->id); |
2098 i = 2; | 2098 i = 2; |
2099 if(buf[1] & 0x20) | 2099 if(buf[1] & 0x20) |
2100 { | 2100 { |
2114 } | 2114 } |
2115 | 2115 |
2116 static int parse_mp4_descriptors(pmt_t *pmt, uint8_t *buf, int len, void *elem) | 2116 static int parse_mp4_descriptors(pmt_t *pmt, uint8_t *buf, int len, void *elem) |
2117 { | 2117 { |
2118 int tag, descr_len, i = 0, j = 0; | 2118 int tag, descr_len, i = 0, j = 0; |
2119 | 2119 |
2120 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DESCRIPTORS, len=%d\n", len); | 2120 mp_msg(MSGT_DEMUX, MSGL_V, "PARSE_MP4_DESCRIPTORS, len=%d\n", len); |
2121 if(! len) | 2121 if(! len) |
2122 return len; | 2122 return len; |
2123 | 2123 |
2124 while(i < len) | 2124 while(i < len) |
2125 { | 2125 { |
2126 tag = buf[i]; | 2126 tag = buf[i]; |
2127 j = len - i -1; | 2127 j = len - i -1; |
2128 descr_len = get_mp4_desc_len(&(buf[i+1]), &j); | 2128 descr_len = get_mp4_desc_len(&(buf[i+1]), &j); |
2131 { | 2131 { |
2132 mp_msg(MSGT_DEMUX, MSGL_V, "descriptor is too long, exit\n"); | 2132 mp_msg(MSGT_DEMUX, MSGL_V, "descriptor is too long, exit\n"); |
2133 return len; | 2133 return len; |
2134 } | 2134 } |
2135 i += j+1; | 2135 i += j+1; |
2136 | 2136 |
2137 switch(tag) | 2137 switch(tag) |
2138 { | 2138 { |
2139 case 0x1: | 2139 case 0x1: |
2140 parse_mp4_object_descriptor(pmt, &(buf[i]), descr_len, elem); | 2140 parse_mp4_object_descriptor(pmt, &(buf[i]), descr_len, elem); |
2141 break; | 2141 break; |
2157 default: | 2157 default: |
2158 mp_msg(MSGT_DEMUX, MSGL_V, "Unsupported mp4 descriptor 0x%x\n", tag); | 2158 mp_msg(MSGT_DEMUX, MSGL_V, "Unsupported mp4 descriptor 0x%x\n", tag); |
2159 } | 2159 } |
2160 i += descr_len; | 2160 i += descr_len; |
2161 } | 2161 } |
2162 | 2162 |
2163 return len; | 2163 return len; |
2164 } | 2164 } |
2165 | 2165 |
2166 static ES_stream_t *new_pid(ts_priv_t *priv, int pid) | 2166 static ES_stream_t *new_pid(ts_priv_t *priv, int pid) |
2167 { | 2167 { |
2168 ES_stream_t *tss; | 2168 ES_stream_t *tss; |
2169 | 2169 |
2170 tss = malloc(sizeof(ES_stream_t)); | 2170 tss = malloc(sizeof(ES_stream_t)); |
2171 if(! tss) | 2171 if(! tss) |
2172 return NULL; | 2172 return NULL; |
2173 memset(tss, 0, sizeof(ES_stream_t)); | 2173 memset(tss, 0, sizeof(ES_stream_t)); |
2174 tss->pid = pid; | 2174 tss->pid = pid; |
2177 tss->subtype = UNKNOWN; | 2177 tss->subtype = UNKNOWN; |
2178 tss->is_synced = 0; | 2178 tss->is_synced = 0; |
2179 tss->extradata = NULL; | 2179 tss->extradata = NULL; |
2180 tss->extradata_alloc = tss->extradata_len = 0; | 2180 tss->extradata_alloc = tss->extradata_len = 0; |
2181 priv->ts.pids[pid] = tss; | 2181 priv->ts.pids[pid] = tss; |
2182 | 2182 |
2183 return tss; | 2183 return tss; |
2184 } | 2184 } |
2185 | 2185 |
2186 | 2186 |
2187 static int parse_program_descriptors(pmt_t *pmt, uint8_t *buf, uint16_t len) | 2187 static int parse_program_descriptors(pmt_t *pmt, uint8_t *buf, uint16_t len) |
2206 parse_mp4_descriptors(pmt, &buf[i+k], (int) buf[i+1]-(k-2), NULL); | 2206 parse_mp4_descriptors(pmt, &buf[i+k], (int) buf[i+1]-(k-2), NULL); |
2207 } | 2207 } |
2208 | 2208 |
2209 len -= 2 + buf[i+1]; | 2209 len -= 2 + buf[i+1]; |
2210 } | 2210 } |
2211 | 2211 |
2212 return olen; | 2212 return olen; |
2213 } | 2213 } |
2214 | 2214 |
2215 static int parse_descriptors(struct pmt_es_t *es, uint8_t *ptr) | 2215 static int parse_descriptors(struct pmt_es_t *es, uint8_t *ptr) |
2216 { | 2216 { |
2338 int tid, len, skip; | 2338 int tid, len, skip; |
2339 uint8_t *ptr; | 2339 uint8_t *ptr; |
2340 skip = collect_section(section, is_start, buff, size); | 2340 skip = collect_section(section, is_start, buff, size); |
2341 if(! skip) | 2341 if(! skip) |
2342 return 0; | 2342 return 0; |
2343 | 2343 |
2344 ptr = &(section->buffer[skip]); | 2344 ptr = &(section->buffer[skip]); |
2345 tid = ptr[0]; | 2345 tid = ptr[0]; |
2346 len = ((ptr[1] & 0x0f) << 8) | ptr[2]; | 2346 len = ((ptr[1] & 0x0f) << 8) | ptr[2]; |
2347 mp_msg(MSGT_DEMUX, MSGL_V, "TABLEID: %d (av. %d), skip=%d, LEN: %d\n", tid, section->buffer_len, skip, len); | 2347 mp_msg(MSGT_DEMUX, MSGL_V, "TABLEID: %d (av. %d), skip=%d, LEN: %d\n", tid, section->buffer_len, skip, len); |
2348 if(len > 4093 || section->buffer_len < len || tid != 5) | 2348 if(len > 4093 || section->buffer_len < len || tid != 5) |
2349 { | 2349 { |
2350 mp_msg(MSGT_DEMUX, MSGL_V, "SECTION TOO LARGE or wrong section type, EXIT\n"); | 2350 mp_msg(MSGT_DEMUX, MSGL_V, "SECTION TOO LARGE or wrong section type, EXIT\n"); |
2351 return 0; | 2351 return 0; |
2352 } | 2352 } |
2353 | 2353 |
2354 if(! (ptr[5] & 1)) | 2354 if(! (ptr[5] & 1)) |
2355 return 0; | 2355 return 0; |
2356 | 2356 |
2357 //8 is the current position, len - 9 is the amount of data available | 2357 //8 is the current position, len - 9 is the amount of data available |
2358 parse_mp4_descriptors(pmt, &ptr[8], len - 9, NULL); | 2358 parse_mp4_descriptors(pmt, &ptr[8], len - 9, NULL); |
2359 | 2359 |
2360 return 1; | 2360 return 1; |
2361 } | 2361 } |
2362 | 2362 |
2363 static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_start, unsigned char *buff, int size) | 2363 static int parse_pmt(ts_priv_t * priv, uint16_t progid, uint16_t pid, int is_start, unsigned char *buff, int size) |
2364 { | 2364 { |
2369 int skip; | 2369 int skip; |
2370 pmt_t *tmp; | 2370 pmt_t *tmp; |
2371 struct pmt_es_t *tmp_es; | 2371 struct pmt_es_t *tmp_es; |
2372 ts_section_t *section; | 2372 ts_section_t *section; |
2373 ES_stream_t *tss; | 2373 ES_stream_t *tss; |
2374 | 2374 |
2375 idx = progid_idx_in_pmt(priv, progid); | 2375 idx = progid_idx_in_pmt(priv, progid); |
2376 | 2376 |
2377 if(idx == -1) | 2377 if(idx == -1) |
2378 { | 2378 { |
2379 int sz = (priv->pmt_cnt + 1) * sizeof(pmt_t); | 2379 int sz = (priv->pmt_cnt + 1) * sizeof(pmt_t); |
2394 | 2394 |
2395 section = &(pmt->section); | 2395 section = &(pmt->section); |
2396 skip = collect_section(section, is_start, buff, size); | 2396 skip = collect_section(section, is_start, buff, size); |
2397 if(! skip) | 2397 if(! skip) |
2398 return 0; | 2398 return 0; |
2399 | 2399 |
2400 base = &(section->buffer[skip]); | 2400 base = &(section->buffer[skip]); |
2401 | 2401 |
2402 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_PMT(prog=%d), PMT_len: %d, IS_START: %d, TS_PID: %d, SIZE=%d, M=%d, ES_CNT=%d, IDX=%d, PMT_PTR=%p\n", | 2402 mp_msg(MSGT_DEMUX, MSGL_V, "FILL_PMT(prog=%d), PMT_len: %d, IS_START: %d, TS_PID: %d, SIZE=%d, M=%d, ES_CNT=%d, IDX=%d, PMT_PTR=%p\n", |
2403 progid, pmt->section.buffer_len, is_start, pid, size, m, pmt->es_cnt, idx, pmt); | 2403 progid, pmt->section.buffer_len, is_start, pid, size, m, pmt->es_cnt, idx, pmt); |
2404 | 2404 |
2464 pmt->es[idx].pid = es_pid; | 2464 pmt->es[idx].pid = es_pid; |
2465 if(es_type != 0x6) | 2465 if(es_type != 0x6) |
2466 pmt->es[idx].type = UNKNOWN; | 2466 pmt->es[idx].type = UNKNOWN; |
2467 else | 2467 else |
2468 pmt->es[idx].type = es_type; | 2468 pmt->es[idx].type = es_type; |
2469 | 2469 |
2470 parse_descriptors(&pmt->es[idx], &es_base[5]); | 2470 parse_descriptors(&pmt->es[idx], &es_base[5]); |
2471 | 2471 |
2472 switch(es_type) | 2472 switch(es_type) |
2473 { | 2473 { |
2474 case 1: | 2474 case 1: |
2514 break; | 2514 break; |
2515 default: | 2515 default: |
2516 mp_msg(MSGT_DEMUX, MSGL_DBG2, "UNKNOWN ES TYPE=0x%x\n", es_type); | 2516 mp_msg(MSGT_DEMUX, MSGL_DBG2, "UNKNOWN ES TYPE=0x%x\n", es_type); |
2517 pmt->es[idx].type = UNKNOWN; | 2517 pmt->es[idx].type = UNKNOWN; |
2518 } | 2518 } |
2519 | 2519 |
2520 tss = priv->ts.pids[es_pid]; //an ES stream | 2520 tss = priv->ts.pids[es_pid]; //an ES stream |
2521 if(tss == NULL) | 2521 if(tss == NULL) |
2522 { | 2522 { |
2523 tss = new_pid(priv, es_pid); | 2523 tss = new_pid(priv, es_pid); |
2524 if(tss) | 2524 if(tss) |
2563 *mp4_dec = &(priv->pmt[i].mp4es[k].decoder); | 2563 *mp4_dec = &(priv->pmt[i].mp4es[k].decoder); |
2564 break; | 2564 break; |
2565 } | 2565 } |
2566 } | 2566 } |
2567 } | 2567 } |
2568 | 2568 |
2569 return &(priv->pmt[i]); | 2569 return &(priv->pmt[i]); |
2570 } | 2570 } |
2571 } | 2571 } |
2572 } | 2572 } |
2573 } | 2573 } |
2574 } | 2574 } |
2575 | 2575 |
2576 return NULL; | 2576 return NULL; |
2577 } | 2577 } |
2578 | 2578 |
2579 | 2579 |
2580 static inline int32_t pid_type_from_pmt(ts_priv_t *priv, int pid) | 2580 static inline int32_t pid_type_from_pmt(ts_priv_t *priv, int pid) |
2674 } | 2674 } |
2675 | 2675 |
2676 static int fill_extradata(mp4_decoder_config_t * mp4_dec, ES_stream_t *tss) | 2676 static int fill_extradata(mp4_decoder_config_t * mp4_dec, ES_stream_t *tss) |
2677 { | 2677 { |
2678 uint8_t *tmp; | 2678 uint8_t *tmp; |
2679 | 2679 |
2680 mp_msg(MSGT_DEMUX, MSGL_DBG2, "MP4_dec: %p, pid: %d\n", mp4_dec, tss->pid); | 2680 mp_msg(MSGT_DEMUX, MSGL_DBG2, "MP4_dec: %p, pid: %d\n", mp4_dec, tss->pid); |
2681 | 2681 |
2682 if(mp4_dec->buf_size > tss->extradata_alloc) | 2682 if(mp4_dec->buf_size > tss->extradata_alloc) |
2683 { | 2683 { |
2684 tmp = (uint8_t *) realloc(tss->extradata, mp4_dec->buf_size); | 2684 tmp = (uint8_t *) realloc(tss->extradata, mp4_dec->buf_size); |
2685 if(!tmp) | 2685 if(!tmp) |
2686 return 0; | 2686 return 0; |
2688 tss->extradata_alloc = mp4_dec->buf_size; | 2688 tss->extradata_alloc = mp4_dec->buf_size; |
2689 } | 2689 } |
2690 memcpy(tss->extradata, mp4_dec->buf, mp4_dec->buf_size); | 2690 memcpy(tss->extradata, mp4_dec->buf, mp4_dec->buf_size); |
2691 tss->extradata_len = mp4_dec->buf_size; | 2691 tss->extradata_len = mp4_dec->buf_size; |
2692 mp_msg(MSGT_DEMUX, MSGL_V, "EXTRADATA: %p, alloc=%d, len=%d\n", tss->extradata, tss->extradata_alloc, tss->extradata_len); | 2692 mp_msg(MSGT_DEMUX, MSGL_V, "EXTRADATA: %p, alloc=%d, len=%d\n", tss->extradata, tss->extradata_alloc, tss->extradata_len); |
2693 | 2693 |
2694 return tss->extradata_len; | 2694 return tss->extradata_len; |
2695 } | 2695 } |
2696 | 2696 |
2697 // 0 = EOF or no stream found | 2697 // 0 = EOF or no stream found |
2698 // else = [-] number of bytes written to the packet | 2698 // else = [-] number of bytes written to the packet |
2768 } | 2768 } |
2769 | 2769 |
2770 cc = (packet[3] & 0xf); | 2770 cc = (packet[3] & 0xf); |
2771 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); | 2771 cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); |
2772 tss->last_cc = cc; | 2772 tss->last_cc = cc; |
2773 | 2773 |
2774 bad = ts_error; // || (! cc_ok); | 2774 bad = ts_error; // || (! cc_ok); |
2775 if(bad) | 2775 if(bad) |
2776 { | 2776 { |
2777 if(priv->keep_broken == 0) | 2777 if(priv->keep_broken == 0) |
2778 { | 2778 { |
2779 stream_skip(stream, buf_size-1+junk); | 2779 stream_skip(stream, buf_size-1+junk); |
2780 continue; | 2780 continue; |
2781 } | 2781 } |
2782 | 2782 |
2783 is_start = 0; //queued to the packet data | 2783 is_start = 0; //queued to the packet data |
2784 } | 2784 } |
2785 | 2785 |
2786 if(is_start) | 2786 if(is_start) |
2787 tss->is_synced = 1; | 2787 tss->is_synced = 1; |
2790 { | 2790 { |
2791 stream_skip(stream, buf_size-1+junk); | 2791 stream_skip(stream, buf_size-1+junk); |
2792 continue; | 2792 continue; |
2793 } | 2793 } |
2794 | 2794 |
2795 | 2795 |
2796 afc = (packet[3] >> 4) & 3; | 2796 afc = (packet[3] >> 4) & 3; |
2797 if(! (afc % 2)) //no payload in this TS packet | 2797 if(! (afc % 2)) //no payload in this TS packet |
2798 { | 2798 { |
2799 stream_skip(stream, buf_size-1+junk); | 2799 stream_skip(stream, buf_size-1+junk); |
2800 continue; | 2800 continue; |
2801 } | 2801 } |
2802 | 2802 |
2803 if(afc > 1) | 2803 if(afc > 1) |
2804 { | 2804 { |
2805 int c; | 2805 int c; |
2806 c = stream_read_char(stream); | 2806 c = stream_read_char(stream); |
2807 buf_size--; | 2807 buf_size--; |
2808 if(c < 0 || c > 183) //broken from the stream layer or invalid | 2808 if(c < 0 || c > 183) //broken from the stream layer or invalid |
2809 { | 2809 { |
2810 stream_skip(stream, buf_size-1+junk); | 2810 stream_skip(stream, buf_size-1+junk); |
2811 continue; | 2811 continue; |
2812 } | 2812 } |
2813 | 2813 |
2814 //c==0 is allowed! | 2814 //c==0 is allowed! |
2815 if(c > 0) | 2815 if(c > 0) |
2816 { | 2816 { |
2817 uint8_t pcrbuf[188]; | 2817 uint8_t pcrbuf[188]; |
2818 int flags = stream_read_char(stream); | 2818 int flags = stream_read_char(stream); |
2819 int has_pcr; | 2819 int has_pcr; |
2820 rap_flag = (flags & 0x40) >> 6; | 2820 rap_flag = (flags & 0x40) >> 6; |
2821 has_pcr = flags & 0x10; | 2821 has_pcr = flags & 0x10; |
2822 | 2822 |
2823 buf_size--; | 2823 buf_size--; |
2824 c--; | 2824 c--; |
2825 stream_read(stream, pcrbuf, c); | 2825 stream_read(stream, pcrbuf, c); |
2826 | 2826 |
2827 if(has_pcr) | 2827 if(has_pcr) |
2828 { | 2828 { |
2829 int pcr_pid = prog_pcr_pid(priv, priv->prog); | 2829 int pcr_pid = prog_pcr_pid(priv, priv->prog); |
2830 if(pcr_pid == pid) | 2830 if(pcr_pid == pid) |
2831 { | 2831 { |
2832 uint64_t pcr, pcr_ext; | 2832 uint64_t pcr, pcr_ext; |
2833 | 2833 |
2834 pcr = (int64_t)(pcrbuf[0]) << 25; | 2834 pcr = (int64_t)(pcrbuf[0]) << 25; |
2835 pcr |= pcrbuf[1] << 17 ; | 2835 pcr |= pcrbuf[1] << 17 ; |
2836 pcr |= (pcrbuf[2]) << 9; | 2836 pcr |= (pcrbuf[2]) << 9; |
2837 pcr |= pcrbuf[3] << 1 ; | 2837 pcr |= pcrbuf[3] << 1 ; |
2838 pcr |= (pcrbuf[4] & 0x80) >> 7; | 2838 pcr |= (pcrbuf[4] & 0x80) >> 7; |
2839 | 2839 |
2840 pcr_ext = (pcrbuf[4] & 0x01) << 8; | 2840 pcr_ext = (pcrbuf[4] & 0x01) << 8; |
2841 pcr_ext |= pcrbuf[5]; | 2841 pcr_ext |= pcrbuf[5]; |
2842 | 2842 |
2843 pcr = pcr * 300 + pcr_ext; | 2843 pcr = pcr * 300 + pcr_ext; |
2844 | 2844 |
2845 demuxer->reference_clock = (double)pcr/(double)27000000.0; | 2845 demuxer->reference_clock = (double)pcr/(double)27000000.0; |
2846 } | 2846 } |
2847 } | 2847 } |
2848 | 2848 |
2849 buf_size -= c; | 2849 buf_size -= c; |
2850 if(buf_size == 0) | 2850 if(buf_size == 0) |
2851 continue; | 2851 continue; |
2852 } | 2852 } |
2853 } | 2853 } |
2862 { | 2862 { |
2863 tss->type = SL_PES_STREAM; | 2863 tss->type = SL_PES_STREAM; |
2864 tss->subtype = mp4_dec->object_type; | 2864 tss->subtype = mp4_dec->object_type; |
2865 } | 2865 } |
2866 } | 2866 } |
2867 | 2867 |
2868 | 2868 |
2869 //TABLE PARSING | 2869 //TABLE PARSING |
2870 | 2870 |
2871 base = priv->ts.packet_size - buf_size; | 2871 base = priv->ts.packet_size - buf_size; |
2872 | 2872 |
2873 priv->last_pid = pid; | 2873 priv->last_pid = pid; |
3061 memcpy(es->lang, lang, 3); | 3061 memcpy(es->lang, lang, 3); |
3062 es->lang[3] = 0; | 3062 es->lang[3] = 0; |
3063 } | 3063 } |
3064 else | 3064 else |
3065 es->lang[0] = 0; | 3065 es->lang[0] = 0; |
3066 | 3066 |
3067 if(probe) | 3067 if(probe) |
3068 { | 3068 { |
3069 if(es->type == UNKNOWN) | 3069 if(es->type == UNKNOWN) |
3070 return 0; | 3070 return 0; |
3071 | 3071 |
3072 tss->type = es->type; | 3072 tss->type = es->type; |
3073 tss->subtype = es->subtype; | 3073 tss->subtype = es->subtype; |
3074 | 3074 |
3075 return 1; | 3075 return 1; |
3076 } | 3076 } |
3077 else | 3077 else |
3078 { | 3078 { |
3079 if(es->pts == 0.0f) | 3079 if(es->pts == 0.0f) |
3290 | 3290 |
3291 static int demux_ts_fill_buffer(demuxer_t * demuxer, demux_stream_t *ds) | 3291 static int demux_ts_fill_buffer(demuxer_t * demuxer, demux_stream_t *ds) |
3292 { | 3292 { |
3293 ES_stream_t es; | 3293 ES_stream_t es; |
3294 ts_priv_t *priv = (ts_priv_t *)demuxer->priv; | 3294 ts_priv_t *priv = (ts_priv_t *)demuxer->priv; |
3295 | 3295 |
3296 return -ts_parse(demuxer, &es, priv->packet, 0); | 3296 return -ts_parse(demuxer, &es, priv->packet, 0); |
3297 } | 3297 } |
3298 | 3298 |
3299 | 3299 |
3300 static int ts_check_file_dmx(demuxer_t *demuxer) | 3300 static int ts_check_file_dmx(demuxer_t *demuxer) |
3331 { | 3331 { |
3332 void *sh = NULL; | 3332 void *sh = NULL; |
3333 int i, n; | 3333 int i, n; |
3334 int reftype, areset = 0, vreset = 0; | 3334 int reftype, areset = 0, vreset = 0; |
3335 demux_stream_t *ds; | 3335 demux_stream_t *ds; |
3336 | 3336 |
3337 if(cmd == DEMUXER_CTRL_SWITCH_VIDEO) | 3337 if(cmd == DEMUXER_CTRL_SWITCH_VIDEO) |
3338 { | 3338 { |
3339 reftype = TYPE_VIDEO; | 3339 reftype = TYPE_VIDEO; |
3340 ds = demuxer->video; | 3340 ds = demuxer->video; |
3341 vreset = 1; | 3341 vreset = 1; |