Skip to content

Commit 8d0ac3f

Browse files
author
Clement Champetier
committed
VideoFrame: fix memory leak when allocating a new picture
See ffmpeg doc: https://www.ffmpeg.org/doxygen/3.0/group__lavc__picture.html#ga40412936f5777964c0c80b1742ec58ef
1 parent 88af737 commit 8d0ac3f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/AvTranscoder/data/decoded/VideoFrame.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ VideoFrame::VideoFrame(const Frame& otherFrame)
5656
{
5757
}
5858

59+
VideoFrame::~VideoFrame()
60+
{
61+
freeAVPicture();
62+
}
63+
5964
size_t VideoFrame::getSize() const
6065
{
6166
if(getPixelFormat() == AV_PIX_FMT_NONE)
@@ -87,6 +92,11 @@ void VideoFrame::allocateAVPicture(const VideoFrameDesc& desc)
8792
_frame->format = desc._pixelFormat;
8893
}
8994

95+
void VideoFrame::freeAVPicture()
96+
{
97+
avpicture_free(reinterpret_cast<AVPicture*>(_frame));
98+
}
99+
90100
void VideoFrame::assign(const unsigned char value)
91101
{
92102
// Create the image buffer

src/AvTranscoder/data/decoded/VideoFrame.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AvExport VideoFrame : public Frame
4545
public:
4646
VideoFrame(const VideoFrameDesc& ref);
4747
VideoFrame(const Frame& otherFrame);
48+
~VideoFrame();
4849

4950
size_t getWidth() const { return _frame->width; }
5051
size_t getHeight() const { return _frame->height; }
@@ -68,9 +69,16 @@ class AvExport VideoFrame : public Frame
6869
private:
6970
/**
7071
* @brief Allocate the image buffer of the frame.
72+
* @warning The allocated data should be freed by the caller.
73+
* @see freeAVPicture
7174
*/
7275
void allocateAVPicture(const VideoFrameDesc& desc);
7376

77+
/**
78+
* @brief Free the image buffer of the frame.
79+
*/
80+
void freeAVPicture();
81+
7482
/**
7583
* @note To allocate new image buffer if needed.
7684
* @see allocateAVPicture

0 commit comments

Comments
 (0)