From 2ce11e4bacf7d3691dac48a4947cfec116274c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wang=20Xin-yu=20=28=E7=8E=8B=E6=98=95=E5=AE=87=29?= Date: Wed, 23 Jul 2014 10:25:31 +0800 Subject: [PATCH] gl: fix multi gl object leaks 1. fix FBO leaks in decide_allocation 2. fix texture leaks in decide_allocation and reset 3. fix texture leaks in FBO incomplete error path --- ext/gl/gstgleffects.c | 6 ++++++ ext/gl/gstglmixer.c | 6 ++++++ gst-libs/gst/gl/gstglcolorconvert.c | 3 +++ gst-libs/gst/gl/gstglfilter.c | 26 ++++++++++++++++++++++++++ gst-libs/gst/gl/gstglframebuffer.c | 3 +++ 5 files changed, 44 insertions(+) diff --git a/ext/gl/gstgleffects.c b/ext/gl/gstgleffects.c index 4027e9cb0f..c142821590 100644 --- a/ext/gl/gstgleffects.c +++ b/ext/gl/gstgleffects.c @@ -197,6 +197,12 @@ gst_gl_effects_init_gl_resources (GstGLFilter * filter) gint i = 0; for (i = 0; i < NEEDED_TEXTURES; i++) { + + if (effects->midtexture[i]) { + gl->DeleteTextures (1, &effects->midtexture[i]); + effects->midtexture[i] = 0; + } + gl->GenTextures (1, &effects->midtexture[i]); gl->BindTexture (GL_TEXTURE_2D, effects->midtexture[i]); gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, diff --git a/ext/gl/gstglmixer.c b/ext/gl/gstglmixer.c index 626eb967c7..0d4d7e92ba 100644 --- a/ext/gl/gstglmixer.c +++ b/ext/gl/gstglmixer.c @@ -641,6 +641,12 @@ gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query) out_width = GST_VIDEO_INFO_WIDTH (&vagg->info); out_height = GST_VIDEO_INFO_HEIGHT (&vagg->info); + if (mix->fbo) { + gst_gl_context_del_fbo (mix->context, mix->fbo, mix->depthbuffer); + mix->fbo = 0; + mix->depthbuffer = 0; + } + if (!gst_gl_context_gen_fbo (mix->context, out_width, out_height, &mix->fbo, &mix->depthbuffer)) goto context_error; diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c index 42cc95d94e..dc433531ba 100644 --- a/gst-libs/gst/gl/gstglcolorconvert.c +++ b/gst-libs/gst/gl/gstglcolorconvert.c @@ -1137,6 +1137,9 @@ _init_convert_fbo (GstGLColorConvert * convert) if (!gst_gl_context_check_framebuffer_status (convert->context)) { gst_gl_context_set_error (convert->context, "GL framebuffer status incomplete"); + + gl->DeleteTextures (1, &fake_texture); + return FALSE; } diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c index 1f8ccd951e..397e866485 100644 --- a/gst-libs/gst/gl/gstglfilter.c +++ b/gst-libs/gst/gl/gstglfilter.c @@ -268,6 +268,17 @@ gst_gl_filter_reset (GstGLFilter * filter) gst_gl_context_del_fbo (filter->context, filter->fbo, filter->depthbuffer); } + + if (filter->in_tex_id) { + gst_gl_context_del_texture (filter->context, &filter->in_tex_id); + filter->in_tex_id = 0; + } + + if (filter->out_tex_id) { + gst_gl_context_del_texture (filter->context, &filter->out_tex_id); + filter->out_tex_id = 0; + } + gst_object_unref (filter->context); filter->context = NULL; } @@ -1070,6 +1081,21 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query) out_width = GST_VIDEO_INFO_WIDTH (&filter->out_info); out_height = GST_VIDEO_INFO_HEIGHT (&filter->out_info); + if (filter->fbo) { + gst_gl_context_del_fbo (filter->context, filter->fbo, filter->depthbuffer); + filter->fbo = 0; + filter->depthbuffer = 0; + } + + if (filter->in_tex_id) { + gst_gl_context_del_texture (filter->context, &filter->in_tex_id); + filter->in_tex_id = 0; + } + + if (filter->out_tex_id) { + gst_gl_context_del_texture (filter->context, &filter->out_tex_id); + filter->out_tex_id = 0; + } //blocking call, generate a FBO if (!gst_gl_context_gen_fbo (filter->context, out_width, out_height, &filter->fbo, &filter->depthbuffer)) diff --git a/gst-libs/gst/gl/gstglframebuffer.c b/gst-libs/gst/gl/gstglframebuffer.c index 2de236bca3..6cde96ce70 100644 --- a/gst-libs/gst/gl/gstglframebuffer.c +++ b/gst-libs/gst/gl/gstglframebuffer.c @@ -149,6 +149,9 @@ gst_gl_framebuffer_generate (GstGLFramebuffer * frame, gint width, gint height, if (gl->CheckFramebufferStatus (GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { gst_gl_context_set_error (frame->context, "GL framebuffer status incomplete"); + + gl->DeleteTextures (1, &fake_texture); + return FALSE; }