From: Ilkka Ollakka Date: Tue, 4 Jul 2023 13:55:28 +0000 (+0300) Subject: avcodec: use ch_layout for channel layout in audio encoder X-Git-Tag: archive/raspbian/3.0.21-2+rpi1^2~2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=06e54190bfdfdc575e2c1cbe7ccf2284bb042e90;p=vlc.git avcodec: use ch_layout for channel layout in audio encoder channels and channel_layout has been deprecated in FFMPEG 5.1 and will be removed eventually also always create the mapping, as ch_layout is always there (cherry picked from commit b73dc8841d999c6be9de718cd2cd3aeb13279792) Gbp-Pq: Name 0012-avcodec-use-ch_layout-for-channel-layout-in-audio-en.patch --- diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c index 757f93b4..ae746c99 100644 --- a/modules/codec/avcodec/encoder.c +++ b/modules/codec/avcodec/encoder.c @@ -183,6 +183,7 @@ static const uint64_t pi_channels_map[][2] = { AV_CH_STEREO_RIGHT, 0 }, }; +# if !LIBAVCODEC_VERSION_CHECK(59, 999, 999, 24, 100) static const uint32_t channel_mask[][2] = { {0,0}, {AOUT_CHAN_CENTER, AV_CH_LAYOUT_MONO}, @@ -195,6 +196,7 @@ static const uint32_t channel_mask[][2] = { {AOUT_CHANS_7_1, AV_CH_LAYOUT_7POINT1}, {AOUT_CHANS_8_1, AV_CH_LAYOUT_OCTAGONAL}, }; +# endif #endif static const char *const ppsz_enc_options[] = { @@ -748,49 +750,36 @@ int InitVideoEnc( vlc_object_t *p_this ) date_Set( &p_sys->buffer_date, AV_NOPTS_VALUE ); p_context->time_base.num = 1; p_context->time_base.den = p_context->sample_rate; - p_context->channels = p_enc->fmt_out.audio.i_channels; -#if API_CHANNEL_LAYOUT - p_context->channel_layout = channel_mask[p_context->channels][1]; - /* Setup Channel ordering for multichannel audio + /* Setup Channel ordering for audio * as VLC channel order isn't same as libavcodec expects */ p_sys->i_channels_to_reorder = 0; - /* Specified order + /* Create channel layout for avcodec * Copied from audio.c */ - const unsigned i_order_max = 8 * sizeof(p_context->channel_layout); - uint32_t pi_order_dst[AOUT_CHAN_MAX] = { }; +#if API_CHANNEL_LAYOUT + uint32_t pi_order_dst[AOUT_CHAN_MAX] = { 0 }; uint32_t order_mask = 0; int i_channels_src = 0; - - if( p_context->channel_layout ) - { - msg_Dbg( p_enc, "Creating channel order for reordering"); - for( unsigned i = 0; i < sizeof(pi_channels_map)/sizeof(*pi_channels_map); i++ ) - { - if( p_context->channel_layout & pi_channels_map[i][0] ) - { - msg_Dbg( p_enc, "%d %"PRIx64" mapped to %"PRIx64"", i_channels_src, pi_channels_map[i][0], pi_channels_map[i][1]); - pi_order_dst[i_channels_src++] = pi_channels_map[i][1]; - order_mask |= pi_channels_map[i][1]; - } - } - } - else + msg_Dbg( p_enc, "Creating channel order for reordering"); +# if LIBAVCODEC_VERSION_CHECK(59, 999, 999, 24, 100) + av_channel_layout_default( &p_context->ch_layout, p_enc->fmt_out.audio.i_channels ); + uint64_t channel_mask = p_context->ch_layout.u.mask; +# else + p_context->channels = p_enc->fmt_out.audio.i_channels; + p_context->channel_layout = channel_mask[p_context->channels][1]; + uint64_t channel_mask = p_context->channel_layout; +# endif + for( unsigned i = 0; i < sizeof(pi_channels_map)/sizeof(*pi_channels_map); i++ ) { - msg_Dbg( p_enc, "Creating default channel order for reordering"); - /* Create default order */ - for( unsigned int i = 0; i < __MIN( i_order_max, (unsigned)p_sys->p_context->channels ); i++ ) + if( channel_mask & pi_channels_map[i][0] ) { - if( i < sizeof(pi_channels_map)/sizeof(*pi_channels_map) ) - { - msg_Dbg( p_enc, "%d channel is %"PRIx64"", i_channels_src, pi_channels_map[i][1]); - pi_order_dst[i_channels_src++] = pi_channels_map[i][1]; - order_mask |= pi_channels_map[i][1]; - } + msg_Dbg( p_enc, "%d %"PRIx64" mapped to %"PRIx64"", i_channels_src, pi_channels_map[i][0], pi_channels_map[i][1]); + pi_order_dst[i_channels_src++] = pi_channels_map[i][1]; + order_mask |= pi_channels_map[i][1]; } } if( i_channels_src != p_enc->fmt_out.audio.i_channels ) @@ -799,6 +788,8 @@ int InitVideoEnc( vlc_object_t *p_this ) p_sys->i_channels_to_reorder = aout_CheckChannelReorder( NULL, pi_order_dst, order_mask, p_sys->pi_reorder_layout ); +#else + p_context->channels = p_enc->fmt_out.audio.i_channels; #endif if ( p_enc->fmt_out.i_codec == VLC_CODEC_MP4A )