512
511
uint32_t stream_type;
513
512
enum AVMediaType codec_type;
514
enum CodecID codec_id;
513
enum AVCodecID codec_id;
517
516
static const StreamType ISO_types[] = {
518
{ 0x01, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
519
{ 0x02, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
520
{ 0x03, AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3 },
521
{ 0x04, AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3 },
522
{ 0x0f, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC },
523
{ 0x10, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4 },
524
{ 0x11, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */
525
{ 0x1b, AVMEDIA_TYPE_VIDEO, CODEC_ID_H264 },
526
{ 0xd1, AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC },
527
{ 0xea, AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 },
517
{ 0x01, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO },
518
{ 0x02, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG2VIDEO },
519
{ 0x03, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
520
{ 0x04, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_MP3 },
521
{ 0x0f, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC },
522
{ 0x10, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_MPEG4 },
523
{ 0x11, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AAC_LATM }, /* LATM syntax */
524
{ 0x1b, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264 },
525
{ 0xd1, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC },
526
{ 0xea, AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1 },
531
530
static const StreamType HDMV_types[] = {
532
{ 0x80, AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_BLURAY },
533
{ 0x81, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 },
534
{ 0x82, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
535
{ 0x83, AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUEHD },
536
{ 0x84, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 },
537
{ 0x90, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE },
531
{ 0x80, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_PCM_BLURAY },
532
{ 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
533
{ 0x82, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
534
{ 0x83, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_TRUEHD },
535
{ 0x84, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_EAC3 },
536
{ 0x85, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /* DTS HD */
537
{ 0x86, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS }, /* DTS HD MASTER*/
538
{ 0x90, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_HDMV_PGS_SUBTITLE },
542
543
static const StreamType MISC_types[] = {
543
{ 0x81, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 },
544
{ 0x8a, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
544
{ 0x81, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
545
{ 0x8a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
548
549
static const StreamType REGD_types[] = {
549
{ MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC },
550
{ MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 },
551
{ MKTAG('B','S','S','D'), AVMEDIA_TYPE_AUDIO, CODEC_ID_S302M },
550
{ MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_DIRAC },
551
{ MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 },
552
{ MKTAG('B','S','S','D'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_S302M },
553
{ MKTAG('D','T','S','1'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
554
{ MKTAG('D','T','S','2'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
555
{ MKTAG('D','T','S','3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
556
{ MKTAG('V','C','-','1'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1 },
555
560
/* descriptor present */
556
561
static const StreamType DESC_types[] = {
557
{ 0x6a, AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, /* AC-3 descriptor */
558
{ 0x7a, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, /* E-AC-3 descriptor */
559
{ 0x7b, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS },
560
{ 0x56, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_TELETEXT },
561
{ 0x59, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */
562
{ 0x6a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_AC3 }, /* AC-3 descriptor */
563
{ 0x7a, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_EAC3 }, /* E-AC-3 descriptor */
564
{ 0x7b, AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
565
{ 0x56, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_DVB_TELETEXT },
566
{ 0x59, AVMEDIA_TYPE_SUBTITLE, AV_CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */
1273
1266
ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
1274
1267
mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
1275
1268
ff_mp4_read_dec_config_descr(fc, st, &pb);
1276
if (st->codec->codec_id == CODEC_ID_AAC &&
1269
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
1277
1270
st->codec->extradata_size > 0)
1278
1271
st->need_parsing = 0;
1279
if (st->codec->codec_id == CODEC_ID_MPEG4SYSTEMS)
1272
if (st->codec->codec_id == AV_CODEC_ID_MPEG4SYSTEMS)
1280
1273
mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1);
1283
1276
case 0x1F: /* FMC descriptor */
1284
1277
get16(pp, desc_end);
1285
if (mp4_descr_count > 0 && st->codec->codec_id == CODEC_ID_AAC_LATM &&
1278
if (mp4_descr_count > 0 && st->codec->codec_id == AV_CODEC_ID_AAC_LATM &&
1286
1279
mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) {
1287
1280
AVIOContext pb;
1288
1281
ffio_init_context(&pb, mp4_descr->dec_config_descr,
1289
1282
mp4_descr->dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
1290
1283
ff_mp4_read_dec_config_descr(fc, st, &pb);
1291
if (st->codec->codec_id == CODEC_ID_AAC &&
1284
if (st->codec->codec_id == AV_CODEC_ID_AAC &&
1292
1285
st->codec->extradata_size > 0)
1293
1286
st->need_parsing = 0;
2088
2081
return timestamp;
2091
#ifdef USE_SYNCPOINT_SEARCH
2093
static int read_seek2(AVFormatContext *s,
2102
int64_t ts_ret, ts_adj;
2103
int stream_index_gen_search;
2105
AVParserState *backup;
2107
backup = ff_store_parser_state(s);
2109
// detect direction of seeking for search purposes
2110
flags |= (target_ts - min_ts > (uint64_t)(max_ts - target_ts)) ?
2111
AVSEEK_FLAG_BACKWARD : 0;
2113
if (flags & AVSEEK_FLAG_BYTE) {
2114
// use position directly, we will search starting from it
2117
// search for some position with good timestamp match
2118
if (stream_index < 0) {
2119
stream_index_gen_search = av_find_default_stream_index(s);
2120
if (stream_index_gen_search < 0) {
2121
ff_restore_parser_state(s, backup);
2125
st = s->streams[stream_index_gen_search];
2126
// timestamp for default must be expressed in AV_TIME_BASE units
2127
ts_adj = av_rescale(target_ts,
2129
AV_TIME_BASE * (int64_t)st->time_base.num);
2132
stream_index_gen_search = stream_index;
2134
pos = ff_gen_search(s, stream_index_gen_search, ts_adj,
2138
flags, &ts_ret, mpegts_get_pcr);
2140
ff_restore_parser_state(s, backup);
2145
// search for actual matching keyframe/starting position for all streams
2146
if (ff_gen_syncpoint_search(s, stream_index, pos,
2147
min_ts, target_ts, max_ts,
2149
ff_restore_parser_state(s, backup);
2153
ff_free_parser_state(s, backup);
2157
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
2160
if (flags & AVSEEK_FLAG_BACKWARD) {
2161
flags &= ~AVSEEK_FLAG_BACKWARD;
2162
ret = read_seek2(s, stream_index, INT64_MIN, target_ts, target_ts, flags);
2164
// for compatibility reasons, seek to the best-fitting timestamp
2165
ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags);
2167
ret = read_seek2(s, stream_index, target_ts, target_ts, INT64_MAX, flags);
2169
// for compatibility reasons, seek to the best-fitting timestamp
2170
ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags);
2177
2084
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){
2178
2085
MpegTSContext *ts = s->priv_data;
2179
2086
uint8_t buf[TS_PACKET_SIZE];