From ec934655d379d43646eb8f3471653f68b6b1a47a Mon Sep 17 00:00:00 2001 From: codestation Date: Sat, 28 Feb 2015 09:37:39 -0430 Subject: [PATCH] Use av_frame_free() to match calls to av_frame_alloc. Use version checks to use older libav functions on older distros. --- src/avdecoder.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/avdecoder.cpp b/src/avdecoder.cpp index 4f5b4f1..56c0370 100644 --- a/src/avdecoder.cpp +++ b/src/avdecoder.cpp @@ -144,7 +144,11 @@ QByteArray AVDecoder::getAudioThumbnail(int width, int height) AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_index) { +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) AVFrame *pFrame = av_frame_alloc(); +#else + AVFrame *pFrame = avcodec_alloc_frame(); +#endif AVPacket packet; int frame_finished = 0; @@ -159,7 +163,11 @@ AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_ if(frame_finished) { return pFrame; } else { +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) + av_frame_free(pFrame); +#else av_free(pFrame); +#endif return NULL; } } @@ -188,7 +196,11 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height) return data; } +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) AVFrame *pFrameRGB = av_frame_alloc(); +#else + AVFrame *pFrameRGB = avcodec_alloc_frame(); +#endif int numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); uint8_t *buffer = (uint8_t *)av_malloc(numBytes); @@ -235,8 +247,14 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height) result.save(&imgbuffer, "JPEG"); av_free(buffer); + +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1) + av_frame_free(pFrameRGB); + av_frame_free(pFrame); +#else av_free(pFrameRGB); av_free(pFrame); +#endif avcodec_close(pCodecCtx);