Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

tests/decodeinputavformat: use heap-allocated m_packet #138

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions tests/decodeinputavformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@
#include "common/log.h"
#include <Yami.h>

#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)
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);

}
2 changes: 1 addition & 1 deletion tests/decodeinputavformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down