summaryrefslogtreecommitdiff
path: root/libavformat/mpegts.c
diff options
context:
space:
mode:
authorKieran Kunhya <kierank@obe.tv>2014-10-18 00:25:16 +0100
committerAnton Khirnov <anton@khirnov.net>2014-12-20 11:29:19 +0100
commit9cfa68c560bdec82d2d5ec079f9c5b0f9ca37af0 (patch)
tree6fbd13f5452daad0169f6d39548f4328a5ee5513 /libavformat/mpegts.c
parent8ebf02f8f530240edf7e45f35f7647ef9dd44a58 (diff)
mpegts: add support for Opus
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Diffstat (limited to 'libavformat/mpegts.c')
-rw-r--r--libavformat/mpegts.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 1377d9ceb4..cb548d2bd0 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -28,6 +28,7 @@
#include "libavutil/opt.h"
#include "libavcodec/bytestream.h"
#include "libavcodec/get_bits.h"
+#include "libavcodec/opus.h"
#include "avformat.h"
#include "mpegts.h"
#include "internal.h"
@@ -613,6 +614,7 @@ static const StreamType REGD_types[] = {
{ MKTAG('D', 'T', 'S', '3'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_DTS },
{ MKTAG('H', 'E', 'V', 'C'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_HEVC },
{ MKTAG('V', 'C', '-', '1'), AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_VC1 },
+ { MKTAG('O', 'p', 'u', 's'), AVMEDIA_TYPE_AUDIO, AV_CODEC_ID_OPUS },
{ 0 },
};
@@ -1314,13 +1316,32 @@ 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_stream_cnt[9] = {
+ 1, 1, 1, 2, 2, 3, 4, 4, 5,
+};
+
+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;
@@ -1444,6 +1465,37 @@ int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
if (st->codec->codec_id == AV_CODEC_ID_NONE)
mpegts_find_stream_type(st, st->codec->codec_tag, REGD_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] = channel_config_code ? (channels > 2) : 255;
+ st->codec->extradata[19] = opus_stream_cnt[channel_config_code];
+ 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;
}