From 0ba0dba63dcb17fde3d2020af722b32ca2f67789 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 30 Mar 2014 13:44:32 -0700 Subject: [PATCH] Correctly free a few FFmpeg resources. --- Core/HW/MediaEngine.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index 145212df41..bd9706092a 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -301,9 +301,9 @@ void MediaEngine::closeContext() if (m_buffer) av_free(m_buffer); if (m_pFrameRGB) - av_free(m_pFrameRGB); + av_frame_free(&m_pFrameRGB); if (m_pFrame) - av_free(m_pFrame); + av_frame_free(&m_pFrame); if (m_pIOContext && m_pIOContext->buffer) av_free(m_pIOContext->buffer); if (m_pIOContext) @@ -313,10 +313,9 @@ void MediaEngine::closeContext() m_pCodecCtxs.clear(); if (m_pFormatCtx) avformat_close_input(&m_pFormatCtx); - m_pFrame = 0; - m_pFrameRGB = 0; + if (m_sws_ctx != NULL) + sws_freeContext(m_sws_ctx); m_pIOContext = 0; - m_pFormatCtx = 0; #endif m_buffer = 0; } @@ -415,6 +414,9 @@ bool MediaEngine::setVideoDim(int width, int height) // Allocate video frame m_pFrame = av_frame_alloc(); + if (m_sws_ctx != NULL) { + sws_freeContext(m_sws_ctx); + } m_sws_ctx = NULL; m_sws_fmt = -1; updateSwsFormat(GE_CMODE_32BIT_ABGR8888); @@ -474,6 +476,7 @@ bool MediaEngine::stepVideo(int videoPixelMode) { m_pFrameRGB->linesize[0] = getPixelFormatBytes(videoPixelMode) * m_desWidth; AVPacket packet; + av_init_packet(&packet); int frameFinished; bool bGetFrame = false; while (!bGetFrame) {