build: fix compatibility with older ffmpeg

Check LIBAVCODEC_VERSION_MAJOR and use the older channel_layout API if
it's below 60.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2024-04-16 16:19:12 +00:00
parent af6028a9dd
commit 8d08223dbc
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 19 additions and 1 deletions

View File

@ -137,7 +137,12 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
}
}
if (!isSupported && acodec->supported_samplerates) return MRET_ERR_NOCODEC;
#if LIBAVCODEC_VERSION_MAJOR >= 60
av_channel_layout_from_mask(&(aenc->ch_layout), AV_CH_LAYOUT_STEREO);
#else
aenc->channel_layout = AV_CH_LAYOUT_STEREO;
aenc->channels = 2;
#endif
aenc->time_base = { 1, aenc->sample_rate };
ast->time_base = { 1, STREAM_FRAME_RATE };
// open and use codec on stream
@ -158,7 +163,11 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
audioframeTmp = av_frame_alloc();
if (!audioframeTmp) return MRET_ERR_BUFSIZE;
audioframeTmp->format = IN_SOUND_FORMAT;
#if LIBAVCODEC_VERSION_MAJOR >= 60
audioframeTmp->ch_layout = aenc->ch_layout;
#else
audioframeTmp->channel_layout = AV_CH_LAYOUT_STEREO;
#endif
audioframeTmp->sample_rate = aenc->sample_rate;
audioframeTmp->nb_samples = nb_samples;
if (nb_samples)
@ -170,7 +179,11 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
audioframe = av_frame_alloc();
if (!audioframe) return MRET_ERR_BUFSIZE;
audioframe->format = aenc->sample_fmt;
#if LIBAVCODEC_VERSION_MAJOR >= 60
audioframe->ch_layout = aenc->ch_layout;
#else
audioframe->channel_layout = AV_CH_LAYOUT_STEREO;
#endif
audioframe->sample_rate = aenc->sample_rate;
audioframe->nb_samples = nb_samples;
if (nb_samples)
@ -184,10 +197,15 @@ recording::MediaRet recording::MediaRecorder::setup_audio_stream()
{
return MRET_ERR_BUFSIZE;
}
#if LIBAVCODEC_VERSION_MAJOR >= 60
av_opt_set_chlayout (swr, "in_chlayout", &(aenc->ch_layout),0);
av_opt_set_chlayout (swr, "out_chlayout", &(aenc->ch_layout),0);
#else
av_opt_set_int (swr, "in_channel_count", 2, 0);
av_opt_set_int (swr, "out_channel_count", 2, 0);
#endif
av_opt_set_int (swr, "in_sample_rate", aenc->sample_rate, 0);
av_opt_set_sample_fmt(swr, "in_sample_fmt", IN_SOUND_FORMAT, 0);
av_opt_set_chlayout (swr, "out_chlayout", &(aenc->ch_layout),0);
av_opt_set_int (swr, "out_sample_rate", aenc->sample_rate, 0);
av_opt_set_sample_fmt(swr, "out_sample_fmt", aenc->sample_fmt, 0);
if (swr_init(swr) < 0)