~ubuntu-branches/ubuntu/trusty/gst-libav1.0/trusty-proposed

« back to all changes in this revision

Viewing changes to gst-libs/ext/libav/libavformat/mpegts.c

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2013-09-24 17:07:00 UTC
  • mfrom: (1.1.17) (7.1.9 experimental)
  • Revision ID: package-import@ubuntu.com-20130924170700-4dg62s3pwl0pdakz
Tags: 1.2.0-1
* New upstream stable release:
  + debian/control:
    - Build depend on GStreamer and gst-plugins-base >= 1.2.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
22
 
//#define USE_SYNCPOINT_SEARCH
23
 
 
24
22
#include "libavutil/crc.h"
25
23
#include "libavutil/intreadwrite.h"
26
24
#include "libavutil/log.h"
131
129
 
132
130
static const AVOption options[] = {
133
131
    {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), AV_OPT_TYPE_INT,
134
 
     {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
 
132
     {.i64 = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM },
135
133
    { NULL },
136
134
};
137
135
 
413
411
    score    = analyze(buf, size, TS_PACKET_SIZE, NULL);
414
412
    dvhs_score    = analyze(buf, size, TS_DVHS_PACKET_SIZE, NULL);
415
413
    fec_score= analyze(buf, size, TS_FEC_PACKET_SIZE, NULL);
416
 
//    av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score);
 
414
    av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
 
415
            score, dvhs_score, fec_score);
417
416
 
418
417
    if     (score > fec_score && score > dvhs_score) return TS_PACKET_SIZE;
419
418
    else if(dvhs_score > score && dvhs_score > fec_score) return TS_DVHS_PACKET_SIZE;
511
510
typedef struct {
512
511
    uint32_t stream_type;
513
512
    enum AVMediaType codec_type;
514
 
    enum CodecID codec_id;
 
513
    enum AVCodecID codec_id;
515
514
} StreamType;
516
515
 
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 },
528
527
    { 0 },
529
528
};
530
529
 
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 },
538
539
    { 0 },
539
540
};
540
541
 
541
542
/* ATSC ? */
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 },
545
546
    { 0 },
546
547
};
547
548
 
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 },
552
557
    { 0 },
553
558
};
554
559
 
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 */
562
567
    { 0 },
563
568
};
564
569
 
580
585
    avpriv_set_pts_info(st, 33, 1, 90000);
581
586
    st->priv_data = pes;
582
587
    st->codec->codec_type = AVMEDIA_TYPE_DATA;
583
 
    st->codec->codec_id   = CODEC_ID_NONE;
 
588
    st->codec->codec_id   = AV_CODEC_ID_NONE;
584
589
    st->need_parsing = AVSTREAM_PARSE_FULL;
585
590
    pes->st = st;
586
591
    pes->stream_type = stream_type;
593
598
 
594
599
    mpegts_find_stream_type(st, pes->stream_type, ISO_types);
595
600
    if (prog_reg_desc == AV_RL32("HDMV") &&
596
 
        st->codec->codec_id == CODEC_ID_NONE) {
 
601
        st->codec->codec_id == AV_CODEC_ID_NONE) {
597
602
        mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
598
603
        if (pes->stream_type == 0x83) {
599
604
            // HDMV TrueHD streams also contain an AC3 coded version of the
615
620
            avpriv_set_pts_info(sub_st, 33, 1, 90000);
616
621
            sub_st->priv_data = sub_pes;
617
622
            sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
618
 
            sub_st->codec->codec_id   = CODEC_ID_AC3;
 
623
            sub_st->codec->codec_id   = AV_CODEC_ID_AC3;
619
624
            sub_st->need_parsing = AVSTREAM_PARSE_FULL;
620
625
            sub_pes->sub_st = pes->sub_st = sub_st;
621
626
        }
622
627
    }
623
 
    if (st->codec->codec_id == CODEC_ID_NONE)
 
628
    if (st->codec->codec_id == AV_CODEC_ID_NONE)
624
629
        mpegts_find_stream_type(st, pes->stream_type, MISC_types);
625
630
 
626
631
    return 0;
660
665
    pes->flags = 0;
661
666
}
662
667
 
663
 
static uint64_t get_bits64(GetBitContext *gb, int bits)
664
 
{
665
 
    uint64_t ret = 0;
666
 
    while (bits > 17) {
667
 
        ret <<= 17;
668
 
        ret |= get_bits(gb, 17);
669
 
        bits -= 17;
670
 
    }
671
 
    ret <<= bits;
672
 
    ret |= get_bits(gb, bits);
673
 
    return ret;
674
 
}
675
 
 
676
668
static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size)
677
669
{
678
670
    GetBitContext gb;
780
772
                    code = pes->header[3] | 0x100;
781
773
                    av_dlog(pes->stream, "pid=%x pes_code=%#x\n", pes->pid, code);
782
774
 
783
 
                    if ((pes->st && pes->st->discard == AVDISCARD_ALL) ||
 
775
                    if ((pes->st && pes->st->discard == AVDISCARD_ALL &&
 
776
                         (!pes->sub_st || pes->sub_st->discard == AVDISCARD_ALL)) ||
784
777
                        code == 0x1be) /* padding_stream */
785
778
                        goto skip;
786
779
 
809
802
                        code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */
810
803
                        code != 0x1f8) {                  /* ITU-T Rec. H.222.1 type E stream */
811
804
                        pes->state = MPEGTS_PESHEADER;
812
 
                        if (pes->st->codec->codec_id == CODEC_ID_NONE) {
 
805
                        if (pes->st->codec->codec_id == AV_CODEC_ID_NONE) {
813
806
                            av_dlog(pes->stream, "pid=%x stream_type=%x probing\n",
814
807
                                    pes->pid, pes->stream_type);
815
 
                            pes->st->codec->codec_id = CODEC_ID_PROBE;
 
808
                            pes->st->codec->codec_id = AV_CODEC_ID_PROBE;
816
809
                        }
817
810
                    } else {
818
811
                        pes->state = MPEGTS_PAYLOAD;
1214
1207
            ffio_init_context(&pb, mp4_descr[i].dec_config_descr,
1215
1208
                              mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL);
1216
1209
            ff_mp4_read_dec_config_descr(s, st, &pb);
1217
 
            if (st->codec->codec_id == CODEC_ID_AAC &&
 
1210
            if (st->codec->codec_id == AV_CODEC_ID_AAC &&
1218
1211
                st->codec->extradata_size > 0)
1219
1212
                st->need_parsing = 0;
1220
 
            if (st->codec->codec_id == CODEC_ID_H264 &&
 
1213
            if (st->codec->codec_id == AV_CODEC_ID_H264 &&
1221
1214
                st->codec->extradata_size > 0)
1222
1215
                st->need_parsing = 0;
1223
1216
 
1224
 
            if (st->codec->codec_id <= CODEC_ID_NONE) {
1225
 
            } else if (st->codec->codec_id < CODEC_ID_FIRST_AUDIO) {
 
1217
            if (st->codec->codec_id <= AV_CODEC_ID_NONE) {
 
1218
            } else if (st->codec->codec_id < AV_CODEC_ID_FIRST_AUDIO) {
1226
1219
                st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
1227
 
            } else if (st->codec->codec_id < CODEC_ID_FIRST_SUBTITLE) {
 
1220
            } else if (st->codec->codec_id < AV_CODEC_ID_FIRST_SUBTITLE) {
1228
1221
                st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
1229
 
            } else if (st->codec->codec_id < CODEC_ID_FIRST_UNKNOWN) {
 
1222
            } else if (st->codec->codec_id < AV_CODEC_ID_FIRST_UNKNOWN) {
1230
1223
                st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
1231
1224
            }
1232
1225
        }
1257
1250
 
1258
1251
    av_dlog(fc, "tag: 0x%02x len=%d\n", desc_tag, desc_len);
1259
1252
 
1260
 
    if (st->codec->codec_id == CODEC_ID_NONE &&
 
1253
    if (st->codec->codec_id == AV_CODEC_ID_NONE &&
1261
1254
        stream_type == STREAM_TYPE_PRIVATE_DATA)
1262
1255
        mpegts_find_stream_type(st, desc_tag, DESC_types);
1263
1256
 
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);
1281
1274
        }
1282
1275
        break;
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;
1294
1287
        }
1349
1342
    case 0x05: /* registration descriptor */
1350
1343
        st->codec->codec_tag = bytestream_get_le32(pp);
1351
1344
        av_dlog(fc, "reg_desc=%.4s\n", (char*)&st->codec->codec_tag);
1352
 
        if (st->codec->codec_id == CODEC_ID_NONE &&
1353
 
            stream_type == STREAM_TYPE_PRIVATE_DATA)
 
1345
        if (st->codec->codec_id == AV_CODEC_ID_NONE)
1354
1346
            mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types);
1355
1347
        break;
1356
1348
    default:
1376
1368
    int i;
1377
1369
 
1378
1370
    av_dlog(ts->stream, "PMT: len %i\n", section_len);
1379
 
    hex_dump_debug(ts->stream, (uint8_t *)section, section_len);
 
1371
    hex_dump_debug(ts->stream, section, section_len);
1380
1372
 
1381
1373
    p_end = section + section_len - 4;
1382
1374
    p = section;
1390
1382
        return;
1391
1383
 
1392
1384
    clear_program(ts, h->id);
1393
 
    pcr_pid = get16(&p, p_end) & 0x1fff;
 
1385
    pcr_pid = get16(&p, p_end);
1394
1386
    if (pcr_pid < 0)
1395
1387
        return;
 
1388
    pcr_pid &= 0x1fff;
1396
1389
    add_pid_to_pmt(ts, h->id, pcr_pid);
1397
1390
 
1398
1391
    av_dlog(ts->stream, "pcr_pid=0x%x\n", pcr_pid);
1399
1392
 
1400
 
    program_info_length = get16(&p, p_end) & 0xfff;
 
1393
    program_info_length = get16(&p, p_end);
1401
1394
    if (program_info_length < 0)
1402
1395
        return;
 
1396
    program_info_length &= 0xfff;
1403
1397
    while(program_info_length >= 2) {
1404
1398
        uint8_t tag, len;
1405
1399
        tag = get8(&p, p_end);
1437
1431
        stream_type = get8(&p, p_end);
1438
1432
        if (stream_type < 0)
1439
1433
            break;
1440
 
        pid = get16(&p, p_end) & 0x1fff;
 
1434
        pid = get16(&p, p_end);
1441
1435
        if (pid < 0)
1442
1436
            break;
 
1437
        pid &= 0x1fff;
1443
1438
 
1444
1439
        /* now create stream */
1445
1440
        if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) {
1477
1472
 
1478
1473
        ff_program_add_stream_index(ts->stream, h->id, st->index);
1479
1474
 
1480
 
        desc_list_len = get16(&p, p_end) & 0xfff;
 
1475
        desc_list_len = get16(&p, p_end);
1481
1476
        if (desc_list_len < 0)
1482
1477
            break;
 
1478
        desc_list_len &= 0xfff;
1483
1479
        desc_list_end = p + desc_list_len;
1484
1480
        if (desc_list_end > p_end)
1485
1481
            break;
1509
1505
    int sid, pmt_pid;
1510
1506
 
1511
1507
    av_dlog(ts->stream, "PAT:\n");
1512
 
    hex_dump_debug(ts->stream, (uint8_t *)section, section_len);
 
1508
    hex_dump_debug(ts->stream, section, section_len);
1513
1509
 
1514
1510
    p_end = section + section_len - 4;
1515
1511
    p = section;
1523
1519
        sid = get16(&p, p_end);
1524
1520
        if (sid < 0)
1525
1521
            break;
1526
 
        pmt_pid = get16(&p, p_end) & 0x1fff;
 
1522
        pmt_pid = get16(&p, p_end);
1527
1523
        if (pmt_pid < 0)
1528
1524
            break;
 
1525
        pmt_pid &= 0x1fff;
1529
1526
 
1530
1527
        av_dlog(ts->stream, "sid=0x%x pid=0x%x\n", sid, pmt_pid);
1531
1528
 
1552
1549
    char *name, *provider_name;
1553
1550
 
1554
1551
    av_dlog(ts->stream, "SDT:\n");
1555
 
    hex_dump_debug(ts->stream, (uint8_t *)section, section_len);
 
1552
    hex_dump_debug(ts->stream, section, section_len);
1556
1553
 
1557
1554
    p_end = section + section_len - 4;
1558
1555
    p = section;
1573
1570
        val = get8(&p, p_end);
1574
1571
        if (val < 0)
1575
1572
            break;
1576
 
        desc_list_len = get16(&p, p_end) & 0xfff;
 
1573
        desc_list_len = get16(&p, p_end);
1577
1574
        if (desc_list_len < 0)
1578
1575
            break;
 
1576
        desc_list_len &= 0xfff;
1579
1577
        desc_list_end = p + desc_list_len;
1580
1578
        if (desc_list_end > p_end)
1581
1579
            break;
1814
1812
 
1815
1813
static int mpegts_probe(AVProbeData *p)
1816
1814
{
1817
 
#if 1
1818
1815
    const int size= p->buf_size;
1819
1816
    int score, fec_score, dvhs_score;
1820
1817
    int check_count= size / TS_FEC_PACKET_SIZE;
1826
1823
    score     = analyze(p->buf, TS_PACKET_SIZE     *check_count, TS_PACKET_SIZE     , NULL)*CHECK_COUNT/check_count;
1827
1824
    dvhs_score= analyze(p->buf, TS_DVHS_PACKET_SIZE*check_count, TS_DVHS_PACKET_SIZE, NULL)*CHECK_COUNT/check_count;
1828
1825
    fec_score = analyze(p->buf, TS_FEC_PACKET_SIZE *check_count, TS_FEC_PACKET_SIZE , NULL)*CHECK_COUNT/check_count;
1829
 
//    av_log(NULL, AV_LOG_DEBUG, "score: %d, dvhs_score: %d, fec_score: %d \n", score, dvhs_score, fec_score);
 
1826
    av_dlog(NULL, "score: %d, dvhs_score: %d, fec_score: %d \n",
 
1827
            score, dvhs_score, fec_score);
1830
1828
 
1831
1829
// we need a clear definition for the returned score otherwise things will become messy sooner or later
1832
1830
    if     (score > fec_score && score > dvhs_score && score > 6) return AVPROBE_SCORE_MAX + score     - CHECK_COUNT;
1833
1831
    else if(dvhs_score > score && dvhs_score > fec_score && dvhs_score > 6) return AVPROBE_SCORE_MAX + dvhs_score  - CHECK_COUNT;
1834
1832
    else if(                 fec_score > 6) return AVPROBE_SCORE_MAX + fec_score - CHECK_COUNT;
1835
1833
    else                                    return -1;
1836
 
#else
1837
 
    /* only use the extension for safer guess */
1838
 
    if (av_match_ext(p->filename, "ts"))
1839
 
        return AVPROBE_SCORE_MAX;
1840
 
    else
1841
 
        return 0;
1842
 
#endif
1843
1834
}
1844
1835
 
1845
1836
/* return the 90kHz PCR and the extension for the 27MHz PCR. return
1871
1862
    return 0;
1872
1863
}
1873
1864
 
1874
 
static int mpegts_read_header(AVFormatContext *s,
1875
 
                              AVFormatParameters *ap)
 
1865
static int mpegts_read_header(AVFormatContext *s)
1876
1866
{
1877
1867
    MpegTSContext *ts = s->priv_data;
1878
1868
    AVIOContext *pb = s->pb;
1895
1885
        /* normal demux */
1896
1886
 
1897
1887
        /* first do a scan to get all the services */
1898
 
        if (pb->seekable && avio_seek(pb, pos, SEEK_SET) < 0)
 
1888
        if (avio_seek(pb, pos, SEEK_SET) < 0 && pb->seekable)
1899
1889
            av_log(s, AV_LOG_ERROR, "Unable to seek back to the start\n");
1900
1890
 
1901
1891
        mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1);
1924
1914
            goto fail;
1925
1915
        avpriv_set_pts_info(st, 60, 1, 27000000);
1926
1916
        st->codec->codec_type = AVMEDIA_TYPE_DATA;
1927
 
        st->codec->codec_id = CODEC_ID_MPEG2TS;
 
1917
        st->codec->codec_id = AV_CODEC_ID_MPEG2TS;
1928
1918
 
1929
1919
        /* we iterate until we find two PCRs to estimate the bitrate */
1930
1920
        pcr_pid = -1;
2016
2006
    MpegTSContext *ts = s->priv_data;
2017
2007
    int ret, i;
2018
2008
 
 
2009
    pkt->size = -1;
2019
2010
    ts->pkt = pkt;
2020
2011
    ret = handle_packets(ts, 0);
2021
2012
    if (ret < 0) {
2033
2024
        }
2034
2025
    }
2035
2026
 
 
2027
    if (!ret && pkt->size < 0)
 
2028
        ret = AVERROR(EINTR);
2036
2029
    return ret;
2037
2030
}
2038
2031
 
2088
2081
    return timestamp;
2089
2082
}
2090
2083
 
2091
 
#ifdef USE_SYNCPOINT_SEARCH
2092
 
 
2093
 
static int read_seek2(AVFormatContext *s,
2094
 
                      int stream_index,
2095
 
                      int64_t min_ts,
2096
 
                      int64_t target_ts,
2097
 
                      int64_t max_ts,
2098
 
                      int flags)
2099
 
{
2100
 
    int64_t pos;
2101
 
 
2102
 
    int64_t ts_ret, ts_adj;
2103
 
    int stream_index_gen_search;
2104
 
    AVStream *st;
2105
 
    AVParserState *backup;
2106
 
 
2107
 
    backup = ff_store_parser_state(s);
2108
 
 
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;
2112
 
 
2113
 
    if (flags & AVSEEK_FLAG_BYTE) {
2114
 
        // use position directly, we will search starting from it
2115
 
        pos = target_ts;
2116
 
    } else {
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);
2122
 
                return -1;
2123
 
            }
2124
 
 
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,
2128
 
                                st->time_base.den,
2129
 
                                AV_TIME_BASE * (int64_t)st->time_base.num);
2130
 
        } else {
2131
 
            ts_adj = target_ts;
2132
 
            stream_index_gen_search = stream_index;
2133
 
        }
2134
 
        pos = ff_gen_search(s, stream_index_gen_search, ts_adj,
2135
 
                            0, INT64_MAX, -1,
2136
 
                            AV_NOPTS_VALUE,
2137
 
                            AV_NOPTS_VALUE,
2138
 
                            flags, &ts_ret, mpegts_get_pcr);
2139
 
        if (pos < 0) {
2140
 
            ff_restore_parser_state(s, backup);
2141
 
            return -1;
2142
 
        }
2143
 
    }
2144
 
 
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,
2148
 
                                flags) < 0) {
2149
 
        ff_restore_parser_state(s, backup);
2150
 
        return -1;
2151
 
    }
2152
 
 
2153
 
    ff_free_parser_state(s, backup);
2154
 
    return 0;
2155
 
}
2156
 
 
2157
 
static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
2158
 
{
2159
 
    int ret;
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);
2163
 
        if (ret < 0)
2164
 
            // for compatibility reasons, seek to the best-fitting timestamp
2165
 
            ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags);
2166
 
    } else {
2167
 
        ret = read_seek2(s, stream_index, target_ts, target_ts, INT64_MAX, flags);
2168
 
        if (ret < 0)
2169
 
            // for compatibility reasons, seek to the best-fitting timestamp
2170
 
            ret = read_seek2(s, stream_index, INT64_MIN, target_ts, INT64_MAX, flags);
2171
 
    }
2172
 
    return ret;
2173
 
}
2174
 
 
2175
 
#else
2176
 
 
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];
2197
2104
    return 0;
2198
2105
}
2199
2106
 
2200
 
#endif
2201
 
 
2202
2107
/**************************************************************/
2203
2108
/* parsing functions - called from other demuxers such as RTP */
2204
2109
 
2254
2159
 
2255
2160
AVInputFormat ff_mpegts_demuxer = {
2256
2161
    .name           = "mpegts",
2257
 
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"),
 
2162
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-TS (MPEG-2 Transport Stream)"),
2258
2163
    .priv_data_size = sizeof(MpegTSContext),
2259
2164
    .read_probe     = mpegts_probe,
2260
2165
    .read_header    = mpegts_read_header,
2262
2167
    .read_close     = mpegts_read_close,
2263
2168
    .read_seek      = read_seek,
2264
2169
    .read_timestamp = mpegts_get_pcr,
2265
 
    .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
2266
 
#ifdef USE_SYNCPOINT_SEARCH
2267
 
    .read_seek2 = read_seek2,
2268
 
#endif
 
2170
    .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
2269
2171
};
2270
2172
 
2271
2173
AVInputFormat ff_mpegtsraw_demuxer = {
2272
2174
    .name           = "mpegtsraw",
2273
 
    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"),
 
2175
    .long_name      = NULL_IF_CONFIG_SMALL("raw MPEG-TS (MPEG-2 Transport Stream)"),
2274
2176
    .priv_data_size = sizeof(MpegTSContext),
2275
2177
    .read_header    = mpegts_read_header,
2276
2178
    .read_packet    = mpegts_raw_read_packet,
2277
2179
    .read_close     = mpegts_read_close,
2278
2180
    .read_seek      = read_seek,
2279
2181
    .read_timestamp = mpegts_get_pcr,
2280
 
    .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT,
2281
 
#ifdef USE_SYNCPOINT_SEARCH
2282
 
    .read_seek2 = read_seek2,
2283
 
#endif
2284
 
    .priv_class = &mpegtsraw_class,
 
2182
    .flags          = AVFMT_SHOW_IDS | AVFMT_TS_DISCONT,
 
2183
    .priv_class     = &mpegtsraw_class,
2285
2184
};