From c4302ca59dd79efd7208a45a3fcdc44388fd03a8 Mon Sep 17 00:00:00 2001
From: Ilkka Ollakka <ileoo@videolan.org>
Date: Tue, 4 Jul 2023 16:53:43 +0300
Subject: [PATCH] avcodec: add handling of new ch_layout in audio encoder

conditioned to avcodec version where is it added
---
 modules/codec/avcodec/encoder.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 0ef334212ba4..38a8437261dc 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -934,8 +934,12 @@ errmsg:
 
         if( p_enc->fmt_out.audio.i_channels > 2 )
         {
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
+            av_channel_layout_default( &p_context->ch_layout, 2 );
+#else
             p_context->channels = 2;
             p_context->channel_layout = channel_mask[p_context->channels][1];
+#endif
 
             /* Change fmt_in in order to ask for a channels conversion */
             p_enc->fmt_in.audio.i_channels =
@@ -1295,8 +1299,12 @@ static block_t *handle_delay_buffer( encoder_t *p_enc, encoder_sys_t *p_sys, uns
     av_frame_unref( p_sys->frame );
     p_sys->frame->format     = p_sys->p_context->sample_fmt;
     p_sys->frame->nb_samples = leftover_samples + p_sys->i_samples_delay;
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
+    av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
+#else
     p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
     p_sys->frame->channels = p_sys->p_context->channels;
+#endif
 
     if( likely( date_Get( &p_sys->buffer_date ) != VLC_TICK_INVALID) )
     {
@@ -1425,8 +1433,12 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
         else
             p_sys->frame->nb_samples = p_sys->i_frame_size;
         p_sys->frame->format = p_sys->p_context->sample_fmt;
+#if LIBAVCODEC_VERSION_CHECK(59, 24, 100)
+        av_channel_layout_copy(&p_sys->frame->ch_layout, &p_sys->p_context->ch_layout);
+#else
         p_sys->frame->channel_layout = p_sys->p_context->channel_layout;
         p_sys->frame->channels = p_sys->p_context->channels;
+#endif
 
         if( likely(date_Get( &p_sys->buffer_date ) != VLC_TICK_INVALID) )
         {
-- 
GitLab