From 70a04d71b81e5ba4cf77d2302cd14628f1ca8a80 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Mon, 2 Dec 2024 09:56:00 +0100 Subject: [PATCH] lavc audio chann removed: compat --- src/audio/codec/libavcodec.cpp | 13 +++++++------ src/libavcodec_common.h | 7 +++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/audio/codec/libavcodec.cpp b/src/audio/codec/libavcodec.cpp index 02fc06e96..17755de82 100644 --- a/src/audio/codec/libavcodec.cpp +++ b/src/audio/codec/libavcodec.cpp @@ -296,10 +296,7 @@ static bool reinitialize_coder(struct libavcodec_codec_state *s, struct audio_de return false; } - s->codec_ctx->channels = 1; -#if LIBAVCODEC_VERSION_MAJOR >= 54 - s->codec_ctx->channel_layout = AV_CH_LAYOUT_MONO; -#endif + AVCODECCTX_CHANNELS(s->codec_ctx) = 1; pthread_mutex_lock(s->libav_global_lock); /* open it */ @@ -316,8 +313,12 @@ static bool reinitialize_coder(struct libavcodec_codec_state *s, struct audio_de s->av_frame->nb_samples = s->codec_ctx->frame_size; s->av_frame->format = s->codec_ctx->sample_fmt; -#if LIBAVCODEC_VERSION_MAJOR >= 54 +#if FF_API_NEW_CHANNEL_LAYOUT + s->av_frame->ch_layout = (struct AVChannelLayout) AV_CHANNEL_LAYOUT_MONO; +#else s->av_frame->channel_layout = AV_CH_LAYOUT_MONO; +#endif +#if LIBAVCODEC_VERSION_MAJOR >= 54 s->av_frame->sample_rate = s->codec_ctx->sample_rate; #endif @@ -347,7 +348,7 @@ static bool reinitialize_decoder(struct libavcodec_codec_state *s, struct audio_ avcodec_close(s->codec_ctx); pthread_mutex_unlock(s->libav_global_lock); - s->codec_ctx->channels = 1; + AVCODECCTX_CHANNELS(s->codec_ctx) = 1; s->codec_ctx->bits_per_coded_sample = 4; // ADPCM s->codec_ctx->sample_rate = desc.sample_rate; diff --git a/src/libavcodec_common.h b/src/libavcodec_common.h index 0f44c6c84..6ed273a9a 100644 --- a/src/libavcodec_common.h +++ b/src/libavcodec_common.h @@ -120,6 +120,13 @@ extern "C" { #define AV_CODEC_ID_AV1 AV_CODEC_ID_NONE #endif +#if defined FF_API_OLD_CHANNEL_LAYOUT || (LIBAVUTIL_VERSION_MAJOR >= 58) +#define AVCODECCTX_CHANNELS(context) (context)->ch_layout.nb_channels +#define FF_API_NEW_CHANNEL_LAYOUT 1 +#else +#define AVCODECCTX_CHANNELS(context) (context)->channels +#endif + // avutil #if LIBAVUTIL_VERSION_INT < AV_VERSION_INT(51, 42, 0) // FFMPEG commit 78071a1420b #define AV_PIX_FMT_NONE PIX_FMT_NONE