1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-14 02:51:26 +00:00

Reduce vo_corevideo memleaks by initializing static context etc. only once

in preinit and freeing the video-specific data before reallocating in config.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29608 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2009-09-01 10:48:47 +00:00
parent b125a31886
commit 0f7fe32725

View File

@ -431,6 +431,9 @@ static int control(uint32_t request, void *data, ...)
@implementation MPlayerOpenGLView
- (void) preinit
{
GLint swapInterval = 1;
CVReturn error;
//init menu
[self initMenu];
@ -448,22 +451,6 @@ static int control(uint32_t request, void *data, ...)
isFullscreen = 0;
winSizeMult = 1;
}
- (void) config
{
uint32_t d_width;
uint32_t d_height;
GLint swapInterval = 1;
NSRect frame;
CVReturn error = kCVReturnSuccess;
//config window
d_width = vo_dwidth; d_height = vo_dheight;
frame = NSMakeRect(0, 0, d_width, d_height);
[window setContentSize: frame.size];
//create OpenGL Context
glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
@ -473,6 +460,35 @@ static int control(uint32_t request, void *data, ...)
[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
{
uint32_t d_width;
uint32_t d_height;
NSRect frame;
CVReturn error = kCVReturnSuccess;
//config window
d_width = vo_dwidth; d_height = vo_dheight;
frame = NSMakeRect(0, 0, d_width, d_height);
[window setContentSize: frame.size];
[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 @@ static int control(uint32_t request, void *data, ...)
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);