Skip to content

Commit

Permalink
Merge pull request #10866 from uklotzde/ffmpeg-4.1.9
Browse files Browse the repository at this point in the history
Cleanup: Require FFmpeg v4.1.9 or later
  • Loading branch information
Holzhaus authored Sep 3, 2022
2 parents a2b7367 + 8b97df0 commit 55a8272
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 50 deletions.
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://ffmpeg.org/download.html>
# 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)
Expand Down
8 changes: 0 additions & 8 deletions src/encoder/encoderffmpegcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 3 additions & 31 deletions src/sources/soundsourceffmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <libavutil/channel_layout.h>
#endif

#include <mutex>

#include "util/logger.h"
#include "util/sample.h"

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/sources/soundsourceffmpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class SoundSourceProviderFFmpeg : public SoundSourceProvider {
public:
static const QString kDisplayName;

SoundSourceProviderFFmpeg();
~SoundSourceProviderFFmpeg() override = default;

QString getDisplayName() const override {
return kDisplayName;
Expand Down

0 comments on commit 55a8272

Please sign in to comment.