From 0685b8921e45032baa63912ff5e0b3deee6757e1 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 2 Dec 2010 01:33:19 -0300 Subject: [PATCH] viewfinderbin: Improve elements creation Be more careful with cleanup of elements. Also add some logs and improve docs a little. --- gst/camerabin2/gstviewfinderbin.c | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/gst/camerabin2/gstviewfinderbin.c b/gst/camerabin2/gstviewfinderbin.c index 5d92526ad4..1910bbbd83 100644 --- a/gst/camerabin2/gstviewfinderbin.c +++ b/gst/camerabin2/gstviewfinderbin.c @@ -19,14 +19,14 @@ /** * SECTION:element-gstviewfinderbin * - * The gstviewfinderbin element does FIXME stuff. + * The gstviewfinderbin element is a displaying element for camerabin2. * * * Example launch line * |[ * gst-launch -v videotestsrc ! viewfinderbin * ]| - * FIXME Describe what the pipeline does. + * Feeds the viewfinderbin with video test data. * */ @@ -36,6 +36,9 @@ #include "gstviewfinderbin.h" +GST_DEBUG_CATEGORY_STATIC (gst_viewfinder_bin_debug); +#define GST_CAT_DEFAULT gst_viewfinder_bin_debug + /* prototypes */ @@ -97,10 +100,13 @@ gst_viewfinder_bin_init (GstViewfinderBin * viewfinderbin, static gboolean gst_viewfinder_bin_create_elements (GstViewfinderBin * vfbin) { - GstElement *csp; - GstElement *videoscale; - GstElement *sink; + GstElement *csp = NULL; + GstElement *videoscale = NULL; + GstElement *sink = NULL; GstPad *pad = NULL; + gboolean added = FALSE; + + GST_DEBUG_OBJECT (vfbin, "Creating internal elements"); if (vfbin->elements_created) return TRUE; @@ -118,8 +124,11 @@ gst_viewfinder_bin_create_elements (GstViewfinderBin * vfbin) if (!sink) goto error; + GST_DEBUG_OBJECT (vfbin, "Internal elements created, proceding to linking"); + /* add and link */ gst_bin_add_many (GST_BIN_CAST (vfbin), csp, videoscale, sink, NULL); + added = TRUE; if (!gst_element_link_many (csp, videoscale, sink, NULL)) goto error; @@ -129,11 +138,23 @@ gst_viewfinder_bin_create_elements (GstViewfinderBin * vfbin) goto error; vfbin->elements_created = TRUE; + GST_DEBUG_OBJECT (vfbin, "Elements succesfully created and linked"); return TRUE; error: + GST_WARNING_OBJECT (vfbin, "Creating internal elements failed"); if (pad) gst_object_unref (pad); + if (!added) { + if (csp) + gst_object_unref (csp); + if (videoscale) + gst_object_unref (videoscale); + if (sink) + gst_object_unref (sink); + } else { + gst_bin_remove_many (GST_BIN_CAST (vfbin), csp, videoscale, sink, NULL); + } return FALSE; } @@ -168,6 +189,8 @@ gst_viewfinder_bin_change_state (GstElement * element, GstStateChange trans) gboolean gst_viewfinder_bin_plugin_init (GstPlugin * plugin) { + GST_DEBUG_CATEGORY_INIT (gst_viewfinder_bin_debug, "viewfinderbin", 0, + "ViewFinderBin"); return gst_element_register (plugin, "viewfinderbin", GST_RANK_NONE, gst_viewfinder_bin_get_type ()); }