comparison libvo/vo_corevideo.m @ 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 4ae3d2d7946e
children 349de9bdfcce
comparison
equal deleted inserted replaced
29565:d39aa2e3a91f 29566:b128ce47771d
429 // NSOpenGLView Subclass 429 // NSOpenGLView Subclass
430 ////////////////////////////////////////////////////////////////////////// 430 //////////////////////////////////////////////////////////////////////////
431 @implementation MPlayerOpenGLView 431 @implementation MPlayerOpenGLView
432 - (void) preinit 432 - (void) preinit
433 { 433 {
434 GLint swapInterval = 1;
435 CVReturn error;
436
434 //init menu 437 //init menu
435 [self initMenu]; 438 [self initMenu];
436 439
437 //create window 440 //create window
438 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) 441 window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100)
446 [window setAcceptsMouseMovedEvents:YES]; 449 [window setAcceptsMouseMovedEvents:YES];
447 [window setTitle:@"MPlayer - The Movie Player"]; 450 [window setTitle:@"MPlayer - The Movie Player"];
448 451
449 isFullscreen = 0; 452 isFullscreen = 0;
450 winSizeMult = 1; 453 winSizeMult = 1;
454
455 //create OpenGL Context
456 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
457
458 [self setOpenGLContext:glContext];
459 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
460 [glContext setView:self];
461 [glContext makeCurrentContext];
462
463 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
464 if(error != kCVReturnSuccess)
465 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
466 }
467
468 - (void) releaseVideoSpecific
469 {
470 CVPixelBufferRelease(frameBuffers[0]);
471 frameBuffers[0] = NULL;
472 CVPixelBufferRelease(frameBuffers[1]);
473 frameBuffers[1] = NULL;
474 CVOpenGLTextureRelease(texture);
475 texture = NULL;
451 } 476 }
452 477
453 - (void) config 478 - (void) config
454 { 479 {
455 uint32_t d_width; 480 uint32_t d_width;
456 uint32_t d_height; 481 uint32_t d_height;
457
458 GLint swapInterval = 1;
459 482
460 NSRect frame; 483 NSRect frame;
461 CVReturn error = kCVReturnSuccess; 484 CVReturn error = kCVReturnSuccess;
462 485
463 //config window 486 //config window
464 d_width = vo_dwidth; d_height = vo_dheight; 487 d_width = vo_dwidth; d_height = vo_dheight;
465 frame = NSMakeRect(0, 0, d_width, d_height); 488 frame = NSMakeRect(0, 0, d_width, d_height);
466 [window setContentSize: frame.size]; 489 [window setContentSize: frame.size];
467 490
468 //create OpenGL Context 491 [self releaseVideoSpecific];
469 glContext = [[NSOpenGLContext alloc] initWithFormat:[NSOpenGLView defaultPixelFormat] shareContext:nil];
470
471 [self setOpenGLContext:glContext];
472 [glContext setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
473 [glContext setView:self];
474 [glContext makeCurrentContext];
475
476 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]); 492 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[0], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[0]);
477 if(error != kCVReturnSuccess) 493 if(error != kCVReturnSuccess)
478 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error); 494 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Buffer(%d)\n", error);
479 if (vo_doublebuffering) { 495 if (vo_doublebuffering) {
480 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]); 496 error = CVPixelBufferCreateWithBytes(NULL, image_width, image_height, pixelFormat, image_datas[1], image_width*image_bytes, NULL, NULL, NULL, &frameBuffers[1]);
481 if(error != kCVReturnSuccess) 497 if(error != kCVReturnSuccess)
482 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error); 498 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create Pixel Double Buffer(%d)\n", error);
483 } 499 }
484
485 error = CVOpenGLTextureCacheCreate(NULL, 0, [glContext CGLContextObj], [[self pixelFormat] CGLPixelFormatObj], 0, &textureCache);
486 if(error != kCVReturnSuccess)
487 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture Cache(%d)\n", error);
488 500
489 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture); 501 error = CVOpenGLTextureCacheCreateTextureFromImage(NULL, textureCache, frameBuffers[image_page], 0, &texture);
490 if(error != kCVReturnSuccess) 502 if(error != kCVReturnSuccess)
491 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error); 503 mp_msg(MSGT_VO, MSGL_ERR,"[vo_corevideo] Failed to create OpenGL texture(%d)\n", error);
492 504