From 20e3eeddde72026e500fe6fd42fdece599c1d53e Mon Sep 17 00:00:00 2001 From: elsid Date: Mon, 5 Aug 2024 23:24:48 +0200 Subject: [PATCH] Fix libavformat version check https://github.com/FFmpeg/FFmpeg/commit/2a68d945cd74265bb71c3d38b7a2e7f7d7e87be5 added const version of a callback functions but didn't enable them. They were guarded by a version check: https://github.com/FFmpeg/FFmpeg/blob/2a68d945cd74265bb71c3d38b7a2e7f7d7e87be5/libavformat/version_major.h#L48 So for anything LIBAVFORMAT_VERSION_MAJOR < 61 they are not enabled therefore they are enabled for everything >= 61.0.100. See https://github.com/elsid/openmw/actions/runs/10255993574/job/28374152796 as example of failure when building with 60.16.100. --- apps/openmw/mwsound/ffmpeg_decoder.cpp | 27 ++++++++++--------- apps/openmw/mwsound/ffmpeg_decoder.hpp | 10 +++---- apps/openmw/mwsound/movieaudiofactory.cpp | 3 ++- .../osg-ffmpeg-videoplayer/audiodecoder.cpp | 24 +++++++++-------- .../osg-ffmpeg-videoplayer/audiodecoder.hpp | 6 ++--- .../libavformatdefines.hpp | 13 +++++++++ .../libavutildefines.hpp | 13 +++++++++ extern/osg-ffmpeg-videoplayer/videostate.cpp | 3 ++- extern/osg-ffmpeg-videoplayer/videostate.hpp | 7 +++-- 9 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 extern/osg-ffmpeg-videoplayer/libavformatdefines.hpp create mode 100644 extern/osg-ffmpeg-videoplayer/libavutildefines.hpp diff --git a/apps/openmw/mwsound/ffmpeg_decoder.cpp b/apps/openmw/mwsound/ffmpeg_decoder.cpp index 88bcdcebdd..54fd126c41 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.cpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.cpp @@ -8,7 +8,10 @@ #include #include -#if FFMPEG_5_OR_GREATER +#include +#include + +#if OPENMW_FFMPEG_5_OR_GREATER #include #endif @@ -61,7 +64,7 @@ namespace MWSound } } -#if FFMPEG_CONST_WRITEPACKET +#if OPENMW_FFMPEG_CONST_WRITEPACKET int FFmpeg_Decoder::writePacket(void*, const uint8_t*, int) #else int FFmpeg_Decoder::writePacket(void*, uint8_t*, int) @@ -160,7 +163,7 @@ namespace MWSound if (!mDataBuf || mDataBufLen < mFrame->nb_samples) { av_freep(&mDataBuf); -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER if (av_samples_alloc(&mDataBuf, nullptr, mOutputChannelLayout.nb_channels, #else if (av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout), @@ -201,7 +204,7 @@ namespace MWSound if (!getAVAudioData()) break; mFramePos = 0; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER mFrameSize = mFrame->nb_samples * mOutputChannelLayout.nb_channels #else mFrameSize = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) @@ -293,7 +296,7 @@ namespace MWSound else mOutputSampleFormat = AV_SAMPLE_FMT_S16; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER mOutputChannelLayout = (*stream)->codecpar->ch_layout; // sefault if (mOutputChannelLayout.u.mask == 0) av_channel_layout_default(&mOutputChannelLayout, codecCtxPtr->ch_layout.nb_channels); @@ -356,7 +359,7 @@ namespace MWSound *type = SampleType_Int16; } -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER switch (mOutputChannelLayout.u.mask) #else switch (mOutputChannelLayout) @@ -379,7 +382,7 @@ namespace MWSound break; default: char str[1024]; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER av_channel_layout_describe(&mCodecCtx->ch_layout, str, sizeof(str)); Log(Debug::Error) << "Unsupported channel layout: " << str; @@ -412,7 +415,7 @@ namespace MWSound } *samplerate = mCodecCtx->sample_rate; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER AVChannelLayout ch_layout = mCodecCtx->ch_layout; if (ch_layout.u.mask == 0) av_channel_layout_default(&ch_layout, mCodecCtx->ch_layout.nb_channels); @@ -427,7 +430,7 @@ namespace MWSound #endif { -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER swr_alloc_set_opts2(&mSwr, // SwrContext &mOutputChannelLayout, // output ch layout mOutputSampleFormat, // output sample format @@ -476,7 +479,7 @@ namespace MWSound while (getAVAudioData()) { -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER size_t got = mFrame->nb_samples * mOutputChannelLayout.nb_channels #else size_t got = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) @@ -489,7 +492,7 @@ namespace MWSound size_t FFmpeg_Decoder::getSampleOffset() { -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER std::size_t delay = (mFrameSize - mFramePos) / mOutputChannelLayout.nb_channels #else std::size_t delay = (mFrameSize - mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout) @@ -506,7 +509,7 @@ namespace MWSound , mNextPts(0.0) , mSwr(nullptr) , mOutputSampleFormat(AV_SAMPLE_FMT_NONE) -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER , mOutputChannelLayout({}) #else , mOutputChannelLayout(0) diff --git a/apps/openmw/mwsound/ffmpeg_decoder.hpp b/apps/openmw/mwsound/ffmpeg_decoder.hpp index 92c4478d17..e67b8efbf3 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.hpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.hpp @@ -3,6 +3,9 @@ #include +#include +#include + #if defined(_MSC_VER) #pragma warning(push) #pragma warning(disable : 4244) @@ -30,9 +33,6 @@ extern "C" #include "sound_decoder.hpp" -#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)) -#define FFMPEG_CONST_WRITEPACKET (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(60, 12, 100)) - namespace MWSound { struct AVIOContextDeleter @@ -80,7 +80,7 @@ namespace MWSound SwrContext* mSwr; enum AVSampleFormat mOutputSampleFormat; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER AVChannelLayout mOutputChannelLayout; #else int64_t mOutputChannelLayout; @@ -94,7 +94,7 @@ namespace MWSound Files::IStreamPtr mDataStream; static int readPacket(void* user_data, uint8_t* buf, int buf_size); -#if FFMPEG_CONST_WRITEPACKET +#if OPENMW_FFMPEG_CONST_WRITEPACKET static int writePacket(void* user_data, const uint8_t* buf, int buf_size); #else static int writePacket(void* user_data, uint8_t* buf, int buf_size); diff --git a/apps/openmw/mwsound/movieaudiofactory.cpp b/apps/openmw/mwsound/movieaudiofactory.cpp index 7d21b8c5af..962086701a 100644 --- a/apps/openmw/mwsound/movieaudiofactory.cpp +++ b/apps/openmw/mwsound/movieaudiofactory.cpp @@ -1,6 +1,7 @@ #include "movieaudiofactory.hpp" #include +#include #include #include "../mwbase/environment.hpp" @@ -46,7 +47,7 @@ namespace MWSound size_t getSampleOffset() { -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER ssize_t clock_delay = (mFrameSize - mFramePos) / mOutputChannelLayout.nb_channels #else ssize_t clock_delay = (mFrameSize - mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout) diff --git a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp index 841535f823..9a48dff459 100644 --- a/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp +++ b/extern/osg-ffmpeg-videoplayer/audiodecoder.cpp @@ -1,5 +1,7 @@ #include "audiodecoder.hpp" +#include + #include #include #include @@ -18,7 +20,7 @@ extern "C" #pragma warning (pop) #endif -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER #include #endif @@ -57,7 +59,7 @@ MovieAudioDecoder::MovieAudioDecoder(VideoState* videoState) : mVideoState(videoState) , mAVStream(*videoState->audio_st) , mOutputSampleFormat(AV_SAMPLE_FMT_NONE) - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER , mOutputChannelLayout({}) #else , mOutputChannelLayout(0) @@ -117,7 +119,7 @@ void MovieAudioDecoder::setupFormat() AVSampleFormat inputSampleFormat = mAudioContext->sample_fmt; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER AVChannelLayout inputChannelLayout = mAudioContext->ch_layout; if (inputChannelLayout.u.mask != 0) mOutputChannelLayout = inputChannelLayout; @@ -134,7 +136,7 @@ void MovieAudioDecoder::setupFormat() mOutputSampleRate = inputSampleRate; mOutputSampleFormat = inputSampleFormat; -#if FFMPEG_5_OR_GREATER +#if OPENMW_FFMPEG_5_OR_GREATER adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout.u.mask, mOutputSampleRate); #else mOutputChannelLayout = inputChannelLayout; @@ -142,14 +144,14 @@ void MovieAudioDecoder::setupFormat() #endif if (inputSampleFormat != mOutputSampleFormat - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER || inputChannelLayout.u.mask != mOutputChannelLayout.u.mask #else || inputChannelLayout != mOutputChannelLayout #endif || inputSampleRate != mOutputSampleRate) { - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER swr_alloc_set_opts2(&mAudioResampler->mSwr, &mOutputChannelLayout, mOutputSampleFormat, @@ -196,7 +198,7 @@ int MovieAudioDecoder::synchronize_audio() if(fabs(avg_diff) >= mAudioDiffThreshold) { int n = av_get_bytes_per_sample(mOutputSampleFormat) * - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER mOutputChannelLayout.nb_channels; #else av_get_channel_layout_nb_channels(mOutputChannelLayout); @@ -246,7 +248,7 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *frame, int &sample_skip) if(!mDataBuf || mDataBufLen < frame->nb_samples) { av_freep(&mDataBuf); - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER if(av_samples_alloc(&mDataBuf, nullptr, mOutputChannelLayout.nb_channels, #else if(av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout), @@ -267,7 +269,7 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *frame, int &sample_skip) else mFrameData = &frame->data[0]; - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER int result = frame->nb_samples * mOutputChannelLayout.nb_channels * #else int result = frame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) * @@ -348,7 +350,7 @@ size_t MovieAudioDecoder::read(char *stream, size_t len) len1 = std::min(len1, -mFramePos); int n = av_get_bytes_per_sample(mOutputSampleFormat) - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER * mOutputChannelLayout.nb_channels; #else * av_get_channel_layout_nb_channels(mOutputChannelLayout); @@ -402,7 +404,7 @@ int MovieAudioDecoder::getOutputSampleRate() const uint64_t MovieAudioDecoder::getOutputChannelLayout() const { - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER return mOutputChannelLayout.u.mask; #else return mOutputChannelLayout; diff --git a/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp b/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp index 7163b30459..250ba1db64 100644 --- a/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp +++ b/extern/osg-ffmpeg-videoplayer/audiodecoder.hpp @@ -6,6 +6,8 @@ #include #include +#include + #if defined(_MSC_VER) #pragma warning (push) #pragma warning (disable : 4244) @@ -29,8 +31,6 @@ extern "C" typedef SSIZE_T ssize_t; #endif -#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)) - namespace Video { @@ -45,7 +45,7 @@ protected: AVCodecContext* mAudioContext; AVStream *mAVStream; enum AVSampleFormat mOutputSampleFormat; - #if FFMPEG_5_OR_GREATER + #if OPENMW_FFMPEG_5_OR_GREATER AVChannelLayout mOutputChannelLayout; #else uint64_t mOutputChannelLayout; diff --git a/extern/osg-ffmpeg-videoplayer/libavformatdefines.hpp b/extern/osg-ffmpeg-videoplayer/libavformatdefines.hpp new file mode 100644 index 0000000000..106259ced7 --- /dev/null +++ b/extern/osg-ffmpeg-videoplayer/libavformatdefines.hpp @@ -0,0 +1,13 @@ +#ifndef OPENMW_EXTERN_OSG_FFMPEG_VIDEOPLAYER_LIBAVFORMATDEFINES_H +#define OPENMW_EXTERN_OSG_FFMPEG_VIDEOPLAYER_LIBAVFORMATDEFINES_H + +extern "C" +{ + +#include + +} + +#define OPENMW_FFMPEG_CONST_WRITEPACKET (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(61, 0, 100)) + +#endif diff --git a/extern/osg-ffmpeg-videoplayer/libavutildefines.hpp b/extern/osg-ffmpeg-videoplayer/libavutildefines.hpp new file mode 100644 index 0000000000..e1b0ac93bd --- /dev/null +++ b/extern/osg-ffmpeg-videoplayer/libavutildefines.hpp @@ -0,0 +1,13 @@ +#ifndef OPENMW_EXTERN_OSG_FFMPEG_VIDEOPLAYER_LIBAVUTILDEFINES_H +#define OPENMW_EXTERN_OSG_FFMPEG_VIDEOPLAYER_LIBAVUTILDEFINES_H + +extern "C" +{ + +#include + +} + +#define OPENMW_FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)) + +#endif diff --git a/extern/osg-ffmpeg-videoplayer/videostate.cpp b/extern/osg-ffmpeg-videoplayer/videostate.cpp index 2b192209a0..61e4f09cf3 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.cpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.cpp @@ -43,6 +43,7 @@ static FlushPacket flush_pkt; #include "videoplayer.hpp" #include "audiodecoder.hpp" #include "audiofactory.hpp" +#include "libavformatdefines.hpp" namespace { @@ -243,7 +244,7 @@ int VideoState::istream_read(void *user_data, uint8_t *buf, int buf_size) } } -#if FFMPEG_CONST_WRITEPACKET +#if OPENMW_FFMPEG_CONST_WRITEPACKET int VideoState::istream_write(void *, const unsigned char *, int) #else int VideoState::istream_write(void *, uint8_t *, int) diff --git a/extern/osg-ffmpeg-videoplayer/videostate.hpp b/extern/osg-ffmpeg-videoplayer/videostate.hpp index 09ea44cfd0..548bbca713 100644 --- a/extern/osg-ffmpeg-videoplayer/videostate.hpp +++ b/extern/osg-ffmpeg-videoplayer/videostate.hpp @@ -11,6 +11,7 @@ #include #include + namespace osg { class Texture2D; @@ -39,12 +40,10 @@ extern "C" #endif #include "videodefs.hpp" +#include "libavformatdefines.hpp" #define VIDEO_PICTURE_QUEUE_SIZE 50 -#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100)) -#define FFMPEG_CONST_WRITEPACKET (LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(60, 12, 100)) - extern "C" { struct SwsContext; @@ -159,7 +158,7 @@ struct VideoState { static int istream_read(void *user_data, uint8_t *buf, int buf_size); -#if FFMPEG_CONST_WRITEPACKET +#if OPENMW_FFMPEG_CONST_WRITEPACKET static int istream_write(void *, const unsigned char *, int); #else static int istream_write(void *, uint8_t *, int);