docs: fix problems introduced by c068b225fef5a9bf0
[platform/upstream/gstreamer.git] / gst / gstpreset.c
index a30d2e6..6f51447 100644 (file)
@@ -15,8 +15,8 @@
  *
  * 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 /**
  * SECTION:gstpreset
  *      wide
  *     - can we use a lock inside a names shared memory segment?
  *
- * - need to add support for GstChildProxy
- *   we can do this in a next iteration, the format is flexible enough
- *   http://www.buzztard.org/index.php/Preset_handling_interface
- *
  * - should there be a 'preset-list' property to get the preset list
  *   (and to connect a notify:: to to listen for changes)
  *   we could use gnome_vfs_monitor_add() to monitor the user preset_file.
  * - should there be a 'preset-name' property so that we can set a preset via
  *   gst-launch, or should we handle this with special syntax in gst-launch:
  *   gst-launch element preset:<preset-name> property=value ...
- *   - this would alloow to hanve preset-bundles too (a preset on bins that
+ *   - this would allow to have preset-bundles too (a preset on bins that
  *     specifies presets for children
- *
- * - GstChildProxy suport
- *   - if we stick with GParamSpec **_list_properties()
- *     we need to use g_param_spec_set_qdata() to specify the instance on each GParamSpec
- *     OBJECT_LOCK(obj);  // ChildProxy needs GstIterator support
- *     num=gst_child_proxy_get_children_count(obj);
- *     for(i=0;i<num;i++) {
- *       child=gst_child_proxy_get_child_by_index(obj,i);
- *       // v1 ----
- *       g_object_class_list_properties(child,&num);
- *       // foreach prop
- *       //   g_param_spec_set_qdata(prop, quark, (gpointer)child);
- *       //   add to result
- *       // v2 ----
- *       // children have to implement preset-iface too tag the returned GParamSpec* with the owner
- *       props=gst_preset_list_properties(child);
- *       // add props to result
- *     }
- *     OBJECT_UNLOCK(obj);
- *
  */
 
 #include "gst_private.h"
 
 #include "gstpreset.h"
+#include "gstchildproxy.h"
 #include "gstinfo.h"
 #include "gstvalue.h"
 
 #endif
 #include <glib/gstdio.h>
 
+#ifdef G_OS_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+extern HMODULE _priv_gst_dll_handle;
+#endif
+
 #define GST_CAT_DEFAULT preset_debug
 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
 
@@ -119,7 +103,7 @@ static GQuark preset_quark = 0;
 
 /*static GQuark property_list_quark = 0;*/
 
-/* the application can set a custom path that is checked in addition to standart
+/* the application can set a custom path that is checked in addition to standard
  * system and user dirs. This helps to develop new presets first local to the
  * application.
  */
@@ -149,7 +133,7 @@ preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
   gchar *preset_path;
   const gchar *element_name;
 
-  /* we use the element name when we must contruct the paths */
+  /* we use the element name when we must construct the paths */
   element_name = G_OBJECT_TYPE_NAME (preset);
   GST_INFO_OBJECT (preset, "element_name: '%s'", element_name);
 
@@ -160,7 +144,7 @@ preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
 
       /* user presets go in  user's XDG data directory. */
       preset_dir = g_build_filename (g_get_user_data_dir (),
-          "gstreamer-" GST_MAJORMINOR, "presets", NULL);
+          "gstreamer-" GST_API_VERSION, "presets", NULL);
       GST_INFO_OBJECT (preset, "user_preset_dir: '%s'", preset_dir);
       preset_path =
           g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs", preset_dir,
@@ -197,9 +181,19 @@ preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
     if (!(preset_path = g_type_get_qdata (type, preset_system_path_quark))) {
       gchar *preset_dir;
 
-      /* system presets in '$GST_DATADIR/gstreamer-0.10/presets/GstAudioPanorama.prs' */
-      preset_dir = g_build_filename (GST_DATADIR, "gstreamer-" GST_MAJORMINOR,
+      /* system presets in '$GST_DATADIR/gstreamer-1.0/presets/GstAudioPanorama.prs' */
+#ifdef G_OS_WIN32
+      gchar *basedir = g_win32_get_package_installation_directory_of_module (_priv_gst_dll_handle);
+      preset_dir = g_build_filename (basedir,
+                                     "share",
+                                     "gstreamer-" GST_API_VERSION,
+                                     "presets",
+                                     NULL);
+      g_free (basedir);
+#else
+      preset_dir = g_build_filename (GST_DATADIR, "gstreamer-" GST_API_VERSION,
           "presets", NULL);
+#endif
       GST_INFO_OBJECT (preset, "system_preset_dir: '%s'", preset_dir);
       preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs",
           preset_dir, element_name);
@@ -236,7 +230,7 @@ preset_parse_version (const gchar * str_version)
 
   /* parse version (e.g. 0.10.15.1) to guint64 */
   num = sscanf (str_version, "%u.%u.%u.%u", &major, &minor, &micro, &nano);
-  /* make sure we have atleast "major.minor" */
+  /* make sure we have at least "major.minor" */
   if (num > 1) {
     guint64 version;
 
@@ -413,7 +407,6 @@ preset_get_keyfile (GstPreset * preset)
         if (presets)
           g_key_file_free (presets);
         presets = in_user;
-        version = version_user;
       }
     }
 
@@ -486,42 +479,66 @@ static gchar **
 gst_preset_default_get_property_names (GstPreset * preset)
 {
   GParamSpec **props;
-  guint i, j, n_props;
+  guint i, j = 0, n_props;
   GObjectClass *gclass;
-  gchar **result;
+  gboolean is_child_proxy;
+  gchar **result = NULL;
 
   gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
+  is_child_proxy = GST_IS_CHILD_PROXY (preset);
 
-  /* get a list of normal properties. 
-   * FIXME, change this for childproxy support. */
+  /* get a list of object properties */
   props = g_object_class_list_properties (gclass, &n_props);
-  if (!props)
-    goto no_properties;
-
-  /* allocate array big enough to hold the worst case, including a terminating
-   * NULL pointer. */
-  result = g_new (gchar *, n_props + 1);
-
-  /* now filter out the properties that we can use for presets */
-  GST_DEBUG_OBJECT (preset, "  filtering properties: %u", n_props);
-  for (i = j = 0; i < n_props; i++) {
-    if (preset_skip_property (props[i]))
-      continue;
-
-    /* copy and increment out pointer */
-    result[j++] = g_strdup (props[i]->name);
+  if (props) {
+    /* allocate array big enough to hold the worst case, including a terminating
+     * NULL pointer. */
+    result = g_new (gchar *, n_props + 1);
+
+    /* now filter out the properties that we can use for presets */
+    GST_DEBUG_OBJECT (preset, "  filtering properties: %u", n_props);
+    for (i = 0; i < n_props; i++) {
+      if (preset_skip_property (props[i]))
+        continue;
+      GST_DEBUG_OBJECT (preset, "    using: %s", props[i]->name);
+      result[j++] = g_strdup (props[i]->name);
+    }
+    g_free (props);
   }
-  result[j] = NULL;
-  g_free (props);
 
-  return result;
-
-  /* ERRORS */
-no_properties:
-  {
+  if (is_child_proxy) {
+    guint c, n_children;
+    GObject *child;
+
+    n_children = gst_child_proxy_get_children_count ((GstChildProxy *) preset);
+    for (c = 0; c < n_children; c++) {
+      child = gst_child_proxy_get_child_by_index ((GstChildProxy *) preset, c);
+      gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (child));
+
+      props = g_object_class_list_properties (gclass, &n_props);
+      if (props) {
+        /* resize property name array */
+        result = g_renew (gchar *, result, j + n_props + 1);
+
+        /* now filter out the properties that we can use for presets */
+        GST_DEBUG_OBJECT (preset, "  filtering properties: %u", n_props);
+        for (i = 0; i < n_props; i++) {
+          if (preset_skip_property (props[i]))
+            continue;
+          GST_DEBUG_OBJECT (preset, "    using: %s::%s",
+              GST_OBJECT_NAME (child), props[i]->name);
+          result[j++] = g_strdup_printf ("%s::%s", GST_OBJECT_NAME (child),
+              props[i]->name);
+        }
+        g_free (props);
+      }
+    }
+  }
+  if (!result) {
     GST_INFO_OBJECT (preset, "object has no properties");
-    return NULL;
+  } else {
+    result[j] = NULL;
   }
+  return result;
 }
 
 /* load the presets of @name for the instance @preset. Returns %FALSE if something
@@ -533,6 +550,7 @@ gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
   gchar **props;
   guint i;
   GObjectClass *gclass;
+  gboolean is_child_proxy;
 
   /* get the presets from the type */
   if (!(presets = preset_get_keyfile (preset)))
@@ -549,13 +567,14 @@ gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
     goto no_properties;
 
   gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
+  is_child_proxy = GST_IS_CHILD_PROXY (preset);
 
   /* for each of the property names, find the preset parameter and try to
    * configure the property with its value */
   for (i = 0; props[i]; i++) {
     gchar *str;
     GValue gvalue = { 0, };
-    GParamSpec *property;
+    GParamSpec *property = NULL;
 
     /* check if we have a settings for this element property */
     if (!(str = g_key_file_get_value (presets, name, props[i], NULL))) {
@@ -567,8 +586,13 @@ gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
     GST_DEBUG_OBJECT (preset, "setting value '%s' for property '%s'", str,
         props[i]);
 
-    /* FIXME, change for childproxy to get the property and element.  */
-    if (!(property = g_object_class_find_property (gclass, props[i]))) {
+    if (is_child_proxy) {
+      gst_child_proxy_lookup ((GstChildProxy *) preset, props[i], NULL,
+          &property);
+    } else {
+      property = g_object_class_find_property (gclass, props[i]);
+    }
+    if (!property) {
       /* the parameter was in the keyfile, the element said it supported it but
        * then the property was not found in the element. This should not happen. */
       GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
@@ -580,8 +604,12 @@ gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
      * the object property */
     g_value_init (&gvalue, property->value_type);
     if (gst_value_deserialize (&gvalue, str)) {
-      /* FIXME, change for childproxy support */
-      g_object_set_property (G_OBJECT (preset), props[i], &gvalue);
+      if (is_child_proxy) {
+        gst_child_proxy_set_property ((GstChildProxy *) preset, props[i],
+            &gvalue);
+      } else {
+        g_object_set_property ((GObject *) preset, props[i], &gvalue);
+      }
     } else {
       GST_WARNING_OBJECT (preset,
           "deserialization of value '%s' for property '%s' failed", str,
@@ -701,6 +729,7 @@ gst_preset_default_save_preset (GstPreset * preset, const gchar * name)
   gchar **props;
   guint i;
   GObjectClass *gclass;
+  gboolean is_child_proxy;
 
   GST_INFO_OBJECT (preset, "saving new preset: %s", name);
 
@@ -713,16 +742,22 @@ gst_preset_default_save_preset (GstPreset * preset, const gchar * name)
     goto no_properties;
 
   gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
+  is_child_proxy = GST_IS_CHILD_PROXY (preset);
 
   /* loop over the object properties and store the property value in the
    * keyfile */
   for (i = 0; props[i]; i++) {
     GValue gvalue = { 0, };
     gchar *str;
-    GParamSpec *property;
+    GParamSpec *property = NULL;
 
-    /* FIXME, change for childproxy to get the property and element.  */
-    if (!(property = g_object_class_find_property (gclass, props[i]))) {
+    if (is_child_proxy) {
+      gst_child_proxy_lookup ((GstChildProxy *) preset, props[i], NULL,
+          &property);
+    } else {
+      property = g_object_class_find_property (gclass, props[i]);
+    }
+    if (!property) {
       /* the element said it supported the property but then it does not have
        * that property. This should not happen. */
       GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
@@ -730,8 +765,12 @@ gst_preset_default_save_preset (GstPreset * preset, const gchar * name)
     }
 
     g_value_init (&gvalue, property->value_type);
-    /* FIXME, change for childproxy */
-    g_object_get_property (G_OBJECT (preset), props[i], &gvalue);
+    if (is_child_proxy) {
+      gst_child_proxy_get_property ((GstChildProxy *) preset, props[i],
+          &gvalue);
+    } else {
+      g_object_get_property ((GObject *) preset, props[i], &gvalue);
+    }
 
     if ((str = gst_value_serialize (&gvalue))) {
       g_key_file_set_string (presets, name, props[i], (gpointer) str);
@@ -918,9 +957,7 @@ no_presets:
  * Get a copy of preset names as a NULL terminated string array.
  *
  * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*):
- *     list with names, ue g_strfreev() after usage.
- *
- * Since: 0.10.20
+ *     list with names, use g_strfreev() after usage.
  */
 gchar **
 gst_preset_get_preset_names (GstPreset * preset)
@@ -938,8 +975,6 @@ gst_preset_get_preset_names (GstPreset * preset)
  *
  * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*): an
  *   array of property names which should be freed with g_strfreev() after use.
- *
- * Since: 0.10.20
  */
 gchar **
 gst_preset_get_property_names (GstPreset * preset)
@@ -957,8 +992,6 @@ gst_preset_get_property_names (GstPreset * preset)
  * Load the given preset.
  *
  * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_load_preset (GstPreset * preset, const gchar * name)
@@ -978,8 +1011,6 @@ gst_preset_load_preset (GstPreset * preset, const gchar * name)
  * is already a preset by this @name it will be overwritten.
  *
  * Returns: %TRUE for success, %FALSE
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_save_preset (GstPreset * preset, const gchar * name)
@@ -1000,8 +1031,6 @@ gst_preset_save_preset (GstPreset * preset, const gchar * name)
  * overwritten.
  *
  * Returns: %TRUE for success, %FALSE if e.g. there is no preset with @old_name
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_rename_preset (GstPreset * preset, const gchar * old_name,
@@ -1023,8 +1052,6 @@ gst_preset_rename_preset (GstPreset * preset, const gchar * old_name,
  * Delete the given preset.
  *
  * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_delete_preset (GstPreset * preset, const gchar * name)
@@ -1047,8 +1074,6 @@ gst_preset_delete_preset (GstPreset * preset, const gchar * name)
  * @value will unset an existing value.
  *
  * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_set_meta (GstPreset * preset, const gchar * name, const gchar * tag,
@@ -1073,8 +1098,6 @@ gst_preset_set_meta (GstPreset * preset, const gchar * name, const gchar * tag,
  *
  * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
  * or no value for the given @tag
- *
- * Since: 0.10.20
  */
 gboolean
 gst_preset_get_meta (GstPreset * preset, const gchar * name, const gchar * tag,
@@ -1097,8 +1120,6 @@ gst_preset_get_meta (GstPreset * preset, const gchar * name, const gchar * tag,
  * system presets.
  *
  * Returns: %TRUE for success, %FALSE if the dir already has been set
- *
- * Since: 0.10.36
  */
 gboolean
 gst_preset_set_app_dir (const gchar * app_dir)
@@ -1119,8 +1140,6 @@ gst_preset_set_app_dir (const gchar * app_dir)
  * application.
  *
  * Returns: the directory or %NULL, don't free or modify the string
- *
- * Since: 0.10.36
  */
 const gchar *
 gst_preset_get_app_dir (void)