Commit 4ef6e73a authored by Yann Diorcet's avatar Yann Diorcet
Browse files

OpenGL: Again a memory leak fix and remove useless stuff

parent ec3580ad
......@@ -236,7 +236,6 @@
unsigned int i = 0;
AVCaptureDevice * device = NULL;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray * array = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (i = 0 ; i < [array count]; i++) {
AVCaptureDevice * currentDevice = [array objectAtIndex:i];
......@@ -256,15 +255,13 @@
AVCaptureSession *session = [(AVCaptureVideoPreviewLayer *)self.layer session];
[session addInput:input];
[session addOutput:output ];
[pool drain];
}
- (void)dealloc {
AVCaptureSession *session = [(AVCaptureVideoPreviewLayer *)self.layer session];
[session removeInput:input];
[session removeOutput:output];
[input release];
[output release];
[parentView release];
......@@ -447,12 +444,11 @@ static void ioscapture_init(MSFilter *f) {
static void ioscapture_uninit(MSFilter *f) {
IOSCapture *thiz = (IOSCapture*)f->data;
if(thiz != nil) {
if(thiz != NULL) {
[thiz performSelectorInBackground:@selector(stop) withObject:nil];
[thiz performSelectorOnMainThread:@selector(setParentView:) withObject:nil waitUntilDone:NO];
[thiz release];
f->data = NULL;
}
}
......@@ -474,7 +470,7 @@ static void ioscapture_process(MSFilter * obj) {
static void ioscapture_preprocess(MSFilter *f) {
IOSCapture *thiz = (IOSCapture*)f->data;
if (thiz != NULL) {
if(thiz != NULL) {
[thiz performSelectorInBackground:@selector(start) withObject:nil];
}
}
......@@ -646,8 +642,10 @@ static void ms_v4ios_cam_init(MSWebCam *cam) {
}
static MSFilter *ms_v4ios_create_reader(MSWebCam *obj) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MSFilter *f= ms_filter_new_from_desc(&ms_ioscapture_desc);
[((IOSCapture*)f->data) openDevice:obj->data];
[pool drain];
return f;
}
......
......@@ -246,57 +246,63 @@ static void iosdisplay_process(MSFilter *f) {
if (thiz != nil && m != nil) {
ogl_display_set_yuv_to_display(thiz->display_helper, m);
}
ms_queue_flush(f->inputs[0]);
if (f->inputs[1])
if (f->inputs[1] != NULL) {
ms_queue_flush(f->inputs[1]);
}
}
static void iosdisplay_uninit(MSFilter *f) {
IOSDisplay* thiz = (IOSDisplay*)f->data;
// Remove from parent view in order to release all reference to IOSDisplay
[thiz performSelectorOnMainThread:@selector(setParentView:) withObject:nil waitUntilDone:NO];
[thiz release];
if (thiz != nil) {
// Remove from parent view in order to release all reference to IOSDisplay
[thiz performSelectorOnMainThread:@selector(setParentView:) withObject:nil waitUntilDone:NO];
[thiz release];
}
}
static int iosdisplay_set_native_window(MSFilter *f, void *arg) {
IOSDisplay *thiz = (IOSDisplay*)f->data;
UIView* parentView = *(UIView**)arg;
if (thiz != nil) {
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
// set current parent view
[thiz performSelectorOnMainThread:@selector(setParentView:) withObject:parentView waitUntilDone:NO];
[loopPool drain];
}
return 0;
}
static int iosdisplay_get_native_window(MSFilter *f, void *arg) {
IOSDisplay* thiz=(IOSDisplay*)f->data;
*(UIView**)arg = thiz.parentView;
IOSDisplay* thiz = (IOSDisplay*)f->data;
if (thiz != NULL) {
*(UIView**)arg = thiz.parentView;
}
return 0;
}
static int iosdisplay_set_device_orientation(MSFilter* f, void* arg) {
IOSDisplay* thiz=(IOSDisplay*)f->data;
if (!thiz)
return 0;
thiz.deviceRotation = *((int*)arg);
IOSDisplay* thiz = (IOSDisplay*)f->data;
if (thiz != NULL) {
thiz.deviceRotation = *((int*)arg);
}
return 0;
}
static int iosdisplay_set_device_orientation_display(MSFilter* f, void* arg) {
IOSDisplay* thiz=(IOSDisplay*)f->data;
if (!thiz)
return 0;
thiz.displayRotation = *((int*)arg);
IOSDisplay* thiz = (IOSDisplay*)f->data;
if (thiz != NULL) {
thiz.displayRotation = *((int*)arg);
}
return 0;
}
static int iosdisplay_set_zoom(MSFilter* f, void* arg) {
IOSDisplay* thiz=(IOSDisplay*)f->data;
ogl_display_zoom(thiz->display_helper, arg);
IOSDisplay* thiz = (IOSDisplay*)f->data;
if (thiz != NULL) {
ogl_display_zoom(thiz->display_helper, arg);
}
return 0;
}
static MSFilterMethod iosdisplay_methods[] = {
......
......@@ -292,17 +292,13 @@ static void osx_gl_init(MSFilter* f) {
static void osx_gl_preprocess(MSFilter* f) {
OSXDisplay* thiz = (OSXDisplay*) f->data;
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
[thiz performSelectorOnMainThread:@selector(createWindowIfNeeded) withObject:nil waitUntilDone:FALSE];
[loopPool drain];
}
static void osx_gl_process(MSFilter* f) {
OSXDisplay* thiz = (OSXDisplay*) f->data;
mblk_t* m = 0;
MSPicture pic;
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
if ((m=ms_queue_peek_last(f->inputs[0])) != NULL) {
if (ms_yuv_buf_init_from_mblk (&pic,m) == 0) {
......@@ -334,8 +330,6 @@ static void osx_gl_process(MSFilter* f) {
}
ms_queue_flush(f->inputs[1]);
}
[loopPool drain];
}
static void osx_gl_uninit(MSFilter* f) {
......@@ -367,7 +361,6 @@ static int osx_gl_set_native_window_id(MSFilter* f, void* arg) {
OSXDisplay* thiz = (OSXDisplay*) f->data;
NSObject *obj = *((NSObject **)arg);
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
if(obj != nil) {
if([obj isKindOfClass:[NSWindow class]]) {
[thiz performSelectorOnMainThread:@selector(setWindow:) withObject:(NSWindow*)obj waitUntilDone:NO];
......@@ -381,8 +374,9 @@ static int osx_gl_set_native_window_id(MSFilter* f, void* arg) {
}
} else {
[thiz performSelectorOnMainThread:@selector(resetContainers) withObject:nil waitUntilDone:NO];
return 0;
}
[loopPool drain];
return -1;
}
......
......@@ -23,7 +23,8 @@
enum ImageType {
REMOTE_IMAGE = 0,
PREVIEW_IMAGE
PREVIEW_IMAGE,
MAX_IMAGE
};
/* helper functions */
......@@ -72,14 +73,14 @@ enum {
struct opengles_display {
/* input: yuv image to display */
ms_mutex_t yuv_mutex;
mblk_t *yuv[2];
bool_t new_yuv_image[TEXTURE_BUFFER_SIZE][2];
mblk_t *yuv[MAX_IMAGE];
bool_t new_yuv_image[TEXTURE_BUFFER_SIZE][MAX_IMAGE];
/* GL resources */
bool_t glResourcesInitialized;
GLuint program, textures[TEXTURE_BUFFER_SIZE][2][3];
GLuint program, textures[TEXTURE_BUFFER_SIZE][MAX_IMAGE][3];
GLint uniforms[NUM_UNIFORMS];
MSVideoSize allocatedTexturesSize[2];
MSVideoSize allocatedTexturesSize[MAX_IMAGE];
int texture_index;
......@@ -88,8 +89,8 @@ struct opengles_display {
GLint backingHeight;
/* runtime data */
float uvx[2], uvy[2];
MSVideoSize yuv_size[2];
float uvx[MAX_IMAGE], uvy[MAX_IMAGE];
MSVideoSize yuv_size[MAX_IMAGE];
/* coordinates of for zoom-in */
float zoom_factor;
......@@ -122,7 +123,7 @@ void ogl_display_free(struct opengles_display* gldisp) {
return;
}
for(i=0; i<2; i++) {
for(i=0; i<MAX_IMAGE; i++) {
if (gldisp->yuv[i]) {
ms_free(gldisp->yuv[i]);
gldisp->yuv[i] = NULL;
......@@ -162,7 +163,7 @@ void ogl_display_init(struct opengles_display* gldisp, int width, int height) {
for(j=0; j<TEXTURE_BUFFER_SIZE; j++) {
// init textures
for(i=0; i<2; i++) {
for(i=0; i<MAX_IMAGE; i++) {
GL_OPERATION(glGenTextures(3, gldisp->textures[j][i]))
gldisp->allocatedTexturesSize[i].width = gldisp->allocatedTexturesSize[i].height = 0;
}
......@@ -194,7 +195,7 @@ void ogl_display_uninit(struct opengles_display* gldisp, bool_t freeGLresources)
return;
}
ms_message("uninit opengles_display (gl initialized:%d)\n", gldisp->glResourcesInitialized);
for(i=0; i<2; i++) {
for(i=0; i<MAX_IMAGE; i++) {
if (gldisp->yuv[i]) {
ms_free(gldisp->yuv[i]);
gldisp->yuv[i] = NULL;
......@@ -202,9 +203,9 @@ void ogl_display_uninit(struct opengles_display* gldisp, bool_t freeGLresources)
}
if (gldisp->glResourcesInitialized && freeGLresources) {
// destroy gl resources
for(j=0; j<TEXTURE_BUFFER_SIZE; j++) {
// destroy gl resources
for(i=0; i<2; i++) {
for(i=0; i<MAX_IMAGE; i++) {
GL_OPERATION(glDeleteTextures(3, gldisp->textures[j][i]));
gldisp->allocatedTexturesSize[i].width = gldisp->allocatedTexturesSize[i].height = 0;
}
......
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