From e24cfbb0c6f4df1e4abcd369448103ee8ff2a1ec Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Sat, 4 Jun 2011 08:11:43 +0200 Subject: [PATCH] alloc and free a sws context --- cap_lavc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cap_lavc.c b/cap_lavc.c index f70db120..e1d899a2 100644 --- a/cap_lavc.c +++ b/cap_lavc.c @@ -827,6 +827,7 @@ typedef struct capturevideostate_lavc_formatspecific_s qboolean pcmhack; quint8_t bytebuffer[32768]; qint64_t asavepts; + struct SwsContext *sws; } capturevideostate_lavc_formatspecific_t; #define LOAD_FORMATSPECIFIC_LAVC() capturevideostate_lavc_formatspecific_t *format = (capturevideostate_lavc_formatspecific_t *) cls.capturevideo.formatspecific @@ -896,11 +897,15 @@ static void SCR_CaptureVideo_Lavc_VideoFrames(int num) do { qavcodec_get_frame_defaults(&frame); + if(num > 0) + { + SCR_CaptureVideo_Lavc_ConvertFrame_BGRA_to_YUV(&frame); + frame.pts = format->vpts; + } if(format->avf->oformat->flags & AVFMT_RAWPICTURE) { if(num > 0) { - SCR_CaptureVideo_Lavc_ConvertFrame_BGRA_to_YUV(&frame); memcpy(format->buffer, &frame, sizeof(AVPicture)); size = sizeof(AVPicture); } @@ -910,15 +915,9 @@ static void SCR_CaptureVideo_Lavc_VideoFrames(int num) else { if(num > 0) - { - SCR_CaptureVideo_Lavc_ConvertFrame_BGRA_to_YUV(&frame); - frame.pts = format->vpts; size = qavcodec_encode_video(avc, format->buffer, format->bufsize, &frame); - } else - { size = qavcodec_encode_video(avc, format->buffer, format->bufsize, NULL); - } } if(size < 0) @@ -1099,12 +1098,13 @@ static void SCR_CaptureVideo_Lavc_EndVideo(void) } if(format->aframe) Mem_Free(format->aframe); + if(format->sws) + qsws_freeContext(format->sws); Mem_Free(format); + cls.capturevideo.formatspecific = NULL; FS_Close(cls.capturevideo.videofile); cls.capturevideo.videofile = NULL; - - cls.capturevideo.formatspecific = NULL; } static int lavc_write(void *f, quint8_t *buf, int bufsize) @@ -1252,6 +1252,8 @@ void SCR_CaptureVideo_Lavc_BeginVideo(void) else video_str->codec->pix_fmt = PIX_FMT_YUV420P; } + if(video_str->codec->pix_fmt != PIX_FMT_BGRA) + format->sws = qsws_getCachedContext(NULL, cls.capturevideo.width, cls.capturevideo.height, PIX_FMT_BGRA, cls.capturevideo.width, cls.capturevideo.height, video_str->codec->pix_fmt, 0, NULL, NULL, NULL); FindFraction(1 / vid_pixelheight.value, &num, &denom, 1000); video_str->sample_aspect_ratio.num = num; video_str->sample_aspect_ratio.den = denom; -- 2.39.2