Revision 08f94e98 libavformat/mpegts.c

View differences:

libavformat/mpegts.c
41 41
typedef struct PESContext PESContext;
42 42

  
43 43
static PESContext* add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type);
44
static AVStream* new_pes_av_stream(PESContext *pes, uint32_t code, uint32_t prog_reg_desc, uint32_t reg_desc);
45 44

  
46 45
enum MpegTSFilterType {
47 46
    MPEGTS_PES,
......
483 482
    return 0;
484 483
}
485 484

  
485
typedef struct {
486
    uint32_t stream_type;
487
    enum CodecType codec_type;
488
    enum CodecID codec_id;
489
} StreamType;
490

  
491
static const StreamType ISO_types[] = {
492
    { 0x01, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
493
    { 0x02, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
494
    { 0x03, CODEC_TYPE_AUDIO,        CODEC_ID_MP3 },
495
    { 0x04, CODEC_TYPE_AUDIO,        CODEC_ID_MP3 },
496
    { 0x0f, CODEC_TYPE_AUDIO,        CODEC_ID_AAC },
497
    { 0x10, CODEC_TYPE_VIDEO,      CODEC_ID_MPEG4 },
498
    { 0x1b, CODEC_TYPE_VIDEO,       CODEC_ID_H264 },
499
    { 0xd1, CODEC_TYPE_VIDEO,      CODEC_ID_DIRAC },
500
    { 0xea, CODEC_TYPE_VIDEO,        CODEC_ID_VC1 },
501
    { 0 },
502
};
503

  
504
static const StreamType HDMV_types[] = {
505
    { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 },
506
    { 0x82, CODEC_TYPE_AUDIO, CODEC_ID_DTS },
507
    { 0 },
508
};
509

  
510
/* ATSC ? */
511
static const StreamType MISC_types[] = {
512
    { 0x81, CODEC_TYPE_AUDIO,   CODEC_ID_AC3 },
513
    { 0x8a, CODEC_TYPE_AUDIO,   CODEC_ID_DTS },
514
    {0x100, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, // demuxer internal
515
    { 0 },
516
};
517

  
518
static const StreamType REGD_types[] = {
519
    { MKTAG('d','r','a','c'), CODEC_TYPE_VIDEO, CODEC_ID_DIRAC },
520
    { MKTAG('A','C','-','3'), CODEC_TYPE_AUDIO,   CODEC_ID_AC3 },
521
    { 0 },
522
};
523

  
524
static void mpegts_find_stream_type(AVStream *st,
525
                                    uint32_t stream_type, const StreamType *types)
526
{
527
    for (; types->stream_type; types++) {
528
        if (stream_type == types->stream_type) {
529
            st->codec->codec_type = types->codec_type;
530
            st->codec->codec_id   = types->codec_id;
531
            return;
532
        }
533
    }
534
}
535

  
536
static AVStream *new_pes_av_stream(PESContext *pes, uint32_t code,
537
                                   uint32_t prog_reg_desc, uint32_t reg_desc)
538
{
539
    AVStream *st = av_new_stream(pes->stream, pes->pid);
540

  
541
    if (!st)
542
        return NULL;
543

  
544
    av_set_pts_info(st, 33, 1, 90000);
545
    st->priv_data = pes;
546
    st->codec->codec_type = CODEC_TYPE_DATA;
547
    st->codec->codec_id   = CODEC_ID_PROBE;
548
    st->need_parsing = AVSTREAM_PARSE_FULL;
549
    pes->st = st;
550

  
551
    dprintf(pes->stream, "stream_type=%x prog_reg_desc=%.4s reg_desc=%.4s\n",
552
            pes->stream_type, (char*)&prog_reg_desc, (char*)&reg_desc);
553

  
554
    if (pes->stream_type == 0x06) { // private data carrying pes data
555
        mpegts_find_stream_type(st, reg_desc, REGD_types);
556
    } else {
557
        mpegts_find_stream_type(st, pes->stream_type, ISO_types);
558
        if (prog_reg_desc == AV_RL32("HDMV") &&
559
            st->codec->codec_id == CODEC_ID_PROBE)
560
            mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
561
        if (st->codec->codec_id == CODEC_ID_PROBE)
562
            mpegts_find_stream_type(st, pes->stream_type, MISC_types);
563
    }
564

  
565
    return st;
566
}
486 567

  
487 568
static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len)
488 569
{
......
926 1007
    return 0;
927 1008
}
928 1009

  
929
typedef struct {
930
    uint32_t stream_type;
931
    enum CodecType codec_type;
932
    enum CodecID codec_id;
933
} StreamType;
934

  
935
static const StreamType ISO_types[] = {
936
    { 0x01, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
937
    { 0x02, CODEC_TYPE_VIDEO, CODEC_ID_MPEG2VIDEO },
938
    { 0x03, CODEC_TYPE_AUDIO,        CODEC_ID_MP3 },
939
    { 0x04, CODEC_TYPE_AUDIO,        CODEC_ID_MP3 },
940
    { 0x0f, CODEC_TYPE_AUDIO,        CODEC_ID_AAC },
941
    { 0x10, CODEC_TYPE_VIDEO,      CODEC_ID_MPEG4 },
942
    { 0x1b, CODEC_TYPE_VIDEO,       CODEC_ID_H264 },
943
    { 0xd1, CODEC_TYPE_VIDEO,      CODEC_ID_DIRAC },
944
    { 0xea, CODEC_TYPE_VIDEO,        CODEC_ID_VC1 },
945
    { 0 },
946
};
947

  
948
static const StreamType HDMV_types[] = {
949
    { 0x81, CODEC_TYPE_AUDIO, CODEC_ID_AC3 },
950
    { 0x82, CODEC_TYPE_AUDIO, CODEC_ID_DTS },
951
    { 0 },
952
};
953

  
954
/* ATSC ? */
955
static const StreamType MISC_types[] = {
956
    { 0x81, CODEC_TYPE_AUDIO,   CODEC_ID_AC3 },
957
    { 0x8a, CODEC_TYPE_AUDIO,   CODEC_ID_DTS },
958
    {0x100, CODEC_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, // demuxer internal
959
    { 0 },
960
};
961

  
962
static const StreamType REGD_types[] = {
963
    { MKTAG('d','r','a','c'), CODEC_TYPE_VIDEO, CODEC_ID_DIRAC },
964
    { MKTAG('A','C','-','3'), CODEC_TYPE_AUDIO,   CODEC_ID_AC3 },
965
    { 0 },
966
};
967

  
968
static void mpegts_find_stream_type(AVStream *st,
969
                                    uint32_t stream_type, const StreamType *types)
970
{
971
    for (; types->stream_type; types++) {
972
        if (stream_type == types->stream_type) {
973
            st->codec->codec_type = types->codec_type;
974
            st->codec->codec_id   = types->codec_id;
975
            return;
976
        }
977
    }
978
}
979

  
980
static AVStream *new_pes_av_stream(PESContext *pes, uint32_t code,
981
                                   uint32_t prog_reg_desc, uint32_t reg_desc)
982
{
983
    AVStream *st = av_new_stream(pes->stream, pes->pid);
984

  
985
    if (!st)
986
        return NULL;
987

  
988
    av_set_pts_info(st, 33, 1, 90000);
989
    st->priv_data = pes;
990
    st->codec->codec_type = CODEC_TYPE_DATA;
991
    st->codec->codec_id   = CODEC_ID_PROBE;
992
    st->need_parsing = AVSTREAM_PARSE_FULL;
993
    pes->st = st;
994

  
995
    dprintf(pes->stream, "stream_type=%x prog_reg_desc=%.4s reg_desc=%.4s\n",
996
            pes->stream_type, (char*)&prog_reg_desc, (char*)&reg_desc);
997

  
998
    if (pes->stream_type == 0x06) { // private data carrying pes data
999
        mpegts_find_stream_type(st, reg_desc, REGD_types);
1000
    } else {
1001
        mpegts_find_stream_type(st, pes->stream_type, ISO_types);
1002
        if (prog_reg_desc == AV_RL32("HDMV") &&
1003
            st->codec->codec_id == CODEC_ID_PROBE)
1004
            mpegts_find_stream_type(st, pes->stream_type, HDMV_types);
1005
        if (st->codec->codec_id == CODEC_ID_PROBE)
1006
            mpegts_find_stream_type(st, pes->stream_type, MISC_types);
1007
    }
1008

  
1009
    return st;
1010
}
1011

  
1012

  
1013 1010
static PESContext *add_pes_stream(MpegTSContext *ts, int pid, int pcr_pid, int stream_type)
1014 1011
{
1015 1012
    MpegTSFilter *tss;

Also available in: Unified diff