Use av_frame_free() to match calls to av_frame_alloc.

Use version checks to use older libav functions on older distros.
This commit is contained in:
codestation
2015-02-28 09:37:39 -04:30
parent 5788141912
commit ec934655d3

View File

@@ -144,7 +144,11 @@ QByteArray AVDecoder::getAudioThumbnail(int width, int height)
AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_index) 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(); AVFrame *pFrame = av_frame_alloc();
#else
AVFrame *pFrame = avcodec_alloc_frame();
#endif
AVPacket packet; AVPacket packet;
int frame_finished = 0; int frame_finished = 0;
@@ -159,7 +163,11 @@ AVFrame *AVDecoder::getDecodedFrame(AVCodecContext *codec_ctx, int frame_stream_
if(frame_finished) { if(frame_finished) {
return pFrame; return pFrame;
} else { } else {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
av_frame_free(pFrame);
#else
av_free(pFrame); av_free(pFrame);
#endif
return NULL; return NULL;
} }
} }
@@ -188,7 +196,11 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
return data; return data;
} }
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(55,28,1)
AVFrame *pFrameRGB = av_frame_alloc(); AVFrame *pFrameRGB = av_frame_alloc();
#else
AVFrame *pFrameRGB = avcodec_alloc_frame();
#endif
int numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height); int numBytes = avpicture_get_size(PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height);
uint8_t *buffer = (uint8_t *)av_malloc(numBytes); uint8_t *buffer = (uint8_t *)av_malloc(numBytes);
@@ -235,8 +247,14 @@ QByteArray AVDecoder::getVideoThumbnail(int width, int height)
result.save(&imgbuffer, "JPEG"); result.save(&imgbuffer, "JPEG");
av_free(buffer); 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(pFrameRGB);
av_free(pFrame); av_free(pFrame);
#endif
avcodec_close(pCodecCtx); avcodec_close(pCodecCtx);