changeset 29566:b128ce47771d

Reduce vo_corevideo memleaks by initializing static context etc. only once in preinit and freeing the video-specific data before reallocating in config.
author reimar
date Tue, 01 Sep 2009 10:48:47 +0000
parents d39aa2e3a91f
children 349de9bdfcce
files libvo/vo_corevideo.m
diffstat 1 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/vo_corevideo.m	Tue Sep 01 10:17:22 2009 +0000
+++ b/libvo/vo_corevideo.m	Tue Sep 01 10:48:47 2009 +0000
@@ -431,6 +431,9 @@
 @implementation MPlayerOpenGLView
 - (void) preinit
 {
+	GLint swapInterval = 1;
+	CVReturn error;
+
 	//init menu
 	[self initMenu];
 
@@ -448,6 +451,28 @@
 
 	isFullscreen = 0;
 	winSizeMult = 1;
+
+	//create OpenGL Context
+	glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
+
+	[self setOpenGLContext:glContext];
+	[glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
+	[glContext setView:self];
+	[glContext makeCurrentContext];
+
+	error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
+	if(error != kCVReturnSuccess)
+		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
+}
+
+- (void) releaseVideoSpecific
+{
+	CVPixelBufferRelease(frameBuffers[0]);
+	frameBuffers[0] = NULL;
+	CVPixelBufferRelease(frameBuffers[1]);
+	frameBuffers[1] = NULL;
+	CVOpenGLTextureRelease(texture);
+	texture = NULL;
 }
 
 - (void) config
@@ -455,8 +480,6 @@
 	uint32_t d_width;
 	uint32_t d_height;
 
-	GLint swapInterval = 1;
-
 	NSRect frame;
 	CVReturn error = kCVReturnSuccess;
 
@@ -465,14 +488,7 @@
 	frame = NSMakeRect(0, 0, d_width, d_height);
 	[window setContentSize: frame.size];
 
-	//create OpenGL Context
-	glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
-
-	[self setOpenGLContext:glContext];
-	[glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
-	[glContext setView:self];
-	[glContext makeCurrentContext];
-
+	[self releaseVideoSpecific];
 	error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]);
 	if(error != kCVReturnSuccess)
 		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error);
@@ -482,10 +498,6 @@
 			mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error);
 	}
 
-	error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
-	if(error != kCVReturnSuccess)
-		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
-
 	error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
 	if(error != kCVReturnSuccess)
 		mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);