1 /* GStreamer TagXmpWriter
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:gsttagxmpwriter
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;
50 #if !GLIB_CHECK_VERSION (2, 31, 0)
55 } GstTagXmpWriterData;
57 #if !GLIB_CHECK_VERSION (2, 31, 0)
58 #define GST_TAG_XMP_WRITER_DATA_LOCK(data) g_static_mutex_lock(&data->lock)
59 #define GST_TAG_XMP_WRITER_DATA_UNLOCK(data) g_static_mutex_unlock(&data->lock)
61 #define GST_TAG_XMP_WRITER_DATA_LOCK(data) g_mutex_lock(&data->lock)
62 #define GST_TAG_XMP_WRITER_DATA_UNLOCK(data) g_mutex_unlock(&data->lock)
66 gst_tag_xmp_writer_get_type (void)
68 static volatile gsize xmp_config_type = 0;
70 if (g_once_init_enter (&xmp_config_type)) {
72 static const GTypeInfo xmp_config_info = {
73 sizeof (GstTagXmpWriterInterface), /* class_size */
75 NULL, /* base_finalize */
77 NULL, /* class_finalize */
78 NULL, /* class_data */
84 _type = g_type_register_static (G_TYPE_INTERFACE, "GstTagXmpWriter",
86 tag_xmp_writer_key = g_quark_from_static_string ("GST_TAG_XMP_WRITER");
87 g_type_interface_add_prerequisite (_type, GST_TYPE_ELEMENT);
89 g_once_init_leave (&xmp_config_type, _type);
92 return xmp_config_type;
96 gst_tag_xmp_writer_data_add_schema_unlocked (GstTagXmpWriterData * data,
99 if (!g_slist_find_custom (data->schemas, schema, (GCompareFunc) strcmp)) {
100 data->schemas = g_slist_prepend (data->schemas, g_strdup (schema));
105 gst_tag_xmp_writer_data_add_all_schemas_unlocked (GstTagXmpWriterData * data)
107 const gchar **schemas;
110 /* initialize it with all schemas */
111 schemas = gst_tag_xmp_list_schemas ();
112 while (schemas[i] != NULL) {
113 gst_tag_xmp_writer_data_add_schema_unlocked (data, schemas[i]);
120 gst_tag_xmp_writer_data_free (gpointer p)
122 GstTagXmpWriterData *data = (GstTagXmpWriterData *) p;
126 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
129 g_slist_free (data->schemas);
131 #if !GLIB_CHECK_VERSION (2, 31, 0)
132 g_static_mutex_free (&data->lock);
134 g_mutex_clear (&data->lock);
137 g_slice_free (GstTagXmpWriterData, data);
140 static GstTagXmpWriterData *
141 gst_tag_xmp_writer_get_data (GstTagXmpWriter * xmpconfig)
143 GstTagXmpWriterData *data;
145 data = g_object_get_qdata (G_OBJECT (xmpconfig), tag_xmp_writer_key);
147 /* make sure no other thread is creating a GstTagData at the same time */
148 #if !GLIB_CHECK_VERSION (2, 31, 0)
149 static GStaticMutex create_mutex = G_STATIC_MUTEX_INIT;
151 g_static_mutex_lock (&create_mutex);
153 static GMutex create_mutex; /* no initialisation required */
155 g_mutex_lock (&create_mutex);
158 data = g_object_get_qdata (G_OBJECT (xmpconfig), tag_xmp_writer_key);
160 data = g_slice_new (GstTagXmpWriterData);
162 #if !GLIB_CHECK_VERSION (2, 31, 0)
163 g_static_mutex_init (&data->lock);
165 g_mutex_init (&data->lock);
167 data->schemas = NULL;
168 gst_tag_xmp_writer_data_add_all_schemas_unlocked (data);
170 g_object_set_qdata_full (G_OBJECT (xmpconfig), tag_xmp_writer_key, data,
171 gst_tag_xmp_writer_data_free);
173 #if !GLIB_CHECK_VERSION (2, 31, 0)
174 g_static_mutex_unlock (&create_mutex);
176 g_mutex_unlock (&create_mutex);
184 * gst_tag_xmp_writer_add_all_schemas:
185 * @config: a #GstTagXmpWriter
187 * Adds all available XMP schemas to the configuration. Meaning that
193 gst_tag_xmp_writer_add_all_schemas (GstTagXmpWriter * config)
195 GstTagXmpWriterData *data;
197 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
199 data = gst_tag_xmp_writer_get_data (config);
201 GST_TAG_XMP_WRITER_DATA_LOCK (data);
202 gst_tag_xmp_writer_data_add_all_schemas_unlocked (data);
203 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);
207 * gst_tag_xmp_writer_add_schema:
208 * @config: a #GstTagXmpWriter
209 * @schema: the schema to be added
211 * Adds @schema to the list schemas
216 gst_tag_xmp_writer_add_schema (GstTagXmpWriter * config, const gchar * schema)
218 GstTagXmpWriterData *data;
220 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
222 data = gst_tag_xmp_writer_get_data (config);
224 GST_TAG_XMP_WRITER_DATA_LOCK (data);
225 gst_tag_xmp_writer_data_add_schema_unlocked (data, schema);
226 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);
230 * gst_tag_xmp_writer_has_schema:
231 * @config: a #GstTagXmpWriter
232 * @schema: the schema to test
234 * Checks if @schema is going to be used
236 * Returns: %TRUE if it is going to be used
240 gst_tag_xmp_writer_has_schema (GstTagXmpWriter * config, const gchar * schema)
242 GstTagXmpWriterData *data;
243 gboolean ret = FALSE;
246 g_return_val_if_fail (GST_IS_TAG_XMP_WRITER (config), FALSE);
248 data = gst_tag_xmp_writer_get_data (config);
250 GST_TAG_XMP_WRITER_DATA_LOCK (data);
251 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
252 if (strcmp ((const gchar *) iter->data, schema) == 0) {
257 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);
263 * gst_tag_xmp_writer_remove_schema:
264 * @config: a #GstTagXmpWriter
265 * @schema: the schema to remove
267 * Removes a schema from the list of schemas to use. Nothing is done if
268 * the schema wasn't in the list
273 gst_tag_xmp_writer_remove_schema (GstTagXmpWriter * config,
274 const gchar * schema)
276 GstTagXmpWriterData *data;
279 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
281 data = gst_tag_xmp_writer_get_data (config);
283 GST_TAG_XMP_WRITER_DATA_LOCK (data);
284 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
285 if (strcmp ((const gchar *) iter->data, schema) == 0) {
287 data->schemas = g_slist_delete_link (data->schemas, iter);
291 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);
295 * gst_tag_xmp_writer_remove_all_schemas:
296 * @config: a #GstTagXmpWriter
298 * Removes all schemas from the list of schemas to use. Meaning that no
299 * XMP will be generated.
304 gst_tag_xmp_writer_remove_all_schemas (GstTagXmpWriter * config)
306 GstTagXmpWriterData *data;
309 g_return_if_fail (GST_IS_TAG_XMP_WRITER (config));
311 data = gst_tag_xmp_writer_get_data (config);
313 GST_TAG_XMP_WRITER_DATA_LOCK (data);
315 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
318 g_slist_free (data->schemas);
320 data->schemas = NULL;
321 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);
325 gst_tag_xmp_writer_tag_list_to_xmp_buffer (GstTagXmpWriter * config,
326 const GstTagList * taglist, gboolean read_only)
328 GstTagXmpWriterData *data;
329 GstBuffer *buf = NULL;
333 g_return_val_if_fail (GST_IS_TAG_XMP_WRITER (config), NULL);
335 data = gst_tag_xmp_writer_get_data (config);
337 GST_TAG_XMP_WRITER_DATA_LOCK (data);
339 gchar **array = g_new0 (gchar *, g_slist_length (data->schemas) + 1);
341 for (iter = data->schemas; iter; iter = g_slist_next (iter)) {
342 array[i++] = (gchar *) iter->data;
344 buf = gst_tag_list_to_xmp_buffer_full (taglist, read_only,
345 (const gchar **) array);
349 GST_TAG_XMP_WRITER_DATA_UNLOCK (data);