[FFmpeg-devel] [PATCH 007/244] lavf: convert the generic layer to the new channel layout

Anton Khirnov anton at khirnov.net
Fri Dec 6 12:17:01 EET 2019


---
 libavformat/mux.c   | 13 ++++++++++++-
 libavformat/utils.c | 18 +++++++++++++++++-
 2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/libavformat/mux.c b/libavformat/mux.c
index ae1f26c3da..dc4dc4518c 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -333,8 +333,19 @@ FF_ENABLE_DEPRECATION_WARNINGS
                                       par->ch_layout.u.mask : 0;
             }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+            /* if the caller is using the deprecated channel layout API,
+             * convert it to the new style */
+            if (!par->ch_layout.nb_channels) {
+                par->ch_layout.order       = par->channel_layout ? AV_CHANNEL_ORDER_NATIVE : AV_CHANNEL_ORDER_UNSPEC;
+                par->ch_layout.nb_channels = par->channels;
+            }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
             if (!par->block_align)
-                par->block_align = par->channels *
+                par->block_align = par->ch_layout.nb_channels *
                                    av_get_bits_per_sample(par->codec_id) >> 3;
             break;
         case AVMEDIA_TYPE_VIDEO:
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 13eadbbfd0..4eaeba2fb5 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -528,6 +528,18 @@ static int update_stream_avctx(AVFormatContext *s)
             }
         }
 
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        if (st->codecpar->ch_layout.nb_channels &&
+            !st->codecpar->channels) {
+            st->codecpar->channels = st->codecpar->ch_layout.nb_channels;
+            st->codecpar->channel_layout = st->codecpar->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
+                                           st->codecpar->ch_layout.u.mask : 0;
+
+        }
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
         /* update internal codec context, for the parser */
         ret = avcodec_parameters_to_context(st->internal->avctx, st->codecpar);
         if (ret < 0)
@@ -1695,8 +1707,12 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 return ret;
             st->codecpar->sample_rate = st->internal->avctx->sample_rate;
             st->codecpar->bit_rate = st->internal->avctx->bit_rate;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
             st->codecpar->channels = st->internal->avctx->channels;
             st->codecpar->channel_layout = st->internal->avctx->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
             st->codecpar->codec_id = st->internal->avctx->codec_id;
         } else {
             /* free packet */
@@ -4263,7 +4279,7 @@ int av_find_best_stream(AVFormatContext *ic, enum AVMediaType type,
             continue;
         if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb)
             continue;
-        if (type == AVMEDIA_TYPE_AUDIO && !(par->channels && par->sample_rate))
+        if (type == AVMEDIA_TYPE_AUDIO && !(par->ch_layout.nb_channels && par->sample_rate))
             continue;
         if (decoder_ret) {
             decoder = find_decoder(ic, st, par->codec_id);
-- 
2.24.0



More information about the ffmpeg-devel mailing list