mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Support compiling with ffmpeg 5 and greater
This commit is contained in:
parent
d45d251fae
commit
61cb5b4da6
7 changed files with 204 additions and 25 deletions
|
@ -8,6 +8,10 @@
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/vfs/manager.hpp>
|
#include <components/vfs/manager.hpp>
|
||||||
|
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
#include <libavutil/channel_layout.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
void AVIOContextDeleter::operator()(AVIOContext* ptr) const
|
void AVIOContextDeleter::operator()(AVIOContext* ptr) const
|
||||||
|
@ -57,7 +61,11 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FFMPEG_CONST_WRITEPACKET
|
||||||
|
int FFmpeg_Decoder::writePacket(void*, const uint8_t*, int)
|
||||||
|
#else
|
||||||
int FFmpeg_Decoder::writePacket(void*, uint8_t*, int)
|
int FFmpeg_Decoder::writePacket(void*, uint8_t*, int)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
Log(Debug::Error) << "can't write to read-only stream";
|
Log(Debug::Error) << "can't write to read-only stream";
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -152,7 +160,11 @@ namespace MWSound
|
||||||
if (!mDataBuf || mDataBufLen < mFrame->nb_samples)
|
if (!mDataBuf || mDataBufLen < mFrame->nb_samples)
|
||||||
{
|
{
|
||||||
av_freep(&mDataBuf);
|
av_freep(&mDataBuf);
|
||||||
|
#if 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),
|
if (av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout),
|
||||||
|
#endif
|
||||||
mFrame->nb_samples, mOutputSampleFormat, 0)
|
mFrame->nb_samples, mOutputSampleFormat, 0)
|
||||||
< 0)
|
< 0)
|
||||||
return false;
|
return false;
|
||||||
|
@ -189,7 +201,11 @@ namespace MWSound
|
||||||
if (!getAVAudioData())
|
if (!getAVAudioData())
|
||||||
break;
|
break;
|
||||||
mFramePos = 0;
|
mFramePos = 0;
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
mFrameSize = mFrame->nb_samples * mOutputChannelLayout.nb_channels
|
||||||
|
#else
|
||||||
mFrameSize = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout)
|
mFrameSize = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout)
|
||||||
|
#endif
|
||||||
* av_get_bytes_per_sample(mOutputSampleFormat);
|
* av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,11 +293,19 @@ namespace MWSound
|
||||||
else
|
else
|
||||||
mOutputSampleFormat = AV_SAMPLE_FMT_S16;
|
mOutputSampleFormat = AV_SAMPLE_FMT_S16;
|
||||||
|
|
||||||
|
#if 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);
|
||||||
|
|
||||||
|
codecCtxPtr->ch_layout = mOutputChannelLayout;
|
||||||
|
#else
|
||||||
mOutputChannelLayout = (*stream)->codecpar->channel_layout;
|
mOutputChannelLayout = (*stream)->codecpar->channel_layout;
|
||||||
if (mOutputChannelLayout == 0)
|
if (mOutputChannelLayout == 0)
|
||||||
mOutputChannelLayout = av_get_default_channel_layout(codecCtxPtr->channels);
|
mOutputChannelLayout = av_get_default_channel_layout(codecCtxPtr->channels);
|
||||||
|
|
||||||
codecCtxPtr->channel_layout = mOutputChannelLayout;
|
codecCtxPtr->channel_layout = mOutputChannelLayout;
|
||||||
|
#endif
|
||||||
|
|
||||||
mIoCtx = std::move(ioCtx);
|
mIoCtx = std::move(ioCtx);
|
||||||
mFrame = std::move(frame);
|
mFrame = std::move(frame);
|
||||||
|
@ -332,19 +356,44 @@ namespace MWSound
|
||||||
*type = SampleType_Int16;
|
*type = SampleType_Int16;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mOutputChannelLayout == AV_CH_LAYOUT_MONO)
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
switch (mOutputChannelLayout.u.mask)
|
||||||
|
#else
|
||||||
|
switch (mOutputChannelLayout)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
case AV_CH_LAYOUT_MONO:
|
||||||
*chans = ChannelConfig_Mono;
|
*chans = ChannelConfig_Mono;
|
||||||
else if (mOutputChannelLayout == AV_CH_LAYOUT_STEREO)
|
break;
|
||||||
|
case AV_CH_LAYOUT_STEREO:
|
||||||
*chans = ChannelConfig_Stereo;
|
*chans = ChannelConfig_Stereo;
|
||||||
else if (mOutputChannelLayout == AV_CH_LAYOUT_QUAD)
|
break;
|
||||||
|
case AV_CH_LAYOUT_QUAD:
|
||||||
*chans = ChannelConfig_Quad;
|
*chans = ChannelConfig_Quad;
|
||||||
else if (mOutputChannelLayout == AV_CH_LAYOUT_5POINT1)
|
break;
|
||||||
|
case AV_CH_LAYOUT_5POINT1:
|
||||||
*chans = ChannelConfig_5point1;
|
*chans = ChannelConfig_5point1;
|
||||||
else if (mOutputChannelLayout == AV_CH_LAYOUT_7POINT1)
|
break;
|
||||||
|
case AV_CH_LAYOUT_7POINT1:
|
||||||
*chans = ChannelConfig_7point1;
|
*chans = ChannelConfig_7point1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
char str[1024];
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
av_channel_layout_describe(&mCodecCtx->ch_layout, str, sizeof(str));
|
||||||
|
Log(Debug::Error) << "Unsupported channel layout: " << str;
|
||||||
|
|
||||||
|
if (mCodecCtx->ch_layout.nb_channels == 1)
|
||||||
|
{
|
||||||
|
mOutputChannelLayout = AV_CHANNEL_LAYOUT_MONO;
|
||||||
|
*chans = ChannelConfig_Mono;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char str[1024];
|
mOutputChannelLayout = AV_CHANNEL_LAYOUT_STEREO;
|
||||||
|
*chans = ChannelConfig_Stereo;
|
||||||
|
}
|
||||||
|
#else
|
||||||
av_get_channel_layout_string(str, sizeof(str), mCodecCtx->channels, mCodecCtx->channel_layout);
|
av_get_channel_layout_string(str, sizeof(str), mCodecCtx->channels, mCodecCtx->channel_layout);
|
||||||
Log(Debug::Error) << "Unsupported channel layout: " << str;
|
Log(Debug::Error) << "Unsupported channel layout: " << str;
|
||||||
|
|
||||||
|
@ -358,15 +407,37 @@ namespace MWSound
|
||||||
mOutputChannelLayout = AV_CH_LAYOUT_STEREO;
|
mOutputChannelLayout = AV_CH_LAYOUT_STEREO;
|
||||||
*chans = ChannelConfig_Stereo;
|
*chans = ChannelConfig_Stereo;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*samplerate = mCodecCtx->sample_rate;
|
*samplerate = mCodecCtx->sample_rate;
|
||||||
|
#if 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);
|
||||||
|
|
||||||
|
if (mOutputSampleFormat != mCodecCtx->sample_fmt || mOutputChannelLayout.u.mask != ch_layout.u.mask)
|
||||||
|
#else
|
||||||
int64_t ch_layout = mCodecCtx->channel_layout;
|
int64_t ch_layout = mCodecCtx->channel_layout;
|
||||||
if (ch_layout == 0)
|
if (ch_layout == 0)
|
||||||
ch_layout = av_get_default_channel_layout(mCodecCtx->channels);
|
ch_layout = av_get_default_channel_layout(mCodecCtx->channels);
|
||||||
|
|
||||||
if (mOutputSampleFormat != mCodecCtx->sample_fmt || mOutputChannelLayout != ch_layout)
|
if (mOutputSampleFormat != mCodecCtx->sample_fmt || mOutputChannelLayout != ch_layout)
|
||||||
|
#endif
|
||||||
|
|
||||||
{
|
{
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
swr_alloc_set_opts2(&mSwr, // SwrContext
|
||||||
|
&mOutputChannelLayout, // output ch layout
|
||||||
|
mOutputSampleFormat, // output sample format
|
||||||
|
mCodecCtx->sample_rate, // output sample rate
|
||||||
|
&ch_layout, // input ch layout
|
||||||
|
mCodecCtx->sample_fmt, // input sample format
|
||||||
|
mCodecCtx->sample_rate, // input sample rate
|
||||||
|
0, // logging level offset
|
||||||
|
nullptr); // log context
|
||||||
|
#else
|
||||||
mSwr = swr_alloc_set_opts(mSwr, // SwrContext
|
mSwr = swr_alloc_set_opts(mSwr, // SwrContext
|
||||||
mOutputChannelLayout, // output ch layout
|
mOutputChannelLayout, // output ch layout
|
||||||
mOutputSampleFormat, // output sample format
|
mOutputSampleFormat, // output sample format
|
||||||
|
@ -376,6 +447,7 @@ namespace MWSound
|
||||||
mCodecCtx->sample_rate, // input sample rate
|
mCodecCtx->sample_rate, // input sample rate
|
||||||
0, // logging level offset
|
0, // logging level offset
|
||||||
nullptr); // log context
|
nullptr); // log context
|
||||||
|
#endif
|
||||||
if (!mSwr)
|
if (!mSwr)
|
||||||
throw std::runtime_error("Couldn't allocate SwrContext");
|
throw std::runtime_error("Couldn't allocate SwrContext");
|
||||||
int init = swr_init(mSwr);
|
int init = swr_init(mSwr);
|
||||||
|
@ -404,7 +476,11 @@ namespace MWSound
|
||||||
|
|
||||||
while (getAVAudioData())
|
while (getAVAudioData())
|
||||||
{
|
{
|
||||||
|
#if 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)
|
size_t got = mFrame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout)
|
||||||
|
#endif
|
||||||
* av_get_bytes_per_sample(mOutputSampleFormat);
|
* av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
const char* inbuf = reinterpret_cast<char*>(mFrameData[0]);
|
const char* inbuf = reinterpret_cast<char*>(mFrameData[0]);
|
||||||
output.insert(output.end(), inbuf, inbuf + got);
|
output.insert(output.end(), inbuf, inbuf + got);
|
||||||
|
@ -413,7 +489,11 @@ namespace MWSound
|
||||||
|
|
||||||
size_t FFmpeg_Decoder::getSampleOffset()
|
size_t FFmpeg_Decoder::getSampleOffset()
|
||||||
{
|
{
|
||||||
|
#if 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)
|
std::size_t delay = (mFrameSize - mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout)
|
||||||
|
#endif
|
||||||
/ av_get_bytes_per_sample(mOutputSampleFormat);
|
/ av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
return static_cast<std::size_t>(mNextPts * mCodecCtx->sample_rate) - delay;
|
return static_cast<std::size_t>(mNextPts * mCodecCtx->sample_rate) - delay;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +506,11 @@ namespace MWSound
|
||||||
, mNextPts(0.0)
|
, mNextPts(0.0)
|
||||||
, mSwr(nullptr)
|
, mSwr(nullptr)
|
||||||
, mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
|
, mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
, mOutputChannelLayout({})
|
||||||
|
#else
|
||||||
, mOutputChannelLayout(0)
|
, mOutputChannelLayout(0)
|
||||||
|
#endif
|
||||||
, mDataBuf(nullptr)
|
, mDataBuf(nullptr)
|
||||||
, mFrameData(nullptr)
|
, mFrameData(nullptr)
|
||||||
, mDataBufLen(0)
|
, mDataBufLen(0)
|
||||||
|
|
|
@ -30,6 +30,9 @@ extern "C"
|
||||||
|
|
||||||
#include "sound_decoder.hpp"
|
#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
|
namespace MWSound
|
||||||
{
|
{
|
||||||
struct AVIOContextDeleter
|
struct AVIOContextDeleter
|
||||||
|
@ -77,7 +80,11 @@ namespace MWSound
|
||||||
|
|
||||||
SwrContext* mSwr;
|
SwrContext* mSwr;
|
||||||
enum AVSampleFormat mOutputSampleFormat;
|
enum AVSampleFormat mOutputSampleFormat;
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
AVChannelLayout mOutputChannelLayout;
|
||||||
|
#else
|
||||||
int64_t mOutputChannelLayout;
|
int64_t mOutputChannelLayout;
|
||||||
|
#endif
|
||||||
uint8_t* mDataBuf;
|
uint8_t* mDataBuf;
|
||||||
uint8_t** mFrameData;
|
uint8_t** mFrameData;
|
||||||
int mDataBufLen;
|
int mDataBufLen;
|
||||||
|
@ -87,7 +94,11 @@ namespace MWSound
|
||||||
Files::IStreamPtr mDataStream;
|
Files::IStreamPtr mDataStream;
|
||||||
|
|
||||||
static int readPacket(void* user_data, uint8_t* buf, int buf_size);
|
static int readPacket(void* user_data, uint8_t* buf, int buf_size);
|
||||||
|
#if 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);
|
static int writePacket(void* user_data, uint8_t* buf, int buf_size);
|
||||||
|
#endif
|
||||||
static int64_t seek(void* user_data, int64_t offset, int whence);
|
static int64_t seek(void* user_data, int64_t offset, int whence);
|
||||||
|
|
||||||
bool getAVAudioData();
|
bool getAVAudioData();
|
||||||
|
|
|
@ -46,12 +46,19 @@ namespace MWSound
|
||||||
|
|
||||||
size_t getSampleOffset()
|
size_t getSampleOffset()
|
||||||
{
|
{
|
||||||
|
#if 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)
|
ssize_t clock_delay = (mFrameSize - mFramePos) / av_get_channel_layout_nb_channels(mOutputChannelLayout)
|
||||||
|
#endif
|
||||||
/ av_get_bytes_per_sample(mOutputSampleFormat);
|
/ av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
return (size_t)(mAudioClock * mAudioContext->sample_rate) - clock_delay;
|
return (size_t)(mAudioClock * mAudioContext->sample_rate) - clock_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getStreamName() { return std::string(); }
|
std::string getStreamName()
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// MovieAudioDecoder overrides
|
// MovieAudioDecoder overrides
|
||||||
|
|
58
extern/osg-ffmpeg-videoplayer/audiodecoder.cpp
vendored
58
extern/osg-ffmpeg-videoplayer/audiodecoder.cpp
vendored
|
@ -18,6 +18,10 @@ extern "C"
|
||||||
#pragma warning (pop)
|
#pragma warning (pop)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
#include <libavutil/channel_layout.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "videostate.hpp"
|
#include "videostate.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -53,7 +57,11 @@ MovieAudioDecoder::MovieAudioDecoder(VideoState* videoState)
|
||||||
: mVideoState(videoState)
|
: mVideoState(videoState)
|
||||||
, mAVStream(*videoState->audio_st)
|
, mAVStream(*videoState->audio_st)
|
||||||
, mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
|
, mOutputSampleFormat(AV_SAMPLE_FMT_NONE)
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
, mOutputChannelLayout({})
|
||||||
|
#else
|
||||||
, mOutputChannelLayout(0)
|
, mOutputChannelLayout(0)
|
||||||
|
#endif
|
||||||
, mOutputSampleRate(0)
|
, mOutputSampleRate(0)
|
||||||
, mFramePos(0)
|
, mFramePos(0)
|
||||||
, mFrameSize(0)
|
, mFrameSize(0)
|
||||||
|
@ -109,21 +117,49 @@ void MovieAudioDecoder::setupFormat()
|
||||||
|
|
||||||
AVSampleFormat inputSampleFormat = mAudioContext->sample_fmt;
|
AVSampleFormat inputSampleFormat = mAudioContext->sample_fmt;
|
||||||
|
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
AVChannelLayout inputChannelLayout = mAudioContext->ch_layout;
|
||||||
|
if (inputChannelLayout.u.mask != 0)
|
||||||
|
mOutputChannelLayout = inputChannelLayout;
|
||||||
|
else
|
||||||
|
av_channel_layout_default(&mOutputChannelLayout, mAudioContext->ch_layout.nb_channels);
|
||||||
|
#else
|
||||||
uint64_t inputChannelLayout = mAudioContext->channel_layout;
|
uint64_t inputChannelLayout = mAudioContext->channel_layout;
|
||||||
if (inputChannelLayout == 0)
|
if (inputChannelLayout == 0)
|
||||||
inputChannelLayout = av_get_default_channel_layout(mAudioContext->channels);
|
inputChannelLayout = av_get_default_channel_layout(mAudioContext->channels);
|
||||||
|
#endif
|
||||||
|
|
||||||
int inputSampleRate = mAudioContext->sample_rate;
|
int inputSampleRate = mAudioContext->sample_rate;
|
||||||
|
|
||||||
mOutputSampleRate = inputSampleRate;
|
mOutputSampleRate = inputSampleRate;
|
||||||
mOutputSampleFormat = inputSampleFormat;
|
mOutputSampleFormat = inputSampleFormat;
|
||||||
|
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout.u.mask, mOutputSampleRate);
|
||||||
|
#else
|
||||||
mOutputChannelLayout = inputChannelLayout;
|
mOutputChannelLayout = inputChannelLayout;
|
||||||
adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout, mOutputSampleRate);
|
adjustAudioSettings(mOutputSampleFormat, mOutputChannelLayout, mOutputSampleRate);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (inputSampleFormat != mOutputSampleFormat
|
if (inputSampleFormat != mOutputSampleFormat
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
|| inputChannelLayout.u.mask != mOutputChannelLayout.u.mask
|
||||||
|
#else
|
||||||
|| inputChannelLayout != mOutputChannelLayout
|
|| inputChannelLayout != mOutputChannelLayout
|
||||||
|
#endif
|
||||||
|| inputSampleRate != mOutputSampleRate)
|
|| inputSampleRate != mOutputSampleRate)
|
||||||
{
|
{
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
swr_alloc_set_opts2(&mAudioResampler->mSwr,
|
||||||
|
&mOutputChannelLayout,
|
||||||
|
mOutputSampleFormat,
|
||||||
|
mOutputSampleRate,
|
||||||
|
&inputChannelLayout,
|
||||||
|
inputSampleFormat,
|
||||||
|
inputSampleRate,
|
||||||
|
0, // logging level offset
|
||||||
|
nullptr); // log context
|
||||||
|
#else
|
||||||
mAudioResampler->mSwr = swr_alloc_set_opts(mAudioResampler->mSwr,
|
mAudioResampler->mSwr = swr_alloc_set_opts(mAudioResampler->mSwr,
|
||||||
mOutputChannelLayout,
|
mOutputChannelLayout,
|
||||||
mOutputSampleFormat,
|
mOutputSampleFormat,
|
||||||
|
@ -133,6 +169,8 @@ void MovieAudioDecoder::setupFormat()
|
||||||
inputSampleRate,
|
inputSampleRate,
|
||||||
0, // logging level offset
|
0, // logging level offset
|
||||||
nullptr); // log context
|
nullptr); // log context
|
||||||
|
#endif
|
||||||
|
|
||||||
if(!mAudioResampler->mSwr)
|
if(!mAudioResampler->mSwr)
|
||||||
fail(std::string("Couldn't allocate SwrContext"));
|
fail(std::string("Couldn't allocate SwrContext"));
|
||||||
if(swr_init(mAudioResampler->mSwr) < 0)
|
if(swr_init(mAudioResampler->mSwr) < 0)
|
||||||
|
@ -158,7 +196,11 @@ int MovieAudioDecoder::synchronize_audio()
|
||||||
if(fabs(avg_diff) >= mAudioDiffThreshold)
|
if(fabs(avg_diff) >= mAudioDiffThreshold)
|
||||||
{
|
{
|
||||||
int n = av_get_bytes_per_sample(mOutputSampleFormat) *
|
int n = av_get_bytes_per_sample(mOutputSampleFormat) *
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
mOutputChannelLayout.nb_channels;
|
||||||
|
#else
|
||||||
av_get_channel_layout_nb_channels(mOutputChannelLayout);
|
av_get_channel_layout_nb_channels(mOutputChannelLayout);
|
||||||
|
#endif
|
||||||
sample_skip = ((int)(diff * mAudioContext->sample_rate) * n);
|
sample_skip = ((int)(diff * mAudioContext->sample_rate) * n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +246,11 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *frame, int &sample_skip)
|
||||||
if(!mDataBuf || mDataBufLen < frame->nb_samples)
|
if(!mDataBuf || mDataBufLen < frame->nb_samples)
|
||||||
{
|
{
|
||||||
av_freep(&mDataBuf);
|
av_freep(&mDataBuf);
|
||||||
|
#if 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),
|
if(av_samples_alloc(&mDataBuf, nullptr, av_get_channel_layout_nb_channels(mOutputChannelLayout),
|
||||||
|
#endif
|
||||||
frame->nb_samples, mOutputSampleFormat, 0) < 0)
|
frame->nb_samples, mOutputSampleFormat, 0) < 0)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
@ -221,7 +267,11 @@ int MovieAudioDecoder::audio_decode_frame(AVFrame *frame, int &sample_skip)
|
||||||
else
|
else
|
||||||
mFrameData = &frame->data[0];
|
mFrameData = &frame->data[0];
|
||||||
|
|
||||||
|
#if 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) *
|
int result = frame->nb_samples * av_get_channel_layout_nb_channels(mOutputChannelLayout) *
|
||||||
|
#endif
|
||||||
av_get_bytes_per_sample(mOutputSampleFormat);
|
av_get_bytes_per_sample(mOutputSampleFormat);
|
||||||
|
|
||||||
/* We have data, return it and come back for more later */
|
/* We have data, return it and come back for more later */
|
||||||
|
@ -298,7 +348,11 @@ size_t MovieAudioDecoder::read(char *stream, size_t len)
|
||||||
len1 = std::min<size_t>(len1, -mFramePos);
|
len1 = std::min<size_t>(len1, -mFramePos);
|
||||||
|
|
||||||
int n = av_get_bytes_per_sample(mOutputSampleFormat)
|
int n = av_get_bytes_per_sample(mOutputSampleFormat)
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
* mOutputChannelLayout.nb_channels;
|
||||||
|
#else
|
||||||
* av_get_channel_layout_nb_channels(mOutputChannelLayout);
|
* av_get_channel_layout_nb_channels(mOutputChannelLayout);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* add samples by copying the first sample*/
|
/* add samples by copying the first sample*/
|
||||||
if(n == 1)
|
if(n == 1)
|
||||||
|
@ -348,7 +402,11 @@ int MovieAudioDecoder::getOutputSampleRate() const
|
||||||
|
|
||||||
uint64_t MovieAudioDecoder::getOutputChannelLayout() const
|
uint64_t MovieAudioDecoder::getOutputChannelLayout() const
|
||||||
{
|
{
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
return mOutputChannelLayout.u.mask;
|
||||||
|
#else
|
||||||
return mOutputChannelLayout;
|
return mOutputChannelLayout;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
AVSampleFormat MovieAudioDecoder::getOutputSampleFormat() const
|
AVSampleFormat MovieAudioDecoder::getOutputSampleFormat() const
|
||||||
|
|
|
@ -29,6 +29,8 @@ extern "C"
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define FFMPEG_5_OR_GREATER (LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(57, 28, 100))
|
||||||
|
|
||||||
namespace Video
|
namespace Video
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -43,7 +45,11 @@ protected:
|
||||||
AVCodecContext* mAudioContext;
|
AVCodecContext* mAudioContext;
|
||||||
AVStream *mAVStream;
|
AVStream *mAVStream;
|
||||||
enum AVSampleFormat mOutputSampleFormat;
|
enum AVSampleFormat mOutputSampleFormat;
|
||||||
|
#if FFMPEG_5_OR_GREATER
|
||||||
|
AVChannelLayout mOutputChannelLayout;
|
||||||
|
#else
|
||||||
uint64_t mOutputChannelLayout;
|
uint64_t mOutputChannelLayout;
|
||||||
|
#endif
|
||||||
int mOutputSampleRate;
|
int mOutputSampleRate;
|
||||||
ssize_t mFramePos;
|
ssize_t mFramePos;
|
||||||
ssize_t mFrameSize;
|
ssize_t mFrameSize;
|
||||||
|
|
4
extern/osg-ffmpeg-videoplayer/videostate.cpp
vendored
4
extern/osg-ffmpeg-videoplayer/videostate.cpp
vendored
|
@ -243,7 +243,11 @@ int VideoState::istream_read(void *user_data, uint8_t *buf, int buf_size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FFMPEG_CONST_WRITEPACKET
|
||||||
|
int VideoState::istream_write(void *, const unsigned char *, int)
|
||||||
|
#else
|
||||||
int VideoState::istream_write(void *, uint8_t *, int)
|
int VideoState::istream_write(void *, uint8_t *, int)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
throw std::runtime_error("can't write to read-only stream");
|
throw std::runtime_error("can't write to read-only stream");
|
||||||
}
|
}
|
||||||
|
|
11
extern/osg-ffmpeg-videoplayer/videostate.hpp
vendored
11
extern/osg-ffmpeg-videoplayer/videostate.hpp
vendored
|
@ -42,6 +42,9 @@ extern "C"
|
||||||
|
|
||||||
#define VIDEO_PICTURE_QUEUE_SIZE 50
|
#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"
|
extern "C"
|
||||||
{
|
{
|
||||||
struct SwsContext;
|
struct SwsContext;
|
||||||
|
@ -155,7 +158,13 @@ struct VideoState {
|
||||||
double get_master_clock();
|
double get_master_clock();
|
||||||
|
|
||||||
static int istream_read(void *user_data, uint8_t *buf, int buf_size);
|
static int istream_read(void *user_data, uint8_t *buf, int buf_size);
|
||||||
static int istream_write(void *user_data, uint8_t *buf, int buf_size);
|
|
||||||
|
#if FFMPEG_CONST_WRITEPACKET
|
||||||
|
static int istream_write(void *, const unsigned char *, int);
|
||||||
|
#else
|
||||||
|
static int istream_write(void *, uint8_t *, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
static int64_t istream_seek(void *user_data, int64_t offset, int whence);
|
static int64_t istream_seek(void *user_data, int64_t offset, int whence);
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> mTexture;
|
osg::ref_ptr<osg::Texture2D> mTexture;
|
||||||
|
|
Loading…
Reference in a new issue