diff mbox

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

Message ID 20191206101710.22028-6-anton@khirnov.net
State New
Headers show

Commit Message

Anton Khirnov Dec. 6, 2019, 10:17 a.m. UTC
Mediates between old-style (de)muxers and new-style callers. Will be
removed once all the (de)muxers are converted to the new API.
---
 libavformat/mux.c   | 10 ++++++++++
 libavformat/utils.c | 12 ++++++++++++
 2 files changed, 22 insertions(+)
diff mbox

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index 411cca3fb2..ae1f26c3da 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -323,6 +323,16 @@  FF_ENABLE_DEPRECATION_WARNINGS
                 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;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index b6b5f0f308..13eadbbfd0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -516,6 +516,18 @@  static int update_stream_avctx(AVFormatContext *s)
             st->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(st->internal->avctx, st->codecpar);
         if (ret < 0)