summaryrefslogtreecommitdiff
path: root/libavformat/mpegtsenc.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-05-13 11:11:26 +0200
committerJames Almer <jamrial@gmail.com>2022-03-15 09:42:35 -0300
commit77869a3e4396f77f3247a16f5ce873a9f3ba6598 (patch)
tree2b9a3bad356d2abf9ab866fd60f6aaf959ce2857 /libavformat/mpegtsenc.c
parent203a7bd7851967259d2e9f200295137d36290e3c (diff)
downloadffmpeg-77869a3e4396f77f3247a16f5ce873a9f3ba6598.tar.gz
mpegtsenc: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavformat/mpegtsenc.c')
-rw-r--r--libavformat/mpegtsenc.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 20dce56122..ead2ca25db 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -466,7 +466,7 @@ static int get_m2ts_stream_type(AVFormatContext *s, AVStream *st)
stream_type = 0x81;
break;
case AV_CODEC_ID_DTS:
- stream_type = (st->codecpar->channels > 6) ? 0x85 : 0x82;
+ stream_type = (st->codecpar->ch_layout.nb_channels > 6) ? 0x85 : 0x82;
break;
case AV_CODEC_ID_TRUEHD:
stream_type = 0x83;
@@ -592,6 +592,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
if (codec_id == AV_CODEC_ID_S302M)
put_registration_descriptor(&q, MKTAG('B', 'S', 'S', 'D'));
if (codec_id == AV_CODEC_ID_OPUS) {
+ int ch = st->codecpar->ch_layout.nb_channels;
+
/* 6 bytes registration descriptor, 4 bytes Opus audio descriptor */
if (q - data > SECTION_LENGTH - 6 - 4) {
err = 1;
@@ -605,11 +607,11 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
*q++ = 0x80;
if (st->codecpar->extradata && st->codecpar->extradata_size >= 19) {
- if (st->codecpar->extradata[18] == 0 && st->codecpar->channels <= 2) {
+ if (st->codecpar->extradata[18] == 0 && ch <= 2) {
/* RTP mapping family */
- *q++ = st->codecpar->channels;
- } else if (st->codecpar->extradata[18] == 1 && st->codecpar->channels <= 8 &&
- st->codecpar->extradata_size >= 21 + st->codecpar->channels) {
+ *q++ = ch;
+ } else if (st->codecpar->extradata[18] == 1 && ch <= 8 &&
+ st->codecpar->extradata_size >= 21 + ch) {
static const uint8_t coupled_stream_counts[9] = {
1, 0, 1, 1, 2, 2, 2, 3, 3
};
@@ -635,14 +637,14 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
};
/* Vorbis mapping family */
- if (st->codecpar->extradata[19] == st->codecpar->channels - coupled_stream_counts[st->codecpar->channels] &&
- st->codecpar->extradata[20] == coupled_stream_counts[st->codecpar->channels] &&
- memcmp(&st->codecpar->extradata[21], channel_map_a[st->codecpar->channels-1], st->codecpar->channels) == 0) {
- *q++ = st->codecpar->channels;
- } else if (st->codecpar->channels >= 2 && st->codecpar->extradata[19] == st->codecpar->channels &&
+ if (st->codecpar->extradata[19] == ch - coupled_stream_counts[ch] &&
+ st->codecpar->extradata[20] == coupled_stream_counts[ch] &&
+ memcmp(&st->codecpar->extradata[21], channel_map_a[ch - 1], ch) == 0) {
+ *q++ = ch;
+ } else if (ch >= 2 && st->codecpar->extradata[19] == ch &&
st->codecpar->extradata[20] == 0 &&
- memcmp(&st->codecpar->extradata[21], channel_map_b[st->codecpar->channels-1], st->codecpar->channels) == 0) {
- *q++ = st->codecpar->channels | 0x80;
+ memcmp(&st->codecpar->extradata[21], channel_map_b[ch - 1], ch) == 0) {
+ *q++ = ch | 0x80;
} else {
/* Unsupported, could write an extended descriptor here */
av_log(s, AV_LOG_ERROR, "Unsupported Opus Vorbis-style channel mapping");
@@ -653,9 +655,9 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping for family %d", st->codecpar->extradata[18]);
*q++ = 0xff;
}
- } else if (st->codecpar->channels <= 2) {
+ } else if (ch <= 2) {
/* Assume RTP mapping family */
- *q++ = st->codecpar->channels;
+ *q++ = ch;
} else {
/* Unsupported */
av_log(s, AV_LOG_ERROR, "Unsupported Opus channel mapping");