2 * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
4 * gstpreset.c: helper interface for element presets
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 * @short_description: helper interface for element presets
25 * This interface offers methods to query and manipulate parameter preset sets.
26 * A preset is a bunch of property settings, together with meta data and a name.
27 * The name of a preset serves as key for subsequent method calls to manipulate
29 * All instances of one type will share the list of presets. The list is created
30 * on demand, if presets are not used, the list is not created.
32 * The interface comes with a default implementation that serves most plugins.
33 * Wrapper plugins will override most methods to implement support for the
34 * native preset format of those wrapped plugins.
35 * One method that is useful to be overridden is gst_preset_get_property_names().
36 * With that one can control which properties are saved and in which order.
40 * - we need to avoid two instances writing the preset file
41 * -> flock(fileno()), http://www.ecst.csuchico.edu/~beej/guide/ipc/flock.html
43 * -> better save the new file to a tempfile and then rename?
44 * - we like to know when any other instance makes changes to the keyfile
45 * - then ui can be updated
46 * - and we make sure that we don't lose edits
47 * -> its the same problem actually, once for inside a process, once system-
49 * - can we use a lock inside a names shared memory segment?
51 * - need to add support for GstChildProxy
52 * we can do this in a next iteration, the format is flexible enough
53 * http://www.buzztard.org/index.php/Preset_handling_interface
55 * - should there be a 'preset-list' property to get the preset list
56 * (and to connect a notify:: to to listen for changes)
57 * we could use gnome_vfs_monitor_add() to monitor the user preset_file.
59 * - should there be a 'preset-name' property so that we can set a preset via
60 * gst-launch, or should we handle this with special syntax in gst-launch:
61 * gst-launch element preset:<preset-name> property=value ...
62 * - this would alloow to hanve preset-bundles too (a preset on bins that
63 * specifies presets for children
65 * - GstChildProxy suport
66 * - if we stick with GParamSpec **_list_properties()
67 * we need to use g_param_spec_set_qdata() to specify the instance on each GParamSpec
68 * OBJECT_LOCK(obj); // ChildProxy needs GstIterator support
69 * num=gst_child_proxy_get_children_count(obj);
70 * for(i=0;i<num;i++) {
71 * child=gst_child_proxy_get_child_by_index(obj,i);
73 * g_object_class_list_properties(child,&num);
75 * // g_param_spec_set_qdata(prop, quark, (gpointer)child);
78 * // children have to implement preset-iface too tag the returned GParamSpec* with the owner
79 * props=gst_preset_list_properties(child);
80 * // add props to result
86 #include "gst_private.h"
88 #include "gstpreset.h"
95 #include <glib/gstdio.h>
97 #define GST_CAT_DEFAULT preset_debug
98 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
100 /* defines for keyfile usage, this group contains the element type name and
101 * version these presets belong to. */
102 #define PRESET_HEADER "_presets_"
104 /* keys of the preset header section */
105 #define PRESET_HEADER_ELEMENT_NAME "element-name"
106 #define PRESET_HEADER_VERSION "version"
108 static GQuark preset_user_path_quark = 0;
109 static GQuark preset_system_path_quark = 0;
110 static GQuark preset_quark = 0;
112 /*static GQuark property_list_quark = 0;*/
114 /* default iface implementation */
116 static gboolean gst_preset_default_save_presets_file (GstPreset * preset);
120 * @preset: a #GObject that implements #GstPreset
121 * @preset_user_path: location for path or %NULL
122 * @preset_system_path: location for path or %NULL
124 * Fetch the preset_path for user local and system wide settings. Don't free
127 * Returns: %FALSE if no paths could be found.
130 preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
131 const gchar ** preset_system_path)
133 GType type = G_TYPE_FROM_INSTANCE (preset);
135 const gchar *element_name;
137 /* we use the element name when we must contruct the paths */
138 element_name = G_OBJECT_TYPE_NAME (preset);
139 GST_INFO_OBJECT (preset, "element_name: '%s'", element_name);
141 if (preset_user_path) {
142 /* preset user path requested, see if we have it cached in the qdata */
143 if (!(preset_path = g_type_get_qdata (type, preset_user_path_quark))) {
146 /* user presets go in user's XDG data directory. */
147 preset_dir = g_build_filename (g_get_user_data_dir (),
148 "gstreamer-" GST_MAJORMINOR, "presets", NULL);
149 GST_INFO_OBJECT (preset, "user_preset_dir: '%s'", preset_dir);
151 g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs", preset_dir,
153 GST_INFO_OBJECT (preset, "user_preset_path: '%s'", preset_path);
155 g_mkdir_with_parents (preset_dir, 0755);
158 /* cache the preset path to the type */
159 g_type_set_qdata (type, preset_user_path_quark, preset_path);
161 *preset_user_path = preset_path;
164 if (preset_system_path) {
165 /* preset system path requested, see if we have it cached in the qdata */
166 if (!(preset_path = g_type_get_qdata (type, preset_system_path_quark))) {
169 /* system presets in '$GST_DATADIR/gstreamer-0.10/presets/GstAudioPanorama.prs' */
170 preset_dir = g_build_filename (GST_DATADIR, "gstreamer-" GST_MAJORMINOR,
172 GST_INFO_OBJECT (preset, "system_preset_dir: '%s'", preset_dir);
173 preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs",
174 preset_dir, element_name);
175 GST_INFO_OBJECT (preset, "system_preset_path: '%s'", preset_path);
177 g_mkdir_with_parents (preset_dir, 0755);
180 /* cache the preset path to the type */
181 g_type_set_qdata (type, preset_system_path_quark, preset_path);
183 *preset_system_path = preset_path;
189 preset_skip_property (GParamSpec * property)
191 if (((property->flags & G_PARAM_READWRITE) != G_PARAM_READWRITE) ||
192 (property->flags & G_PARAM_CONSTRUCT_ONLY))
194 /* FIXME: skip GST_PARAM_NOT_PRESETABLE, see #522205 */
198 /* caller must free @preset_version after use */
200 preset_open_and_parse_header (GstPreset * preset, const gchar * preset_path,
201 gchar ** preset_version)
204 GError *error = NULL;
206 const gchar *element_name;
209 in = g_key_file_new ();
211 res = g_key_file_load_from_file (in, preset_path,
212 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error);
213 if (!res || error != NULL)
216 /* element type name and preset name must match or we are dealing with a wrong
218 element_name = G_OBJECT_TYPE_NAME (preset);
220 g_key_file_get_value (in, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME,
223 if (!name || strcmp (name, element_name))
228 /* get the version now so that the caller can check it */
231 g_key_file_get_value (in, PRESET_HEADER, PRESET_HEADER_VERSION, NULL);
238 GST_WARNING_OBJECT (preset, "Unable to read preset file %s: %s",
239 preset_path, error->message);
240 g_error_free (error);
241 g_key_file_free (in);
246 GST_WARNING_OBJECT (preset,
247 "Wrong element name in preset file %s. Expected %s, got %s",
248 preset_path, element_name, GST_STR_NULL (name));
250 g_key_file_free (in);
256 preset_parse_version (const gchar * str_version)
258 gint major, minor, micro, nano, num;
260 major = minor = micro = nano = 0;
262 /* parse version (e.g. 0.10.15.1) to guint64 */
263 num = sscanf (str_version, "%d.%d.%d.%d", &major, &minor, µ, &nano);
264 /* make sure we have atleast "major.minor" */
268 version = ((((major << 8 | minor) << 8) | micro) << 8) | nano;
269 GST_DEBUG ("version %s -> %" G_GUINT64_FORMAT, str_version, version);
272 return G_GUINT64_CONSTANT (0);
276 preset_merge (GKeyFile * system, GKeyFile * user)
279 gchar **groups, **keys;
280 gsize i, j, num_groups, num_keys;
282 /* copy file comment if there is any */
283 if ((str = g_key_file_get_comment (user, NULL, NULL, NULL))) {
284 g_key_file_set_comment (system, NULL, NULL, str, NULL);
288 /* get groups in user and copy into system */
289 groups = g_key_file_get_groups (user, &num_groups);
290 for (i = 0; i < num_groups; i++) {
291 /* copy group comment if there is any */
292 if ((str = g_key_file_get_comment (user, groups[i], NULL, NULL))) {
293 g_key_file_set_comment (system, groups[i], NULL, str, NULL);
297 /* ignore private groups */
298 if (groups[i][0] == '_')
301 /* if group already exists in system, remove and re-add keys from user */
302 if (g_key_file_has_group (system, groups[i])) {
303 g_key_file_remove_group (system, groups[i], NULL);
306 keys = g_key_file_get_keys (user, groups[i], &num_keys, NULL);
307 for (j = 0; j < num_keys; j++) {
308 /* copy key comment if there is any */
309 if ((str = g_key_file_get_comment (user, groups[i], keys[j], NULL))) {
310 g_key_file_set_comment (system, groups[i], keys[j], str, NULL);
313 str = g_key_file_get_value (user, groups[i], keys[j], NULL);
314 g_key_file_set_value (system, groups[i], keys[j], str);
322 /* reads the user and system presets files and merges them together. This
323 * function caches the GKeyFile on the element type. If there is no existing
324 * preset file, a new in-memory GKeyFile will be created. */
326 preset_get_keyfile (GstPreset * preset)
329 GType type = G_TYPE_FROM_INSTANCE (preset);
331 /* first see if the have a cached version for the type */
332 if (!(presets = g_type_get_qdata (type, preset_quark))) {
333 const gchar *preset_user_path, *preset_system_path;
334 gchar *str_version_user = NULL, *str_version_system = NULL;
335 gboolean updated_from_system = FALSE;
336 GKeyFile *in_user, *in_system;
338 preset_get_paths (preset, &preset_user_path, &preset_system_path);
340 /* try to load the user and system presets, we do this to get the versions
342 in_user = preset_open_and_parse_header (preset, preset_user_path,
344 in_system = preset_open_and_parse_header (preset, preset_system_path,
345 &str_version_system);
347 /* compare version to check for merge */
349 /* keep system presets if there is no user preset or when the system
350 * version is higher than the user version. */
353 } else if (preset_parse_version (str_version_system) >
354 preset_parse_version (str_version_user)) {
356 updated_from_system = TRUE;
360 if (updated_from_system) {
361 /* merge user on top of system presets */
362 preset_merge (presets, in_user);
363 g_key_file_free (in_user);
365 /* keep user presets */
369 if (!in_user && !in_system) {
370 /* we did not load a user or system presets file, create a new one */
371 presets = g_key_file_new ();
372 g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME,
373 G_OBJECT_TYPE_NAME (preset));
376 g_free (str_version_user);
377 g_free (str_version_system);
379 /* attach the preset to the type */
380 g_type_set_qdata (type, preset_quark, (gpointer) presets);
382 if (updated_from_system) {
383 gst_preset_default_save_presets_file (preset);
389 /* get a list of all supported preset names for an element */
391 gst_preset_default_get_preset_names (GstPreset * preset)
397 /* get the presets from the type */
398 if (!(presets = preset_get_keyfile (preset)))
401 /* get the groups, which are also the preset names */
402 if (!(groups = g_key_file_get_groups (presets, &num_groups)))
405 /* remove all private group names starting with '_' from the array */
406 for (i = 0; i < num_groups; i++) {
407 if (groups[i][0] == '_') {
408 /* free private group */
410 /* move last element of list down */
412 /* move last element into removed element */
413 groups[i] = groups[num_groups];
414 groups[num_groups] = NULL;
417 /* sort the array now */
418 g_qsort_with_data (groups, num_groups, sizeof (gchar *),
419 (GCompareDataFunc) strcmp, NULL);
426 GST_WARNING_OBJECT (preset, "Could not load presets");
431 GST_WARNING_OBJECT (preset, "Could not find preset groups");
436 /* get a list of all property names that are used for presets */
438 gst_preset_default_get_property_names (GstPreset * preset)
442 GObjectClass *gclass;
445 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
447 /* get a list of normal properties.
448 * FIXME, change this for childproxy support. */
449 props = g_object_class_list_properties (gclass, &n_props);
453 /* allocate array big enough to hold the worst case, including a terminating
455 result = g_new (gchar *, n_props + 1);
457 /* now filter out the properties that we can use for presets */
458 GST_DEBUG_OBJECT (preset, " filtering properties: %u", n_props);
459 for (i = j = 0; i < n_props; i++) {
460 if (preset_skip_property (props[i]))
463 /* copy and increment out pointer */
464 result[j++] = g_strdup (props[i]->name);
474 GST_INFO_OBJECT (preset, "object has no properties");
479 /* load the presets of @name for the instance @preset. Returns %FALSE if something
482 gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
487 GObjectClass *gclass;
489 /* get the presets from the type */
490 if (!(presets = preset_get_keyfile (preset)))
493 /* get the preset name */
494 if (!g_key_file_has_group (presets, name))
497 GST_DEBUG_OBJECT (preset, "loading preset : '%s'", name);
499 /* get the properties that we can configure in this element */
500 if (!(props = gst_preset_get_property_names (preset)))
503 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
505 /* for each of the property names, find the preset parameter and try to
506 * configure the property with its value */
507 for (i = 0; props[i]; i++) {
509 GValue gvalue = { 0, };
510 GParamSpec *property;
512 /* check if we have a settings for this element property */
513 if (!(str = g_key_file_get_value (presets, name, props[i], NULL))) {
514 /* the element has a property but the parameter is not in the keyfile */
515 GST_WARNING_OBJECT (preset, "parameter '%s' not in preset", props[i]);
519 GST_DEBUG_OBJECT (preset, "setting value '%s' for property '%s'", str,
522 /* FIXME, change for childproxy to get the property and element. */
523 if (!(property = g_object_class_find_property (gclass, props[i]))) {
524 /* the parameter was in the keyfile, the element said it supported it but
525 * then the property was not found in the element. This should not happen. */
526 GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
531 /* try to deserialize the property value from the keyfile and set it as
532 * the object property */
533 g_value_init (&gvalue, property->value_type);
534 if (gst_value_deserialize (&gvalue, str)) {
535 /* FIXME, change for childproxy support */
536 g_object_set_property (G_OBJECT (preset), props[i], &gvalue);
538 GST_WARNING_OBJECT (preset,
539 "deserialization of value '%s' for property '%s' failed", str,
542 g_value_unset (&gvalue);
552 GST_WARNING_OBJECT (preset, "no presets");
557 GST_WARNING_OBJECT (preset, "no preset named '%s'", name);
562 GST_INFO_OBJECT (preset, "no properties");
567 /* save the presets file. A copy of the existing presets file is stored in a
570 gst_preset_default_save_presets_file (GstPreset * preset)
573 const gchar *preset_path;
574 GError *error = NULL;
575 gchar *bak_file_name;
576 gboolean backup = TRUE;
580 preset_get_paths (preset, &preset_path, NULL);
582 /* get the presets from the type */
583 if (!(presets = preset_get_keyfile (preset)))
586 GST_DEBUG_OBJECT (preset, "saving preset file: '%s'", preset_path);
588 /* create backup if possible */
589 bak_file_name = g_strdup_printf ("%s.bak", preset_path);
590 if (g_file_test (bak_file_name, G_FILE_TEST_EXISTS)) {
591 if (g_unlink (bak_file_name)) {
593 GST_INFO_OBJECT (preset, "cannot remove old backup file : %s",
598 if (g_rename (preset_path, bak_file_name)) {
599 GST_INFO_OBJECT (preset, "cannot backup file : %s -> %s", preset_path,
603 g_free (bak_file_name);
605 /* update gstreamer version */
606 g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_VERSION,
609 /* get new contents, wee need this to save it */
610 if (!(data = g_key_file_to_data (presets, &data_size, &error)))
614 if (!g_file_set_contents (preset_path, data, data_size, &error))
624 GST_WARNING_OBJECT (preset,
625 "no presets, trying to unlink possibly existing preset file: '%s'",
627 g_unlink (preset_path);
632 GST_WARNING_OBJECT (preset, "can not get the keyfile contents: %s",
634 g_error_free (error);
640 GST_WARNING_OBJECT (preset, "Unable to store preset file %s: %s",
641 preset_path, error->message);
642 g_error_free (error);
648 /* save the preset with the given name */
650 gst_preset_default_save_preset (GstPreset * preset, const gchar * name)
655 GObjectClass *gclass;
657 GST_INFO_OBJECT (preset, "saving new preset: %s", name);
659 /* get the presets from the type */
660 if (!(presets = preset_get_keyfile (preset)))
663 /* take copies of current gobject properties from preset */
664 if (!(props = gst_preset_get_property_names (preset)))
667 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
669 /* loop over the object properties and store the property value in the
671 for (i = 0; props[i]; i++) {
672 GValue gvalue = { 0, };
674 GParamSpec *property;
676 /* FIXME, change for childproxy to get the property and element. */
677 if (!(property = g_object_class_find_property (gclass, props[i]))) {
678 /* the element said it supported the property but then it does not have
679 * that property. This should not happen. */
680 GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
684 g_value_init (&gvalue, property->value_type);
685 /* FIXME, change for childproxy */
686 g_object_get_property (G_OBJECT (preset), props[i], &gvalue);
688 if ((str = gst_value_serialize (&gvalue))) {
689 g_key_file_set_string (presets, name, props[i], (gpointer) str);
692 GST_WARNING_OBJECT (preset, "serialization for property '%s' failed",
695 g_value_unset (&gvalue);
697 GST_INFO_OBJECT (preset, " saved");
700 /* save updated version */
701 return gst_preset_default_save_presets_file (preset);
706 GST_WARNING_OBJECT (preset, "no presets");
711 GST_INFO_OBJECT (preset, "no properties");
716 /* copies all keys and comments from one group to another, deleting the old
719 gst_preset_default_rename_preset (GstPreset * preset, const gchar * old_name,
720 const gchar * new_name)
727 /* get the presets from the type */
728 if (!(presets = preset_get_keyfile (preset)))
731 if (!g_key_file_has_group (presets, old_name))
734 /* copy group comment if there is any */
735 if ((str = g_key_file_get_comment (presets, old_name, NULL, NULL))) {
736 g_key_file_set_comment (presets, new_name, NULL, str, NULL);
740 /* get all keys from the old group and copy them in the new group */
741 keys = g_key_file_get_keys (presets, old_name, &num_keys, NULL);
742 for (i = 0; i < num_keys; i++) {
743 /* copy key comment if there is any */
744 if ((str = g_key_file_get_comment (presets, old_name, keys[i], NULL))) {
745 g_key_file_set_comment (presets, new_name, keys[i], str, NULL);
749 str = g_key_file_get_value (presets, old_name, keys[i], NULL);
750 g_key_file_set_value (presets, new_name, keys[i], str);
755 /* remove old group */
756 g_key_file_remove_group (presets, old_name, NULL);
758 /* save updated version */
759 return gst_preset_default_save_presets_file (preset);
764 GST_WARNING_OBJECT (preset, "no presets");
769 GST_WARNING_OBJECT (preset, "no preset named %s", old_name);
774 /* delete a group from the keyfile */
776 gst_preset_default_delete_preset (GstPreset * preset, const gchar * name)
780 /* get the presets from the type */
781 if (!(presets = preset_get_keyfile (preset)))
785 if (!g_key_file_has_group (presets, name))
788 /* remove the group */
789 g_key_file_remove_group (presets, name, NULL);
791 /* save updated version */
792 return gst_preset_default_save_presets_file (preset);
797 GST_WARNING_OBJECT (preset, "no presets");
802 GST_WARNING_OBJECT (preset, "no preset named %s", name);
808 gst_preset_default_set_meta (GstPreset * preset, const gchar * name,
809 const gchar * tag, const gchar * value)
814 /* get the presets from the type */
815 if (!(presets = preset_get_keyfile (preset)))
818 key = g_strdup_printf ("_meta/%s", tag);
819 if (value && *value) {
820 g_key_file_set_value (presets, name, key, value);
822 g_key_file_remove_key (presets, name, key, NULL);
826 /* save updated keyfile */
827 return gst_preset_default_save_presets_file (preset);
832 GST_WARNING_OBJECT (preset, "no presets");
837 /* the caller must free @value after usage */
839 gst_preset_default_get_meta (GstPreset * preset, const gchar * name,
840 const gchar * tag, gchar ** value)
845 /* get the presets from the type */
846 if (!(presets = preset_get_keyfile (preset)))
849 key = g_strdup_printf ("_meta/%s", tag);
850 *value = g_key_file_get_value (presets, name, key, NULL);
858 GST_WARNING_OBJECT (preset, "no presets");
867 * gst_preset_get_preset_names:
868 * @preset: a #GObject that implements #GstPreset
870 * Get a copy of preset names as a NULL terminated string array.
872 * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*):
873 * list with names, ue g_strfreev() after usage.
878 gst_preset_get_preset_names (GstPreset * preset)
880 g_return_val_if_fail (GST_IS_PRESET (preset), NULL);
882 return (GST_PRESET_GET_INTERFACE (preset)->get_preset_names (preset));
886 * gst_preset_get_property_names:
887 * @preset: a #GObject that implements #GstPreset
889 * Get a the names of the GObject properties that can be used for presets.
891 * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*): an
892 * array of property names which should be freed with g_strfreev() after use.
897 gst_preset_get_property_names (GstPreset * preset)
899 g_return_val_if_fail (GST_IS_PRESET (preset), NULL);
901 return (GST_PRESET_GET_INTERFACE (preset)->get_property_names (preset));
905 * gst_preset_load_preset:
906 * @preset: a #GObject that implements #GstPreset
907 * @name: preset name to load
909 * Load the given preset.
911 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
916 gst_preset_load_preset (GstPreset * preset, const gchar * name)
918 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
919 g_return_val_if_fail (name, FALSE);
921 return (GST_PRESET_GET_INTERFACE (preset)->load_preset (preset, name));
925 * gst_preset_save_preset:
926 * @preset: a #GObject that implements #GstPreset
927 * @name: preset name to save
929 * Save the current object settings as a preset under the given name. If there
930 * is already a preset by this @name it will be overwritten.
932 * Returns: %TRUE for success, %FALSE
937 gst_preset_save_preset (GstPreset * preset, const gchar * name)
939 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
940 g_return_val_if_fail (name, FALSE);
942 return (GST_PRESET_GET_INTERFACE (preset)->save_preset (preset, name));
946 * gst_preset_rename_preset:
947 * @preset: a #GObject that implements #GstPreset
948 * @old_name: current preset name
949 * @new_name: new preset name
951 * Renames a preset. If there is already a preset by the @new_name it will be
954 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with @old_name
959 gst_preset_rename_preset (GstPreset * preset, const gchar * old_name,
960 const gchar * new_name)
962 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
963 g_return_val_if_fail (old_name, FALSE);
964 g_return_val_if_fail (new_name, FALSE);
966 return (GST_PRESET_GET_INTERFACE (preset)->rename_preset (preset, old_name,
971 * gst_preset_delete_preset:
972 * @preset: a #GObject that implements #GstPreset
973 * @name: preset name to remove
975 * Delete the given preset.
977 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
982 gst_preset_delete_preset (GstPreset * preset, const gchar * name)
984 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
985 g_return_val_if_fail (name, FALSE);
987 return (GST_PRESET_GET_INTERFACE (preset)->delete_preset (preset, name));
991 * gst_preset_set_meta:
992 * @preset: a #GObject that implements #GstPreset
994 * @tag: meta data item name
997 * Sets a new @value for an existing meta data item or adds a new item. Meta
998 * data @tag names can be something like e.g. "comment". Supplying %NULL for the
999 * @value will unset an existing value.
1001 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
1006 gst_preset_set_meta (GstPreset * preset, const gchar * name, const gchar * tag,
1007 const gchar * value)
1009 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
1010 g_return_val_if_fail (name, FALSE);
1011 g_return_val_if_fail (tag, FALSE);
1013 return GST_PRESET_GET_INTERFACE (preset)->set_meta (preset, name, tag, value);
1017 * gst_preset_get_meta:
1018 * @preset: a #GObject that implements #GstPreset
1019 * @name: preset name
1020 * @tag: meta data item name
1021 * @value: (out callee-allocates): value
1023 * Gets the @value for an existing meta data @tag. Meta data @tag names can be
1024 * something like e.g. "comment". Returned values need to be released when done.
1026 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
1027 * or no value for the given @tag
1032 gst_preset_get_meta (GstPreset * preset, const gchar * name, const gchar * tag,
1035 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
1036 g_return_val_if_fail (name, FALSE);
1037 g_return_val_if_fail (tag, FALSE);
1038 g_return_val_if_fail (value, FALSE);
1040 return GST_PRESET_GET_INTERFACE (preset)->get_meta (preset, name, tag, value);
1043 /* class internals */
1046 gst_preset_class_init (GstPresetInterface * iface)
1048 iface->get_preset_names = gst_preset_default_get_preset_names;
1049 iface->get_property_names = gst_preset_default_get_property_names;
1051 iface->load_preset = gst_preset_default_load_preset;
1052 iface->save_preset = gst_preset_default_save_preset;
1053 iface->rename_preset = gst_preset_default_rename_preset;
1054 iface->delete_preset = gst_preset_default_delete_preset;
1056 iface->set_meta = gst_preset_default_set_meta;
1057 iface->get_meta = gst_preset_default_get_meta;
1061 gst_preset_base_init (gpointer g_class)
1063 static gboolean initialized = FALSE;
1066 /* init default implementation */
1067 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "preset",
1068 GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLACK, "preset interface");
1070 /* create quarks for use with g_type_{g,s}et_qdata() */
1071 preset_quark = g_quark_from_static_string ("GstPreset::presets");
1072 preset_user_path_quark =
1073 g_quark_from_static_string ("GstPreset::user_path");
1074 preset_system_path_quark =
1075 g_quark_from_static_string ("GstPreset::system_path");
1078 property_list_quark = g_quark_from_static_string ("GstPreset::properties");
1080 /* create interface properties, each element would need to override this
1081 * g_object_class_override_property(gobject_class, PROP_PRESET_NAME, "preset-name");
1082 * and in _set_property() do
1083 * case PROP_PRESET_NAME: {
1084 * gchar *name = g_value_get_string (value);
1086 * gst_preset_load_preset(preset, name);
1089 g_object_interface_install_property (g_class,
1090 g_param_spec_string ("preset-name",
1091 "preset-name property",
1092 "load given preset", NULL, G_PARAM_WRITABLE));
1100 gst_preset_get_type (void)
1102 static volatile gsize type = 0;
1104 if (g_once_init_enter (&type)) {
1106 const GTypeInfo info = {
1107 sizeof (GstPresetInterface),
1108 (GBaseInitFunc) gst_preset_base_init, /* base_init */
1109 NULL, /* base_finalize */
1110 (GClassInitFunc) gst_preset_class_init, /* class_init */
1111 NULL, /* class_finalize */
1112 NULL, /* class_data */
1114 0, /* n_preallocs */
1115 NULL /* instance_init */
1117 _type = g_type_register_static (G_TYPE_INTERFACE, "GstPreset", &info, 0);
1118 g_once_init_leave (&type, _type);