Add compatibility with FFMPEG 7.0

avio: Constify data pointees of write callbacks

avutil: remove deprecated FF_API_PKT_DURATION

Ref: 2a68d945cd
     02aea61d69
     b8fef7e9c5
This commit is contained in:
Robert-André Mauchin 2024-05-10 18:05:08 +02:00 committed by John Preston
parent d28b9f10b4
commit 3358673ba4
5 changed files with 36 additions and 2 deletions

View File

@ -291,7 +291,11 @@ void FrameGenerator::Impl::jumpToStart() {
void FrameGenerator::Impl::resolveNextFrameTiming() {
const auto base = _format->streams[_streamId]->time_base;
#if DA_FFMPEG_HAVE_DURATION
const auto duration = _next.frame->duration;
#else
const auto duration = _next.frame->pkt_duration;
#endif
const auto framePts = _next.frame->pts;
auto framePosition = (framePts * 1000LL * base.num) / base.den;
_currentFrameDelay = _nextFrameDelay;

View File

@ -230,7 +230,11 @@ enum AVPixelFormat GetFormatImplementation(
IOPointer MakeIOPointer(
void *opaque,
int(*read)(void *opaque, uint8_t *buffer, int bufferSize),
#if DA_FFMPEG_CONST_WRITE_CALLBACK
int(*write)(void *opaque, const uint8_t *buffer, int bufferSize),
#else
int(*write)(void *opaque, uint8_t *buffer, int bufferSize),
#endif
int64_t(*seek)(void *opaque, int64_t offset, int whence)) {
auto buffer = reinterpret_cast<uchar*>(av_malloc(kAvioBlockSize));
if (!buffer) {
@ -263,7 +267,11 @@ void IODeleter::operator()(AVIOContext *value) {
FormatPointer MakeFormatPointer(
void *opaque,
int(*read)(void *opaque, uint8_t *buffer, int bufferSize),
#if DA_FFMPEG_CONST_WRITE_CALLBACK
int(*write)(void *opaque, const uint8_t *buffer, int bufferSize),
#else
int(*write)(void *opaque, uint8_t *buffer, int bufferSize),
#endif
int64_t(*seek)(void *opaque, int64_t offset, int whence)) {
auto io = MakeIOPointer(opaque, read, write, seek);
if (!io) {

View File

@ -22,8 +22,14 @@ extern "C" {
#include <libavutil/version.h>
} // extern "C"
#define DA_FFMPEG_NEW_CHANNEL_LAYOUT (LIBAVUTIL_VERSION_MAJOR > 57 \
|| (LIBAVUTIL_VERSION_MAJOR == 57 && LIBAVUTIL_VERSION_MINOR >= 28))
#define DA_FFMPEG_NEW_CHANNEL_LAYOUT (LIBAVUTIL_VERSION_INT >= \
AV_VERSION_INT(57, 28, 100))
#define DA_FFMPEG_CONST_WRITE_CALLBACK (LIBAVFORMAT_VERSION_INT >= \
AV_VERSION_INT(61, 01, 100))
#define DA_FFMPEG_HAVE_DURATION (LIBAVUTIL_VERSION_INT >= \
AV_VERSION_INT(58, 02, 100))
class QImage;
@ -112,7 +118,11 @@ using IOPointer = std::unique_ptr<AVIOContext, IODeleter>;
[[nodiscard]] IOPointer MakeIOPointer(
void *opaque,
int(*read)(void *opaque, uint8_t *buffer, int bufferSize),
#if DA_FFMPEG_CONST_WRITE_CALLBACK
int(*write)(void *opaque, const uint8_t *buffer, int bufferSize),
#else
int(*write)(void *opaque, uint8_t *buffer, int bufferSize),
#endif
int64_t(*seek)(void *opaque, int64_t offset, int whence));
struct FormatDeleter {
@ -122,7 +132,11 @@ using FormatPointer = std::unique_ptr<AVFormatContext, FormatDeleter>;
[[nodiscard]] FormatPointer MakeFormatPointer(
void *opaque,
int(*read)(void *opaque, uint8_t *buffer, int bufferSize),
#if DA_FFMPEG_CONST_WRITE_CALLBACK
int(*write)(void *opaque, const uint8_t *buffer, int bufferSize),
#else
int(*write)(void *opaque, uint8_t *buffer, int bufferSize),
#endif
int64_t(*seek)(void *opaque, int64_t offset, int whence));
struct CodecDeleter {

View File

@ -249,7 +249,11 @@ struct Instance::Inner::Private {
return nbytes;
}
#if DA_FFMPEG_CONST_WRITE_CALLBACK
static int WriteData(void *opaque, const uint8_t *buf, int buf_size) {
#else
static int WriteData(void *opaque, uint8_t *buf, int buf_size) {
#endif
auto l = reinterpret_cast<Private*>(opaque);
if (buf_size <= 0) return 0;

View File

@ -144,7 +144,11 @@ ReaderImplementation::ReadResult FFMpegReaderImplementation::readNextFrame() {
}
void FFMpegReaderImplementation::processReadFrame() {
#if DA_FFMPEG_HAVE_DURATION
int64 duration = _frame->duration;
#else
int64 duration = _frame->pkt_duration;
#endif
int64 framePts = _frame->pts;
crl::time frameMs = (framePts * 1000LL * _fmtContext->streams[_streamId]->time_base.num) / _fmtContext->streams[_streamId]->time_base.den;
_currentFrameDelay = _nextFrameDelay;