Commit 6cc96a67 authored by Thiago Santos's avatar Thiago Santos
Browse files

tag: xmp: Add function to list the available schemas

Adds a function to list the available schemas in our xmp lib

https://bugzilla.gnome.org/show_bug.cgi?id=645167
parent f1f0625e
......@@ -35,6 +35,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "tag.h"
#include <gst/gsttagsetter.h>
#include "gsttageditingprivate.h"
#include <stdio.h>
......@@ -43,6 +44,32 @@
#include <time.h>
#include <ctype.h>
static const gchar *schema_list[] = {
"dc",
"xap",
"tiff",
"exif",
"photoshop",
"Iptc4xmpCore",
NULL
};
/**
* gst_tag_xmp_list_schemas:
*
* Gets the list of supported schemas in the xmp lib
*
* Returns: a %NULL terminated array of strings with the schema names
*
* Since: 0.10.33
*/
const gchar **
gst_tag_xmp_list_schemas (void)
{
return schema_list;
}
typedef struct _XmpSerializationData XmpSerializationData;
typedef struct _XmpTag XmpTag;
/*
......@@ -63,6 +90,29 @@ typedef void (*XmpDeserializationFunc) (XmpTag * xmptag, GstTagList * taglist,
const gchar * gst_tag, const gchar * xmp_tag_value,
const gchar * str, GSList ** pending_tags);
struct _XmpSerializationData
{
GString *data;
GList *schemas;
};
static gboolean
xmp_serialization_data_use_schema (XmpSerializationData * serdata,
const gchar * schemaname)
{
GList *iter;
if (serdata->schemas == NULL)
return TRUE;
for (iter = serdata->schemas; iter; iter = g_list_next (iter)) {
const gchar *name = (const gchar *) iter->data;
if (strcmp (name, schemaname) == 0)
return TRUE;
}
return FALSE;
}
#define GST_XMP_TAG_TYPE_SIMPLE 0
#define GST_XMP_TAG_TYPE_BAG 1
......@@ -192,18 +242,22 @@ _gst_xmp_schema_add_simple_mapping (GstXmpSchema * schema,
* have our lists modified during usage
*/
static GPtrArray *
_xmp_tag_get_mapping (const gchar * gst_tag)
_xmp_tag_get_mapping (const gchar * gst_tag, XmpSerializationData * serdata)
{
GPtrArray *ret = NULL;
GHashTableIter iter;
GQuark key = g_quark_from_string (gst_tag);
gpointer iterkey, value;
const gchar *schemaname;
g_hash_table_iter_init (&iter, __xmp_schemas);
while (!ret && g_hash_table_iter_next (&iter, &iterkey, &value)) {
GstXmpSchema *schema = (GstXmpSchema *) value;
ret = (GPtrArray *) gst_xmp_schema_lookup (schema, GUINT_TO_POINTER (key));
schemaname = g_quark_to_string (GPOINTER_TO_UINT (iterkey));
if (xmp_serialization_data_use_schema (serdata, schemaname))
ret =
(GPtrArray *) gst_xmp_schema_lookup (schema, GUINT_TO_POINTER (key));
}
return ret;
}
......@@ -818,7 +872,7 @@ _init_xmp_tag_map ()
schema = gst_xmp_schema_new ();
_gst_xmp_schema_add_simple_mapping (schema, GST_TAG_USER_RATING,
"xmp:Rating", GST_XMP_TAG_TYPE_SIMPLE, NULL, deserialize_xmp_rating);
_gst_xmp_add_schema ("xmp", schema);
_gst_xmp_add_schema ("xap", schema);
/* tiff */
schema = gst_xmp_schema_new ();
......@@ -1453,12 +1507,13 @@ static void
write_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
{
guint i = 0, ct = gst_tag_list_get_tag_size (list, tag), tag_index;
GString *data = user_data;
XmpSerializationData *serialization_data = user_data;
GString *data = serialization_data->data;
GPtrArray *xmp_tag_array = NULL;
char *s;
/* map gst-tag to xmp tag */
xmp_tag_array = _xmp_tag_get_mapping (tag);
xmp_tag_array = _xmp_tag_get_mapping (tag, serialization_data);
if (!xmp_tag_array) {
GST_WARNING ("no mapping for %s to xmp", tag);
......@@ -1516,23 +1571,32 @@ write_one_tag (const GstTagList * list, const gchar * tag, gpointer user_data)
}
/**
* gst_tag_list_to_xmp_buffer:
* gst_tag_list_to_xmp_buffer_full:
* @list: tags
* @read_only: does the container forbid inplace editing
* @schemas: list of schemas to be used on serialization
*
* Formats a taglist as a xmp packet.
* Formats a taglist as a xmp packet using only the selected
* schemas. An empty list (%NULL) means that all schemas should
* be used
*
* Returns: new buffer or %NULL, unref the buffer when done
*
* Since: 0.10.29
* Since: 0.10.33
*/
GstBuffer *
gst_tag_list_to_xmp_buffer (const GstTagList * list, gboolean read_only)
gst_tag_list_to_xmp_buffer_full (const GstTagList * list, gboolean read_only,
GList * schemas)
{
GstBuffer *buffer = NULL;
GString *data = g_string_sized_new (4096);
XmpSerializationData serialization_data;
GString *data;
guint i;
serialization_data.data = g_string_sized_new (4096);
serialization_data.schemas = schemas;
data = serialization_data.data;
xmp_tags_initialize ();
g_return_val_if_fail (GST_IS_TAG_LIST (list), NULL);
......@@ -1546,15 +1610,17 @@ gst_tag_list_to_xmp_buffer (const GstTagList * list, gboolean read_only)
"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"");
i = 0;
while (ns_match[i].ns_prefix) {
g_string_append_printf (data, " xmlns:%s=\"%s\"", ns_match[i].ns_prefix,
ns_match[i].ns_uri);
if (xmp_serialization_data_use_schema (&serialization_data,
ns_match[i].ns_prefix))
g_string_append_printf (data, " xmlns:%s=\"%s\"",
ns_match[i].ns_prefix, ns_match[i].ns_uri);
i++;
}
g_string_append (data, ">\n");
g_string_append (data, "<rdf:Description rdf:about=\"\">\n");
/* iterate the taglist */
gst_tag_list_foreach (list, write_one_tag, data);
gst_tag_list_foreach (list, write_one_tag, &serialization_data);
/* xmp footer */
g_string_append (data, "</rdf:Description>\n");
......@@ -1581,5 +1647,22 @@ gst_tag_list_to_xmp_buffer (const GstTagList * list, gboolean read_only)
return buffer;
}
/**
* gst_tag_list_to_xmp_buffer:
* @list: tags
* @read_only: does the container forbid inplace editing
*
* Formats a taglist as a xmp packet.
*
* Returns: new buffer or %NULL, unref the buffer when done
*
* Since: 0.10.29
*/
GstBuffer *
gst_tag_list_to_xmp_buffer (const GstTagList * list, gboolean read_only)
{
return gst_tag_list_to_xmp_buffer_full (list, read_only, NULL);
}
#undef gst_xmp_schema_lookup
#undef gst_xmp_schema_insert
......@@ -474,6 +474,9 @@ gboolean gst_tag_list_add_id3_image (GstTagList * tag_list,
GstTagList * gst_tag_list_from_xmp_buffer (const GstBuffer * buffer);
GstBuffer * gst_tag_list_to_xmp_buffer (const GstTagList * list,
gboolean read_only);
GstBuffer * gst_tag_list_to_xmp_buffer_full (const GstTagList * list,
gboolean read_only, GList * schemas);
const gchar** gst_tag_xmp_list_schemas (void);
/* functions related to exif */
GstBuffer * gst_tag_list_to_exif_buffer (const GstTagList * taglist,
......
......@@ -24,9 +24,11 @@ EXPORTS
gst_tag_list_to_exif_buffer_with_tiff_header
gst_tag_list_to_vorbiscomment_buffer
gst_tag_list_to_xmp_buffer
gst_tag_list_to_xmp_buffer_full
gst_tag_parse_extended_comment
gst_tag_register_musicbrainz_tags
gst_tag_to_id3_tag
gst_tag_to_vorbis_comments
gst_tag_to_vorbis_tag
gst_tag_xmp_list_schemas
gst_vorbis_tag_add
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment