X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstpreset.c;h=7584c5be6e52dec9968c025d373c2ab266615bf1;hb=cc6342d853f4252c5d5cf09fff9d3379ad467fbc;hp=6280896ff6509ed70309691a1943793e0a651447;hpb=f1b07c580ebec40d7f3028337bdabeaecb331c6f;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstpreset.c b/gst/gstpreset.c index 6280896..7584c5b 100644 --- a/gst/gstpreset.c +++ b/gst/gstpreset.c @@ -15,11 +15,12 @@ * * 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 + * @title: GstPreset * @short_description: helper interface for element presets * * This interface offers methods to query and manipulate parameter preset sets. @@ -34,6 +35,17 @@ * native preset format of those wrapped plugins. * One method that is useful to be overridden is gst_preset_get_property_names(). * With that one can control which properties are saved and in which order. + * When implementing support for read-only presets, one should set the vmethods + * for gst_preset_save_preset() and gst_preset_delete_preset() to %NULL. + * Applications can use gst_preset_is_editable() to check for that. + * + * The default implementation supports presets located in a system directory, + * application specific directory and in the users home directory. When getting + * a list of presets individual presets are read and overlaid in 1) system, + * 2) application and 3) user order. Whenever an earlier entry is newer, the + * later entries will be updated. Since 1.8 you can also provide extra paths + * where to find presets through the GST_PRESET_PATH environment variable. + * Presets found in those paths will be considered as "app presets". */ /* FIXME: * - non racyness @@ -48,10 +60,6 @@ * 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. @@ -59,33 +67,14 @@ * - 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: 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 +#ifdef G_OS_WIN32 +#define WIN32_LEAN_AND_MEAN +#include + +extern HMODULE _priv_gst_dll_handle; +#endif + #define GST_CAT_DEFAULT preset_debug GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); @@ -106,10 +102,15 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT); #define PRESET_HEADER_VERSION "version" static GQuark preset_user_path_quark = 0; +static GQuark preset_app_path_quark = 0; static GQuark preset_system_path_quark = 0; static GQuark preset_quark = 0; -/*static GQuark property_list_quark = 0;*/ +/* 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. + */ +static gchar *preset_app_dir = NULL; /* default iface implementation */ @@ -118,23 +119,24 @@ static gboolean gst_preset_default_save_presets_file (GstPreset * preset); /* * preset_get_paths: * @preset: a #GObject that implements #GstPreset - * @preset_user_path: location for path or %NULL - * @preset_system_path: location for path or %NULL + * @preset_user_path: (out) (allow-none): location for path or %NULL + * @preset_app_path: (out) (allow-none): location for path or %NULL + * @preset_system_path: (out) (allow-none): location for path or %NULL * - * Fetch the preset_path for user local and system wide settings. Don't free - * after use. + * Fetch the preset_path for user local, application specific and system wide + * settings. Don't free after use. * * Returns: %FALSE if no paths could be found. */ static gboolean preset_get_paths (GstPreset * preset, const gchar ** preset_user_path, - const gchar ** preset_system_path) + const gchar ** preset_app_path, const gchar ** preset_system_path) { GType type = G_TYPE_FROM_INSTANCE (preset); 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); @@ -145,7 +147,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, @@ -161,14 +163,40 @@ preset_get_paths (GstPreset * preset, const gchar ** preset_user_path, *preset_user_path = preset_path; } + if (preset_app_path) { + if (preset_app_dir) { + if (!(preset_path = g_type_get_qdata (type, preset_system_path_quark))) { + preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs", + preset_app_dir, element_name); + GST_INFO_OBJECT (preset, "application_preset_path: '%s'", preset_path); + + /* cache the preset path to the type */ + g_type_set_qdata (type, preset_app_path_quark, preset_path); + } + *preset_app_path = preset_path; + } else { + *preset_app_path = NULL; + } + } + if (preset_system_path) { /* preset system path requested, see if we have it cached in the qdata */ 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); @@ -195,10 +223,30 @@ preset_skip_property (GParamSpec * property) return FALSE; } -/* caller must free @preset_version after use */ +static guint64 +preset_parse_version (const gchar * str_version) +{ + guint major, minor, micro, nano; + gint num; + + major = minor = micro = nano = 0; + + /* parse version (e.g. 0.10.15.1) to guint64 */ + num = sscanf (str_version, "%u.%u.%u.%u", &major, &minor, µ, &nano); + /* make sure we have at least "major.minor" */ + if (num > 1) { + guint64 version; + + version = ((((major << 8 | minor) << 8) | micro) << 8) | nano; + GST_DEBUG ("version %s -> %" G_GUINT64_FORMAT, str_version, version); + return version; + } + return G_GUINT64_CONSTANT (0); +} + static GKeyFile * preset_open_and_parse_header (GstPreset * preset, const gchar * preset_path, - gchar ** preset_version) + guint64 * preset_version) { GKeyFile *in; GError *error = NULL; @@ -226,16 +274,19 @@ preset_open_and_parse_header (GstPreset * preset, const gchar * preset_path, g_free (name); /* get the version now so that the caller can check it */ - if (preset_version) - *preset_version = + if (preset_version) { + gchar *str = g_key_file_get_value (in, PRESET_HEADER, PRESET_HEADER_VERSION, NULL); + *preset_version = preset_parse_version (str); + g_free (str); + } return in; /* ERRORS */ load_error: { - GST_WARNING_OBJECT (preset, "Unable to read preset file %s: %s", + GST_INFO_OBJECT (preset, "Unable to read preset file %s: %s", preset_path, error->message); g_error_free (error); g_key_file_free (in); @@ -252,27 +303,6 @@ wrong_name: } } -static guint64 -preset_parse_version (const gchar * str_version) -{ - guint major, minor, micro, nano; - gint num; - - major = minor = micro = nano = 0; - - /* parse version (e.g. 0.10.15.1) to guint64 */ - num = sscanf (str_version, "%u.%u.%u.%u", &major, &minor, µ, &nano); - /* make sure we have atleast "major.minor" */ - if (num > 1) { - guint64 version; - - version = ((((major << 8 | minor) << 8) | micro) << 8) | nano; - GST_DEBUG ("version %s -> %" G_GUINT64_FORMAT, str_version, version); - return version; - } - return G_GUINT64_CONSTANT (0); -} - static void preset_merge (GKeyFile * system, GKeyFile * user) { @@ -320,6 +350,26 @@ preset_merge (GKeyFile * system, GKeyFile * user) g_strfreev (groups); } +typedef struct +{ + GKeyFile *preset; + guint64 version; +} PresetAndVersion; + +static gint +compare_preset_and_version (gconstpointer a, gconstpointer b, + gpointer user_data) +{ + const PresetAndVersion *pa = a, *pb = b; + + if (pa->version > pb->version) + return -1; + if (pa->version < pb->version) + return 1; + else + return 0; +} + /* reads the user and system presets files and merges them together. This * function caches the GKeyFile on the element type. If there is no existing * preset file, a new in-memory GKeyFile will be created. */ @@ -331,62 +381,136 @@ preset_get_keyfile (GstPreset * preset) /* first see if the have a cached version for the type */ if (!(presets = g_type_get_qdata (type, preset_quark))) { - const gchar *preset_user_path, *preset_system_path; - gchar *str_version_user = NULL, *str_version_system = NULL; - gboolean updated_from_system = FALSE; - GKeyFile *in_user, *in_system; + const gchar *preset_user_path, *preset_app_path, *preset_system_path; + guint64 version_system = G_GUINT64_CONSTANT (0); + guint64 version_app = G_GUINT64_CONSTANT (0); + guint64 version_user = G_GUINT64_CONSTANT (0); + guint64 version = G_GUINT64_CONSTANT (0); + gboolean merged = FALSE; + GKeyFile *in_user, *in_app = NULL, *in_system; + GQueue in_env = G_QUEUE_INIT; + gboolean have_env = FALSE; + const gchar *envvar; + + /* try to load the user, app and system presets, we do this to get the + * versions of all files. */ + preset_get_paths (preset, &preset_user_path, &preset_app_path, + &preset_system_path); + in_user = preset_open_and_parse_header (preset, preset_user_path, + &version_user); - preset_get_paths (preset, &preset_user_path, &preset_system_path); + if (preset_app_path) { + in_app = preset_open_and_parse_header (preset, preset_app_path, + &version_app); + } + + envvar = g_getenv ("GST_PRESET_PATH"); + if (envvar) { + gint i; + gchar **preset_dirs = g_strsplit (envvar, G_SEARCHPATH_SEPARATOR_S, -1); + + for (i = 0; preset_dirs[i]; i++) { + gchar *preset_path = g_strdup_printf ("%s" G_DIR_SEPARATOR_S "%s.prs", + preset_dirs[i], G_OBJECT_TYPE_NAME (preset)); + GKeyFile *env_file; + guint64 env_version; + + env_file = preset_open_and_parse_header (preset, preset_path, + &env_version); + g_free (preset_path); + if (env_file) { + PresetAndVersion *pv = g_new (PresetAndVersion, 1); + pv->preset = env_file; + pv->version = env_version; + g_queue_push_tail (&in_env, pv); + have_env = TRUE; + } + } + g_strfreev (preset_dirs); + } - /* try to load the user and system presets, we do this to get the versions - * of both files. */ - in_user = preset_open_and_parse_header (preset, preset_user_path, - &str_version_user); in_system = preset_open_and_parse_header (preset, preset_system_path, - &str_version_system); + &version_system); /* compare version to check for merge */ if (in_system) { - /* keep system presets if there is no user preset or when the system - * version is higher than the user version. */ - if (!in_user) { - presets = in_system; - } else if (preset_parse_version (str_version_system) > - preset_parse_version (str_version_user)) { - presets = in_system; - updated_from_system = TRUE; + presets = in_system; + version = version_system; + } + + if (have_env) { + GList *l; + + /* merge the ones from the environment paths. If any of them has a + * higher version, take that as the "master" version. Lower versions are + * then just merged in. */ + g_queue_sort (&in_env, compare_preset_and_version, NULL); + /* highest version to lowest */ + for (l = in_env.head; l; l = l->next) { + PresetAndVersion *pv = l->data; + + if (version > pv->version) { + preset_merge (presets, pv->preset); + g_key_file_free (pv->preset); + } else { + if (presets) + g_key_file_free (presets); + presets = pv->preset; + version = pv->version; + } + g_free (pv); + } + g_queue_clear (&in_env); + } + + if (in_app) { + /* if system/env version is higher, merge */ + if (version > version_app) { + preset_merge (presets, in_app); + g_key_file_free (in_app); + } else { + if (presets) + g_key_file_free (presets); + presets = in_app; + version = version_app; } } if (in_user) { - if (updated_from_system) { - /* merge user on top of system presets */ + /* if system/env or app version is higher, merge */ + if (version > version_user) { preset_merge (presets, in_user); g_key_file_free (in_user); + merged = TRUE; } else { - /* keep user presets */ + if (presets) + g_key_file_free (presets); presets = in_user; } } - if (!in_user && !in_system) { - /* we did not load a user or system presets file, create a new one */ + + if (!presets) { + /* we did not load a user, app or system presets file, create a new one */ presets = g_key_file_new (); g_key_file_set_string (presets, PRESET_HEADER, PRESET_HEADER_ELEMENT_NAME, G_OBJECT_TYPE_NAME (preset)); } - g_free (str_version_user); - g_free (str_version_system); - /* attach the preset to the type */ g_type_set_qdata (type, preset_quark, (gpointer) presets); - if (updated_from_system) { + if (merged) { gst_preset_default_save_presets_file (preset); } } return presets; } +static gint +compare_strings (gchar ** a, gchar ** b, gpointer user_data) +{ + return g_strcmp0 (*a, *b); +} + /* get a list of all supported preset names for an element */ static gchar ** gst_preset_default_get_preset_names (GstPreset * preset) @@ -415,9 +539,15 @@ gst_preset_default_get_preset_names (GstPreset * preset) groups[num_groups] = NULL; } } + if (!num_groups) { + GST_INFO_OBJECT (preset, "Empty preset file"); + g_strfreev (groups); + return NULL; + } + /* sort the array now */ g_qsort_with_data (groups, num_groups, sizeof (gchar *), - (GCompareDataFunc) strcmp, NULL); + (GCompareDataFunc) compare_strings, NULL); return groups; @@ -439,42 +569,68 @@ 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; + 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); + } - /* ERRORS */ -no_properties: - { + g_object_unref (child); + } + } + 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 @@ -486,6 +642,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))) @@ -502,26 +659,32 @@ 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))) { /* the element has a property but the parameter is not in the keyfile */ - GST_WARNING_OBJECT (preset, "parameter '%s' not in preset", props[i]); + GST_INFO_OBJECT (preset, "parameter '%s' not in preset", props[i]); continue; } 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]); @@ -533,8 +696,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, @@ -578,7 +745,7 @@ gst_preset_default_save_presets_file (GstPreset * preset) gchar *data; gsize data_size; - preset_get_paths (preset, &preset_path, NULL); + preset_get_paths (preset, &preset_path, NULL, NULL); /* get the presets from the type */ if (!(presets = preset_get_keyfile (preset))) @@ -654,6 +821,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); @@ -666,25 +834,41 @@ 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]); continue; } + if (property->flags & G_PARAM_DEPRECATED) { + GST_INFO_OBJECT (preset, "Not saving property %s as it is deprecated", + property->name); + continue; + } + 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); @@ -868,12 +1052,10 @@ no_presets: * gst_preset_get_preset_names: * @preset: a #GObject that implements #GstPreset * - * Get a copy of preset names as a NULL terminated string array. + * 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) @@ -891,8 +1073,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) @@ -910,8 +1090,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) @@ -931,8 +1109,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) @@ -953,8 +1129,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, @@ -976,8 +1150,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) @@ -993,15 +1165,13 @@ gst_preset_delete_preset (GstPreset * preset, const gchar * name) * @preset: a #GObject that implements #GstPreset * @name: preset name * @tag: meta data item name - * @value: new value + * @value: (allow-none): new value * * Sets a new @value for an existing meta data item or adds a new item. Meta * data @tag names can be something like e.g. "comment". Supplying %NULL for the * @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, @@ -1026,8 +1196,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, @@ -1041,6 +1209,61 @@ gst_preset_get_meta (GstPreset * preset, const gchar * name, const gchar * tag, return GST_PRESET_GET_INTERFACE (preset)->get_meta (preset, name, tag, value); } +/** + * gst_preset_set_app_dir: + * @app_dir: (type filename): the application specific preset dir + * + * Sets an extra directory as an absolute path that should be considered when + * looking for presets. Any presets in the application dir will shadow the + * system presets. + * + * Returns: %TRUE for success, %FALSE if the dir already has been set + */ +gboolean +gst_preset_set_app_dir (const gchar * app_dir) +{ + g_return_val_if_fail (app_dir, FALSE); + + if (!preset_app_dir) { + preset_app_dir = g_strdup (app_dir); + return TRUE; + } + return FALSE; +} + +/** + * gst_preset_get_app_dir: + * + * Gets the directory for application specific presets if set by the + * application. + * + * Returns: (nullable) (type filename): the directory or %NULL, don't free or modify + * the string + */ +const gchar * +gst_preset_get_app_dir (void) +{ + return preset_app_dir; +} + +/** + * gst_preset_is_editable: + * @preset: a #GObject that implements #GstPreset + * + * Check if one can add new presets, change existing ones and remove presets. + * + * Returns: %TRUE if presets are editable or %FALSE if they are static + * + * Since: 1.6 + */ +gboolean +gst_preset_is_editable (GstPreset * preset) +{ + GstPresetInterface *iface = GST_PRESET_GET_INTERFACE (preset); + + return iface->save_preset && iface->delete_preset; +} + /* class internals */ static void @@ -1072,12 +1295,11 @@ gst_preset_base_init (gpointer g_class) preset_quark = g_quark_from_static_string ("GstPreset::presets"); preset_user_path_quark = g_quark_from_static_string ("GstPreset::user_path"); + preset_app_path_quark = g_quark_from_static_string ("GstPreset::app_path"); preset_system_path_quark = g_quark_from_static_string ("GstPreset::system_path"); #if 0 - property_list_quark = g_quark_from_static_string ("GstPreset::properties"); - /* create interface properties, each element would need to override this * g_object_class_override_property(gobject_class, PROP_PRESET_NAME, "preset-name"); * and in _set_property() do