From a27e9459f54122b09cb4df36cb8f33b9ca7ffd0f Mon Sep 17 00:00:00 2001 From: PioLing <964472638@qq.com> Date: Mon, 20 Jan 2025 18:00:13 +0800 Subject: [PATCH] Fix the compilation error of ffmpeg 7 (#4129) --- player/test_player.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/player/test_player.cpp b/player/test_player.cpp index 0db673c3..df93b28d 100644 --- a/player/test_player.cpp +++ b/player/test_player.cpp @@ -96,17 +96,18 @@ int main(int argc, char *argv[]) { FFmpegSwr::Ptr swr; decoder->setOnDecode([audio_player, swr](const FFmpegFrame::Ptr &frame) mutable { + int chs = 0; if (!swr) { - # if LIBAVCODEC_VERSION_INT >= FF_CODEC_VER_7_1 swr = std::make_shared(AV_SAMPLE_FMT_S16, &(frame->get()->ch_layout), frame->get()->sample_rate); + chs = (&frame->get()->ch_layout)->nb_channels; #else swr = std::make_shared(AV_SAMPLE_FMT_S16, frame->get()->channels, frame->get()->channel_layout, frame->get()->sample_rate); + chs = pcm->get()->channels; #endif - } auto pcm = swr->inputFrame(frame); - auto len = pcm->get()->nb_samples * pcm->get()->channels * av_get_bytes_per_sample((enum AVSampleFormat)pcm->get()->format); + auto len = pcm->get()->nb_samples * chs * av_get_bytes_per_sample((enum AVSampleFormat)pcm->get()->format); audio_player->playPCM((const char *)(pcm->get()->data[0]), MIN(len, frame->get()->linesize[0])); }); audioTrack->addDelegate([decoder](const Frame::Ptr &frame) { return decoder->inputFrame(frame, false, true); });