diff options
author | Kieran Kunhya <kierank@obe.tv> | 2014-10-18 00:25:16 +0100 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-10-26 22:29:47 +0100 |
commit | 61e42c1124e42285715e21926070c580c4e4ece0 (patch) | |
tree | d42cbe5e069c55b96fbee59edf80db189644b82d | |
parent | 74141f693ded2fbf75af56fff309d2db35183635 (diff) | |
download | ffmpeg-61e42c1124e42285715e21926070c580c4e4ece0.tar.gz |
avformat/mpegts: Add support for Opus in MPEG-TS
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/mpegts.c | 54 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
2 files changed, 54 insertions, 2 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c index cc0ce790f0..c01f954c84 100644 --- a/libavformat/mpegts.c +++ b/libavformat/mpegts.c @@ -29,6 +29,7 @@ #include "libavutil/avassert.h" #include "libavcodec/bytestream.h" #include "libavcodec/get_bits.h" +#include "libavcodec/opus.h" #include "avformat.h" #include "mpegts.h" #include "internal.h" @@ -701,6 +702,7 @@ static const StreamType REGD_types[] = { { MKTAG('H', 'E', 'V', 'C'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC }, { MKTAG('K', 'L', 'V', 'A'), AVMEDIA_TYPE_DATA, AV_CODEC_ID_SMPTE_KLV }, { MKTAG('V', 'C', '-', '1'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1 }, + { MKTAG('O', 'p', 'u', 's'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_OPUS }, { 0 }, }; @@ -1499,13 +1501,28 @@ static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, av_free(mp4_descr[i].dec_config_descr); } +static const uint8_t opus_coupled_stream_cnt[9] = { + 1, 0, 1, 1, 2, 2, 2, 3, 3 +}; + +static const uint8_t opus_channel_map[8][8] = { + { 0 }, + { 0,1 }, + { 0,2,1 }, + { 0,1,2,3 }, + { 0,4,1,2,3 }, + { 0,4,1,2,3,5 }, + { 0,4,1,2,3,5,6 }, + { 0,6,1,2,3,4,5,7 }, +}; + int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, const uint8_t **pp, const uint8_t *desc_list_end, Mp4Descr *mp4_descr, int mp4_descr_count, int pid, MpegTSContext *ts) { const uint8_t *desc_end; - int desc_len, desc_tag, desc_es_id; + int desc_len, desc_tag, desc_es_id, ext_desc_tag, channels, channel_config_code; char language[252]; int i; @@ -1710,6 +1727,41 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type mpegts_find_stream_type(st, st->codec->codec_tag, METADATA_types); } break; + case 0x7f: /* DVB extension descriptor */ + ext_desc_tag = get8(pp, desc_end); + if (ext_desc_tag < 0) + return AVERROR_INVALIDDATA; + if (st->codec->codec_id == AV_CODEC_ID_OPUS && + ext_desc_tag == 0x80) { /* User defined (provisional Opus) */ + if (!st->codec->extradata) { + st->codec->extradata = av_mallocz(sizeof(opus_default_extradata) + + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + + st->codec->extradata_size = sizeof(opus_default_extradata); + memcpy(st->codec->extradata, opus_default_extradata, sizeof(opus_default_extradata)); + + channel_config_code = get8(pp, desc_end); + if (channel_config_code < 0) + return AVERROR_INVALIDDATA; + if (channel_config_code <= 0x8) { + st->codec->extradata[9] = channels = channel_config_code ? channel_config_code : 2; + st->codec->extradata[18] = channels > 2; + st->codec->extradata[19] = channel_config_code; + if (channel_config_code == 0) { /* Dual Mono */ + st->codec->extradata[18] = 255; /* Mapping */ + st->codec->extradata[19] = 2; /* Stream Count */ + } + st->codec->extradata[20] = opus_coupled_stream_cnt[channel_config_code]; + memcpy(&st->codec->extradata[21], opus_channel_map[channels - 1], channels); + } else { + avpriv_request_sample(fc, "Opus in MPEG-TS - channel_config_code > 0x8"); + } + st->need_parsing = AVSTREAM_PARSE_FULL; + } + } + break; default: break; } diff --git a/libavformat/version.h b/libavformat/version.h index f54f445d7b..af49ffad57 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -30,7 +30,7 @@ #include "libavutil/version.h" #define LIBAVFORMAT_VERSION_MAJOR 56 -#define LIBAVFORMAT_VERSION_MINOR 10 +#define LIBAVFORMAT_VERSION_MINOR 11 #define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ |