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"
93 #include <glib/gstdio.h>
95 #define GST_CAT_DEFAULT preset_debug
96 GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
98 /* defines for keyfile usage, this group contains the element type name and
99 * version these presets belong to. */
100 #define PRESET_HEADER "_presets_"
102 /* keys of the preset header section */
103 #define PRESET_HEADER_ELEMENT_NAME "element-name"
104 #define PRESET_HEADER_VERSION "version"
106 static GQuark preset_user_path_quark = 0;
107 static GQuark preset_system_path_quark = 0;
108 static GQuark preset_quark = 0;
110 /*static GQuark property_list_quark = 0;*/
112 /* default iface implementation */
114 static gboolean gst_preset_default_save_presets_file (GstPreset * preset);
118 * @preset: a #GObject that implements #GstPreset
119 * @preset_user_path: location for path or %NULL
120 * @preset_system_path: location for path or %NULL
122 * Fetch the preset_path for user local and system wide settings. Don't free
125 * Returns: %FALSE if no paths could be found.
128 preset_get_paths (GstPreset * preset, const gchar ** preset_user_path,
129 const gchar ** preset_system_path)
131 GType type = G_TYPE_FROM_INSTANCE (preset);
133 const gchar *element_name;
135 /* we use the element name when we must contruct the paths */
136 element_name = G_OBJECT_TYPE_NAME (preset);
137 GST_INFO_OBJECT (preset, "element_name: '%s'", element_name);
139 if (preset_user_path) {
140 /* preset user path requested, see if we have it cached in the qdata */
141 if (!(preset_path = g_type_get_qdata (type, preset_user_path_quark))) {
144 /* user presets go in '$HOME/.gstreamer-0.10/presets/GstSimSyn.prs' */
145 preset_dir = g_build_filename (g_get_home_dir (),
146 ".gstreamer-" GST_MAJORMINOR, "presets", NULL);
147 GST_INFO_OBJECT (preset, "user_preset_dir: '%s'", preset_dir);
149 g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs", preset_dir,
151 GST_INFO_OBJECT (preset, "user_preset_path: '%s'", preset_path);
153 g_mkdir_with_parents (preset_dir, 0755);
156 /* cache the preset path to the type */
157 g_type_set_qdata (type, preset_user_path_quark, preset_path);
159 *preset_user_path = preset_path;
162 if (preset_system_path) {
163 /* preset system path requested, see if we have it cached in the qdata */
164 if (!(preset_path = g_type_get_qdata (type, preset_system_path_quark))) {
167 /* system presets in '$GST_DATADIR/gstreamer-0.10/presets/GstAudioPanorama.prs' */
168 preset_dir = g_build_filename (GST_DATADIR, "gstreamer-" GST_MAJORMINOR,
170 GST_INFO_OBJECT (preset, "system_preset_dir: '%s'", preset_dir);
171 preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs",
172 preset_dir, element_name);
173 GST_INFO_OBJECT (preset, "system_preset_path: '%s'", preset_path);
175 g_mkdir_with_parents (preset_dir, 0755);
178 /* cache the preset path to the type */
179 g_type_set_qdata (type, preset_system_path_quark, preset_path);
181 *preset_system_path = preset_path;
187 preset_skip_property (GParamSpec * property)
189 if (((property->flags & G_PARAM_READWRITE) != G_PARAM_READWRITE) ||
190 (property->flags & G_PARAM_CONSTRUCT_ONLY))
192 /* FIXME: skip GST_PARAM_NOT_PRESETABLE, see #522205 */
196 /* caller must free @preset_version after use */
198 preset_open_and_parse_header (GstPreset * preset, const gchar * preset_path,
199 gchar ** preset_version)
202 GError *error = NULL;
204 const gchar *element_name;
207 in = g_key_file_new ();
209 res = g_key_file_load_from_file (in, preset_path,
210 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error);
211 if (!res || error != NULL)
214 /* element type name and preset name must match or we are dealing with a wrong
216 element_name = G_OBJECT_TYPE_NAME (preset);
218 g_key_file_get_value (in, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME,
221 if (!name || strcmp (name, element_name))
226 /* get the version now so that the caller can check it */
229 g_key_file_get_value (in, PRESET_HEADER, PRESET_HEADER_VERSION, NULL);
236 GST_WARNING_OBJECT (preset, "Unable to read preset file %s: %s",
237 preset_path, error->message);
238 g_error_free (error);
239 g_key_file_free (in);
244 GST_WARNING_OBJECT (preset,
245 "Wrong element name in preset file %s. Expected %s, got %s",
246 preset_path, element_name, GST_STR_NULL (name));
248 g_key_file_free (in);
254 preset_parse_version (const gchar * str_version)
256 gint major, minor, micro, nano, num;
258 major = minor = micro = nano = 0;
260 /* parse version (e.g. 0.10.15.1) to guint64 */
261 num = sscanf (str_version, "%d.%d.%d.%d", &major, &minor, µ, &nano);
262 /* make sure we have atleast "major.minor" */
266 version = ((((major << 8 | minor) << 8) | micro) << 8) | nano;
267 GST_DEBUG ("version %s -> %" G_GUINT64_FORMAT, str_version, version);
270 return G_GUINT64_CONSTANT (0);
274 preset_merge (GKeyFile * system, GKeyFile * user)
277 gchar **groups, **keys;
278 gsize i, j, num_groups, num_keys;
280 /* copy file comment if there is any */
281 if ((str = g_key_file_get_comment (user, NULL, NULL, NULL))) {
282 g_key_file_set_comment (system, NULL, NULL, str, NULL);
286 /* get groups in user and copy into system */
287 groups = g_key_file_get_groups (user, &num_groups);
288 for (i = 0; i < num_groups; i++) {
289 /* copy group comment if there is any */
290 if ((str = g_key_file_get_comment (user, groups[i], NULL, NULL))) {
291 g_key_file_set_comment (system, groups[i], NULL, str, NULL);
295 /* ignore private groups */
296 if (groups[i][0] == '_')
299 /* if group already exists in system, remove and re-add keys from user */
300 if (g_key_file_has_group (system, groups[i])) {
301 g_key_file_remove_group (system, groups[i], NULL);
304 keys = g_key_file_get_keys (user, groups[i], &num_keys, NULL);
305 for (j = 0; j < num_keys; j++) {
306 /* copy key comment if there is any */
307 if ((str = g_key_file_get_comment (user, groups[i], keys[j], NULL))) {
308 g_key_file_set_comment (system, groups[i], keys[j], str, NULL);
311 str = g_key_file_get_value (user, groups[i], keys[j], NULL);
312 g_key_file_set_value (system, groups[i], keys[j], str);
320 /* reads the user and system presets files and merges them together. This
321 * function caches the GKeyFile on the element type. If there is no existing
322 * preset file, a new in-memory GKeyFile will be created. */
324 preset_get_keyfile (GstPreset * preset)
327 GType type = G_TYPE_FROM_INSTANCE (preset);
329 /* first see if the have a cached version for the type */
330 if (!(presets = g_type_get_qdata (type, preset_quark))) {
331 const gchar *preset_user_path, *preset_system_path;
332 gchar *str_version_user = NULL, *str_version_system = NULL;
333 gboolean updated_from_system = FALSE;
334 GKeyFile *in_user, *in_system;
336 preset_get_paths (preset, &preset_user_path, &preset_system_path);
338 /* try to load the user and system presets, we do this to get the versions
340 in_user = preset_open_and_parse_header (preset, preset_user_path,
342 in_system = preset_open_and_parse_header (preset, preset_system_path,
343 &str_version_system);
345 /* compare version to check for merge */
347 /* keep system presets if there is no user preset or when the system
348 * version is higher than the user version. */
351 } else if (preset_parse_version (str_version_system) >
352 preset_parse_version (str_version_user)) {
354 updated_from_system = TRUE;
358 if (updated_from_system) {
359 /* merge user on top of system presets */
360 preset_merge (presets, in_user);
361 g_key_file_free (in_user);
363 /* keep user presets */
367 if (!in_user && !in_system) {
368 /* we did not load a user or system presets file, create a new one */
369 presets = g_key_file_new ();
370 g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME,
371 G_OBJECT_TYPE_NAME (preset));
374 g_free (str_version_user);
375 g_free (str_version_system);
377 /* attach the preset to the type */
378 g_type_set_qdata (type, preset_quark, (gpointer) presets);
380 if (updated_from_system) {
381 gst_preset_default_save_presets_file (preset);
387 /* get a list of all supported preset names for an element */
389 gst_preset_default_get_preset_names (GstPreset * preset)
395 /* get the presets from the type */
396 if (!(presets = preset_get_keyfile (preset)))
399 /* get the groups, which are also the preset names */
400 if (!(groups = g_key_file_get_groups (presets, &num_groups)))
403 /* remove all private group names starting with '_' from the array */
404 for (i = 0; i < num_groups; i++) {
405 if (groups[i][0] == '_') {
406 /* free private group */
408 /* move last element of list down */
410 /* move last element into removed element */
411 groups[i] = groups[num_groups];
412 groups[num_groups] = NULL;
415 /* sort the array now */
416 g_qsort_with_data (groups, num_groups, sizeof (gchar *),
417 (GCompareDataFunc) strcmp, NULL);
424 GST_WARNING_OBJECT (preset, "Could not load presets");
429 GST_WARNING_OBJECT (preset, "Could not find preset groups");
434 /* get a list of all property names that are used for presets */
436 gst_preset_default_get_property_names (GstPreset * preset)
440 GObjectClass *gclass;
443 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
445 /* get a list of normal properties.
446 * FIXME, change this for childproxy support. */
447 props = g_object_class_list_properties (gclass, &n_props);
451 /* allocate array big enough to hold the worst case, including a terminating
453 result = g_new (gchar *, n_props + 1);
455 /* now filter out the properties that we can use for presets */
456 GST_DEBUG_OBJECT (preset, " filtering properties: %u", n_props);
457 for (i = j = 0; i < n_props; i++) {
458 if (preset_skip_property (props[i]))
461 /* copy and increment out pointer */
462 result[j++] = g_strdup (props[i]->name);
472 GST_INFO_OBJECT (preset, "object has no properties");
477 /* load the presets of @name for the instance @preset. Returns %FALSE if something
480 gst_preset_default_load_preset (GstPreset * preset, const gchar * name)
485 GObjectClass *gclass;
487 /* get the presets from the type */
488 if (!(presets = preset_get_keyfile (preset)))
491 /* get the preset name */
492 if (!g_key_file_has_group (presets, name))
495 GST_DEBUG_OBJECT (preset, "loading preset : '%s'", name);
497 /* get the properties that we can configure in this element */
498 if (!(props = gst_preset_get_property_names (preset)))
501 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
503 /* for each of the property names, find the preset parameter and try to
504 * configure the property with its value */
505 for (i = 0; props[i]; i++) {
507 GValue gvalue = { 0, };
508 GParamSpec *property;
510 /* check if we have a settings for this element property */
511 if (!(str = g_key_file_get_value (presets, name, props[i], NULL))) {
512 /* the element has a property but the parameter is not in the keyfile */
513 GST_WARNING_OBJECT (preset, "parameter '%s' not in preset", props[i]);
517 GST_DEBUG_OBJECT (preset, "setting value '%s' for property '%s'", str,
520 /* FIXME, change for childproxy to get the property and element. */
521 if (!(property = g_object_class_find_property (gclass, props[i]))) {
522 /* the parameter was in the keyfile, the element said it supported it but
523 * then the property was not found in the element. This should not happen. */
524 GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
529 /* try to deserialize the property value from the keyfile and set it as
530 * the object property */
531 g_value_init (&gvalue, property->value_type);
532 if (gst_value_deserialize (&gvalue, str)) {
533 /* FIXME, change for childproxy support */
534 g_object_set_property (G_OBJECT (preset), props[i], &gvalue);
536 GST_WARNING_OBJECT (preset,
537 "deserialization of value '%s' for property '%s' failed", str,
540 g_value_unset (&gvalue);
550 GST_WARNING_OBJECT (preset, "no presets");
555 GST_WARNING_OBJECT (preset, "no preset named '%s'", name);
560 GST_INFO_OBJECT (preset, "no properties");
565 /* save the presets file. A copy of the existing presets file is stored in a
568 gst_preset_default_save_presets_file (GstPreset * preset)
571 const gchar *preset_path;
572 GError *error = NULL;
573 gchar *bak_file_name;
574 gboolean backup = TRUE;
578 preset_get_paths (preset, &preset_path, NULL);
580 /* get the presets from the type */
581 if (!(presets = preset_get_keyfile (preset)))
584 GST_DEBUG_OBJECT (preset, "saving preset file: '%s'", preset_path);
586 /* create backup if possible */
587 bak_file_name = g_strdup_printf ("%s.bak", preset_path);
588 if (g_file_test (bak_file_name, G_FILE_TEST_EXISTS)) {
589 if (g_unlink (bak_file_name)) {
591 GST_INFO_OBJECT (preset, "cannot remove old backup file : %s",
596 if (g_rename (preset_path, bak_file_name)) {
597 GST_INFO_OBJECT (preset, "cannot backup file : %s -> %s", preset_path,
601 g_free (bak_file_name);
603 /* update gstreamer version */
604 g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_VERSION,
607 /* get new contents, wee need this to save it */
608 if (!(data = g_key_file_to_data (presets, &data_size, &error)))
612 if (!g_file_set_contents (preset_path, data, data_size, &error))
622 GST_WARNING_OBJECT (preset,
623 "no presets, trying to unlink possibly existing preset file: '%s'",
625 g_unlink (preset_path);
630 GST_WARNING_OBJECT (preset, "can not get the keyfile contents: %s",
632 g_error_free (error);
638 GST_WARNING_OBJECT (preset, "Unable to store preset file %s: %s",
639 preset_path, error->message);
640 g_error_free (error);
646 /* save the preset with the given name */
648 gst_preset_default_save_preset (GstPreset * preset, const gchar * name)
653 GObjectClass *gclass;
655 GST_INFO_OBJECT (preset, "saving new preset: %s", name);
657 /* get the presets from the type */
658 if (!(presets = preset_get_keyfile (preset)))
661 /* take copies of current gobject properties from preset */
662 if (!(props = gst_preset_get_property_names (preset)))
665 gclass = G_OBJECT_CLASS (GST_ELEMENT_GET_CLASS (preset));
667 /* loop over the object properties and store the property value in the
669 for (i = 0; props[i]; i++) {
670 GValue gvalue = { 0, };
672 GParamSpec *property;
674 /* FIXME, change for childproxy to get the property and element. */
675 if (!(property = g_object_class_find_property (gclass, props[i]))) {
676 /* the element said it supported the property but then it does not have
677 * that property. This should not happen. */
678 GST_WARNING_OBJECT (preset, "property '%s' not in object", props[i]);
682 g_value_init (&gvalue, property->value_type);
683 /* FIXME, change for childproxy */
684 g_object_get_property (G_OBJECT (preset), props[i], &gvalue);
686 if ((str = gst_value_serialize (&gvalue))) {
687 g_key_file_set_string (presets, name, props[i], (gpointer) str);
690 GST_WARNING_OBJECT (preset, "serialization for property '%s' failed",
693 g_value_unset (&gvalue);
695 GST_INFO_OBJECT (preset, " saved");
698 /* save updated version */
699 return gst_preset_default_save_presets_file (preset);
704 GST_WARNING_OBJECT (preset, "no presets");
709 GST_INFO_OBJECT (preset, "no properties");
714 /* copies all keys and comments from one group to another, deleting the old
717 gst_preset_default_rename_preset (GstPreset * preset, const gchar * old_name,
718 const gchar * new_name)
725 /* get the presets from the type */
726 if (!(presets = preset_get_keyfile (preset)))
729 if (!g_key_file_has_group (presets, old_name))
732 /* copy group comment if there is any */
733 if ((str = g_key_file_get_comment (presets, old_name, NULL, NULL))) {
734 g_key_file_set_comment (presets, new_name, NULL, str, NULL);
738 /* get all keys from the old group and copy them in the new group */
739 keys = g_key_file_get_keys (presets, old_name, &num_keys, NULL);
740 for (i = 0; i < num_keys; i++) {
741 /* copy key comment if there is any */
742 if ((str = g_key_file_get_comment (presets, old_name, keys[i], NULL))) {
743 g_key_file_set_comment (presets, new_name, keys[i], str, NULL);
747 str = g_key_file_get_value (presets, old_name, keys[i], NULL);
748 g_key_file_set_value (presets, new_name, keys[i], str);
753 /* remove old group */
754 g_key_file_remove_group (presets, old_name, NULL);
756 /* save updated version */
757 return gst_preset_default_save_presets_file (preset);
762 GST_WARNING_OBJECT (preset, "no presets");
767 GST_WARNING_OBJECT (preset, "no preset named %s", old_name);
772 /* delete a group from the keyfile */
774 gst_preset_default_delete_preset (GstPreset * preset, const gchar * name)
778 /* get the presets from the type */
779 if (!(presets = preset_get_keyfile (preset)))
783 if (!g_key_file_has_group (presets, name))
786 /* remove the group */
787 g_key_file_remove_group (presets, name, NULL);
789 /* save updated version */
790 return gst_preset_default_save_presets_file (preset);
795 GST_WARNING_OBJECT (preset, "no presets");
800 GST_WARNING_OBJECT (preset, "no preset named %s", name);
806 gst_preset_default_set_meta (GstPreset * preset, const gchar * name,
807 const gchar * tag, const gchar * value)
812 /* get the presets from the type */
813 if (!(presets = preset_get_keyfile (preset)))
816 key = g_strdup_printf ("_meta/%s", tag);
817 if (value && *value) {
818 g_key_file_set_value (presets, name, key, value);
820 g_key_file_remove_key (presets, name, key, NULL);
824 /* save updated keyfile */
825 return gst_preset_default_save_presets_file (preset);
830 GST_WARNING_OBJECT (preset, "no presets");
835 /* the caller must free @value after usage */
837 gst_preset_default_get_meta (GstPreset * preset, const gchar * name,
838 const gchar * tag, gchar ** value)
843 /* get the presets from the type */
844 if (!(presets = preset_get_keyfile (preset)))
847 key = g_strdup_printf ("_meta/%s", tag);
848 *value = g_key_file_get_value (presets, name, key, NULL);
856 GST_WARNING_OBJECT (preset, "no presets");
865 * gst_preset_get_preset_names:
866 * @preset: a #GObject that implements #GstPreset
868 * Get a copy of preset names as a NULL terminated string array.
870 * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*):
871 * list with names, ue g_strfreev() after usage.
876 gst_preset_get_preset_names (GstPreset * preset)
878 g_return_val_if_fail (GST_IS_PRESET (preset), NULL);
880 return (GST_PRESET_GET_INTERFACE (preset)->get_preset_names (preset));
884 * gst_preset_get_property_names:
885 * @preset: a #GObject that implements #GstPreset
887 * Get a the names of the GObject properties that can be used for presets.
889 * Returns: (transfer full) (array zero-terminated=1) (element-type gchar*): an
890 * array of property names which should be freed with g_strfreev() after use.
895 gst_preset_get_property_names (GstPreset * preset)
897 g_return_val_if_fail (GST_IS_PRESET (preset), NULL);
899 return (GST_PRESET_GET_INTERFACE (preset)->get_property_names (preset));
903 * gst_preset_load_preset:
904 * @preset: a #GObject that implements #GstPreset
905 * @name: preset name to load
907 * Load the given preset.
909 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
914 gst_preset_load_preset (GstPreset * preset, const gchar * name)
916 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
917 g_return_val_if_fail (name, FALSE);
919 return (GST_PRESET_GET_INTERFACE (preset)->load_preset (preset, name));
923 * gst_preset_save_preset:
924 * @preset: a #GObject that implements #GstPreset
925 * @name: preset name to save
927 * Save the current object settings as a preset under the given name. If there
928 * is already a preset by this @name it will be overwritten.
930 * Returns: %TRUE for success, %FALSE
935 gst_preset_save_preset (GstPreset * preset, const gchar * name)
937 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
938 g_return_val_if_fail (name, FALSE);
940 return (GST_PRESET_GET_INTERFACE (preset)->save_preset (preset, name));
944 * gst_preset_rename_preset:
945 * @preset: a #GObject that implements #GstPreset
946 * @old_name: current preset name
947 * @new_name: new preset name
949 * Renames a preset. If there is already a preset by the @new_name it will be
952 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with @old_name
957 gst_preset_rename_preset (GstPreset * preset, const gchar * old_name,
958 const gchar * new_name)
960 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
961 g_return_val_if_fail (old_name, FALSE);
962 g_return_val_if_fail (new_name, FALSE);
964 return (GST_PRESET_GET_INTERFACE (preset)->rename_preset (preset, old_name,
969 * gst_preset_delete_preset:
970 * @preset: a #GObject that implements #GstPreset
971 * @name: preset name to remove
973 * Delete the given preset.
975 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
980 gst_preset_delete_preset (GstPreset * preset, const gchar * name)
982 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
983 g_return_val_if_fail (name, FALSE);
985 return (GST_PRESET_GET_INTERFACE (preset)->delete_preset (preset, name));
989 * gst_preset_set_meta:
990 * @preset: a #GObject that implements #GstPreset
992 * @tag: meta data item name
995 * Sets a new @value for an existing meta data item or adds a new item. Meta
996 * data @tag names can be something like e.g. "comment". Supplying %NULL for the
997 * @value will unset an existing value.
999 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
1004 gst_preset_set_meta (GstPreset * preset, const gchar * name, const gchar * tag,
1005 const gchar * value)
1007 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
1008 g_return_val_if_fail (name, FALSE);
1009 g_return_val_if_fail (tag, FALSE);
1011 return GST_PRESET_GET_INTERFACE (preset)->set_meta (preset, name, tag, value);
1015 * gst_preset_get_meta:
1016 * @preset: a #GObject that implements #GstPreset
1017 * @name: preset name
1018 * @tag: meta data item name
1019 * @value: (out callee-allocates): value
1021 * Gets the @value for an existing meta data @tag. Meta data @tag names can be
1022 * something like e.g. "comment". Returned values need to be released when done.
1024 * Returns: %TRUE for success, %FALSE if e.g. there is no preset with that @name
1025 * or no value for the given @tag
1030 gst_preset_get_meta (GstPreset * preset, const gchar * name, const gchar * tag,
1033 g_return_val_if_fail (GST_IS_PRESET (preset), FALSE);
1034 g_return_val_if_fail (name, FALSE);
1035 g_return_val_if_fail (tag, FALSE);
1036 g_return_val_if_fail (value, FALSE);
1038 return GST_PRESET_GET_INTERFACE (preset)->get_meta (preset, name, tag, value);
1041 /* class internals */
1044 gst_preset_class_init (GstPresetInterface * iface)
1046 iface->get_preset_names = gst_preset_default_get_preset_names;
1047 iface->get_property_names = gst_preset_default_get_property_names;
1049 iface->load_preset = gst_preset_default_load_preset;
1050 iface->save_preset = gst_preset_default_save_preset;
1051 iface->rename_preset = gst_preset_default_rename_preset;
1052 iface->delete_preset = gst_preset_default_delete_preset;
1054 iface->set_meta = gst_preset_default_set_meta;
1055 iface->get_meta = gst_preset_default_get_meta;
1059 gst_preset_base_init (gpointer g_class)
1061 static gboolean initialized = FALSE;
1064 /* init default implementation */
1065 GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "preset",
1066 GST_DEBUG_FG_WHITE | GST_DEBUG_BG_BLACK, "preset interface");
1068 /* create quarks for use with g_type_{g,s}et_qdata() */
1069 preset_quark = g_quark_from_static_string ("GstPreset::presets");
1070 preset_user_path_quark =
1071 g_quark_from_static_string ("GstPreset::user_path");
1072 preset_system_path_quark =
1073 g_quark_from_static_string ("GstPreset::system_path");
1076 property_list_quark = g_quark_from_static_string ("GstPreset::properties");
1078 /* create interface properties, each element would need to override this
1079 * g_object_class_override_property(gobject_class, PROP_PRESET_NAME, "preset-name");
1080 * and in _set_property() do
1081 * case PROP_PRESET_NAME: {
1082 * gchar *name = g_value_get_string (value);
1084 * gst_preset_load_preset(preset, name);
1087 g_object_interface_install_property (g_class,
1088 g_param_spec_string ("preset-name",
1089 "preset-name property",
1090 "load given preset", NULL, G_PARAM_WRITABLE));
1098 gst_preset_get_type (void)
1100 static volatile gsize type = 0;
1102 if (g_once_init_enter (&type)) {
1104 const GTypeInfo info = {
1105 sizeof (GstPresetInterface),
1106 (GBaseInitFunc) gst_preset_base_init, /* base_init */
1107 NULL, /* base_finalize */
1108 (GClassInitFunc) gst_preset_class_init, /* class_init */
1109 NULL, /* class_finalize */
1110 NULL, /* class_data */
1112 0, /* n_preallocs */
1113 NULL /* instance_init */
1115 _type = g_type_register_static (G_TYPE_INTERFACE, "GstPreset", &info, 0);
1116 g_once_init_leave (&type, _type);