Commit b72c1460 authored by Yann Diorcet's avatar Yann Diorcet
Browse files

Fix memory leak and optimize OpenGL stuff

parent 863022b5
......@@ -280,6 +280,7 @@
}
- (int)start {
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
@synchronized(self) {
AVCaptureSession *session = [(AVCaptureVideoPreviewLayer *)self.layer session];
if (!session.running) {
......@@ -290,16 +291,19 @@
ms_message("ioscapture video device started.");
}
}
[myPool drain];
return 0;
}
- (int)stop {
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
@synchronized(self) {
AVCaptureSession *session = [(AVCaptureVideoPreviewLayer *)self.layer session];
if (session.running) {
[session stopRunning];
}
}
[myPool drain];
return 0;
}
......@@ -441,7 +445,6 @@ static void ioscapture_init(MSFilter *f) {
}
static void ioscapture_uninit(MSFilter *f) {
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
IOSCapture *thiz = (IOSCapture*)f->data;
if(thiz != nil) {
......@@ -451,7 +454,6 @@ static void ioscapture_uninit(MSFilter *f) {
[thiz release];
f->data = NULL;
}
[myPool drain];
}
static void ioscapture_process(MSFilter * obj) {
......@@ -471,12 +473,10 @@ static void ioscapture_process(MSFilter * obj) {
}
static void ioscapture_preprocess(MSFilter *f) {
NSAutoreleasePool* myPool = [[NSAutoreleasePool alloc] init];
IOSCapture *thiz = (IOSCapture*)f->data;
if (thiz != NULL) {
[thiz performSelectorInBackground:@selector(start) withObject:nil];
}
[myPool drain];
}
static void ioscapture_postprocess(MSFilter *f) {
......
......@@ -55,7 +55,7 @@
CGRect prevBounds;
}
- (void) drawView:(id)sender;
- (void)drawView:(id)sender;
- (BOOL)loadShaders;
- (void)initIOSDisplay;
......@@ -152,13 +152,10 @@
ms_message("GL renderbuffer allocation size (layer %p frame size: %f x %f)", layer, layer.frame.size.width, layer.frame.size.height);
ogl_display_init(helper, prevBounds.size.width, prevBounds.size.height);
glBindFramebuffer(GL_FRAMEBUFFER, defaultFrameBuffer);
glClearColor(0,0,0,1);
glClearColor(0, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
}
}
glBindFramebuffer(GL_FRAMEBUFFER, defaultFrameBuffer);
}
if (!animating) {
glClear(GL_COLOR_BUFFER_BIT);
......@@ -166,7 +163,6 @@
ogl_display_render(helper, 0);
}
glBindRenderbuffer(GL_RENDERBUFFER, colorRenderBuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
}
......
......@@ -108,10 +108,11 @@
if (!NSEqualRects(prevBounds, [self bounds])) {
prevBounds = [self bounds];
ogl_display_init(display_helper, prevBounds.size.width, prevBounds.size.height);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
}
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
ogl_display_render(display_helper, 0);
CGLUnlockContext(cglContext);
......
......@@ -143,6 +143,8 @@ void ogl_display_init(struct opengles_display* gldisp, int width, int height) {
gldisp->backingWidth = width;
gldisp->backingHeight = height;
GL_OPERATION(glViewport(0, 0, gldisp->backingWidth, gldisp->backingHeight));
if (gldisp->glResourcesInitialized)
return;
......@@ -163,6 +165,8 @@ void ogl_display_init(struct opengles_display* gldisp, int width, int height) {
}
load_shaders(&gldisp->program, gldisp->uniforms);
check_GL_errors("load_shaders");
GL_OPERATION(glUseProgram(gldisp->program))
gldisp->glResourcesInitialized = TRUE;
}
......@@ -224,8 +228,6 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
return;
}
GL_OPERATION(glUseProgram(gldisp->program))
ms_mutex_lock(&gldisp->yuv_mutex);
if (gldisp->new_yuv_image[type]) {
update_textures_with_yuv(gldisp, type);
......@@ -247,7 +249,6 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
};
if (clear) {
GL_OPERATION(glViewport(0, 0, gldisp->backingWidth, gldisp->backingHeight));
GL_OPERATION(glClearColor(0, 0, 0, 1))
GL_OPERATION(glClear(GL_COLOR_BUFFER_BIT))
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment