VideoFFmpegComponent: Fix build with FFMpeg 6.0.

Version 58 of libav removes the deprecated enums AV_CODEC_CAP_TRUNCATED
and AV_CODEC_FLAG_TRUNCATED, just don't use these. They are "redunant
with parsers".
See https://github.com/FFmpeg/FFmpeg/commit/dd846bc4a91

The struct member `pkt_duration` was also deprecatred in favor of
`duration`.
See https://github.com/FFmpeg/FFmpeg/commit/4397f9a5a0

Remove LIBAVUTIL_VERSION_MINOR requirement in branches for FFmpeg 5.1+,
as they also apply for 6.0.
This commit is contained in:
Lubosz Sarnecki 2023-03-08 12:26:53 +01:00
parent f89ad4911b
commit aae8eee6d0

View file

@ -21,7 +21,8 @@
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
#if LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28 #if LIBAVUTIL_VERSION_MAJOR >= 58 || \
(LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28)
// FFmpeg 5.1 and above. // FFmpeg 5.1 and above.
#define CHANNELS ch_layout.nb_channels #define CHANNELS ch_layout.nb_channels
#else #else
@ -502,7 +503,10 @@ bool VideoFFmpegComponent::setupAudioFilters()
int returnValue {0}; int returnValue {0};
std::string errorMessage(512, '\0'); std::string errorMessage(512, '\0');
const int outSampleRates[] {AudioManager::getInstance().sAudioFormat.freq, -1}; const int outSampleRates[] {AudioManager::getInstance().sAudioFormat.freq, -1};
const enum AVSampleFormat outSampleFormats[] {AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE}; const enum AVSampleFormat outSampleFormats[] {
AV_SAMPLE_FMT_FLT,
AV_SAMPLE_FMT_NONE
};
mAFilterInputs = avfilter_inout_alloc(); mAFilterInputs = avfilter_inout_alloc();
mAFilterOutputs = avfilter_inout_alloc(); mAFilterOutputs = avfilter_inout_alloc();
@ -533,7 +537,8 @@ bool VideoFFmpegComponent::setupAudioFilters()
std::string channelLayout(128, '\0'); std::string channelLayout(128, '\0');
#if LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28 #if LIBAVUTIL_VERSION_MAJOR >= 58 || \
(LIBAVUTIL_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MINOR >= 28)
// FFmpeg 5.1 and above. // FFmpeg 5.1 and above.
AVChannelLayout chLayout {}; AVChannelLayout chLayout {};
av_channel_layout_from_mask(&chLayout, mAudioCodecContext->ch_layout.u.mask); av_channel_layout_from_mask(&chLayout, mAudioCodecContext->ch_layout.u.mask);
@ -687,7 +692,11 @@ void VideoFFmpegComponent::readFrames()
destFrame->chroma_location = destFrame->chroma_location =
mVideoFrame->chroma_location; mVideoFrame->chroma_location;
destFrame->pkt_pos = mVideoFrame->pkt_pos; destFrame->pkt_pos = mVideoFrame->pkt_pos;
#if LIBAVUTIL_VERSION_MAJOR < 58
destFrame->pkt_duration = mVideoFrame->pkt_duration; destFrame->pkt_duration = mVideoFrame->pkt_duration;
#else
destFrame->duration = mVideoFrame->duration;
#endif
destFrame->pkt_size = mVideoFrame->pkt_size; destFrame->pkt_size = mVideoFrame->pkt_size;
} }
} }
@ -781,9 +790,14 @@ void VideoFFmpegComponent::getProcessedFrames()
const double pts {static_cast<double>(mVideoFrameResampled->pkt_dts) * const double pts {static_cast<double>(mVideoFrameResampled->pkt_dts) *
av_q2d(mVideoStream->time_base)}; av_q2d(mVideoStream->time_base)};
// Needs to be adjusted if changing the rate? // Needs to be adjusted if changing the rate?
#if LIBAVUTIL_VERSION_MAJOR < 58
const double frameDuration {static_cast<double>(mVideoFrameResampled->pkt_duration) * const double frameDuration {static_cast<double>(mVideoFrameResampled->pkt_duration) *
av_q2d(mVideoStream->time_base)}; av_q2d(mVideoStream->time_base)};
#else
const double frameDuration {static_cast<double>(mVideoFrameResampled->duration) *
av_q2d(mVideoStream->time_base)};
#endif
currFrame.pts = pts; currFrame.pts = pts;
currFrame.frameDuration = frameDuration; currFrame.frameDuration = frameDuration;
@ -1441,8 +1455,10 @@ void VideoFFmpegComponent::startVideoStream()
return; return;
} }
#if LIBAVUTIL_VERSION_MAJOR < 58
if (mVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED) if (mVideoCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
mVideoCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED; mVideoCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
#endif
if (avcodec_parameters_to_context(mVideoCodecContext, mVideoStream->codecpar)) { if (avcodec_parameters_to_context(mVideoCodecContext, mVideoStream->codecpar)) {
LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): " LOG(LogError) << "VideoFFmpegComponent::startVideoStream(): "
@ -1484,8 +1500,10 @@ void VideoFFmpegComponent::startVideoStream()
mAudioCodecContext = avcodec_alloc_context3(mAudioCodec); mAudioCodecContext = avcodec_alloc_context3(mAudioCodec);
#if LIBAVUTIL_VERSION_MAJOR < 58
if (mAudioCodec->capabilities & AV_CODEC_CAP_TRUNCATED) if (mAudioCodec->capabilities & AV_CODEC_CAP_TRUNCATED)
mAudioCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED; mAudioCodecContext->flags |= AV_CODEC_FLAG_TRUNCATED;
#endif
// Some formats want separate stream headers. // Some formats want separate stream headers.
if (mAudioCodecContext->flags & AVFMT_GLOBALHEADER) if (mAudioCodecContext->flags & AVFMT_GLOBALHEADER)