Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com>
---
 libavcodec/avcodec.h          | 11 +++++++++++
 libavcodec/utils.c            | 31 +++++++++++++++++++++++++++----
 libavformat/audiointerleave.c |  2 +-
 libavformat/mux.c             |  2 +-
 4 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 4089c08a24..bc7097c7bd 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3202,16 +3202,22 @@ typedef struct AVCodecParameters {
     enum AVColorSpace                  color_space;
     enum AVChromaLocation              chroma_location;
 
+#if FF_API_OLD_CHANNEL_LAYOUT
     /**
      * Audio only. The channel layout bitmask. May be 0 if the channel layout 
is
      * unknown or unspecified, otherwise the number of bits set must be equal 
to
      * the channels field.
+     * @deprecated use ch_layout
      */
+    attribute_deprecated
     uint64_t channel_layout;
     /**
      * Audio only. The number of audio channels.
+     * @deprecated use ch_layout.nb_channels
      */
+    attribute_deprecated
     int      channels;
+#endif
     /**
      * Audio only. The number of audio samples per second.
      */
@@ -3238,6 +3244,11 @@ typedef struct AVCodecParameters {
      * audio without any trailing padding.
      */
     int trailing_padding;
+
+    /**
+     * Audio only. The channel layout and number of channels.
+     */
+    AVChannelLayout ch_layout;
 } AVCodecParameters;
 
 /**
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index bc421f67f8..f8ae415d52 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1300,8 +1300,15 @@ int av_get_audio_frame_duration(AVCodecContext *avctx, 
int frame_bytes)
 
 int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
 {
+    int channels = par->ch_layout.nb_channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (!channels)
+        channels = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
     return get_audio_frame_duration(par->codec_id, par->sample_rate,
-                                    par->channels, par->block_align,
+                                    channels, par->block_align,
                                     par->codec_tag, par->bits_per_coded_sample,
                                     frame_bytes);
 }
@@ -1588,7 +1595,7 @@ int avcodec_parameters_copy(AVCodecParameters *dst, const 
AVCodecParameters *src
         dst->extradata_size = src->extradata_size;
     }
 
-    return 0;
+    return av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
 }
 
 int avcodec_parameters_from_context(AVCodecParameters *par,
@@ -1620,8 +1627,16 @@ int avcodec_parameters_from_context(AVCodecParameters 
*par,
         break;
     case AVMEDIA_TYPE_AUDIO:
         par->format          = codec->sample_fmt;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         par->channel_layout  = codec->channel_layout;
         par->channels        = codec->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        if (codec->channel_layout)
+            av_channel_layout_from_mask(&par->ch_layout, 
codec->channel_layout);
+        else
+            av_channel_layout_default(&par->ch_layout, codec->channels);
         par->sample_rate     = codec->sample_rate;
         par->block_align     = codec->block_align;
         par->initial_padding = codec->initial_padding;
@@ -1666,8 +1681,16 @@ int avcodec_parameters_to_context(AVCodecContext *codec,
         break;
     case AVMEDIA_TYPE_AUDIO:
         codec->sample_fmt      = par->format;
-        codec->channel_layout  = par->channel_layout;
-        codec->channels        = par->channels;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+        codec->channel_layout = par->channel_layout;
+        codec->channels       = par->channels;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        if (par->ch_layout.u.mask)
+            codec->channel_layout = par->ch_layout.u.mask;
+        if (par->ch_layout.nb_channels)
+            codec->channels = par->ch_layout.nb_channels;
         codec->sample_rate     = par->sample_rate;
         codec->block_align     = par->block_align;
         codec->initial_padding = par->initial_padding;
diff --git a/libavformat/audiointerleave.c b/libavformat/audiointerleave.c
index aa379f675e..4923c55b35 100644
--- a/libavformat/audiointerleave.c
+++ b/libavformat/audiointerleave.c
@@ -52,7 +52,7 @@ int ff_audio_interleave_init(AVFormatContext *s,
         AudioInterleaveContext *aic = st->priv_data;
 
         if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
-            aic->sample_size = (st->codecpar->channels *
+            aic->sample_size = (st->codecpar->ch_layout.nb_channels *
                                 
av_get_bits_per_sample(st->codecpar->codec_id)) / 8;
             if (!aic->sample_size) {
                 av_log(s, AV_LOG_ERROR, "could not compute sample size\n");
diff --git a/libavformat/mux.c b/libavformat/mux.c
index cc92f2a960..0084107dd5 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -140,7 +140,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
                 goto fail;
             }
             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:
-- 
2.13.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to