2 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * SECTION:gstxmpconfig
22 * @short_description: Interface for elements that provide XMP serialization
26 * This interface is implemented by elements that are able to do XMP serialization. Examples for
27 * such elements are #jifmux and #qtmux.
30 * Applications can use this interface to configure which XMP schemas should be used when serializing
31 * tags into XMP. Schemas are represented by their names, a full list of the supported schemas can be
32 * obtained from gst_tag_xmp_list_schemas(). By default, all schemas are used.
41 #include "xmpwriter.h"
43 #include <gst/tag/tag.h>
45 static GQuark tag_xmp_writer_key;
51 } GstTagXmpWriterData;
54 gst_tag_xmp_writer_get_type (void)
56 static volatile gsize xmp_config_type = 0;
58 if (g_once_init_enter (&xmp_config_type)) {
60 static const GTypeInfo xmp_config_info = {
61 sizeof (GstTagXmpWriterInterface), /* class_size */
63 NULL, /* base_finalize */
65 NULL, /* class_finalize */
66 NULL, /* class_data */
72 _type = g_type_register_static (G_TYPE_INTERFACE, "GstTagXmpWriter",
74 tag_xmp_writer_key = g_quark_from_static_string ("GST_TAG_XMP_WRITER");
75 g_type_interface_add_prerequisite (_type, GST_TYPE_ELEMENT);
77 g_once_init_leave (&xmp_config_type, _type);
80 return xmp_config_type;
84 gst_tag_xmp_writer_data_add_schema_unlocked (GstTagXmpWriterData * data,
87 if (!g_slist_find_custom (data->schemas, schema, (GCompareFunc) strcmp)) {
88 data->schemas = g_slist_prepend (data->schemas, g_strdup (schema));
93 gst_tag_xmp_writer_data_add_all_schemas_unlocked (GstTagXmpWriterData * data)
95 const gchar **schemas;
98 /* initialize it with all schemas */
99 schemas = gst_tag_xmp_list_schemas ();
100 while (schemas[i] != NULL) {
101 gst_tag_xmp_writer_data_add_schema_unlocked (data, schemas[i]);
108 gst_tag_xmp_writer_data_free (gpointer p)
110 GstTagXmpWriterData *data = (GstTagXmpWriterData *) p;
114 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
117 g_slist_free (data->schemas);
120 g_static_mutex_free (&data->lock);
122 g_slice_free (GstTagXmpWriterData, data);
125 static GstTagXmpWriterData *
126 gst_tag_xmp_writer_get_data (GstTagXmpWriter * xmpconfig)
128 GstTagXmpWriterData *data;
130 data = g_object_get_qdata (G_OBJECT (xmpconfig), tag_xmp_writer_key);
132 static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT;
134 /* make sure no other thread is creating a GstTagXmpWriterData at the same time */
135 g_static_mutex_lock (&create_mutex);
136 data = g_object_get_qdata (G_OBJECT (xmpconfig), tag_xmp_writer_key);
138 data = g_slice_new (GstTagXmpWriterData);
139 g_static_mutex_init (&data->lock);
141 data->schemas = NULL;
142 gst_tag_xmp_writer_data_add_all_schemas_unlocked (data);
144 g_object_set_qdata_full (G_OBJECT (xmpconfig), tag_xmp_writer_key, data,
145 gst_tag_xmp_writer_data_free);
147 g_static_mutex_unlock (&create_mutex);
154 * gst_tag_xmp_writer_add_all_schemas:
155 * @config: a #GstTagXmpWriter
157 * Adds all available XMP schemas to the configuration. Meaning that
163 gst_tag_xmp_writer_add_all_schemas (GstTagXmpWriter * config)
165 GstTagXmpWriterData *data;
167 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
169 data = gst_tag_xmp_writer_get_data (config);
171 g_static_mutex_lock (&data->lock);
172 gst_tag_xmp_writer_data_add_all_schemas_unlocked (data);
173 g_static_mutex_unlock (&data->lock);
177 * gst_tag_xmp_writer_add_schema:
178 * @config: a #GstTagXmpWriter
179 * @schema: the schema to be added
181 * Adds @schema to the list schemas
186 gst_tag_xmp_writer_add_schema (GstTagXmpWriter * config, const gchar * schema)
188 GstTagXmpWriterData *data;
190 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
192 data = gst_tag_xmp_writer_get_data (config);
194 g_static_mutex_lock (&data->lock);
195 gst_tag_xmp_writer_data_add_schema_unlocked (data, schema);
196 g_static_mutex_unlock (&data->lock);
200 * gst_tag_xmp_writer_has_schema:
201 * @config: a #GstTagXmpWriter
202 * @schema: the schema to test
204 * Checks if @schema is going to be used
206 * Returns: %TRUE if it is going to be used
210 gst_tag_xmp_writer_has_schema (GstTagXmpWriter * config, const gchar * schema)
212 GstTagXmpWriterData *data;
213 gboolean ret = FALSE;
216 g_return_val_if_fail (GST_IS_TAG_XMP_WRITER (config), FALSE);
218 data = gst_tag_xmp_writer_get_data (config);
220 g_static_mutex_lock (&data->lock);
221 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
222 if (strcmp ((const gchar *) iter->data, schema) == 0) {
227 g_static_mutex_unlock (&data->lock);
233 * gst_tag_xmp_writer_remove_schema:
234 * @config: a #GstTagXmpWriter
235 * @schema: the schema to remove
237 * Removes a schema from the list of schemas to use. Nothing is done if
238 * the schema wasn't in the list
243 gst_tag_xmp_writer_remove_schema (GstTagXmpWriter * config,
244 const gchar * schema)
246 GstTagXmpWriterData *data;
249 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
251 data = gst_tag_xmp_writer_get_data (config);
253 g_static_mutex_lock (&data->lock);
254 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
255 if (strcmp ((const gchar *) iter->data, schema) == 0) {
257 data->schemas = g_slist_delete_link (data->schemas, iter);
261 g_static_mutex_unlock (&data->lock);
265 * gst_tag_xmp_writer_remove_all_schemas:
266 * @config: a #GstTagXmpWriter
268 * Removes all schemas from the list of schemas to use. Meaning that no
269 * XMP will be generated.
274 gst_tag_xmp_writer_remove_all_schemas (GstTagXmpWriter * config)
276 GstTagXmpWriterData *data;
279 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
281 data = gst_tag_xmp_writer_get_data (config);
283 g_static_mutex_lock (&data->lock);
285 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
288 g_slist_free (data->schemas);
290 data->schemas = NULL;
291 g_static_mutex_unlock (&data->lock);
295 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GstTagXmpWriter * config,
296 const GstTagList * taglist, gboolean read_only)
298 GstTagXmpWriterData *data;
299 GstBuffer *buf = NULL;
303 g_return_val_if_fail (GST_IS_TAG_XMP_WRITER (config), NULL);
305 data = gst_tag_xmp_writer_get_data (config);
307 g_static_mutex_lock (&data->lock);
309 gchar **array = g_new0 (gchar *, g_slist_length (data->schemas) + 1);
311 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
312 array[i++] = (gchar *) iter->data;
314 buf = gst_tag_list_to_xmp_buffer_full (taglist, read_only,
315 (const gchar **) array);
319 g_static_mutex_unlock (&data->lock);