Compare commits

...

2 commits

Author SHA1 Message Date
Robert-André Mauchin 8bf3b170a1
Merge 4a1047151c into 79fc73f0de 2024-05-09 08:27:25 +00:00
Robert-André Mauchin 4a1047151c Add compatibility with FFMPEG 7.0
channel_layout has been replaced with ch_layout

Fix: #16437
2024-05-09 10:26:44 +02:00
2 changed files with 34 additions and 3 deletions

View file

@ -65,6 +65,8 @@ extern "C" {
s ##_version() >> 8 & 0xFF, \
s ##_version() & 0xFF);
#define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
static bool reset_triggered;
static bool libretro_supports_bitmasks = false;
@ -1726,8 +1728,14 @@ static void decode_thread(void *data)
{
swr[i] = swr_alloc();
#if HAVE_CH_LAYOUT
AVChannelLayout out_chlayout = AV_CHANNEL_LAYOUT_STEREO;
av_opt_set_chlayout(swr[i], "in_chlayout", &actx[i]->ch_layout, 0);
av_opt_set_chlayout(swr[i], "out_chlayout", &out_chlayout, 0);
#else
av_opt_set_int(swr[i], "in_channel_layout", actx[i]->channel_layout, 0);
av_opt_set_int(swr[i], "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
#endif
av_opt_set_int(swr[i], "in_sample_rate", actx[i]->sample_rate, 0);
av_opt_set_int(swr[i], "out_sample_rate", media.sample_rate, 0);
av_opt_set_int(swr[i], "in_sample_fmt", actx[i]->sample_fmt, 0);

View file

@ -70,6 +70,7 @@ extern "C" {
#include "../../verbosity.h"
#define FFMPEG3 (LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100))
#define HAVE_CH_LAYOUT (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
struct ff_video_info
{
@ -301,9 +302,15 @@ static bool ffmpeg_init_audio(ffmpeg_t *handle, const char *audio_resampler)
audio->codec = avcodec_alloc_context3(codec);
audio->codec->codec_type = AVMEDIA_TYPE_AUDIO;
#if HAVE_CH_LAYOUT
audio->codec->ch_layout = (param->channels > 1)
? (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO
: (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
#else
audio->codec->channels = param->channels;
audio->codec->channel_layout = (param->channels > 1)
? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
#endif
ffmpeg_audio_resolve_format(audio, codec);
ffmpeg_audio_resolve_sample_rate(handle, codec);
@ -351,9 +358,15 @@ static bool ffmpeg_init_audio(ffmpeg_t *handle, const char *audio_resampler)
if (!audio->codec->frame_size)
audio->codec->frame_size = 1024;
#if HAVE_CH_LAYOUT
int nb_channels = audio->codec->ch_layout.nb_channels;
#else
int nb_channels = audio->codec->channels;
#endif
audio->buffer = (uint8_t*)av_malloc(
audio->codec->frame_size *
audio->codec->channels *
nb_channels *
audio->sample_size);
if (!audio->buffer)
@ -1342,20 +1355,30 @@ static bool encode_audio(ffmpeg_t *handle, bool dry)
frame->nb_samples = handle->audio.frames_in_buffer;
frame->format = handle->audio.codec->sample_fmt;
#if HAVE_CH_LAYOUT
av_channel_layout_copy(&frame->ch_layout, &handle->audio.codec->ch_layout);
#else
frame->channel_layout = handle->audio.codec->channel_layout;
#endif
frame->pts = handle->audio.frame_cnt;
planarize_audio(handle);
#if HAVE_CH_LAYOUT
int nb_channels = handle->audio.codec->ch_layout.nb_channels;
#else
int nb_channels = handle->audio.codec->channels;
#endif
samples_size = av_samples_get_buffer_size(
NULL,
handle->audio.codec->channels,
nb_channels,
handle->audio.frames_in_buffer,
handle->audio.codec->sample_fmt, 0);
av_frame_get_buffer(frame, 0);
avcodec_fill_audio_frame(frame,
handle->audio.codec->channels,
nb_channels,
handle->audio.codec->sample_fmt,
handle->audio.is_planar
? (uint8_t*)handle->audio.planar_buf :