Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com>
---
 libavfilter/audio.c         | 17 +++++++++++++++--
 libavfilter/avfilter.c      |  9 ++++-----
 libavfilter/avfilter.h      | 13 ++++++++++++-
 libavfilter/avfiltergraph.c | 35 +++++++++++++++++++++++++++--------
 libavfilter/buffersink.c    |  2 +-
 libavfilter/fifo.c          |  7 +++----
 6 files changed, 62 insertions(+), 21 deletions(-)

diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index 5fe9da95c3..afd8bdc169 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -31,7 +31,7 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int 
nb_samples)
 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
 {
     AVFrame *frame = av_frame_alloc();
-    int channels = av_get_channel_layout_nb_channels(link->channel_layout);
+    int channels = link->ch_layout.nb_channels;
     int ret;
 
     if (!frame)
@@ -39,7 +39,20 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int 
nb_samples)
 
     frame->nb_samples     = nb_samples;
     frame->format         = link->format;
-    frame->channel_layout = link->channel_layout;
+
+    ret = av_channel_layout_copy(&frame->ch_layout, &link->ch_layout);
+    if (ret < 0) {
+        av_frame_free(&frame);
+        return NULL;
+    }
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (link->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ||
+        link->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC)
+        frame->channel_layout = link->channel_layout;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+
     frame->sample_rate    = link->sample_rate;
     ret = av_frame_get_buffer(frame, 0);
     if (ret < 0) {
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 83c1a7c20d..f2adefff3d 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -247,16 +247,15 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
                 link->dst ? link->dst->filter->name : "",
                 end ? "\n" : "");
     } else {
-        char buf[128];
-        av_get_channel_layout_string(buf, sizeof(buf), -1, 
link->channel_layout);
-
+        char *chlstr = av_channel_layout_describe(&link->ch_layout);
         av_log(ctx, AV_LOG_TRACE,
                 "link[%p r:%d cl:%s fmt:%-16s %-16s->%-16s]%s",
-                link, link->sample_rate, buf,
+                link, link->sample_rate, chlstr,
                 av_get_sample_fmt_name(link->format),
                 link->src ? link->src->filter->name : "",
                 link->dst ? link->dst->filter->name : "",
                 end ? "\n" : "");
+        av_free(chlstr);
     }
 }
 
@@ -683,7 +682,7 @@ int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
         case AVMEDIA_TYPE_AUDIO:
             av_samples_copy(out->extended_data, frame->extended_data,
                             0, 0, frame->nb_samples,
-                            
av_get_channel_layout_nb_channels(frame->channel_layout),
+                            frame->ch_layout.nb_channels,
                             frame->format);
             break;
         default:
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 6df69dbbbf..5d5edf0ed3 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -36,6 +36,7 @@
 #include "libavutil/attributes.h"
 #include "libavutil/avutil.h"
 #include "libavutil/buffer.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
@@ -334,7 +335,12 @@ struct AVFilterLink {
     int h;                      ///< agreed upon image height
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
     /* These two parameters apply only to audio */
-    uint64_t channel_layout;    ///< channel layout of current buffer (see 
libavutil/channel_layout.h)
+#if FF_API_OLD_CHANNEL_LAYOUT
+    /**
+     * @deprecated use ch_layout instead
+     */
+    attribute_deprecated uint64_t channel_layout;
+#endif
     int sample_rate;            ///< samples per second
 
     int format;                 ///< agreed upon media format
@@ -405,6 +411,11 @@ struct AVFilterLink {
      * AVHWFramesContext describing the frames.
      */
     AVBufferRef *hw_frames_ctx;
+
+    /**
+     * Channel layout of current buffer.
+     */
+    AVChannelLayout ch_layout;
 };
 
 /**
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index a0f797e283..c72016d2c8 100644
--- a/libavfilter/avfiltergraph.c
+++ b/libavfilter/avfiltergraph.c
@@ -397,7 +397,13 @@ static int pick_format(AVFilterLink *link)
             return AVERROR(EINVAL);
         }
         link->in_channel_layouts->nb_channel_layouts = 1;
+#if FF_API_OLD_CHANNEL_LAYOUT
+FF_DISABLE_DEPRECATION_WARNINGS
         link->channel_layout = link->in_channel_layouts->channel_layouts[0];
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+        av_channel_layout_from_mask(&link->ch_layout,
+                                    
link->in_channel_layouts->channel_layouts[0]);
     }
 
     ff_formats_unref(&link->in_formats);
@@ -578,23 +584,33 @@ static void 
swap_channel_layouts_on_filter(AVFilterContext *filter)
         for (j = 0; j < outlink->in_channel_layouts->nb_channel_layouts; j++) {
             uint64_t  in_chlayout = 
link->out_channel_layouts->channel_layouts[0];
             uint64_t out_chlayout = 
outlink->in_channel_layouts->channel_layouts[j];
-            int  in_channels      = 
av_get_channel_layout_nb_channels(in_chlayout);
-            int out_channels      = 
av_get_channel_layout_nb_channels(out_chlayout);
-            int count_diff        = out_channels - in_channels;
+            int  in_channels;
+            int out_channels;
+            int count_diff;
             int matched_channels, extra_channels;
             int score = 0;
+            AVChannelLayout  in_ch_layout = {0};
+            AVChannelLayout out_ch_layout = {0};
+
+            av_channel_layout_from_mask( &in_ch_layout,  in_chlayout);
+            av_channel_layout_from_mask(&out_ch_layout, out_chlayout);
+            in_channels  =  in_ch_layout.nb_channels;
+            out_channels = out_ch_layout.nb_channels;
+            count_diff = out_channels - in_channels;
 
             /* channel substitution */
             for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) {
                 uint64_t cmp0 = ch_subst[k][0];
                 uint64_t cmp1 = ch_subst[k][1];
+                AVChannelLayout tmp = {0};
                 if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) &&
                     (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) {
                     in_chlayout  &= ~cmp0;
                     out_chlayout &= ~cmp1;
                     /* add score for channel match, minus a deduction for
                        having to do the substitution */
-                    score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2;
+                    av_channel_layout_from_mask(&tmp, cmp1);
+                    score += 10 * tmp.nb_channels - 2;
                 }
             }
 
@@ -605,10 +621,13 @@ static void 
swap_channel_layouts_on_filter(AVFilterContext *filter)
             in_chlayout  &= ~AV_CH_LOW_FREQUENCY;
             out_chlayout &= ~AV_CH_LOW_FREQUENCY;
 
-            matched_channels = av_get_channel_layout_nb_channels(in_chlayout &
-                                                                 out_chlayout);
-            extra_channels   = av_get_channel_layout_nb_channels(out_chlayout &
-                                                                 
(~in_chlayout));
+            av_channel_layout_uninit( &in_ch_layout);
+            av_channel_layout_uninit(&out_ch_layout);
+            av_channel_layout_from_mask( &in_ch_layout,  in_chlayout &  
out_chlayout);
+            av_channel_layout_from_mask(&out_ch_layout, out_chlayout & 
(~in_chlayout));
+
+            matched_channels = in_ch_layout.nb_channels;
+            extra_channels   = out_ch_layout.nb_channels;
             score += 10 * matched_channels - 5 * extra_channels;
 
             if (score > best_score ||
diff --git a/libavfilter/buffersink.c b/libavfilter/buffersink.c
index 3b4d285ffd..1c2d912ad4 100644
--- a/libavfilter/buffersink.c
+++ b/libavfilter/buffersink.c
@@ -107,7 +107,7 @@ int attribute_align_arg 
av_buffersink_get_samples(AVFilterContext *ctx,
     int ret = 0;
 
     if (!s->audio_fifo) {
-        int nb_channels = 
av_get_channel_layout_nb_channels(link->channel_layout);
+        int nb_channels = link->ch_layout.nb_channels;
         if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, 
nb_samples)))
             return AVERROR(ENOMEM);
     }
diff --git a/libavfilter/fifo.c b/libavfilter/fifo.c
index a414585ece..85730cccd7 100644
--- a/libavfilter/fifo.c
+++ b/libavfilter/fifo.c
@@ -104,7 +104,7 @@ static void queue_pop(FifoContext *s)
 static void buffer_offset(AVFilterLink *link, AVFrame *frame,
                           int offset)
 {
-    int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
+    int nb_channels = link->ch_layout.nb_channels;
     int planar = av_sample_fmt_is_planar(link->format);
     int planes = planar ? nb_channels : 1;
     int block_align = av_get_bytes_per_sample(link->format) * (planar ? 1 : 
nb_channels);
@@ -128,8 +128,7 @@ static void buffer_offset(AVFilterLink *link, AVFrame 
*frame,
 
 static int calc_ptr_alignment(AVFrame *frame)
 {
-    int planes = av_sample_fmt_is_planar(frame->format) ?
-                 av_get_channel_layout_nb_channels(frame->channel_layout) : 1;
+    int planes = av_sample_fmt_is_planar(frame->format) ? 
frame->ch_layout.nb_channels : 1;
     int min_align = 128;
     int p;
 
@@ -170,7 +169,7 @@ static int return_audio_frame(AVFilterContext *ctx)
             buffer_offset(link, head, link->request_samples);
         }
     } else {
-        int nb_channels = 
av_get_channel_layout_nb_channels(link->channel_layout);
+        int nb_channels = link->ch_layout.nb_channels;
 
         if (!s->out) {
             s->out = ff_get_audio_buffer(link, link->request_samples);
-- 
2.12.0

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

Reply via email to