From 8b97df087f0f48742c355304a8e86a6b601b146e Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Sat, 3 Sep 2022 15:06:33 +0200 Subject: [PATCH] Require FFmpeg v4.1.9 or later - Require FFmpeg v4.1.9 as the minimum version - Consistently use AV_VERSION_INT >= minimum_version - Delete dead code --- CMakeLists.txt | 21 ++++++++++--------- src/encoder/encoderffmpegcore.cpp | 8 -------- src/sources/soundsourceffmpeg.cpp | 34 +++---------------------------- src/sources/soundsourceffmpeg.h | 2 +- 4 files changed, 15 insertions(+), 50 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e71513c621..53ca2445172 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2375,29 +2375,30 @@ elseif(WIN32) endif() endif() -# FFmpeg 4.x support +# FFmpeg support # FFmpeg is multimedia library that can be found http://ffmpeg.org/ find_package(FFMPEG COMPONENTS libavcodec libavformat libavutil libswresample) -default_option(FFMPEG "FFmpeg 4.x support" "FFMPEG_FOUND") +default_option(FFMPEG "FFmpeg support (version 4.1.9 or later)" "FFMPEG_FOUND") if(FFMPEG) if(NOT FFMPEG_FOUND) message(FATAL_ERROR "FFMPEG was not found") endif() # Check minimum required versions + # Minimum library versions according to # Windows: Version numbers are not available!? # macOS: Untested - if(FFMPEG_libavcodec_VERSION AND FFMPEG_libavcodec_VERSION VERSION_LESS 58) - message(FATAL_ERROR "FFmpeg support requires at least version 58 of libavcodec (found: ${FFMPEG_libavcodec_VERSION}).") + if(FFMPEG_libavcodec_VERSION AND FFMPEG_libavcodec_VERSION VERSION_LESS 58.35.100) + message(FATAL_ERROR "FFmpeg support requires at least version 58.35.100 of libavcodec (found: ${FFMPEG_libavcodec_VERSION}).") endif() - if(FFMPEG_libavformat_VERSION AND FFMPEG_libavformat_VERSION VERSION_LESS 58) - message(FATAL_ERROR "FFmpeg support requires at least version 58 of libavformat (found: ${FFMPEG_libavformat_VERSION}).") + if(FFMPEG_libavformat_VERSION AND FFMPEG_libavformat_VERSION VERSION_LESS 58.20.100) + message(FATAL_ERROR "FFmpeg support requires at least version 58.20.100 of libavformat (found: ${FFMPEG_libavformat_VERSION}).") endif() - if(FFMPEG_libavutil_VERSION AND FFMPEG_libavutil_VERSION VERSION_LESS 56) - message(FATAL_ERROR "FFmpeg support requires at least version 56 of libavutil (found: ${FFMPEG_libavutil_VERSION}).") + if(FFMPEG_libavutil_VERSION AND FFMPEG_libavutil_VERSION VERSION_LESS 56.22.100) + message(FATAL_ERROR "FFmpeg support requires at least version 56.22.100 of libavutil (found: ${FFMPEG_libavutil_VERSION}).") endif() - if(FFMPEG_libswresample_VERSION AND FFMPEG_libswresample_VERSION VERSION_LESS 3.1) - message(FATAL_ERROR "FFmpeg support requires at least version 3.1 of libswresample (found: ${FFMPEG_libswresample_VERSION}).") + if(FFMPEG_libswresample_VERSION AND FFMPEG_libswresample_VERSION VERSION_LESS 3.3.100) + message(FATAL_ERROR "FFmpeg support requires at least version 3.3.100 of libswresample (found: ${FFMPEG_libswresample_VERSION}).") endif() target_sources(mixxx-lib PRIVATE src/sources/soundsourceffmpeg.cpp) diff --git a/src/encoder/encoderffmpegcore.cpp b/src/encoder/encoderffmpegcore.cpp index 273209a5cbf..83c693610f1 100644 --- a/src/encoder/encoderffmpegcore.cpp +++ b/src/encoder/encoderffmpegcore.cpp @@ -450,11 +450,7 @@ int EncoderFfmpegCore::openAudio(AVCodec *codec, AVStream *stream) { return -1; } -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 89, 100) if (l_SCodecCtx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE) { -#else - if (l_SCodecCtx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) { -#endif m_iAudioInputFrameSize = 10000; } else { m_iAudioInputFrameSize = l_SCodecCtx->frame_size; @@ -531,11 +527,7 @@ AVStream *EncoderFfmpegCore::addStream(AVFormatContext *formatctx, // Some formats want stream headers to be separate. if (formatctx->oformat->flags & AVFMT_GLOBALHEADER) { -#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 89, 100) l_SCodecCtx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; -#else - l_SCodecCtx->flags |= CODEC_FLAG_GLOBAL_HEADER; -#endif } return l_SStream; diff --git a/src/sources/soundsourceffmpeg.cpp b/src/sources/soundsourceffmpeg.cpp index 9936d318da6..4f359f0436e 100644 --- a/src/sources/soundsourceffmpeg.cpp +++ b/src/sources/soundsourceffmpeg.cpp @@ -4,8 +4,6 @@ #include #endif -#include - #include "util/logger.h" #include "util/sample.h" @@ -68,21 +66,9 @@ constexpr SINT kMaxSamplesPerMP3Frame = 1152; const Logger kLogger("SoundSourceFFmpeg"); -std::once_flag initFFmpegLibFlag; - // FFmpeg API Changes: // https://github.com/FFmpeg/FFmpeg/blob/master/doc/APIchanges -// This function must be called once during startup. -void initFFmpegLib() { -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) - av_register_all(); -#endif -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 10, 100) - avcodec_register_all(); -#endif -} - #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100) // FFmpeg 5.1 inline void getStreamChannelLayout(AVChannelLayout* pChannelLayout, const AVStream& avStream) { if (avStream.codecpar->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) { @@ -367,23 +353,14 @@ void SoundSourceFFmpeg::SwrContextPtr::close() { const QString SoundSourceProviderFFmpeg::kDisplayName = QStringLiteral("FFmpeg"); -SoundSourceProviderFFmpeg::SoundSourceProviderFFmpeg() { - std::call_once(initFFmpegLibFlag, initFFmpegLib); -} - QStringList SoundSourceProviderFFmpeg::getSupportedFileExtensions() const { QStringList list; QStringList disabledInputFormats; // Collect all supported formats (whitelist) -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) - AVInputFormat* pavInputFormat = nullptr; - while ((pavInputFormat = av_iformat_next(pavInputFormat))) { -#else const AVInputFormat* pavInputFormat = nullptr; void* pOpaqueInputFormatIterator = nullptr; while ((pavInputFormat = av_demuxer_iterate(&pOpaqueInputFormatIterator))) { -#endif if (pavInputFormat->flags | AVFMT_SEEK_TO_PTS) { /////////////////////////////////////////////////////////// // Whitelist of tested codecs (including variants) @@ -553,11 +530,11 @@ SoundSource::OpenResult SoundSourceFFmpeg::tryOpen( } // Find the best stream -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(59, 0, 100) +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(59, 0, 100) // FFmpeg 5.0 + const AVCodec* pDecoder = nullptr; +#else // https://github.com/FFmpeg/FFmpeg/blob/dd17c86aa11feae2b86de054dd0679cc5f88ebab/doc/APIchanges#L175 AVCodec* pDecoder = nullptr; -#else - const AVCodec* pDecoder = nullptr; #endif const int av_find_best_stream_result = av_find_best_stream( m_pavInputFormatContext, @@ -607,11 +584,6 @@ SoundSource::OpenResult SoundSourceFFmpeg::tryOpen( return SoundSource::OpenResult::Aborted; } -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 18, 100) - // Align the time base of the context with that of the selected stream - av_codec_set_pkt_timebase(pavCodecContext, pavStream->time_base); -#endif - // Request output format pavCodecContext->request_sample_fmt = kavSampleFormat; if (params.getSignalInfo().getChannelCount().isValid()) { diff --git a/src/sources/soundsourceffmpeg.h b/src/sources/soundsourceffmpeg.h index 395946f0a36..6d593e13723 100644 --- a/src/sources/soundsourceffmpeg.h +++ b/src/sources/soundsourceffmpeg.h @@ -196,7 +196,7 @@ class SoundSourceProviderFFmpeg : public SoundSourceProvider { public: static const QString kDisplayName; - SoundSourceProviderFFmpeg(); + ~SoundSourceProviderFFmpeg() override = default; QString getDisplayName() const override { return kDisplayName;