From 58a23c99e932eb4a221673a118d1675fdabd58e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 15 Jul 2017 14:59:42 +0100 Subject: [PATCH] x264enc: fix caps leak Move creation of supported sink pads into class_init function which is also the only place where they're used. Unref the caps when no longer needed, the pad template will take its own ref. https://bugzilla.gnome.org/show_bug.cgi?id=784982 --- ext/x264/gstx264enc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ext/x264/gstx264enc.c b/ext/x264/gstx264enc.c index 6ce73d0..57ecc68 100644 --- a/ext/x264/gstx264enc.c +++ b/ext/x264/gstx264enc.c @@ -140,7 +140,6 @@ struct _GstX264EncVTable static GstX264EncVTable default_vtable; static GstX264EncVTable *vtable_8bit = NULL, *vtable_10bit = NULL; -static GstCaps *supported_sinkcaps = NULL; #define LOAD_SYMBOL(name) G_STMT_START { \ if (!g_module_symbol (module, #name, (gpointer *) &vtable->name)) { \ @@ -324,14 +323,6 @@ load_x264_libraries (void) if (!vtable_8bit && !vtable_10bit) return FALSE; - supported_sinkcaps = gst_caps_new_simple ("video/x-raw", - "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, - "width", GST_TYPE_INT_RANGE, 16, G_MAXINT, - "height", GST_TYPE_INT_RANGE, 16, G_MAXINT, NULL); - - gst_x264_enc_add_x264_chroma_format (gst_caps_get_structure - (supported_sinkcaps, 0), TRUE, TRUE, TRUE); - return TRUE; } @@ -874,6 +865,7 @@ gst_x264_enc_class_init (GstX264EncClass * klass) GstVideoEncoderClass *gstencoder_class; const gchar *partitions = NULL; GstPadTemplate *sink_templ; + GstCaps *supported_sinkcaps; x264enc_defaults = g_string_new (""); @@ -1134,9 +1126,19 @@ gst_x264_enc_class_init (GstX264EncClass * klass) "Josef Zlomek , " "Mark Nauwelaerts "); + supported_sinkcaps = gst_caps_new_simple ("video/x-raw", + "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, + "width", GST_TYPE_INT_RANGE, 16, G_MAXINT, + "height", GST_TYPE_INT_RANGE, 16, G_MAXINT, NULL); + + gst_x264_enc_add_x264_chroma_format (gst_caps_get_structure + (supported_sinkcaps, 0), TRUE, TRUE, TRUE); + sink_templ = gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, supported_sinkcaps); + gst_caps_unref (supported_sinkcaps); + gst_element_class_add_pad_template (element_class, sink_templ); gst_element_class_add_static_pad_template (element_class, &src_factory); } -- 2.7.4