now require gst_control_init to initialise dparams. a start has been made on disposin...
authorSteve Baker <steve@stevebaker.org>
Thu, 29 Nov 2001 20:31:53 +0000 (20:31 +0000)
committerSteve Baker <steve@stevebaker.org>
Thu, 29 Nov 2001 20:31:53 +0000 (20:31 +0000)
Original commit message from CVS:
now require gst_control_init to initialise dparams. a start has been made on disposing of the objects as well

libs/control/gstcontrol.c
libs/control/gstcontrol.h
libs/control/gstdparam.c
libs/control/gstdparam.h
libs/control/gstdparamcommon.h [new file with mode: 0644]
libs/control/gstdparammanager.c
libs/control/gstdparammanager.h

index 9be5095..aaf9993 100644 (file)
@@ -20,3 +20,8 @@
  */
  
 #include "gstcontrol.h"
+
+void
+gst_control_init (int *argc, char **argv[]) {
+       _gst_dpman_initialize ();
+}
index 764f37b..293f831 100644 (file)
@@ -22,9 +22,6 @@
 #ifndef __GST_CONTROL_H__
 #define __GST_CONTROL_H__
 
-#include <gst/gstobject.h>
-#include <gst/gstprops.h>
-
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -34,6 +31,8 @@ extern "C" {
 
 #include <libs/control/gstdplinearinterp.h>
 
+void gst_control_init (int *argc, char **argv[]);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 665b66d..44cceff 100644 (file)
@@ -28,6 +28,7 @@
 
 static void gst_dparam_class_init (GstDParamClass *klass);
 static void gst_dparam_init (GstDParam *dparam);
+static void gst_dparam_dispose (GObject *object);
 
 static void gst_dparam_do_update_realtime (GstDParam *dparam, gint64 timestamp);
 static GValue** gst_dparam_get_point_realtime (GstDParam *dparam, gint64 timestamp);
@@ -63,7 +64,8 @@ gst_dparam_class_init (GstDParamClass *klass)
        gobject_class = (GObjectClass*)klass;
        dparam_class = (GstDParamClass*)klass;
        gstobject_class = (GstObjectClass*) klass;
-
+       
+       gobject_class->dispose = gst_dparam_dispose;
        //gstobject_class->save_thyself = gst_dparam_save_thyself;
 
 }
@@ -101,23 +103,42 @@ gst_dparam_new (GType type)
        return dparam;
 }
 
+static void
+gst_dparam_dispose (GObject *object)
+{
+       GstDParam *dparam = GST_DPARAM(object);
+       GValue **point = dparam->point;
+       guint i = 0;
+       gchar *dparam_name = g_strdup(GST_DPARAM_NAME(dparam));
+       
+       g_print("disposing of %s\n", dparam_name);
+       if (GST_DPARAM_MANAGER(dparam)){
+               gst_dpman_detach_dparam(GST_DPARAM_MANAGER(dparam), dparam_name);
+       }
+       point = dparam->point;
+       while (point[i]){
+               g_value_unset(point[i]);
+               g_free(point[i]);
+               i++;
+       }
+       g_free(dparam_name);
+       
+}
+
 /**
  * gst_dparam_attach
  * @dparam: GstDParam instance
- * @parent: the GstDParamManager that this dparam belongs to
+ * @manager: the GstDParamManager that this dparam belongs to
  *
  */
 void
-gst_dparam_attach (GstDParam *dparam, GstObject *parent, GValue *value, GstDParamSpec *spec)
+gst_dparam_attach (GstDParam *dparam, GstDParamManager *manager, GValue *value, GstDParamSpec *spec)
 {
        
        g_return_if_fail (dparam != NULL);
        g_return_if_fail (GST_IS_DPARAM (dparam));
-       g_return_if_fail (GST_DPARAM_PARENT (dparam) == NULL);
-       g_return_if_fail (parent != NULL);
-       g_return_if_fail (G_IS_OBJECT (parent));
-       g_return_if_fail (GST_IS_DPMAN (parent));
-       g_return_if_fail ((gpointer)dparam != (gpointer)parent);
+       g_return_if_fail (manager != NULL);
+       g_return_if_fail (GST_IS_DPMAN (manager));
        g_return_if_fail (value != NULL);
        g_return_if_fail (spec != NULL);
        g_return_if_fail (GST_DPARAM_TYPE(dparam) == G_VALUE_TYPE(value));
@@ -125,7 +146,26 @@ gst_dparam_attach (GstDParam *dparam, GstObject *parent, GValue *value, GstDPara
        GST_DPARAM_NAME(dparam) = spec->dparam_name;
        GST_DPARAM_VALUE(dparam) = value;
        GST_DPARAM_SPEC(dparam) = spec;
-       gst_object_set_parent (GST_OBJECT (dparam), parent);
+       GST_DPARAM_MANAGER(dparam) = manager;
+}
+
+/**
+ * gst_dparam_detach
+ * @dparam: GstDParam instance
+ * @manager: the GstDParamManager that this dparam belongs to
+ *
+ */
+void
+gst_dparam_detach (GstDParam *dparam)
+{
+       
+       g_return_if_fail (dparam != NULL);
+       g_return_if_fail (GST_IS_DPARAM (dparam));
+       
+       GST_DPARAM_NAME(dparam) = NULL;
+       GST_DPARAM_VALUE(dparam) = NULL;
+       GST_DPARAM_SPEC(dparam) = NULL;
+       GST_DPARAM_MANAGER(dparam) = NULL;
 }
 
 /**
index 72d5fad..1b3131a 100644 (file)
 
 #include <gst/gstobject.h>
 #include <gst/gstprops.h>
+#include <libs/control/gstdparamcommon.h>
 
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
 
-
 #define GST_TYPE_DPARAM                        (gst_dparam_get_type ())
 #define GST_DPARAM(obj)                        (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_DPARAM,GstDParam))
 #define GST_DPARAM_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_DPARAM,GstDParam))
@@ -40,6 +40,7 @@ extern "C" {
 #define GST_DPARAM_PARENT(dparam)                       (GST_OBJECT_PARENT(dparam))
 #define GST_DPARAM_VALUE(dparam)                                ((dparam)->value)
 #define GST_DPARAM_SPEC(dparam)                                 ((dparam)->spec)
+#define GST_DPARAM_MANAGER(dparam)                              ((dparam)->manager)
 #define GST_DPARAM_TYPE(dparam)                                 ((dparam)->type)
 
 #define GST_DPARAM_LOCK(dparam)                (g_mutex_lock((dparam)->lock))
@@ -78,9 +79,7 @@ typedef enum {
   GST_DPARAM_FOUND_CLOSEST,
 } GstDParamSearchResult;
 
-typedef struct _GstDParam GstDParam;
 typedef struct _GstDParamClass GstDParamClass;
-typedef struct _GstDParamSpec GstDParamSpec;
 
 typedef GValue** (*GstDParamInsertPointFunction) (GstDParam *dparam, guint64 timestamp);
 typedef void (*GstDParamRemovePointFunction) (GstDParam *dparam, GValue** point);
@@ -102,6 +101,7 @@ struct _GstDParam {
        
        GMutex *lock;
        GValue *value;
+       GstDParamManager *manager;
        GstDParamSpec *spec;
        GValue **point;
        GType type;
@@ -129,7 +129,8 @@ struct _GstDParamSpec {
 
 GType gst_dparam_get_type (void);
 GstDParam* gst_dparam_new (GType type);
-void gst_dparam_attach (GstDParam *dparam, GstObject *parent, GValue *value, GstDParamSpec *spec);
+void gst_dparam_attach (GstDParam *dparam, GstDParamManager *manager, GValue *value, GstDParamSpec *spec);
+void gst_dparam_detach (GstDParam *dparam);
 GValue** gst_dparam_new_value_array(GType type, ...);
 void gst_dparam_set_value_from_string(GValue *value, const gchar *value_str);
 
diff --git a/libs/control/gstdparamcommon.h b/libs/control/gstdparamcommon.h
new file mode 100644 (file)
index 0000000..96c388b
--- /dev/null
@@ -0,0 +1,37 @@
+/* GStreamer
+ * Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
+ *
+ * gstdparamcommon.h: Dynamic Parameter common header
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_DPCOMMON_H__
+#define __GST_DPCOMMON_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+typedef struct _GstDParam GstDParam;
+typedef struct _GstDParamSpec GstDParamSpec;
+typedef struct _GstDParamManager GstDParamManager;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __GST_DPCOMMON_H__ */
index efba373..de03640 100644 (file)
@@ -27,6 +27,7 @@ static GHashTable *_element_registry;
 
 static void gst_dpman_class_init (GstDParamManagerClass *klass);
 static void gst_dpman_init (GstDParamManager *dpman);
+static void gst_dpman_dispose (GObject *object);
 static GstDParamWrapper* gst_dpman_new_wrapper(GstDParamManager *dpman, gchar *dparam_name, GType type, GstDPMUpdateMethod update_method);
 static GstDParamWrapper* gst_dpman_get_wrapper(GstDParamManager *dpman, gchar *dparam_name);
 static void gst_dpman_state_change (GstElement *element, gint state, GstDParamManager *dpman);
@@ -35,6 +36,12 @@ static guint gst_dpman_preprocess_synchronous(GstDParamManager *dpman, guint fra
 static guint gst_dpman_preprocess_noop(GstDParamManager *dpman, guint frames, gint64 timestamp);
 static guint gst_dpman_process_noop(GstDParamManager *dpman, guint frame_count);
 
+void 
+_gst_dpman_initialize()
+{
+       _element_registry = g_hash_table_new(NULL,NULL);
+}
+
 GType
 gst_dpman_get_type (void)
 {
@@ -65,9 +72,9 @@ gst_dpman_class_init (GstDParamManagerClass *klass)
 
        gstobject_class = (GstObjectClass*) klass;
        gobject_class = (GObjectClass*) klass;
+       gobject_class->dispose = gst_dpman_dispose;
 
        klass->modes = g_hash_table_new(g_str_hash,g_str_equal);
-       _element_registry = g_hash_table_new(NULL,NULL);
 
        gst_dpman_register_mode (klass, "synchronous", 
                               gst_dpman_preprocess_synchronous, gst_dpman_process_noop, NULL, NULL);
@@ -114,6 +121,15 @@ gst_dpman_new (gchar *name, GstElement *parent)
        return dpman;
 }
 
+
+static void
+gst_dpman_dispose (GObject *object)
+{
+       GstDParamManager *dpman = GST_DPMAN(object);
+       
+
+}
+
 /**
  * gst_dpman_add_required_dparam_callback:
  * @dpman: GstDParamManager instance
@@ -268,19 +284,19 @@ gst_dpman_attach_dparam (GstDParamManager *dpman, gchar *dparam_name, GstDParam
        g_return_val_if_fail(dpwrap->value != NULL, FALSE);
 
        dpwrap->dparam = dparam;
-       gst_dparam_attach(dparam, GST_OBJECT(dpman), dpwrap->value, dpwrap->spec);
+       gst_dparam_attach(dparam, dpman, dpwrap->value, dpwrap->spec);
 
        return TRUE;
 }
 
 /**
- * gst_dpman_dettach_dparam:
+ * gst_dpman_detach_dparam:
  * @dpman: GstDParamManager instance
  * @dparam_name: the name of a parameter with a previously attached GstDParam
  *
  */
 void 
-gst_dpman_dettach_dparam (GstDParamManager *dpman, gchar *dparam_name)
+gst_dpman_detach_dparam (GstDParamManager *dpman, gchar *dparam_name)
 {
        GstDParamWrapper* dpwrap;
 
@@ -292,10 +308,7 @@ gst_dpman_dettach_dparam (GstDParamManager *dpman, gchar *dparam_name)
 
        g_return_if_fail(dpwrap);
        
-       GST_DPARAM_VALUE(dpwrap->dparam) = NULL;
-       GST_DPARAM_NAME(dpwrap->dparam) = NULL;
-       gst_object_unparent (GST_OBJECT(dpwrap->dparam));
-
+       gst_dparam_detach(dpwrap->dparam);
        dpwrap->dparam = NULL;
        
 }
@@ -442,6 +455,12 @@ gst_dpman_set_mode(GstDParamManager *dpman, gchar *modename)
        
        mode = g_hash_table_lookup(oclass->modes, modename);
        g_return_val_if_fail (mode != NULL, FALSE);
+       
+       if (GST_DPMAN_MODE(dpman) == mode) {
+               GST_DEBUG(GST_CAT_PARAMS, "mode %s already set\n", modename);
+               return TRUE;
+       }
+       
        GST_DEBUG(GST_CAT_PARAMS, "setting mode to %s\n", modename);
        if (GST_DPMAN_MODE(dpman) && GST_DPMAN_TEARDOWNFUNC(dpman)){
                GST_DPMAN_TEARDOWNFUNC(dpman)(dpman);
@@ -491,7 +510,6 @@ gst_dpman_get_manager (GstElement *parent)
        g_return_val_if_fail (GST_IS_ELEMENT (parent), NULL);
        
        dpman = (GstDParamManager*)g_hash_table_lookup(_element_registry, parent);
-       g_return_val_if_fail (dpman != NULL, NULL);
        return dpman;
 }
 
index e8799e6..59171ac 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <gst/gstobject.h>
 #include <gst/gstprops.h>
+#include <libs/control/gstdparamcommon.h>
 #include <libs/control/gstdparam.h>
 
 #ifdef __cplusplus
@@ -52,7 +53,6 @@ typedef enum {
   GST_DPMAN_ARRAY,
 } GstDPMUpdateMethod;
 
-typedef struct _GstDParamManager GstDParamManager;
 typedef struct _GstDParamManagerClass GstDParamManagerClass;
 typedef struct _GstDPMMode GstDPMMode;
 typedef struct _GstDParamWrapper GstDParamWrapper;
@@ -118,6 +118,7 @@ struct _GstDParamWrapper {
                                
 #define GST_DPMAN_DO_UPDATE(dpwrap) ((dpwrap->update_func)(dpwrap->value, dpwrap->update_data))
 
+void _gst_dpman_initialize();
 GType gst_dpman_get_type (void);
 GstDParamManager* gst_dpman_new (gchar *name, GstElement *parent);
 void gst_dpman_set_parent (GstDParamManager *dpman, GstElement *parent);
@@ -138,7 +139,7 @@ gboolean gst_dpman_add_required_dparam_array (GstDParamManager *dpman,
                                               gpointer update_data);
 void gst_dpman_remove_required_dparam (GstDParamManager *dpman, gchar *dparam_name);
 gboolean gst_dpman_attach_dparam (GstDParamManager *dpman, gchar *dparam_name, GstDParam *dparam);
-void gst_dpman_dettach_dparam (GstDParamManager *dpman, gchar *dparam_name);                         
+void gst_dpman_detach_dparam (GstDParamManager *dpman, gchar *dparam_name);                         
 GstDParam* gst_dpman_get_dparam(GstDParamManager *dpman, gchar *name);
 GType gst_dpman_get_dparam_type (GstDParamManager *dpman, gchar *name);