From dbd0c5508d0084a9b069cafd583e6004a12f562a Mon Sep 17 00:00:00 2001 From: Simon Chopin Date: Fri, 17 Dec 2021 16:03:10 +0100 Subject: [PATCH] tests/decodeinputavformat: use heap-allocated m_packet This allows us to migrate away from av_init_packet() which has been deprecated in recent FFMpeg, making the build fail. This implementation is somewhat rough, there's probably a way to avoid reallocating the packet each iteration, but it does the job. --- tests/decodeinputavformat.cpp | 23 +++++++++-------------- tests/decodeinputavformat.h | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/tests/decodeinputavformat.cpp b/tests/decodeinputavformat.cpp index 22cbe46..696a735 100644 --- a/tests/decodeinputavformat.cpp +++ b/tests/decodeinputavformat.cpp @@ -22,18 +22,12 @@ #include "common/log.h" #include -#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 39, 100) -#define av_packet_unref av_free_packet -#endif - DecodeInputAvFormat::DecodeInputAvFormat() -:m_format(NULL),m_videoId(-1), m_codecId(AV_CODEC_ID_NONE), m_isEos(true) +:m_format(NULL),m_videoId(-1), m_codecId(AV_CODEC_ID_NONE), m_packet(av_packet_alloc()), m_isEos(true) { #if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100) av_register_all(); #endif - - av_init_packet(&m_packet); } bool DecodeInputAvFormat::initInput(const char* fileName) @@ -132,18 +126,19 @@ bool DecodeInputAvFormat::getNextDecodeUnit(VideoDecodeBuffer &inputBuffer) int ret; while (1) { //free old packet - av_packet_unref(&m_packet); + av_packet_free(&m_packet); + m_packet = av_packet_alloc(); - ret = av_read_frame(m_format, &m_packet); + ret = av_read_frame(m_format, m_packet); if (ret) { m_isEos = true; return false; } - if (m_packet.stream_index == m_videoId) { + if (m_packet->stream_index == m_videoId) { memset(&inputBuffer, 0, sizeof(inputBuffer)); - inputBuffer.data = m_packet.data; - inputBuffer.size = m_packet.size; - inputBuffer.timeStamp = m_packet.dts; + inputBuffer.data = m_packet->data; + inputBuffer.size = m_packet->size; + inputBuffer.timeStamp = m_packet->dts; inputBuffer.flag = VIDEO_DECODE_BUFFER_FLAG_FRAME_END; return true; } @@ -159,8 +154,8 @@ const string& DecodeInputAvFormat::getCodecData() DecodeInputAvFormat::~DecodeInputAvFormat() { if (m_format) { - av_packet_unref(&m_packet); avformat_close_input(&m_format); } + av_packet_free(&m_packet); } diff --git a/tests/decodeinputavformat.h b/tests/decodeinputavformat.h index 820c530..3600a1a 100644 --- a/tests/decodeinputavformat.h +++ b/tests/decodeinputavformat.h @@ -47,7 +47,7 @@ class DecodeInputAvFormat : public DecodeInput AVFormatContext* m_format; int m_videoId; AVCodecID m_codecId; - AVPacket m_packet; + AVPacket* m_packet; bool m_isEos; string m_codecData; };