diff mbox series

[FFmpeg-devel,007/281] lavf: add a temporary compat layer for the channel layout API change

Message ID 20220113015101.4-8-jamrial@gmail.com
State New
Headers show
Series New channel layout API | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/makex86 warning New warnings during build
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
yinshiyou/makeloongarch64 warning New warnings during build
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/makeppc warning New warnings during build
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/makeaarch64_jetson warning New warnings during build
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished
andriy/makearmv7_RPi4 warning New warnings during build

Commit Message

James Almer Jan. 13, 2022, 1:49 a.m. UTC
From: Anton Khirnov <anton@khirnov.net>

Mediates between old-style (de)muxers and new-style callers. Will be
removed once all the (de)muxers are converted to the new API.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/demux.c | 12 ++++++++++++
 libavformat/mux.c   | 10 ++++++++++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/libavformat/demux.c b/libavformat/demux.c
index f895f0ba85..c78c6c16a2 100644
--- a/libavformat/demux.c
+++ b/libavformat/demux.c
@@ -194,6 +194,18 @@  static int update_stream_avctx(AVFormatContext *s)
             sti->parser = NULL;
         }
 
+        /* if the demuxer exports old channel layouts, convert it to new */
+        if (!st->codecpar->ch_layout.nb_channels &&
+            st->codecpar->channels) {
+            if (st->codecpar->channel_layout) {
+                av_channel_layout_from_mask(&st->codecpar->ch_layout,
+                                            st->codecpar->channel_layout);
+            } else {
+                st->codecpar->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
+                st->codecpar->ch_layout.nb_channels = st->codecpar->channels;
+            }
+        }
+
         /* update internal codec context, for the parser */
         ret = avcodec_parameters_to_context(sti->avctx, st->codecpar);
         if (ret < 0)
diff --git a/libavformat/mux.c b/libavformat/mux.c
index c387f8ec6e..775e3e0d76 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -272,6 +272,16 @@  static int init_muxer(AVFormatContext *s, AVDictionary **options)
                 ret = AVERROR(EINVAL);
                 goto fail;
             }
+
+            /* if the new-style channel layout is set, convert it to old one
+             * for old-style muxers */
+            if (par->ch_layout.nb_channels &&
+                !par->channels) {
+                par->channels       = par->ch_layout.nb_channels;
+                par->channel_layout = par->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                      par->ch_layout.u.mask : 0;
+            }
+
             if (!par->block_align)
                 par->block_align = par->channels *
                                    av_get_bits_per_sample(par->codec_id) >> 3;