From 8aac9bb90fd33787c5ba5e77080e8d2e93cdb375 Mon Sep 17 00:00:00 2001 From: Torsten Jager Date: Sat, 17 May 2014 18:04:25 +0200 Subject: opengl2: lower YV12 memory fragmentation. When zapping into the same TV channel in Kaffeine, the first attempt yields the lowest CPU load. Any further try was different, and up to 50% higher. With this little hack, the problem seems almost gone. At least with OpenGL2 :-) --- src/video_out/video_out_opengl2.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/video_out/video_out_opengl2.c b/src/video_out/video_out_opengl2.c index b020394ab..45c5abf16 100644 --- a/src/video_out/video_out_opengl2.c +++ b/src/video_out/video_out_opengl2.c @@ -666,8 +666,6 @@ static void opengl2_frame_dispose( vo_frame_t *vo_img ) opengl2_frame_t *frame = (opengl2_frame_t *) vo_img ; av_free (frame->vo_frame.base[0]); - av_free (frame->vo_frame.base[1]); - av_free (frame->vo_frame.base[2]); free (frame); } @@ -711,26 +709,26 @@ static void opengl2_update_frame_format( vo_driver_t *this_gen, vo_frame_t *fram /* (re-) allocate render space */ av_freep (&frame->vo_frame.base[0]); - av_freep (&frame->vo_frame.base[1]); - av_freep (&frame->vo_frame.base[2]); + frame->vo_frame.base[1] = NULL; + frame->vo_frame.base[2] = NULL; if (format == XINE_IMGFMT_YV12) { - frame->vo_frame.pitches[0] = (width + 15) & ~15; - frame->vo_frame.pitches[1] = ((width + 15) & ~15) >> 1; - frame->vo_frame.pitches[2] = ((width + 15) & ~15) >> 1; - frame->vo_frame.base[0] = av_mallocz (frame->vo_frame.pitches[0] * height); - frame->vo_frame.base[1] = av_malloc (frame->vo_frame.pitches[1] * ((height+1)/2)); - frame->vo_frame.base[2] = av_malloc (frame->vo_frame.pitches[2] * ((height+1)/2)); - if (!frame->vo_frame.base[0] || !frame->vo_frame.base[1] || !frame->vo_frame.base[2]) { - av_freep (&frame->vo_frame.base[0]); - av_freep (&frame->vo_frame.base[1]); - av_freep (&frame->vo_frame.base[2]); + int w = (width + 15) & ~15; + int ysize = w * height; + int uvsize = (w >> 1) * ((height + 1) >> 1); + frame->vo_frame.pitches[0] = w; + frame->vo_frame.pitches[1] = w >> 1; + frame->vo_frame.pitches[2] = w >> 1; + frame->vo_frame.base[0] = av_malloc (ysize + 2 * uvsize); + if (!frame->vo_frame.base[0]) { frame->width = 0; frame->vo_frame.width = 0; /* tell vo_get_frame () to retry later */ return; } - memset (frame->vo_frame.base[1], 128, frame->vo_frame.pitches[1] * ((height+1)/2)); - memset (frame->vo_frame.base[2], 128, frame->vo_frame.pitches[2] * ((height+1)/2)); + memset (frame->vo_frame.base[0], 0, ysize); + frame->vo_frame.base[1] = frame->vo_frame.base[0] + ysize; + memset (frame->vo_frame.base[1], 128, 2 * uvsize); + frame->vo_frame.base[2] = frame->vo_frame.base[1] + uvsize; } else if (format == XINE_IMGFMT_YUY2){ frame->vo_frame.pitches[0] = ((width + 15) & ~15) << 1; frame->vo_frame.base[0] = av_malloc (frame->vo_frame.pitches[0] * height); -- cgit v1.2.3