cudamemorycopy: Fix GL resource leak

Clear GL resources on stop()

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1896>
This commit is contained in:
Seungha Yang 2022-03-09 02:14:50 +09:00 committed by GStreamer Marge Bot
parent 17f11c2cda
commit 496b77e6aa

View file

@ -100,6 +100,7 @@ G_DEFINE_ABSTRACT_TYPE (GstCudaMemoryCopy, gst_cuda_memory_copy,
static void gst_cuda_memory_copy_set_context (GstElement * element, static void gst_cuda_memory_copy_set_context (GstElement * element,
GstContext * context); GstContext * context);
static gboolean gst_cuda_memory_copy_transform_stop (GstBaseTransform * trans);
static GstCaps *gst_cuda_memory_copy_transform_caps (GstBaseTransform * trans, static GstCaps *gst_cuda_memory_copy_transform_caps (GstBaseTransform * trans,
GstPadDirection direction, GstCaps * caps, GstCaps * filter); GstPadDirection direction, GstCaps * caps, GstCaps * filter);
static gboolean gst_cuda_memory_copy_query (GstBaseTransform * trans, static gboolean gst_cuda_memory_copy_query (GstBaseTransform * trans,
@ -125,6 +126,7 @@ gst_cuda_memory_copy_class_init (GstCudaMemoryCopyClass * klass)
element_class->set_context = element_class->set_context =
GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_set_context); GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_set_context);
trans_class->stop = GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_transform_stop);
trans_class->transform_caps = trans_class->transform_caps =
GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_transform_caps); GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_transform_caps);
trans_class->propose_allocation = trans_class->propose_allocation =
@ -155,6 +157,20 @@ gst_cuda_memory_copy_set_context (GstElement * element, GstContext * context)
GST_ELEMENT_CLASS (parent_class)->set_context (element, context); GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
} }
static gboolean
gst_cuda_memory_copy_transform_stop (GstBaseTransform * trans)
{
#ifdef HAVE_NVCODEC_GST_GL
GstCudaMemoryCopy *self = GST_CUDA_MEMORY_COPY (trans);
gst_clear_object (&self->gl_display);
gst_clear_object (&self->gl_context);
gst_clear_object (&self->other_gl_context);
#endif
return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (trans);
}
static GstCaps * static GstCaps *
_set_caps_features (const GstCaps * caps, const gchar * feature_name) _set_caps_features (const GstCaps * caps, const gchar * feature_name)
{ {
@ -1329,9 +1345,6 @@ gst_cuda_upload_class_init (GstCudaUploadClass * klass, gpointer data)
GstCudaMemoryCopyClass *copy_class = GST_CUDA_MEMORY_COPY_CLASS (klass); GstCudaMemoryCopyClass *copy_class = GST_CUDA_MEMORY_COPY_CLASS (klass);
GstCudaMemoryCopyClassData *cdata = (GstCudaMemoryCopyClassData *) data; GstCudaMemoryCopyClassData *cdata = (GstCudaMemoryCopyClassData *) data;
element_class->set_context =
GST_DEBUG_FUNCPTR (gst_cuda_memory_copy_set_context);
gst_element_class_add_pad_template (element_class, gst_element_class_add_pad_template (element_class,
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
cdata->sink_caps)); cdata->sink_caps));