avcodec: add handling of new ch_layout in audio encoder
authorIlkka Ollakka <ileoo@videolan.org>
Tue, 4 Jul 2023 13:53:43 +0000 (16:53 +0300)
committerSebastian Ramacher <sramacher@debian.org>
Tue, 14 Jan 2025 22:09:47 +0000 (23:09 +0100)
conditioned to avcodec version where is it added

(cherry picked from commit c4302ca59dd79efd7208a45a3fcdc44388fd03a8)

Gbp-Pq: Name 0073-avcodec-add-handling-of-new-ch_layout-in-audio-encod.patch

modules/codec/avcodec/encoder.c

index 6bd58f5071d2b2052e433fe320f9da9205732850..757f93b468454b2f7c39c1fd7728a03e346b4a52 100644 (file)
@@ -927,11 +927,14 @@ errmsg:
 
         if( p_enc->fmt_out.audio.i_channels > 2 )
         {
+#if LIBAVCODEC_VERSION_CHECK(59, 999, 999, 24, 100)
+            av_channel_layout_default( &p_context->ch_layout, 2 );
+#else
             p_context->channels = 2;
-#if API_CHANNEL_LAYOUT
+# if API_CHANNEL_LAYOUT
             p_context->channel_layout = channel_mask[p_context->channels][1];
+# endif
 #endif
-
             /* Change fmt_in in order to ask for a channels conversion */
             p_enc->fmt_in.audio.i_channels =
             p_enc->fmt_out.audio.i_channels = 2;
@@ -1288,8 +1291,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, 999, 999, 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
 
     p_sys->frame->pts        = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
                                 CLOCK_FREQ / p_sys->p_context->time_base.num;
@@ -1419,8 +1426,12 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
         p_sys->frame->pts        = date_Get( &p_sys->buffer_date ) * p_sys->p_context->time_base.den /
                                     CLOCK_FREQ / p_sys->p_context->time_base.num;
 
+#if LIBAVCODEC_VERSION_CHECK(59, 999, 999, 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
 
         const int in_bytes = p_sys->frame->nb_samples *
             p_enc->fmt_out.audio.i_channels* p_sys->i_sample_bytes;