From c1e6c76cdb550c564f58e84c66b3e993ea36227d Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Wed, 28 Nov 2007 08:13:52 +0000 Subject: Small fixes in get_range and better structure for generic muxer and demuxer. Original commit message from CVS: Small fixes in get_range and better structure for generic muxer and demuxer. --- ext/metadata/Makefile.am | 22 +- ext/metadata/gstmetadata.c | 15 + ext/metadata/gstmetadatamux.c | 1583 +++++++++++++++++++++++++++++++++++++- ext/metadata/gstmetadatamux.h | 49 +- ext/metadata/gstmetadataparse.c | 117 +-- ext/metadata/gstmetadataparse.h | 4 +- ext/metadata/metadata.c | 223 ++++++ ext/metadata/metadata.h | 122 +++ ext/metadata/metadataexif.c | 168 ++++ ext/metadata/metadataexif.h | 61 ++ ext/metadata/metadataiptc.c | 144 ++++ ext/metadata/metadataiptc.h | 61 ++ ext/metadata/metadataparse.c | 224 ------ ext/metadata/metadataparse.h | 122 --- ext/metadata/metadataparseexif.c | 148 ---- ext/metadata/metadataparseexif.h | 58 -- ext/metadata/metadataparseiptc.c | 127 --- ext/metadata/metadataparseiptc.h | 59 -- ext/metadata/metadataparsexmp.c | 245 ------ ext/metadata/metadataparsexmp.h | 63 -- ext/metadata/metadatatags.c | 91 +++ ext/metadata/metadatatags.h | 62 ++ ext/metadata/metadataxmp.c | 261 +++++++ ext/metadata/metadataxmp.h | 65 ++ 24 files changed, 2943 insertions(+), 1151 deletions(-) create mode 100644 ext/metadata/metadata.c create mode 100644 ext/metadata/metadata.h create mode 100644 ext/metadata/metadataexif.c create mode 100644 ext/metadata/metadataexif.h create mode 100644 ext/metadata/metadataiptc.c create mode 100644 ext/metadata/metadataiptc.h delete mode 100644 ext/metadata/metadataparse.c delete mode 100644 ext/metadata/metadataparse.h delete mode 100644 ext/metadata/metadataparseexif.c delete mode 100644 ext/metadata/metadataparseexif.h delete mode 100644 ext/metadata/metadataparseiptc.c delete mode 100644 ext/metadata/metadataparseiptc.h delete mode 100644 ext/metadata/metadataparsexmp.c delete mode 100644 ext/metadata/metadataparsexmp.h create mode 100644 ext/metadata/metadatatags.c create mode 100644 ext/metadata/metadatatags.h create mode 100644 ext/metadata/metadataxmp.c create mode 100644 ext/metadata/metadataxmp.h (limited to 'ext/metadata') diff --git a/ext/metadata/Makefile.am b/ext/metadata/Makefile.am index 950f9ff4..4247a338 100644 --- a/ext/metadata/Makefile.am +++ b/ext/metadata/Makefile.am @@ -2,28 +2,30 @@ plugin_LTLIBRARIES = libgstmetadata.la libgstmetadata_la_SOURCES = gstmetadata.c \ gstmetadataparse.c \ - metadataparse.c \ + metadata.c \ metadataparsejpeg.c \ metadataparsepng.c \ - metadataparseexif.c \ - metadataparseiptc.c \ - metadataparsexmp.c \ + metadataexif.c \ + metadataiptc.c \ + metadataxmp.c \ metadataparseutil.c \ metadatatypes.c \ - gstmetadatamux.c + gstmetadatamux.c \ + metadatatags.c libgstmetadata_la_CFLAGS = $(METADATA_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) libgstmetadata_la_LIBADD = $(METADATA_LIBS) -lgsttag-@GST_MAJORMINOR@ $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) libgstmetadata_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) noinst_HEADERS = gstmetadataparse.h \ - metadataparse.h \ + metadata.h \ metadataparsejpeg.h \ metadataparsepng.h \ - metadataparseexif.h \ - metadataparseiptc.h \ - metadataparsexmp.h \ + metadataexif.h \ + metadataiptc.h \ + metadataxmp.h \ metadataparseutil.h \ metadatatypes.h \ - gstmetadatamux.h + gstmetadatamux.h \ + metadatatags.h diff --git a/ext/metadata/gstmetadata.c b/ext/metadata/gstmetadata.c index 858f33db..4b150a26 100644 --- a/ext/metadata/gstmetadata.c +++ b/ext/metadata/gstmetadata.c @@ -47,15 +47,30 @@ #include +#include "metadatatags.h" + extern gboolean gst_metadata_parse_plugin_init (GstPlugin * plugin); extern gboolean gst_metadata_mux_plugin_init (GstPlugin * plugin); +GST_DEBUG_CATEGORY_EXTERN (gst_metadata_exif_debug); +GST_DEBUG_CATEGORY_EXTERN (gst_metadata_iptc_debug); +GST_DEBUG_CATEGORY_EXTERN (gst_metadata_xmp_debug); + static gboolean plugin_init (GstPlugin * plugin) { gboolean ret = TRUE; + GST_DEBUG_CATEGORY_INIT (gst_metadata_exif_debug, "metadata_exif", + 0, "Metadata exif"); + GST_DEBUG_CATEGORY_INIT (gst_metadata_iptc_debug, "metadata_iptc", + 0, "Metadata iptc"); + GST_DEBUG_CATEGORY_INIT (gst_metadata_xmp_debug, "metadata_xmp", 0, + "Metadata xmp"); + + metadata_tags_register (); + ret = gst_metadata_parse_plugin_init (plugin); ret = ret && gst_metadata_mux_plugin_init (plugin); diff --git a/ext/metadata/gstmetadatamux.c b/ext/metadata/gstmetadatamux.c index 556191b7..02bb99b6 100644 --- a/ext/metadata/gstmetadatamux.c +++ b/ext/metadata/gstmetadatamux.c @@ -42,13 +42,13 @@ */ /** - * SECTION:element-plugin + * SECTION:metadatamux-metadata * * * Example launch line * * - * gst-launch -v -m filesrc location=./test.jpeg ! metadatamux ! filesink location=meta.jpeg + * gst-launch -v -m filesrc location=./test.jpeg ! metadatamux ! fakesink silent=TRUE * * * @@ -62,9 +62,20 @@ #include "gstmetadatamux.h" +#include "metadataexif.h" + +#include "metadataiptc.h" + +#include "metadataxmp.h" + +#include + GST_DEBUG_CATEGORY_STATIC (gst_metadata_mux_debug); #define GST_CAT_DEFAULT gst_metadata_mux_debug +#define GOTO_DONE_IF_NULL(ptr) do { if ( NULL == (ptr) ) goto done; } while(FALSE) +#define GOTO_DONE_IF_NULL_AND_FAIL(ptr, ret) do { if ( NULL == (ptr) ) { (ret) = FALSE; goto done; } } while(FALSE) + /* Filter signals and args */ enum { @@ -75,6 +86,9 @@ enum enum { ARG_0, + ARG_EXIF, + ARG_IPTC, + ARG_XMP }; static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", @@ -93,22 +107,79 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_BOILERPLATE (GstMetadataMux, gst_metadata_mux, GstElement, GST_TYPE_ELEMENT); +static GstMetadataMuxClass *metadata_parent_class = NULL; + +static void gst_metadata_mux_dispose (GObject * object); + +static void gst_metadata_mux_finalize (GObject * object); + static void gst_metadata_mux_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_metadata_mux_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); +static GstStateChangeReturn +gst_metadata_mux_change_state (GstElement * element, GstStateChange transition); + +static GstCaps *gst_metadata_mux_get_caps (GstPad * pad); static gboolean gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps); +static gboolean gst_metadata_mux_src_event (GstPad * pad, GstEvent * event); +static gboolean gst_metadata_mux_sink_event (GstPad * pad, GstEvent * event); + static GstFlowReturn gst_metadata_mux_chain (GstPad * pad, GstBuffer * buf); +static gboolean gst_metadata_mux_checkgetrange (GstPad * srcpad); + +static GstFlowReturn +gst_metadata_mux_get_range (GstPad * pad, guint64 offset_orig, guint size, + GstBuffer ** buf); + +static gboolean gst_metadata_mux_sink_activate (GstPad * pad); + +static gboolean +gst_metadata_mux_src_activate_pull (GstPad * pad, gboolean active); + +static gboolean gst_metadata_mux_pull_range_mux (GstMetadataMux * filter); + +static void gst_metadata_mux_init_members (GstMetadataMux * filter); +static void gst_metadata_mux_dispose_members (GstMetadataMux * filter); + +static gboolean gst_metadata_mux_configure_srccaps (GstMetadataMux * filter); +static gboolean gst_metadata_mux_configure_caps (GstMetadataMux * filter); + +static int +gst_metadata_mux_mux (GstMetadataMux * filter, const guint8 * buf, + guint32 size); + +static void gst_metadata_mux_send_tags (GstMetadataMux * filter); + + + +static int +gst_metadata_mux_get_strip_seg (const gint64 offset, guint32 size, + const gint64 seg_offset, const guint32 seg_size, + gint64 * boffset, guint32 * bsize, guint32 * seg_binter); + +static gboolean +gst_metadata_mux_strip_push_buffer (GstMetadataMux * filter, + gint64 offset_orig, GstBuffer ** prepend, GstBuffer ** buf); + +static gboolean +gst_metadata_mux_translate_pos_to_orig (GstMetadataMux * filter, gint64 pos, + gint64 * orig_pos, GstBuffer ** buf); + +static const GstQueryType *gst_metadata_mux_get_query_types (GstPad * pad); + +static gboolean gst_metadata_mux_src_query (GstPad * pad, GstQuery * query); + static void gst_metadata_mux_base_init (gpointer gclass) { static GstElementDetails element_details = { - "PluginTemplate", - "Generic/PluginTemplate", - "Generic Template Element", - "Thomas Vander Stichele " + "Metadata muxer", + "Muxer/Metadata", + "Convert tags to metadata (EXIF, IPTC and XMP) and insert into the stream", + "Edgard Lima " }; GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); @@ -129,9 +200,27 @@ gst_metadata_mux_class_init (GstMetadataMuxClass * klass) gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; + metadata_parent_class = g_type_class_peek_parent (klass); + + gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_metadata_mux_dispose); + gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_metadata_mux_finalize); + gobject_class->set_property = gst_metadata_mux_set_property; gobject_class->get_property = gst_metadata_mux_get_property; + g_object_class_install_property (gobject_class, ARG_EXIF, + g_param_spec_boolean ("exif", "EXIF", "Send EXIF metadata ?", + TRUE, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, ARG_IPTC, + g_param_spec_boolean ("iptc", "IPTC", "Send IPTC metadata ?", + TRUE, G_PARAM_READWRITE)); + + g_object_class_install_property (gobject_class, ARG_XMP, + g_param_spec_boolean ("xmp", "XMP", "Send XMP metadata ?", + TRUE, G_PARAM_READWRITE)); + + gstelement_class->change_state = gst_metadata_mux_change_state; } @@ -145,24 +234,49 @@ gst_metadata_mux_init (GstMetadataMux * filter, GstMetadataMuxClass * gclass) { GstElementClass *klass = GST_ELEMENT_GET_CLASS (filter); + /* sink pad */ + filter->sinkpad = gst_pad_new_from_template (gst_element_class_get_pad_template (klass, "sink"), "sink"); gst_pad_set_setcaps_function (filter->sinkpad, GST_DEBUG_FUNCPTR (gst_metadata_mux_set_caps)); gst_pad_set_getcaps_function (filter->sinkpad, - GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); + GST_DEBUG_FUNCPTR (gst_metadata_mux_get_caps)); + gst_pad_set_event_function (filter->sinkpad, gst_metadata_mux_sink_event); + gst_pad_set_chain_function (filter->sinkpad, + GST_DEBUG_FUNCPTR (gst_metadata_mux_chain)); + gst_pad_set_activate_function (filter->sinkpad, + gst_metadata_mux_sink_activate); + + /* source pad */ filter->srcpad = gst_pad_new_from_template (gst_element_class_get_pad_template (klass, "src"), "src"); gst_pad_set_getcaps_function (filter->srcpad, - GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps)); + GST_DEBUG_FUNCPTR (gst_metadata_mux_get_caps)); + gst_pad_set_event_function (filter->srcpad, gst_metadata_mux_src_event); + gst_pad_set_query_function (filter->srcpad, + GST_DEBUG_FUNCPTR (gst_metadata_mux_src_query)); + gst_pad_set_query_type_function (filter->srcpad, + GST_DEBUG_FUNCPTR (gst_metadata_mux_get_query_types)); + gst_pad_use_fixed_caps (filter->srcpad); + + gst_pad_set_checkgetrange_function (filter->srcpad, + GST_DEBUG_FUNCPTR (gst_metadata_mux_checkgetrange)); + gst_pad_set_getrange_function (filter->srcpad, gst_metadata_mux_get_range); + + gst_pad_set_activatepull_function (filter->srcpad, + GST_DEBUG_FUNCPTR (gst_metadata_mux_src_activate_pull)); + /* addind pads */ gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); - gst_pad_set_chain_function (filter->sinkpad, - GST_DEBUG_FUNCPTR (gst_metadata_mux_chain)); + + /* init members */ + + gst_metadata_mux_init_members (filter); } @@ -173,6 +287,24 @@ gst_metadata_mux_set_property (GObject * object, guint prop_id, GstMetadataMux *filter = GST_METADATA_MUX (object); switch (prop_id) { + case ARG_EXIF: + if (g_value_get_boolean (value)) + set_meta_option (filter->mux_data, META_OPT_EXIF); + else + unset_meta_option (filter->mux_data, META_OPT_EXIF); + break; + case ARG_IPTC: + if (g_value_get_boolean (value)) + set_meta_option (filter->mux_data, META_OPT_IPTC); + else + unset_meta_option (filter->mux_data, META_OPT_IPTC); + break; + case ARG_XMP: + if (g_value_get_boolean (value)) + set_meta_option (filter->mux_data, META_OPT_XMP); + else + unset_meta_option (filter->mux_data, META_OPT_XMP); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -186,6 +318,18 @@ gst_metadata_mux_get_property (GObject * object, guint prop_id, GstMetadataMux *filter = GST_METADATA_MUX (object); switch (prop_id) { + case ARG_EXIF: + g_value_set_boolean (value, + META_DATA_OPTION (filter->mux_data) & META_OPT_EXIF); + break; + case ARG_IPTC: + g_value_set_boolean (value, + META_DATA_OPTION (filter->mux_data) & META_OPT_IPTC); + break; + case ARG_XMP: + g_value_set_boolean (value, + META_DATA_OPTION (filter->mux_data) & META_OPT_XMP); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -194,49 +338,1422 @@ gst_metadata_mux_get_property (GObject * object, guint prop_id, /* GstElement vmethod implementations */ +static GstCaps * +gst_metadata_mux_get_caps (GstPad * pad) +{ + GstMetadataMux *filter = NULL; + GstPad *otherpad; + GstCaps *caps_new = NULL; + GstCaps *caps_otherpad_peer = NULL; + + filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + (filter->srcpad == pad) ? (otherpad = filter->sinkpad) : (otherpad = + filter->srcpad); + + caps_new = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); + + caps_otherpad_peer = gst_pad_get_allowed_caps (otherpad); + GOTO_DONE_IF_NULL (caps_otherpad_peer); + + if (gst_caps_is_empty (caps_otherpad_peer) + || gst_caps_is_any (caps_otherpad_peer)) { + goto done; + } else { + + guint i; + guint caps_size = 0; + + caps_size = gst_caps_get_size (caps_otherpad_peer); + + gst_caps_unref (caps_new); + + caps_new = gst_caps_new_empty (); + + for (i = 0; i < caps_size; ++i) { + GstStructure *structure = NULL; + GstStructure *structure_new = NULL; + const gchar *mime = NULL; + + structure = gst_caps_get_structure (caps_otherpad_peer, i); + + mime = gst_structure_get_name (structure); + + if (pad == filter->sinkpad) { + structure_new = + gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, FALSE, + NULL); + } else { + structure_new = + gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE, + NULL); + } + + gst_caps_append_structure (caps_new, structure_new); + + } + + } + +done: + + if (caps_otherpad_peer) { + gst_caps_unref (caps_otherpad_peer); + caps_otherpad_peer = NULL; + } + + gst_object_unref (filter); + + return caps_new; + +} + +static gboolean +gst_metadata_mux_src_event (GstPad * pad, GstEvent * event) +{ + GstMetadataMux *filter = NULL; + gboolean ret = FALSE; + + filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_SEEK: + { + gdouble rate; + GstFormat format; + GstSeekFlags flags; + GstSeekType start_type; + gint64 start; + GstSeekType stop_type; + gint64 stop; + + /* we don't know where are the chunks to be stripped before mux */ + if (filter->state != MT_STATE_MUXED) + goto done; + + gst_event_parse_seek (event, &rate, &format, &flags, + &start_type, &start, &stop_type, &stop); + + switch (format) { + case GST_FORMAT_BYTES: + break; + case GST_FORMAT_PERCENT: + if (filter->duration < 0) + goto done; + start = start * filter->duration / 100; + stop = stop * filter->duration / 100; + break; + default: + goto done; + } + format = GST_FORMAT_BYTES; + + if (start_type == GST_SEEK_TYPE_CUR) + start = filter->offset + start; + else if (start_type == GST_SEEK_TYPE_END) { + if (filter->duration < 0) + goto done; + start = filter->duration + start; + } + start_type == GST_SEEK_TYPE_SET; + + if (filter->prepend_buffer) { + gst_buffer_unref (filter->prepend_buffer); + filter->prepend_buffer = NULL; + } + + /* FIXME: related to append */ + filter->offset = start; + gst_metadata_mux_translate_pos_to_orig (filter, start, &start, + &filter->prepend_buffer); + filter->offset_orig = start; + + if (stop_type == GST_SEEK_TYPE_CUR) + stop = filter->offset + stop; + else if (stop_type == GST_SEEK_TYPE_END) { + if (filter->duration < 0) + goto done; + stop = filter->duration + stop; + } + stop_type == GST_SEEK_TYPE_SET; + + gst_metadata_mux_translate_pos_to_orig (filter, stop, &stop, NULL); + + gst_event_unref (event); + event = gst_event_new_seek (rate, format, flags, + start_type, start, stop_type, stop); + + } + break; + default: + break; + } + + ret = gst_pad_event_default (pad, event); + event = NULL; /* event has another owner */ + +done: + + if (event) { + gst_event_unref (event); + } + + gst_object_unref (filter); + + return ret; + +} + +static gboolean +gst_metadata_mux_sink_event (GstPad * pad, GstEvent * event) +{ + GstMetadataMux *filter = NULL; + gboolean ret = FALSE; + + filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_EOS: + if (filter->need_more_data) { + GST_ELEMENT_WARNING (filter, STREAM, DEMUX, (NULL), + ("Need more data. Unexpected EOS")); + } + break; + case GST_EVENT_TAG: + break; + default: + break; + } + + ret = gst_pad_event_default (pad, event); + + gst_object_unref (filter); + + return ret; + +} + +static void +gst_metadata_mux_dispose (GObject * object) +{ + GstMetadataMux *filter = NULL; + + filter = GST_METADATA_MUX (object); + + gst_metadata_mux_dispose_members (filter); + + G_OBJECT_CLASS (metadata_parent_class)->dispose (object); +} + +static void +gst_metadata_mux_finalize (GObject * object) +{ + G_OBJECT_CLASS (metadata_parent_class)->finalize (object); +} + +static void +gst_metadata_mux_dispose_members (GstMetadataMux * filter) +{ + metadata_dispose (&filter->mux_data); + + if (filter->adapter_parsing) { + gst_object_unref (filter->adapter_parsing); + filter->adapter_parsing = NULL; + } + + if (filter->adapter_holding) { + gst_object_unref (filter->adapter_holding); + filter->adapter_holding = NULL; + } + + if (filter->taglist) { + gst_tag_list_free (filter->taglist); + filter->taglist = NULL; + } + + if (filter->append_buffer) { + gst_buffer_unref (filter->append_buffer); + filter->append_buffer = NULL; + } + + if (filter->prepend_buffer) { + gst_buffer_unref (filter->prepend_buffer); + filter->prepend_buffer = NULL; + } +} + +static void +gst_metadata_mux_init_members (GstMetadataMux * filter) +{ + filter->need_send_tag = FALSE; + filter->exif = TRUE; + filter->iptc = TRUE; + filter->xmp = TRUE; + + filter->taglist = NULL; + filter->adapter_parsing = NULL; + filter->adapter_holding = NULL; + filter->next_offset = 0; + filter->next_size = 0; + filter->img_type = IMG_NONE; + filter->offset_orig = 0; + filter->duration_orig = 0; + filter->offset = 0; + filter->duration = 0; + filter->state = MT_STATE_NULL; + filter->need_more_data = FALSE; + + filter->append_buffer = NULL; + filter->prepend_buffer = NULL; + + memset (&filter->mux_data, 0x00, sizeof (MetaData)); +} + +static gboolean +gst_metadata_mux_configure_srccaps (GstMetadataMux * filter) +{ + GstCaps *caps = NULL; + gboolean ret = FALSE; + gchar *mime = NULL; + + switch (filter->img_type) { + case IMG_JPEG: + mime = "image/jpeg"; + break; + case IMG_PNG: + mime = "image/png"; + break; + default: + ret = FALSE; + goto done; + break; + } + + caps = + gst_caps_new_simple (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE, NULL); + + ret = gst_pad_set_caps (filter->srcpad, caps); + +done: + + if (caps) { + gst_caps_unref (caps); + caps = NULL; + } + + return ret; + +} + +static gboolean +gst_metadata_mux_configure_caps (GstMetadataMux * filter) +{ + GstCaps *caps = NULL; + gboolean ret = FALSE; + gchar *mime = NULL; + GstPad *peer = NULL; + + peer = gst_pad_get_peer (filter->sinkpad); + + switch (filter->img_type) { + case IMG_JPEG: + mime = "image/jpeg"; + break; + case IMG_PNG: + mime = "image/png"; + break; + default: + goto done; + break; + } + + caps = gst_caps_new_simple (mime, NULL); + + if (!gst_pad_set_caps (peer, caps)) { + goto done; + } + + ret = gst_pad_set_caps (filter->sinkpad, caps); + +done: + + if (caps) { + gst_caps_unref (caps); + caps = NULL; + } + + if (peer) { + gst_object_unref (peer); + peer = NULL; + } + + return ret; + +} + /* this function handles the link with other elements */ static gboolean gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps) { - GstMetadataMux *filter; - GstPad *otherpad; + GstMetadataMux *filter = NULL; + GstStructure *structure = NULL; + const gchar *mime = NULL; + gboolean ret = FALSE; + gboolean muxd = TRUE; filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); - otherpad = (pad == filter->srcpad) ? filter->sinkpad : filter->srcpad; - return gst_pad_set_caps (pad, caps); + structure = gst_caps_get_structure (caps, 0); + + mime = gst_structure_get_name (structure); + + if (strcmp (mime, "image/jpeg") == 0) { + filter->img_type = IMG_JPEG; + } else if (strcmp (mime, "image/png") == 0) { + filter->img_type = IMG_PNG; + } else { + ret = FALSE; + goto done; + } + + if (gst_structure_get_boolean (structure, "tags-extracted", &muxd)) { + if (muxd == TRUE) { + ret = FALSE; + goto done; + } + } + + ret = gst_metadata_mux_configure_srccaps (filter); + +done: + + gst_object_unref (filter); + + return ret; } -/* chain function - * this function does the actual processing - */ +static const gchar * +gst_metadata_mux_get_type_name (int img_type) +{ + gchar *type_name = NULL; -static GstFlowReturn -gst_metadata_mux_chain (GstPad * pad, GstBuffer * buf) + switch (img_type) { + case IMG_JPEG: + type_name = "jpeg"; + break; + case IMG_PNG: + type_name = "png"; + break; + default: + type_name = "invalid type"; + break; + } + return type_name; +} + +static void +gst_metadata_mux_send_tags (GstMetadataMux * filter) { - GstMetadataMux *filter; - filter = GST_METADATA_MUX (GST_OBJECT_PARENT (pad)); + GstMessage *msg; + GstTagList *taglist; + GstEvent *event; + + if (META_DATA_OPTION (filter->mux_data) & META_OPT_EXIF) + metadatamux_exif_create_chunk_from_tag_list (&filter->mux_data.exif_adapter, + filter->taglist); + + if (META_DATA_OPTION (filter->mux_data) & META_OPT_IPTC) + metadatamux_iptc_create_chunk_from_tag_list (&filter->mux_data.iptc_adapter, + filter->taglist); + + if (META_DATA_OPTION (filter->mux_data) & META_OPT_XMP) + metadatamux_xmp_create_chunk_from_tag_list (&filter->mux_data.exif_adapter, + filter->taglist); + + + if (!gst_tag_list_is_empty (filter->taglist)) { + + taglist = gst_tag_list_copy (filter->taglist); + msg = gst_message_new_tag (GST_OBJECT (filter), taglist); + gst_element_post_message (GST_ELEMENT (filter), msg); - /* just push out the incoming buffer without touching it */ - return gst_pad_push (filter->srcpad, buf); + taglist = gst_tag_list_copy (filter->taglist); + event = gst_event_new_tag (taglist); + gst_pad_push_event (filter->srcpad, event); + } + + + + filter->need_send_tag = FALSE; } +static const GstQueryType * +gst_metadata_mux_get_query_types (GstPad * pad) +{ + static const GstQueryType gst_metadata_mux_src_query_types[] = { + GST_QUERY_POSITION, + GST_QUERY_DURATION, + GST_QUERY_FORMATS, + 0 + }; -/* entry point to initialize the plug-in - * initialize the plug-in itself - * register the element factories and pad templates - * register the features - * - * exchange the string 'plugin' with your elemnt name + return gst_metadata_mux_src_query_types; +} + +static gboolean +gst_metadata_mux_src_query (GstPad * pad, GstQuery * query) +{ + gboolean ret = FALSE; + GstFormat format; + GstMetadataMux *filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + switch (GST_QUERY_TYPE (query)) { + case GST_QUERY_POSITION: + gst_query_parse_position (query, &format, NULL); + + if (format == GST_FORMAT_BYTES) { + gst_query_set_position (query, GST_FORMAT_BYTES, filter->offset); + ret = TRUE; + } + break; + case GST_QUERY_DURATION: + if (filter->state != MT_STATE_MUXED) + goto done; + + gst_query_parse_duration (query, &format, NULL); + + if (format == GST_FORMAT_BYTES) { + if (filter->duration >= 0) { + gst_query_set_duration (query, GST_FORMAT_BYTES, filter->duration); + ret = TRUE; + } + } + break; + case GST_QUERY_FORMATS: + gst_query_set_formats (query, 1, GST_FORMAT_BYTES); + ret = TRUE; + break; + default: + break; + } + +done: + + gst_object_unref (filter); + + return ret; + +} + +/* + * return: + * -1 -> error + * 0 -> succeded + * 1 -> need more data */ + +static int +gst_metadata_mux_mux (GstMetadataMux * filter, const guint8 * buf, guint32 size) +{ + + int ret = -1; + + filter->next_offset = 0; + filter->next_size = 0; + + ret = metadata_parse (&filter->mux_data, buf, size, + &filter->next_offset, &filter->next_size); + + if (ret < 0) { + if (META_DATA_IMG_TYPE (filter->mux_data) == IMG_NONE) { + /* image type not recognized */ + GST_ELEMENT_ERROR (filter, STREAM, TYPE_NOT_FOUND, (NULL), + ("Only jpeg and png are supported")); + goto done; + } + } else if (ret > 0) { + filter->need_more_data = TRUE; + } else { + int i, j; + guint32 append_size; + guint32 bytes_striped, bytes_inject; + MetadataChunk *strip = filter->mux_data.strip_chunks.chunk; + MetadataChunk *inject = filter->mux_data.inject_chunks.chunk; + const gsize strip_len = filter->mux_data.strip_chunks.len; + const gsize inject_len = filter->mux_data.inject_chunks.len; + + bytes_striped = 0; + bytes_inject = 0; + + /* calculate the new position off injected chunks */ + for (i = 0; i < inject_len; ++i) { + for (j = 0; j < strip_len; ++i) { + if (strip[j].offset_orig >= inject[i].offset_orig) { + break; + } + inject[i].offset = inject[i].offset_orig - bytes_striped + bytes_inject; + bytes_striped += strip[j].size; + } + bytes_inject += inject[i].size; + } + + /* calculate append (doesnt make much sense, but, anyway..) */ + append_size = 0; + for (i = inject_len - 1; i >= 0; --i) { + if (inject[i].offset_orig == filter->duration_orig) + append_size += inject[i].size; + else + break; + } + if (append_size) { + guint8 *data; + + filter->append_buffer = gst_buffer_new_and_alloc (append_size); + GST_BUFFER_FLAG_SET (filter->append_buffer, GST_BUFFER_FLAG_READONLY); + data = GST_BUFFER_DATA (filter->append_buffer); + for (i = inject_len - 1; i >= 0; --i) { + if (inject[i].offset_orig == filter->duration_orig) { + memcpy (data, inject[i].data, inject[i].size); + data += inject[i].size; + } else { + break; + } + } + } + + filter->state = MT_STATE_MUXED; + filter->need_more_data = FALSE; + filter->need_send_tag = TRUE; + } + + if (filter->img_type != META_DATA_IMG_TYPE (filter->mux_data)) { + filter->img_type = META_DATA_IMG_TYPE (filter->mux_data); + if (!gst_metadata_mux_configure_caps (filter)) { + GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL), + ("Couldn't reconfigure caps for %s", + gst_metadata_mux_get_type_name (filter->img_type))); + ret = -1; + goto done; + } + } + +done: + + return ret; + +} + +/* chain function + * this function does the actual processing + */ + +/* FIXME */ +/* Current mux is just done before is pull mode could be activated */ +/* may be it is possible to mux in chain mode by doing some trick with gst-adapter */ +/* the pipeline below would be a test for that case */ +/* gst-launch-0.10 filesrc location=Exif.jpg ! queue ! metadatamux ! filesink location=gen3.jpg */ + +static GstFlowReturn +gst_metadata_mux_chain (GstPad * pad, GstBuffer * buf) +{ + GstMetadataMux *filter = NULL; + GstFlowReturn ret = GST_FLOW_ERROR; + guint32 buf_size = 0; + guint32 new_buf_size = 0; + gboolean append = FALSE; + + filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + if (filter->state != MT_STATE_MUXED) { + guint32 adpt_size = gst_adapter_available (filter->adapter_parsing); + + if (filter->next_offset) { + if (filter->next_offset >= adpt_size) { + /* clean adapter */ + gst_adapter_clear (filter->adapter_parsing); + filter->next_offset -= adpt_size; + if (filter->next_offset >= GST_BUFFER_SIZE (buf)) { + /* we don't need data in this buffer */ + filter->next_offset -= GST_BUFFER_SIZE (buf); + } else { + GstBuffer *new_buf; + + /* add to adapter just need part from buf */ + new_buf = + gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) - + filter->next_offset); + memcpy (GST_BUFFER_DATA (new_buf), + GST_BUFFER_DATA (buf) + filter->next_offset, + GST_BUFFER_SIZE (buf) - filter->next_offset); + filter->next_offset = 0; + gst_adapter_push (filter->adapter_parsing, new_buf); + } + } else { + /* remove first bytes and add buffer */ + gst_adapter_flush (filter->adapter_parsing, filter->next_offset); + filter->next_offset = 0; + gst_adapter_push (filter->adapter_parsing, gst_buffer_copy (buf)); + } + } else { + /* just push buffer */ + gst_adapter_push (filter->adapter_parsing, gst_buffer_copy (buf)); + } + + adpt_size = gst_adapter_available (filter->adapter_parsing); + + if (adpt_size && filter->next_size <= adpt_size) { + const guint8 *new_buf = + gst_adapter_peek (filter->adapter_parsing, adpt_size); + + if (gst_metadata_mux_mux (filter, new_buf, adpt_size) < 0) + goto done; + } + } + + if (filter->state == MT_STATE_MUXED) { + + if (filter->adapter_holding) { + gst_adapter_push (filter->adapter_holding, buf); + buf = gst_adapter_take_buffer (filter->adapter_holding, + gst_adapter_available (filter->adapter_holding)); + g_object_unref (filter->adapter_holding); + filter->adapter_holding = NULL; + } + + if (filter->need_send_tag) { + gst_metadata_mux_send_tags (filter); + } + + if (filter->offset_orig + GST_BUFFER_SIZE (buf) == filter->duration_orig) + append = TRUE; + + buf_size = GST_BUFFER_SIZE (buf); + + gst_metadata_mux_strip_push_buffer (filter, filter->offset_orig, + &filter->prepend_buffer, &buf); + + if (buf) { /* may be all buffer has been striped */ + gst_buffer_set_caps (buf, GST_PAD_CAPS (filter->srcpad)); + new_buf_size = GST_BUFFER_SIZE (buf); + + ret = gst_pad_push (filter->srcpad, buf); + buf = NULL; /* this function don't owner it anymore */ + if (ret != GST_FLOW_OK) + goto done; + } else { + ret = GST_FLOW_OK; + } + + if (append && filter->append_buffer) { + gst_buffer_set_caps (filter->append_buffer, + GST_PAD_CAPS (filter->srcpad)); + gst_buffer_ref (filter->append_buffer); + ret = gst_pad_push (filter->srcpad, filter->append_buffer); + if (ret != GST_FLOW_OK) + goto done; + } + + filter->offset_orig += buf_size; + filter->offset += new_buf_size; + + } else { + /* just store while still not muxd */ + if (!filter->adapter_holding) + filter->adapter_holding = gst_adapter_new (); + gst_adapter_push (filter->adapter_holding, buf); + buf = NULL; + ret = GST_FLOW_OK; + } + +done: + + + if (buf) { + /* there was an error and buffer wasn't pushed */ + gst_buffer_unref (buf); + buf = NULL; + } + + gst_object_unref (filter); + + return ret; + +} + +static gboolean +gst_metadata_mux_pull_range_mux (GstMetadataMux * filter) +{ + + int res; + gboolean ret = TRUE; + guint32 offset = 0; + gint64 duration = 0; + GstFormat format = GST_FORMAT_BYTES; + + if (!(ret = + gst_pad_query_peer_duration (filter->sinkpad, &format, &duration))) { + /* this should never happen, but try chain anyway */ + ret = TRUE; + goto done; + } + if (format != GST_FORMAT_BYTES) { + /* this should never happen, but try chain anyway */ + ret = TRUE; + goto done; + } + + do { + GstFlowReturn flow; + GstBuffer *buf = NULL; + + offset += filter->next_offset; + + if (filter->next_size < 4096) { + if (duration - offset < 4096) { + filter->next_size = duration - offset; + } else { + filter->next_size = 4096; + } + } + + flow = + gst_pad_pull_range (filter->sinkpad, offset, filter->next_size, &buf); + if (GST_FLOW_OK != flow) { + ret = FALSE; + goto done; + } + + res = + gst_metadata_mux_mux (filter, GST_BUFFER_DATA (buf), + GST_BUFFER_SIZE (buf)); + if (res < 0) { + ret = FALSE; + goto done; + } + + gst_buffer_unref (buf); + + } while (res > 0); + + if (res == 0) { + int i; + MetadataChunk *strip = filter->mux_data.strip_chunks.chunk; + MetadataChunk *inject = filter->mux_data.inject_chunks.chunk; + const gsize strip_len = filter->mux_data.strip_chunks.len; + const gsize inject_len = filter->mux_data.inject_chunks.len; + + filter->duration = duration; + filter->duration_orig = duration; + + for (i = 0; i < inject_len; ++i) { + filter->duration += inject[i].size; + } + for (i = 0; i < strip_len; ++i) { + filter->duration -= strip[i].size; + } + + } + +done: + + return ret; + +} + +static gboolean +gst_metadata_mux_sink_activate (GstPad * pad) +{ + GstMetadataMux *filter = NULL; + gboolean ret = TRUE; + + + filter = GST_METADATA_MUX (GST_PAD_PARENT (pad)); + + if (!gst_pad_check_pull_range (pad) || + !gst_pad_activate_pull (filter->sinkpad, TRUE)) { + /* FIXME: currently it is not possible to mux in chain. Fail here ? */ + /* nothing to be done by now, activate push mode */ + return gst_pad_activate_push (pad, TRUE); + } + + /* try to mux */ + if (filter->state == MT_STATE_NULL) { + ret = gst_metadata_mux_pull_range_mux (filter); + } + +done: + + if (ret) { + gst_pad_activate_pull (pad, FALSE); + gst_pad_activate_push (filter->srcpad, FALSE); + if (!gst_pad_is_active (pad)) { + ret = gst_pad_activate_push (filter->srcpad, TRUE); + ret = ret && gst_pad_activate_push (pad, TRUE); + } + } + + return ret; + +} + +/* + * offset - offset of buffer in original stream + * size - size of buffer + * seg_offset - offset of segment in original stream + * seg_size - size of segment + * boffset - offset inside buffer where segment starts (-1 for no intersection) + * bsize - size of intersection + * seg_binter - if segment start inside buffer is zero. if segment start before + * buffer and intersect, it is the offset inside segment. + * + * ret: + * -1 - segment before buffer + * 0 - segment intersects + * 1 - segment after buffer + */ + +static int +gst_metadata_mux_get_strip_seg (const gint64 offset, guint32 size, + const gint64 seg_offset, const guint32 seg_size, + gint64 * boffset, guint32 * bsize, guint32 * seg_binter) +{ + int ret = -1; + + *boffset = -1; + *bsize = 0; + *seg_binter = -1; + + /* all segment after buffer */ + if (seg_offset >= offset + size) { + ret = 1; + goto done; + } + + if (seg_offset < offset) { + /* segment start somewhere before buffer */ + + /* all segment before buffer */ + if (seg_offset + seg_size <= offset) { + ret = -1; + goto done; + } + + *seg_binter = offset - seg_offset; + *boffset = 0; + + /* FIXME : optimize to >= size -> = size */ + if (seg_offset + seg_size >= offset + size) { + /* segment cover all buffer */ + *bsize = size; + } else { + /* segment goes from start of buffer to somewhere before end */ + *bsize = seg_size - *seg_binter; + } + + ret = 0; + + } else { + /* segment start somewhere into buffer */ + + *boffset = seg_offset - offset; + *seg_binter = 0; + + if (seg_offset + seg_size <= offset + size) { + /* all segment into buffer */ + *bsize = seg_size; + } else { + *bsize = size - *boffset; + } + + ret = 0; + + } + +done: + + return ret; + +} + +/* + * TRUE -> buffer striped or injeted + * FALSE -> buffer unmodified + */ + +static gboolean +gst_metadata_mux_strip_push_buffer (GstMetadataMux * filter, + gint64 offset_orig, GstBuffer ** prepend, GstBuffer ** buf) +{ + MetadataChunk *strip = filter->mux_data.strip_chunks.chunk; + MetadataChunk *inject = filter->mux_data.inject_chunks.chunk; + const gsize strip_len = filter->mux_data.strip_chunks.len; + const gsize inject_len = filter->mux_data.inject_chunks.len; + + guint32 size_buf_in = GST_BUFFER_SIZE (*buf); + + gint64 *boffset_strip = NULL; + guint32 *bsize_strip = NULL; + guint32 *seg_binter_strip = NULL; + + int i, j; + gboolean need_free_strip = FALSE; + + guint32 striped_bytes = 0; + guint32 injected_bytes = 0; + + guint32 prepend_size = prepend && *prepend ? GST_BUFFER_SIZE (*prepend) : 0; + + if (inject_len) { + + for (i = 0; i < inject_len; ++i) { + int res; + + if (inject[i].offset_orig >= offset_orig) { + if (inject[i].offset_orig < offset_orig + size_buf_in) { + injected_bytes += inject[i].size; + } else { + /* segment is after size (segments are sorted) */ + break; + } + } + } + + } + + /* + * strip segments + */ + + if (strip_len == 0) + goto inject; + + if (G_UNLIKELY (strip_len > 16)) { + boffset_strip = g_new (gint64, strip_len); + bsize_strip = g_new (guint32, strip_len); + seg_binter_strip = g_new (guint32, strip_len); + need_free_strip = TRUE; + } else { + boffset_strip = g_alloca (sizeof (boffset_strip[0]) * strip_len); + bsize_strip = g_alloca (sizeof (bsize_strip[0]) * strip_len); + seg_binter_strip = g_alloca (sizeof (seg_binter_strip[0]) * strip_len); + } + + memset (bsize_strip, 0x00, sizeof (bsize_strip[0]) * strip_len); + + for (i = 0; i < strip_len; ++i) { + int res; + + res = gst_metadata_mux_get_strip_seg (offset_orig, size_buf_in, + strip[i].offset_orig, strip[i].size, &boffset_strip[i], &bsize_strip[i], + &seg_binter_strip[i]); + + /* segment is after size (segments are sorted) */ + striped_bytes += bsize_strip[i]; + if (res > 0) { + break; + } + + } + + if (striped_bytes) { + + guint8 *data; + + if (injected_bytes + prepend_size > striped_bytes) { + GstBuffer *new_buf = + gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes + + prepend_size - striped_bytes); + + memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf), + GST_BUFFER_SIZE (*buf)); + + gst_buffer_unref (*buf); + *buf = new_buf; + + } else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) { + GstBuffer *new_buf = gst_buffer_copy (*buf); + + gst_buffer_unref (*buf); + *buf = new_buf; + GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY); + GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes; + } + + data = GST_BUFFER_DATA (*buf); + + striped_bytes = 0; + for (i = 0; i < strip_len; ++i) { + /* intersect */ + if (bsize_strip[i]) { + memmove (data + boffset_strip[i] - striped_bytes, + data + boffset_strip[i] + bsize_strip[i] - striped_bytes, + size_buf_in - boffset_strip[i] - bsize_strip[i]); + striped_bytes += bsize_strip[i]; + } + } + size_buf_in -= striped_bytes; + + } + +inject: + + /* + * inject segments + */ + + if (inject_len) { + + guint8 *data; + guint32 striped_so_far; + + if (injected_bytes + prepend_size > striped_bytes) { + GstBuffer *new_buf = + gst_buffer_new_and_alloc (GST_BUFFER_SIZE (*buf) + injected_bytes + + prepend_size - striped_bytes); + + memcpy (GST_BUFFER_DATA (new_buf), GST_BUFFER_DATA (*buf), + GST_BUFFER_SIZE (*buf)); + + gst_buffer_unref (*buf); + *buf = new_buf; + + } else if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_READONLY)) { + GstBuffer *new_buf = gst_buffer_copy (*buf); + + gst_buffer_unref (*buf); + *buf = new_buf; + GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY); + GST_BUFFER_SIZE (*buf) += injected_bytes + prepend_size - striped_bytes; + } + + data = GST_BUFFER_DATA (*buf); + + injected_bytes = 0; + striped_so_far = 0; + j = 0; + for (i = 0; i < inject_len; ++i) { + int res; + + while (j < strip_len) { + if (strip[j].offset_orig < inject[i].offset_orig) + striped_so_far += bsize_strip[j++]; + else + break; + } + + if (inject[i].offset_orig >= offset_orig) { + if (inject[i].offset_orig < offset_orig + size_buf_in + striped_bytes) { + /* insert */ + guint32 buf_off = + inject[i].offset_orig - offset_orig - striped_so_far + + injected_bytes; + memmove (data + buf_off + inject[i].size, data + buf_off, + size_buf_in - buf_off); + memcpy (data + buf_off, inject[i].data, inject[i].size); + injected_bytes += inject[i].size; + size_buf_in += injected_bytes; + } else { + /* segment is after size (segments are sorted) */ + break; + } + } + } + + } + + +done: + + if (prepend_size) { + if (injected_bytes == 0 && striped_bytes == 0) { + GstBuffer *new_buf = + gst_buffer_new_and_alloc (size_buf_in + prepend_size); + + memcpy (GST_BUFFER_DATA (new_buf) + prepend_size, GST_BUFFER_DATA (*buf), + size_buf_in); + + gst_buffer_unref (*buf); + *buf = new_buf; + } else { + memmove (GST_BUFFER_DATA (*buf) + prepend_size, GST_BUFFER_DATA (*buf), + size_buf_in); + } + memcpy (GST_BUFFER_DATA (*buf), GST_BUFFER_DATA (*prepend), prepend_size); + gst_buffer_unref (*prepend); + *prepend = NULL; + } + + GST_BUFFER_SIZE (*buf) = size_buf_in + prepend_size; + + if (need_free_strip) { + g_free (boffset_strip); + g_free (bsize_strip); + g_free (seg_binter_strip); + } + + return injected_bytes || striped_bytes; + +} + +/* + * pos - position in stream striped + * orig_pos - position in original stream + * return TRUE - position in original buffer + * FALSE - position in inserted chunk + */ +static gboolean +gst_metadata_mux_translate_pos_to_orig (GstMetadataMux * filter, gint64 pos, + gint64 * orig_pos, GstBuffer ** buf) +{ + int i; + MetadataChunk *strip = filter->mux_data.strip_chunks.chunk; + MetadataChunk *inject = filter->mux_data.inject_chunks.chunk; + const gsize strip_len = filter->mux_data.strip_chunks.len; + const gsize inject_len = filter->mux_data.inject_chunks.len; + gboolean ret = TRUE; + guint64 new_buf_size = 0; + guint64 injected_before = 0; + + if (G_UNLIKELY (pos == -1)) { + *orig_pos = -1; + return TRUE; + } else if (G_UNLIKELY (pos >= filter->duration)) { + /* this should never happen */ + *orig_pos = filter->duration_orig; + return TRUE; + } + + /* calculate for injected */ + + /* just calculate size */ + *orig_pos = pos; /* save pos */ + for (i = 0; i < inject_len; ++i) { + /* check if pos in inside chunk */ + if (inject[i].offset <= pos) { + if (pos < inject[i].offset + inject[i].size) { + /* orig pos points after insert chunk */ + new_buf_size += inject[i].size; + /* put pos after current chunk */ + pos = inject[i].offset + inject[i].size; + ret = FALSE; + } else { + /* in case pos is not inside a injected chunk */ + injected_before += inject[i].size; + } + } else { + break; + } + } + + /* alloc buffer and calcute original pos */ + if (buf && ret == FALSE) { + guint8 *data; + + if (*buf) + gst_buffer_unref (*buf); + *buf = gst_buffer_new_and_alloc (new_buf_size); + data = GST_BUFFER_DATA (*buf); + pos = *orig_pos; /* recover saved pos */ + for (i = 0; i < inject_len; ++i) { + if (inject[i].offset > pos) { + break; + } + if (inject[i].offset <= pos && pos < inject[i].offset + inject[i].size) { + memcpy (data, inject[i].data, inject[i].size); + data += inject[i].size; + pos = inject[i].offset + inject[i].size; + /* out position after insert chunk orig */ + *orig_pos = inject[i].offset_orig + inject[i].size; + } + } + } + + if (ret == FALSE) { + /* if it inside a injected is already done */ + goto done; + } + + /* calculate for striped */ + + *orig_pos = pos - injected_before; + for (i = 0; i < strip_len; ++i) { + if (strip[i].offset_orig > pos) { + break; + } + *orig_pos += strip[i].size; + } + +done: + + if (G_UNLIKELY (*orig_pos >= filter->duration_orig)) { + *orig_pos = filter->duration_orig - 1; + } + + return ret; + +} + +static gboolean +gst_metadata_mux_checkgetrange (GstPad * srcpad) +{ + GstMetadataMux *filter = NULL; + + filter = GST_METADATA_MUX (GST_PAD_PARENT (srcpad)); + + return gst_pad_check_pull_range (filter->sinkpad); +} + +static GstFlowReturn +gst_metadata_mux_get_range (GstPad * pad, + guint64 offset, guint size, GstBuffer ** buf) +{ + GstMetadataMux *filter = NULL; + GstFlowReturn ret = GST_FLOW_OK; + gint64 offset_orig = 0; + guint size_orig; + GstBuffer *prepend = NULL; + gboolean need_append = FALSE; + + filter = GST_METADATA_MUX (GST_PAD_PARENT (pad)); + + if (filter->state != MT_STATE_MUXED) { + ret = GST_FLOW_ERROR; + goto done; + } + + if (offset + size > filter->duration) { + size = filter->duration - offset; + } + + size_orig = size; + + if (filter->need_send_tag) { + gst_metadata_mux_send_tags (filter); + } + + gst_metadata_mux_translate_pos_to_orig (filter, offset, &offset_orig, + &prepend); + + if (size > 1) { + gint64 pos; + + pos = offset + size - 1; + gst_metadata_mux_translate_pos_to_orig (filter, pos, &pos, NULL); + size_orig = pos + 1 - offset_orig; + } + + if (size_orig) { + + ret = gst_pad_pull_range (filter->sinkpad, offset_orig, size_orig, buf); + + if (ret == GST_FLOW_OK && *buf) { + gst_metadata_mux_strip_push_buffer (filter, offset_orig, &prepend, buf); + + if (GST_BUFFER_SIZE (*buf) < size) { + /* need append */ + need_append = TRUE; + } + + } + } else { + *buf = prepend; + } + +done: + + if (need_append) { + /* FIXME: together with SEEK and + * gst_metadata_parse_translate_pos_to_orig + * this way if chunk is added in the end we are in trolble + * ...still not implemented 'cause it will not be the + * case for the time being + */ + } + + return ret; + +} + +static gboolean +gst_metadata_mux_src_activate_pull (GstPad * pad, gboolean active) +{ + GstMetadataMux *filter = NULL; + gboolean ret; + + filter = GST_METADATA_MUX (gst_pad_get_parent (pad)); + + ret = gst_pad_activate_pull (filter->sinkpad, active); + + if (ret && filter->state == MT_STATE_NULL) { + ret = gst_metadata_mux_pull_range_mux (filter); + } + + gst_object_unref (filter); + + return ret; +} + + +static GstStateChangeReturn +gst_metadata_mux_change_state (GstElement * element, GstStateChange transition) +{ + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + GstMetadataMux *filter = GST_METADATA_MUX (element); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + gst_metadata_mux_init_members (filter); + filter->adapter_parsing = gst_adapter_new (); + filter->taglist = gst_tag_list_new (); + metadata_init (&filter->mux_data); + break; + default: + break; + } + + ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); + if (ret == GST_STATE_CHANGE_FAILURE) + goto done; + + switch (transition) { + case GST_STATE_CHANGE_PAUSED_TO_READY: + filter->offset = 0; + filter->offset_orig = 0; + if (filter->adapter_parsing) { + gst_adapter_clear (filter->adapter_parsing); + } + if (filter->adapter_holding) { + gst_adapter_clear (filter->adapter_holding); + } + if (filter->state != MT_STATE_MUXED) { + /* cleanup parser */ + /* FIXME: could be improved a bit to avoid mem allocation */ + metadata_dispose (&filter->mux_data); + metadata_init (&filter->mux_data); + } + break; + case GST_STATE_CHANGE_READY_TO_NULL: + gst_metadata_mux_dispose_members (filter); + break; + default: + break; + } + +done: + + return ret; +} + +/* + * element plugin init function + */ + gboolean gst_metadata_mux_plugin_init (GstPlugin * plugin) { - /* exchange the strings 'plugin' and 'Template plugin' with your - * plugin name and description */ - GST_DEBUG_CATEGORY_INIT (gst_metadata_mux_debug, "metadatamux", - 0, "Metadata muxer"); + GST_DEBUG_CATEGORY_INIT (gst_metadata_mux_debug, "metadatamux", 0, + "Metadata demuxer"); return gst_element_register (plugin, "metadatamux", GST_RANK_NONE, GST_TYPE_METADATA_MUX); diff --git a/ext/metadata/gstmetadatamux.h b/ext/metadata/gstmetadatamux.h index 8deb0f5f..5cc689dd 100644 --- a/ext/metadata/gstmetadatamux.h +++ b/ext/metadata/gstmetadatamux.h @@ -46,8 +46,9 @@ #include -G_BEGIN_DECLS +#include "metadata.h" +G_BEGIN_DECLS /* #defines don't like whitespacey bits */ #define GST_TYPE_METADATA_MUX \ (gst_metadata_mux_get_type()) @@ -55,29 +56,61 @@ G_BEGIN_DECLS (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_METADATA_MUX,GstMetadataMux)) #define GST_METADATA_MUX_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_METADATA_MUX,GstMetadataMuxClass)) -#define GST_IS_METADATAMUX(obj) \ +#define GST_IS_METADATA_MUX(obj) \ (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_METADATA_MUX)) -#define GST_IS_METADATAMUX_CLASS(klass) \ +#define GST_IS_METADATA_MUX_CLASS(klass) \ (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_METADATA_MUX)) - -typedef struct _GstMetadataMux GstMetadataMux; +typedef struct _GstMetadataMux GstMetadataMux; typedef struct _GstMetadataMuxClass GstMetadataMuxClass; +typedef enum _tag_MetadataState +{ + MT_STATE_NULL, /* still need to check media type */ + MT_STATE_MUXED +} MetadataState; + struct _GstMetadataMux { GstElement element; GstPad *sinkpad, *srcpad; + gboolean exif; + gboolean iptc; + gboolean xmp; + + gboolean need_send_tag; + + GstTagList *taglist; + MetaData mux_data; + GstAdapter *adapter_parsing; + GstAdapter *adapter_holding; + guint32 next_offset; + guint32 next_size; + ImageType img_type; + + gint64 offset_orig; /* offset in original stream */ + gint64 duration_orig; /* durarion of stream */ + gint64 offset; /* offset in current stream */ + gint64 duration; /* durarion of modified stream */ + + MetadataState state; + + GstBuffer * prepend_buffer; + GstBuffer * append_buffer; + + gboolean need_more_data; + + + }; -struct _GstMetadataMuxClass +struct _GstMetadataMuxClass { GstElementClass parent_class; }; -GType gst_metadata_mux_get_type (void); +extern GType gst_metadata_mux_get_type (void); G_END_DECLS - #endif /* __GST_METADATA_MUX_H__ */ diff --git a/ext/metadata/gstmetadataparse.c b/ext/metadata/gstmetadataparse.c index cf7783db..45532cd5 100644 --- a/ext/metadata/gstmetadataparse.c +++ b/ext/metadata/gstmetadataparse.c @@ -62,22 +62,17 @@ #include "gstmetadataparse.h" +#include "metadataexif.h" -#include "metadataparseexif.h" +#include "metadataiptc.h" -#include "metadataparseiptc.h" - -#include "metadataparsexmp.h" +#include "metadataxmp.h" #include GST_DEBUG_CATEGORY_STATIC (gst_metadata_parse_debug); #define GST_CAT_DEFAULT gst_metadata_parse_debug -GST_DEBUG_CATEGORY_EXTERN (gst_metadata_parse_exif_debug); -GST_DEBUG_CATEGORY_EXTERN (gst_metadata_parse_iptc_debug); -GST_DEBUG_CATEGORY_EXTERN (gst_metadata_parse_xmp_debug); - #define GOTO_DONE_IF_NULL(ptr) do { if ( NULL == (ptr) ) goto done; } while(FALSE) #define GOTO_DONE_IF_NULL_AND_FAIL(ptr, ret) do { if ( NULL == (ptr) ) { (ret) = FALSE; goto done; } } while(FALSE) @@ -139,7 +134,7 @@ static GstFlowReturn gst_metadata_parse_chain (GstPad * pad, GstBuffer * buf); static gboolean gst_metadata_parse_checkgetrange (GstPad * srcpad); -static gboolean +static GstFlowReturn gst_metadata_parse_get_range (GstPad * pad, guint64 offset_orig, guint size, GstBuffer ** buf); @@ -300,21 +295,21 @@ gst_metadata_parse_set_property (GObject * object, guint prop_id, switch (prop_id) { case ARG_EXIF: if (g_value_get_boolean (value)) - set_parse_option (filter->parse_data, PARSE_OPT_EXIF); + set_meta_option (filter->parse_data, META_OPT_EXIF); else - unset_parse_option (filter->parse_data, PARSE_OPT_EXIF); + unset_meta_option (filter->parse_data, META_OPT_EXIF); break; case ARG_IPTC: if (g_value_get_boolean (value)) - set_parse_option (filter->parse_data, PARSE_OPT_IPTC); + set_meta_option (filter->parse_data, META_OPT_IPTC); else - unset_parse_option (filter->parse_data, PARSE_OPT_IPTC); + unset_meta_option (filter->parse_data, META_OPT_IPTC); break; case ARG_XMP: if (g_value_get_boolean (value)) - set_parse_option (filter->parse_data, PARSE_OPT_XMP); + set_meta_option (filter->parse_data, META_OPT_XMP); else - unset_parse_option (filter->parse_data, PARSE_OPT_XMP); + unset_meta_option (filter->parse_data, META_OPT_XMP); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -331,15 +326,15 @@ gst_metadata_parse_get_property (GObject * object, guint prop_id, switch (prop_id) { case ARG_EXIF: g_value_set_boolean (value, - PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_EXIF); + META_DATA_OPTION (filter->parse_data) & META_OPT_EXIF); break; case ARG_IPTC: g_value_set_boolean (value, - PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_IPTC); + META_DATA_OPTION (filter->parse_data) & META_OPT_IPTC); break; case ARG_XMP: g_value_set_boolean (value, - PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_XMP); + META_DATA_OPTION (filter->parse_data) & META_OPT_XMP); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -473,8 +468,11 @@ gst_metadata_parse_src_event (GstPad * pad, GstEvent * event) filter->prepend_buffer = NULL; } + /* FIXME: related to append */ + filter->offset = start; gst_metadata_parse_translate_pos_to_orig (filter, start, &start, &filter->prepend_buffer); + filter->offset_orig = start; if (stop_type == GST_SEEK_TYPE_CUR) stop = filter->offset + stop; @@ -562,7 +560,7 @@ gst_metadata_parse_finalize (GObject * object) static void gst_metadata_parse_dispose_members (GstMetadataParse * filter) { - metadataparse_dispose (&filter->parse_data); + metadata_dispose (&filter->parse_data); if (filter->adapter_parsing) { gst_object_unref (filter->adapter_parsing); @@ -614,7 +612,7 @@ gst_metadata_parse_init_members (GstMetadataParse * filter) filter->append_buffer = NULL; filter->prepend_buffer = NULL; - memset (&filter->parse_data, 0x00, sizeof (ParseData)); + memset (&filter->parse_data, 0x00, sizeof (MetaData)); } static gboolean @@ -767,13 +765,13 @@ gst_metadata_parse_send_tags (GstMetadataParse * filter) GstTagList *taglist; GstEvent *event; - if (PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_EXIF) + if (META_DATA_OPTION (filter->parse_data) & META_OPT_EXIF) metadataparse_exif_tag_list_add (filter->taglist, GST_TAG_MERGE_KEEP, filter->parse_data.exif_adapter); - if (PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_IPTC) + if (META_DATA_OPTION (filter->parse_data) & META_OPT_IPTC) metadataparse_iptc_tag_list_add (filter->taglist, GST_TAG_MERGE_KEEP, filter->parse_data.iptc_adapter); - if (PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_XMP) + if (META_DATA_OPTION (filter->parse_data) & META_OPT_XMP) metadataparse_xmp_tag_list_add (filter->taglist, GST_TAG_MERGE_KEEP, filter->parse_data.xmp_adapter); @@ -823,6 +821,9 @@ gst_metadata_parse_src_query (GstPad * pad, GstQuery * query) } break; case GST_QUERY_DURATION: + if (filter->state != MT_STATE_PARSED) + goto done; + gst_query_parse_duration (query, &format, NULL); if (format == GST_FORMAT_BYTES) { @@ -840,6 +841,8 @@ gst_metadata_parse_src_query (GstPad * pad, GstQuery * query) break; } +done: + gst_object_unref (filter); return ret; @@ -863,11 +866,11 @@ gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf, filter->next_offset = 0; filter->next_size = 0; - ret = metadataparse_parse (&filter->parse_data, buf, size, + ret = metadata_parse (&filter->parse_data, buf, size, &filter->next_offset, &filter->next_size); if (ret < 0) { - if (PARSE_DATA_IMG_TYPE (filter->parse_data) == IMG_NONE) { + if (META_DATA_IMG_TYPE (filter->parse_data) == IMG_NONE) { /* image type not recognized */ GST_ELEMENT_ERROR (filter, STREAM, TYPE_NOT_FOUND, (NULL), ("Only jpeg and png are supported")); @@ -928,8 +931,8 @@ gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf, filter->need_send_tag = TRUE; } - if (filter->img_type != PARSE_DATA_IMG_TYPE (filter->parse_data)) { - filter->img_type = PARSE_DATA_IMG_TYPE (filter->parse_data); + if (filter->img_type != META_DATA_IMG_TYPE (filter->parse_data)) { + filter->img_type = META_DATA_IMG_TYPE (filter->parse_data); if (!gst_metadata_parse_configure_caps (filter)) { GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL), ("Couldn't reconfigure caps for %s", @@ -966,8 +969,6 @@ gst_metadata_parse_chain (GstPad * pad, GstBuffer * buf) filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); - /* commented until I figure out how to strip if it wasn't parsed yet */ - if (filter->state != MT_STATE_PARSED) { guint32 adpt_size = gst_adapter_available (filter->adapter_parsing); @@ -1607,22 +1608,26 @@ gst_metadata_parse_checkgetrange (GstPad * srcpad) return gst_pad_check_pull_range (filter->sinkpad); } -static gboolean +static GstFlowReturn gst_metadata_parse_get_range (GstPad * pad, guint64 offset, guint size, GstBuffer ** buf) { GstMetadataParse *filter = NULL; - gboolean ret = TRUE; - const gint64 offset_orig = 0; + GstFlowReturn ret = GST_FLOW_OK; + gint64 offset_orig = 0; guint size_orig; GstBuffer *prepend = NULL; gboolean need_append = FALSE; filter = GST_METADATA_PARSE (GST_PAD_PARENT (pad)); + if (filter->state != MT_STATE_PARSED) { + ret = GST_FLOW_ERROR; + goto done; + } + if (offset + size > filter->duration) { - /* this should never happen */ - return FALSE; + size = filter->duration - offset; } size_orig = size; @@ -1647,10 +1652,7 @@ gst_metadata_parse_get_range (GstPad * pad, ret = gst_pad_pull_range (filter->sinkpad, offset_orig, size_orig, buf); if (ret == GST_FLOW_OK && *buf) { - /* FIXEME: put prepend here */ gst_metadata_parse_strip_push_buffer (filter, offset_orig, &prepend, buf); - filter->offset_orig = offset; - filter->offset = offset; if (GST_BUFFER_SIZE (*buf) < size) { /* need append */ @@ -1664,6 +1666,15 @@ gst_metadata_parse_get_range (GstPad * pad, done: + if (need_append) { + /* FIXME: together with SEEK and + * gst_metadata_parse_translate_pos_to_orig + * this way if chunk is added in the end we are in trolble + * ...still not implemented 'cause it will not be the + * case for the time being + */ + } + return ret; } @@ -1700,7 +1711,7 @@ gst_metadata_parse_change_state (GstElement * element, gst_metadata_parse_init_members (filter); filter->adapter_parsing = gst_adapter_new (); filter->taglist = gst_tag_list_new (); - metadataparse_init (&filter->parse_data); + metadata_init (&filter->parse_data); break; default: break; @@ -1711,6 +1722,22 @@ gst_metadata_parse_change_state (GstElement * element, goto done; switch (transition) { + case GST_STATE_CHANGE_PAUSED_TO_READY: + filter->offset = 0; + filter->offset_orig = 0; + if (filter->adapter_parsing) { + gst_adapter_clear (filter->adapter_parsing); + } + if (filter->adapter_holding) { + gst_adapter_clear (filter->adapter_holding); + } + if (filter->state != MT_STATE_PARSED) { + /* cleanup parser */ + /* FIXME: could be improved a bit to avoid mem allocation */ + metadata_dispose (&filter->parse_data); + metadata_init (&filter->parse_data); + } + break; case GST_STATE_CHANGE_READY_TO_NULL: gst_metadata_parse_dispose_members (filter); break; @@ -1733,20 +1760,6 @@ gst_metadata_parse_plugin_init (GstPlugin * plugin) GST_DEBUG_CATEGORY_INIT (gst_metadata_parse_debug, "metadataparse", 0, "Metadata demuxer"); - GST_DEBUG_CATEGORY_INIT (gst_metadata_parse_exif_debug, "metadataparse_exif", - 0, "Metadata exif demuxer"); - GST_DEBUG_CATEGORY_INIT (gst_metadata_parse_iptc_debug, "metadataparse_iptc", - 0, "Metadata iptc demuxer"); - GST_DEBUG_CATEGORY_INIT (gst_metadata_parse_xmp_debug, "metadataparse_xmp", 0, - "Metadata xmp demuxer"); - - /* FIXME: register tag should be done by plugin 'cause muxer element also uses it */ - metadataparse_exif_tags_register (); - - metadataparse_iptc_tags_register (); - - metadataparse_xmp_tags_register (); - return gst_element_register (plugin, "metadataparse", GST_RANK_PRIMARY + 1, GST_TYPE_METADATA_PARSE); } diff --git a/ext/metadata/gstmetadataparse.h b/ext/metadata/gstmetadataparse.h index 0243261e..ca9e7ab4 100644 --- a/ext/metadata/gstmetadataparse.h +++ b/ext/metadata/gstmetadataparse.h @@ -46,7 +46,7 @@ #include -#include "metadataparse.h" +#include "metadata.h" G_BEGIN_DECLS /* #defines don't like whitespacey bits */ @@ -82,7 +82,7 @@ struct _GstMetadataParse gboolean need_send_tag; GstTagList *taglist; - ParseData parse_data; + MetaData parse_data; GstAdapter *adapter_parsing; GstAdapter *adapter_holding; guint32 next_offset; diff --git a/ext/metadata/metadata.c b/ext/metadata/metadata.c new file mode 100644 index 00000000..7ae43fab --- /dev/null +++ b/ext/metadata/metadata.c @@ -0,0 +1,223 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#include + +#include "metadata.h" + +/* + *static declarations + */ + +static int +metadata_parse_none (MetaData * meta_data, const guint8 * buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size); + +/* + * extern implementation + */ + +void +metadata_init (MetaData * meta_data) +{ + meta_data->state = STATE_NULL; + meta_data->img_type = IMG_NONE; + meta_data->option = META_OPT_ALL; + meta_data->offset_orig = 0; + meta_data->exif_adapter = NULL; + meta_data->iptc_adapter = NULL; + meta_data->xmp_adapter = NULL; + metadata_chunk_array_init (&meta_data->strip_chunks, 4); + metadata_chunk_array_init (&meta_data->inject_chunks, 1); +} + +/* + * offset: number of bytes to jump (just a hint to jump a chunk) + * size: number of bytes to read on next call (just a hint to get all chunk) + * return: + * -1 -> error + * 0 -> done + * 1 -> need more data + */ +int +metadata_parse (MetaData * meta_data, const guint8 * buf, + guint32 bufsize, guint32 * next_offset, guint32 * next_size) +{ + + int ret = 0; + + guint8 *next_start = (guint8 *) buf; + + if (meta_data->state == STATE_NULL) { + ret = + metadata_parse_none (meta_data, buf, &bufsize, &next_start, next_size); + if (ret == 0) + meta_data->state = STATE_READING; + else + goto done; + } + + switch (meta_data->img_type) { + case IMG_JPEG: + ret = + metadataparse_jpeg_parse (&meta_data->format_data.jpeg, + (guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start, + next_size); + break; + case IMG_PNG: + ret = + metadataparse_png_parse (&meta_data->format_data.png, + (guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start, + next_size); + break; + default: + /* unexpected */ + ret = -1; + goto done; + break; + } + + *next_offset = next_start - buf; + meta_data->offset_orig += *next_offset; + +done: + + if (ret == 0) { + meta_data->state = STATE_DONE; + } + + return ret; +} + +void +metadata_dispose (MetaData * meta_data) +{ + + switch (meta_data->img_type) { + case IMG_JPEG: + metadataparse_jpeg_dispose (&meta_data->format_data.jpeg); + break; + case IMG_PNG: + metadataparse_png_dispose (&meta_data->format_data.png); + break; + } + + metadata_chunk_array_free (&meta_data->strip_chunks); + metadata_chunk_array_free (&meta_data->inject_chunks); + + if (meta_data->xmp_adapter) { + gst_object_unref (meta_data->xmp_adapter); + meta_data->xmp_adapter = NULL; + } + + if (meta_data->iptc_adapter) { + gst_object_unref (meta_data->iptc_adapter); + meta_data->iptc_adapter = NULL; + } + + if (meta_data->exif_adapter) { + gst_object_unref (meta_data->exif_adapter); + meta_data->exif_adapter = NULL; + } + +} + +/* + * static implementation + */ + +/* find image type */ +static int +metadata_parse_none (MetaData * meta_data, const guint8 * buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + + int ret = -1; + GstAdapter **exif = NULL; + GstAdapter **iptc = NULL; + GstAdapter **xmp = NULL; + + *next_start = (guint8 *) buf; + + meta_data->img_type = IMG_NONE; + + if (*bufsize < 3) { + *next_size = 3; + ret = 1; + goto done; + } + + if (meta_data->option & META_OPT_EXIF) + exif = &meta_data->exif_adapter; + if (meta_data->option & META_OPT_IPTC) + iptc = &meta_data->iptc_adapter; + if (meta_data->option & META_OPT_XMP) + xmp = &meta_data->xmp_adapter; + + if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF) { + metadataparse_jpeg_init (&meta_data->format_data.jpeg, exif, iptc, xmp, + &meta_data->strip_chunks, &meta_data->inject_chunks); + ret = 0; + meta_data->img_type = IMG_JPEG; + goto done; + } + + if (*bufsize < 8) { + *next_size = 8; + ret = 1; + goto done; + } + + if (buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4E && buf[3] == 0x47 && + buf[4] == 0x0D && buf[5] == 0x0A && buf[6] == 0x1A && buf[7] == 0x0A) { + metadataparse_png_init (&meta_data->format_data.png, exif, iptc, xmp, + &meta_data->strip_chunks, &meta_data->inject_chunks); + ret = 0; + meta_data->img_type = IMG_PNG; + goto done; + } + +done: + + return ret; +} diff --git a/ext/metadata/metadata.h b/ext/metadata/metadata.h new file mode 100644 index 00000000..a97f1e48 --- /dev/null +++ b/ext/metadata/metadata.h @@ -0,0 +1,122 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#ifndef __METADATA_H__ +#define __METADATA_H__ + +#include +#include "metadatatypes.h" + +#include "metadataparsejpeg.h" +#include "metadataparsepng.h" + +G_BEGIN_DECLS + +typedef enum _tag_MetaOption +{ + META_OPT_EXIF = (1 << 0), + META_OPT_IPTC = (1 << 1), + META_OPT_XMP = (1 << 2), + META_OPT_ALL = (1 << 3) - 1 +} MetaOption; + +typedef enum _tag_MetaState +{ + STATE_NULL, + STATE_READING, + STATE_DONE +} MetaState; + +typedef enum _tag_ImageType +{ + IMG_NONE, + IMG_JPEG, + IMG_PNG +} ImageType; + +typedef struct _tag_MetaData +{ + MetaState state; + ImageType img_type; + MetaOption option; + guint32 offset_orig; /* offset since begining of stream */ + union + { + JpegData jpeg; + PngData png; + } format_data; + GstAdapter * exif_adapter; + GstAdapter * iptc_adapter; + GstAdapter * xmp_adapter; + + MetadataChunkArray strip_chunks; + MetadataChunkArray inject_chunks; + +} MetaData; + +#define META_DATA_IMG_TYPE(p) (p).img_type +#define META_DATA_OPTION(p) (p).option +#define set_meta_option(p, m) do { (p).option = (p).option | (m); } while(FALSE) +#define unset_meta_option(p, m) do { (p).option = (p).option & ~(m); } while(FALSE) + +extern void metadata_init (MetaData * meta_data); + +/* + * offset: number of bytes that MUST be jumped after current "buf" pointer + * next_size: number of minimum amount of bytes required on next step. + * if less than this is provided, the return will be 1 for sure. + * and the offset will be 0 (zero) + * return: + * -1 -> error + * 0 -> done + * 1 -> need more data + */ +extern int +metadata_meta (MetaData * meta_data, const guint8 * buf, + guint32 bufsize, guint32 * next_offset, guint32 * next_size); + + +extern void metadata_dispose (MetaData * meta_data); + +G_END_DECLS +#endif /* __METADATA_H__ */ diff --git a/ext/metadata/metadataexif.c b/ext/metadata/metadataexif.c new file mode 100644 index 00000000..f7d89c13 --- /dev/null +++ b/ext/metadata/metadataexif.c @@ -0,0 +1,168 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#include "metadataexif.h" +#include "metadataparseutil.h" +#include "metadatatags.h" + +GST_DEBUG_CATEGORY (gst_metadata_exif_debug); +#define GST_CAT_DEFAULT gst_metadata_exif_debug + +#ifndef HAVE_EXIF + +void +metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + + GST_LOG ("EXIF not defined, here I should send just one tag as whole chunk"); + + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_EXIF, adapter); + +} + +void +metadatamux_exif_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + /* do nothing */ +} + +#else /* ifndef HAVE_EXIF */ + +#include + +static void +exif_data_foreach_content_func (ExifContent * content, void *callback_data); + +static void exif_content_foreach_entry_func (ExifEntry * entry, void *); + +void +metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + const guint8 *buf; + guint32 size; + ExifData *exif = NULL; + + if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { + goto done; + } + + /* add chunk tag */ + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_EXIF, adapter); + + buf = gst_adapter_peek (adapter, size); + + exif = exif_data_new_from_data (buf, size); + if (exif == NULL) { + goto done; + } + + exif_data_foreach_content (exif, exif_data_foreach_content_func, + (void *) taglist); + +done: + + if (exif) + exif_data_unref (exif); + + return; + +} + +static void +exif_data_foreach_content_func (ExifContent * content, void *user_data) +{ + ExifIfd ifd = exif_content_get_ifd (content); + GstTagList *taglist = (GstTagList *) user_data; + + GST_LOG ("\n Content %p: %s (ifd=%d)", content, exif_ifd_get_name (ifd), + ifd); + exif_content_foreach_entry (content, exif_content_foreach_entry_func, + user_data); +} + +static void +exif_content_foreach_entry_func (ExifEntry * entry, void *user_data) +{ + char buf[2048]; + GstTagList *taglist = (GstTagList *) user_data; + + GST_LOG ("\n Entry %p: %s (%s)\n" + " Size, Comps: %d, %d\n" + " Value: %s\n" + " Title: %s\n" + " Description: %s\n", + entry, + exif_tag_get_name_in_ifd (entry->tag, EXIF_IFD_0), + exif_format_get_name (entry->format), + entry->size, + (int) (entry->components), + exif_entry_get_value (entry, buf, sizeof (buf)), + exif_tag_get_title_in_ifd (entry->tag, EXIF_IFD_0), + exif_tag_get_description_in_ifd (entry->tag, EXIF_IFD_0)); +} + +/* + * + */ + +void +metadatamux_exif_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + if (adapter == NULL) + goto done; + + if (*adapter) + g_object_unref (*adapter); + + *adapter = gst_adapter_new (); + +done: + + return; +} + +#endif /* else (ifndef HAVE_EXIF) */ diff --git a/ext/metadata/metadataexif.h b/ext/metadata/metadataexif.h new file mode 100644 index 00000000..6394013e --- /dev/null +++ b/ext/metadata/metadataexif.h @@ -0,0 +1,61 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#ifndef __GST_METADATAPARSE_EXIF_H__ +#define __GST_METADATAPARSE_EXIF_H__ + +#include +#include + +G_BEGIN_DECLS + +extern void +metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter); + +extern void +metadatamux_exif_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist); + +G_END_DECLS +#endif /* __GST_METADATAPARSE_EXIF_H__ */ diff --git a/ext/metadata/metadataiptc.c b/ext/metadata/metadataiptc.c new file mode 100644 index 00000000..a391fc78 --- /dev/null +++ b/ext/metadata/metadataiptc.c @@ -0,0 +1,144 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#include "metadataiptc.h" +#include "metadataparseutil.h" +#include "metadatatags.h" + +GST_DEBUG_CATEGORY (gst_metadata_iptc_debug); +#define GST_CAT_DEFAULT gst_metadata_iptc_debug + +#ifndef HAVE_IPTC + +void +metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + + GST_LOG ("IPTC not defined, here I should send just one tag as whole chunk"); + + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC, adapter); + +} + + +void +metadatamux_iptc_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + /* do nothing */ +} + +#else /* ifndef HAVE_IPTC */ + +#include + +static void +iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data); + +void +metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + const guint8 *buf; + guint32 size; + IptcData *iptc = NULL; + + if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { + goto done; + } + + /* add chunk tag */ + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC, adapter); + + buf = gst_adapter_peek (adapter, size); + + iptc = iptc_data_new_from_data (buf, size); + if (iptc == NULL) { + goto done; + } + + iptc_data_foreach_dataset (iptc, iptc_data_foreach_dataset_func, + (void *) taglist); + +done: + + if (iptc) + iptc_data_unref (iptc); + + return; + +} + +static void +iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data) +{ + + char *buf[256]; + GstTagList *taglist = (GstTagList *) user_data; + + GST_LOG ("name -> %s", iptc_tag_get_name (dataset->record, dataset->tag)); + GST_LOG ("title -> %s", iptc_tag_get_title (dataset->record, dataset->tag)); + GST_LOG ("description -> %s", iptc_tag_get_description (dataset->record, + dataset->tag)); + GST_LOG ("value = %s", iptc_dataset_get_as_str (dataset, buf, 256)); +} + +void +metadatamux_iptc_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + if (adapter == NULL) + goto done; + + if (*adapter) + g_object_unref (*adapter); + + *adapter = gst_adapter_new (); + +done: + + return; +} + +#endif /* else (ifndef HAVE_IPTC) */ diff --git a/ext/metadata/metadataiptc.h b/ext/metadata/metadataiptc.h new file mode 100644 index 00000000..4357f7fa --- /dev/null +++ b/ext/metadata/metadataiptc.h @@ -0,0 +1,61 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#ifndef __GST_METADATAPARSE_IPTC_H__ +#define __GST_METADATAPARSE_IPTC_H__ + +#include +#include + +G_BEGIN_DECLS + +extern void +metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter); + +extern void +metadatamux_iptc_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist); + +G_END_DECLS +#endif /* __GST_METADATAPARSE_IPTC_H__ */ diff --git a/ext/metadata/metadataparse.c b/ext/metadata/metadataparse.c deleted file mode 100644 index cb22c795..00000000 --- a/ext/metadata/metadataparse.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#include - -#include "metadataparse.h" - -/* - *static declarations - */ - -static int -metadataparse_parse_none (ParseData * parse_data, const guint8 * buf, - guint32 * bufsize, guint8 ** next_start, guint32 * next_size); - -/* - * extern implementation - */ - -void -metadataparse_init (ParseData * parse_data) -{ - parse_data->state = STATE_NULL; - parse_data->img_type = IMG_NONE; - parse_data->option = PARSE_OPT_ALL; - parse_data->offset_orig = 0; - parse_data->exif_adapter = NULL; - parse_data->iptc_adapter = NULL; - parse_data->xmp_adapter = NULL; - metadata_chunk_array_init (&parse_data->strip_chunks, 4); - metadata_chunk_array_init (&parse_data->inject_chunks, 1); -} - -/* - * offset: number of bytes to jump (just a hint to jump a chunk) - * size: number of bytes to read on next call (just a hint to get all chunk) - * return: - * -1 -> error - * 0 -> done - * 1 -> need more data - */ -int -metadataparse_parse (ParseData * parse_data, const guint8 * buf, - guint32 bufsize, guint32 * next_offset, guint32 * next_size) -{ - - int ret = 0; - - guint8 *next_start = (guint8 *) buf; - - if (parse_data->state == STATE_NULL) { - ret = - metadataparse_parse_none (parse_data, buf, &bufsize, &next_start, - next_size); - if (ret == 0) - parse_data->state = STATE_READING; - else - goto done; - } - - switch (parse_data->img_type) { - case IMG_JPEG: - ret = - metadataparse_jpeg_parse (&parse_data->format_data.jpeg, - (guint8 *) buf, &bufsize, parse_data->offset_orig, &next_start, - next_size); - break; - case IMG_PNG: - ret = - metadataparse_png_parse (&parse_data->format_data.png, - (guint8 *) buf, &bufsize, parse_data->offset_orig, &next_start, - next_size); - break; - default: - /* unexpected */ - ret = -1; - goto done; - break; - } - - *next_offset = next_start - buf; - parse_data->offset_orig += *next_offset; - -done: - - if (ret == 0) { - parse_data->state = STATE_DONE; - } - - return ret; -} - -void -metadataparse_dispose (ParseData * parse_data) -{ - - switch (parse_data->img_type) { - case IMG_JPEG: - metadataparse_jpeg_dispose (&parse_data->format_data.jpeg); - break; - case IMG_PNG: - metadataparse_png_dispose (&parse_data->format_data.png); - break; - } - - metadata_chunk_array_free (&parse_data->strip_chunks); - metadata_chunk_array_free (&parse_data->inject_chunks); - - if (parse_data->xmp_adapter) { - gst_object_unref (parse_data->xmp_adapter); - parse_data->xmp_adapter = NULL; - } - - if (parse_data->iptc_adapter) { - gst_object_unref (parse_data->iptc_adapter); - parse_data->iptc_adapter = NULL; - } - - if (parse_data->exif_adapter) { - gst_object_unref (parse_data->exif_adapter); - parse_data->exif_adapter = NULL; - } - -} - -/* - * static implementation - */ - -/* find image type */ -static int -metadataparse_parse_none (ParseData * parse_data, const guint8 * buf, - guint32 * bufsize, guint8 ** next_start, guint32 * next_size) -{ - - int ret = -1; - GstAdapter **exif = NULL; - GstAdapter **iptc = NULL; - GstAdapter **xmp = NULL; - - *next_start = (guint8 *) buf; - - parse_data->img_type = IMG_NONE; - - if (*bufsize < 3) { - *next_size = 3; - ret = 1; - goto done; - } - - if (parse_data->option & PARSE_OPT_EXIF) - exif = &parse_data->exif_adapter; - if (parse_data->option & PARSE_OPT_IPTC) - iptc = &parse_data->iptc_adapter; - if (parse_data->option & PARSE_OPT_XMP) - xmp = &parse_data->xmp_adapter; - - if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF) { - metadataparse_jpeg_init (&parse_data->format_data.jpeg, exif, iptc, xmp, - &parse_data->strip_chunks, &parse_data->inject_chunks); - ret = 0; - parse_data->img_type = IMG_JPEG; - goto done; - } - - if (*bufsize < 8) { - *next_size = 8; - ret = 1; - goto done; - } - - if (buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4E && buf[3] == 0x47 && - buf[4] == 0x0D && buf[5] == 0x0A && buf[6] == 0x1A && buf[7] == 0x0A) { - metadataparse_png_init (&parse_data->format_data.png, exif, iptc, xmp, - &parse_data->strip_chunks, &parse_data->inject_chunks); - ret = 0; - parse_data->img_type = IMG_PNG; - goto done; - } - -done: - - return ret; -} diff --git a/ext/metadata/metadataparse.h b/ext/metadata/metadataparse.h deleted file mode 100644 index c0b82aa1..00000000 --- a/ext/metadata/metadataparse.h +++ /dev/null @@ -1,122 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#ifndef __METADATAPARSE_H__ -#define __METADATAPARSE_H__ - -#include -#include "metadatatypes.h" - -#include "metadataparsejpeg.h" -#include "metadataparsepng.h" - -G_BEGIN_DECLS - -typedef enum _tag_ParseOption -{ - PARSE_OPT_EXIF = (1 << 0), - PARSE_OPT_IPTC = (1 << 1), - PARSE_OPT_XMP = (1 << 2), - PARSE_OPT_ALL = (1 << 3) - 1 -} ParseOption; - -typedef enum _tag_ParseState -{ - STATE_NULL, - STATE_READING, - STATE_DONE -} ParseState; - -typedef enum _tag_ImageType -{ - IMG_NONE, - IMG_JPEG, - IMG_PNG -} ImageType; - -typedef struct _tag_ParseData -{ - ParseState state; - ImageType img_type; - ParseOption option; - guint32 offset_orig; /* offset since begining of stream */ - union - { - JpegData jpeg; - PngData png; - } format_data; - GstAdapter * exif_adapter; - GstAdapter * iptc_adapter; - GstAdapter * xmp_adapter; - - MetadataChunkArray strip_chunks; - MetadataChunkArray inject_chunks; - -} ParseData; - -#define PARSE_DATA_IMG_TYPE(p) (p).img_type -#define PARSE_DATA_OPTION(p) (p).option -#define set_parse_option(p, m) do { (p).option = (p).option | (m); } while(FALSE) -#define unset_parse_option(p, m) do { (p).option = (p).option & ~(m); } while(FALSE) - -extern void metadataparse_init (ParseData * parse_data); - -/* - * offset: number of bytes that MUST be jumped after current "buf" pointer - * next_size: number of minimum amount of bytes required on next step. - * if less than this is provided, the return will be 1 for sure. - * and the offset will be 0 (zero) - * return: - * -1 -> error - * 0 -> done - * 1 -> need more data - */ -extern int -metadataparse_parse (ParseData * parse_data, const guint8 * buf, - guint32 bufsize, guint32 * next_offset, guint32 * next_size); - - -extern void metadataparse_dispose (ParseData * parse_data); - -G_END_DECLS -#endif /* __METADATAPARSE_H__ */ diff --git a/ext/metadata/metadataparseexif.c b/ext/metadata/metadataparseexif.c deleted file mode 100644 index 4b7fd4f1..00000000 --- a/ext/metadata/metadataparseexif.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#include "metadataparseexif.h" -#include "metadataparseutil.h" - -GST_DEBUG_CATEGORY (gst_metadata_parse_exif_debug); -#define GST_CAT_DEFAULT gst_metadata_parse_exif_debug - -#define GST_TAG_EXIF "exif" - -void -metadataparse_exif_tags_register (void) -{ - gst_tag_register (GST_TAG_EXIF, GST_TAG_FLAG_META, - GST_TYPE_BUFFER, GST_TAG_EXIF, "exif metadata chunk", NULL); -} - -#ifndef HAVE_EXIF - -void -metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - - GST_LOG ("EXIF not defined, here I should send just one tag as whole chunk"); - - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_EXIF, adapter); - -} - -#else /* ifndef HAVE_EXIF */ - -#include - -static void -exif_data_foreach_content_func (ExifContent * content, void *callback_data); - -static void exif_content_foreach_entry_func (ExifEntry * entry, void *); - -void -metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - const guint8 *buf; - guint32 size; - ExifData *exif = NULL; - - if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { - goto done; - } - - /* add chunk tag */ - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_EXIF, adapter); - - buf = gst_adapter_peek (adapter, size); - - exif = exif_data_new_from_data (buf, size); - if (exif == NULL) { - goto done; - } - - exif_data_foreach_content (exif, exif_data_foreach_content_func, - (void *) taglist); - -done: - - if (exif) - exif_data_unref (exif); - - return; - -} - -static void -exif_data_foreach_content_func (ExifContent * content, void *user_data) -{ - ExifIfd ifd = exif_content_get_ifd (content); - GstTagList *taglist = (GstTagList *) user_data; - - GST_LOG ("\n Content %p: %s (ifd=%d)", content, exif_ifd_get_name (ifd), - ifd); - exif_content_foreach_entry (content, exif_content_foreach_entry_func, - user_data); -} - -static void -exif_content_foreach_entry_func (ExifEntry * entry, void *user_data) -{ - char buf[2048]; - GstTagList *taglist = (GstTagList *) user_data; - - GST_LOG ("\n Entry %p: %s (%s)\n" - " Size, Comps: %d, %d\n" - " Value: %s\n" - " Title: %s\n" - " Description: %s\n", - entry, - exif_tag_get_name_in_ifd (entry->tag, EXIF_IFD_0), - exif_format_get_name (entry->format), - entry->size, - (int) (entry->components), - exif_entry_get_value (entry, buf, sizeof (buf)), - exif_tag_get_title_in_ifd (entry->tag, EXIF_IFD_0), - exif_tag_get_description_in_ifd (entry->tag, EXIF_IFD_0)); -} - -#endif /* else (ifndef HAVE_EXIF) */ diff --git a/ext/metadata/metadataparseexif.h b/ext/metadata/metadataparseexif.h deleted file mode 100644 index 8c6ecb2c..00000000 --- a/ext/metadata/metadataparseexif.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#ifndef __GST_METADATAPARSE_EXIF_H__ -#define __GST_METADATAPARSE_EXIF_H__ - -#include -#include - -G_BEGIN_DECLS - extern void -metadataparse_exif_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter); - -extern void metadataparse_exif_tags_register (void); - -G_END_DECLS -#endif /* __GST_METADATAPARSE_EXIF_H__ */ diff --git a/ext/metadata/metadataparseiptc.c b/ext/metadata/metadataparseiptc.c deleted file mode 100644 index ed4f803e..00000000 --- a/ext/metadata/metadataparseiptc.c +++ /dev/null @@ -1,127 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#include "metadataparseiptc.h" -#include "metadataparseutil.h" - -GST_DEBUG_CATEGORY (gst_metadata_parse_iptc_debug); -#define GST_CAT_DEFAULT gst_metadata_parse_iptc_debug - -#define GST_TAG_IPTC "iptc" - -void -metadataparse_iptc_tags_register (void) -{ - gst_tag_register (GST_TAG_IPTC, GST_TAG_FLAG_META, - GST_TYPE_BUFFER, GST_TAG_IPTC, "iptc metadata chunk", NULL); -} - -#ifndef HAVE_IPTC - -void -metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - - GST_LOG ("IPTC not defined, here I should send just one tag as whole chunk"); - - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC, adapter); - -} - -#else /* ifndef HAVE_IPTC */ - -#include - -static void -iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data); - -void -metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - const guint8 *buf; - guint32 size; - IptcData *iptc = NULL; - - if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { - goto done; - } - - /* add chunk tag */ - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_IPTC, adapter); - - buf = gst_adapter_peek (adapter, size); - - iptc = iptc_data_new_from_data (buf, size); - if (iptc == NULL) { - goto done; - } - - iptc_data_foreach_dataset (iptc, iptc_data_foreach_dataset_func, - (void *) taglist); - -done: - - if (iptc) - iptc_data_unref (iptc); - - return; - -} - -static void -iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data) -{ - - char *buf[256]; - GstTagList *taglist = (GstTagList *) user_data; - - GST_LOG ("name -> %s", iptc_tag_get_name (dataset->record, dataset->tag)); - GST_LOG ("title -> %s", iptc_tag_get_title (dataset->record, dataset->tag)); - GST_LOG ("description -> %s", iptc_tag_get_description (dataset->record, - dataset->tag)); - GST_LOG ("value = %s", iptc_dataset_get_as_str (dataset, buf, 256)); -} - -#endif /* else (ifndef HAVE_IPTC) */ diff --git a/ext/metadata/metadataparseiptc.h b/ext/metadata/metadataparseiptc.h deleted file mode 100644 index e45d350f..00000000 --- a/ext/metadata/metadataparseiptc.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#ifndef __GST_METADATAPARSE_IPTC_H__ -#define __GST_METADATAPARSE_IPTC_H__ - -#include -#include - -G_BEGIN_DECLS - -extern void -metadataparse_iptc_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter); - -extern void metadataparse_iptc_tags_register (void); - -G_END_DECLS -#endif /* __GST_METADATAPARSE_IPTC_H__ */ diff --git a/ext/metadata/metadataparsexmp.c b/ext/metadata/metadataparsexmp.c deleted file mode 100644 index 0b73f2f0..00000000 --- a/ext/metadata/metadataparsexmp.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#include "metadataparsexmp.h" -#include "metadataparseutil.h" - -GST_DEBUG_CATEGORY (gst_metadata_parse_xmp_debug); -#define GST_CAT_DEFAULT gst_metadata_parse_xmp_debug - -#define GST_TAG_XMP "xmp" - -void -metadataparse_xmp_tags_register (void) -{ - gst_tag_register (GST_TAG_XMP, GST_TAG_FLAG_META, - GST_TYPE_BUFFER, GST_TAG_XMP, "xmp metadata chunk", NULL); -} - -#ifndef HAVE_XMP - -void -metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - - GST_LOG ("XMP not defined, here I should send just one tag as whole chunk"); - - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_XMP, adapter); - -} - -gboolean -metadataparse_xmp_init (void) -{ - return TRUE; -} - -void -metadataparse_xmp_dispose (void) -{ - return; -} - -#else /* ifndef HAVE_XMP */ - -#include - -#define XMP_SCHEMA_NODE 0x80000000UL - -void -metadataparse_xmp_iter_array (XmpPtr xmp, const char *schema, const char *path); - -static void -metadataparse_xmp_iter_simple (const char *schema, const char *path, - const char *value); - -static void metadataparse_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter); - -gboolean -metadataparse_xmp_init (void) -{ - return xmp_init (); -} - -void -metadataparse_xmp_dispose (void) -{ - xmp_terminate (); -} - -void -metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter) -{ - const guint8 *buf; - guint32 size; - XmpPtr xmp = NULL; - XmpIteratorPtr xmp_iter = NULL; - - if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { - goto done; - } - - /* add chunk tag */ - metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_XMP, adapter); - - buf = gst_adapter_peek (adapter, size); - - xmp = xmp_new (buf, size); - if (!xmp) - goto done; - - xmp_iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_JUSTCHILDREN); - - if (!xmp_iter) - goto done; - - metadataparse_xmp_iter (xmp, xmp_iter); - -done: - - if (xmp_iter) { - xmp_iterator_free (xmp_iter); - } - - if (xmp) { - xmp_free (xmp); - } - - return; - -} - -void -metadataparse_xmp_iter_simple_qual (const char *schema, const char *path, - const char *value) -{ - GString *string = g_string_new (path); - gchar *ch; - - ch = string->str + string->len - 3; - while (ch != string->str) { - if (*ch == '[') { - *ch = '\0'; - } - --ch; - } - - GST_LOG (" %s = %s\n", string->str, value); - g_string_free (string, TRUE); -} - -void -metadataparse_xmp_iter_simple (const char *schema, const char *path, - const char *value) -{ - GST_LOG (" %s = %s\n", path, value); -} - -void -metadataparse_xmp_iter_array (XmpPtr xmp, const char *schema, const char *path) -{ - - XmpIteratorPtr xmp_iter = NULL; - - xmp_iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN); - - if (xmp_iter) { - metadataparse_xmp_iter (xmp, xmp_iter); - - xmp_iterator_free (xmp_iter); - } - -} - -void -metadataparse_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter) -{ - XmpStringPtr xstr_schema = xmp_string_new (); - XmpStringPtr xstr_path = xmp_string_new (); - XmpStringPtr xstr_prop = xmp_string_new (); - uint32_t opt = 0; - - while (xmp_iterator_next (iter, xstr_schema, xstr_path, xstr_prop, &opt)) { - const char *schema = xmp_string_cstr (xstr_schema); - const char *path = xmp_string_cstr (xstr_path); - const char *value = xmp_string_cstr (xstr_prop); - - if (XMP_IS_NODE_SCHEMA (opt)) { - GST_LOG ("%s\n", schema); - metadataparse_xmp_iter_array (xmp, schema, path); - } else if (XMP_IS_PROP_SIMPLE (opt)) { - if (strcmp (path, "") != 0) { - if (XMP_HAS_PROP_QUALIFIERS (opt)) { - metadataparse_xmp_iter_simple_qual (schema, path, value); - } else { - metadataparse_xmp_iter_simple (schema, path, value); - } - } - } else if (XMP_IS_PROP_ARRAY (opt)) { - if (XMP_IS_ARRAY_ALTTEXT (opt)) { - metadataparse_xmp_iter_array (xmp, schema, path); - xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE); - } else { - metadataparse_xmp_iter_array (xmp, schema, path); - xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE); - } - } - - - - } - - if (xstr_prop) { - xmp_string_free (xstr_prop); - } - if (xstr_path) { - xmp_string_free (xstr_path); - } - if (xstr_schema) { - xmp_string_free (xstr_schema); - } -} - -#endif /* else (ifndef HAVE_XMP) */ diff --git a/ext/metadata/metadataparsexmp.h b/ext/metadata/metadataparsexmp.h deleted file mode 100644 index 80b93a39..00000000 --- a/ext/metadata/metadataparsexmp.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * GStreamer - * Copyright 2007 Edgard Lima - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * 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. - */ - -#ifndef __GST_METADATAPARSE_XMP_H__ -#define __GST_METADATAPARSE_XMP_H__ - -#include -#include - -G_BEGIN_DECLS - -extern void -metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, - GstAdapter * adapter); - -extern gboolean metadataparse_xmp_init (void); - -extern void metadataparse_xmp_dispose (void); - -extern void metadataparse_xmp_tags_register (void); - -G_END_DECLS -#endif /* __GST_METADATAPARSE_XMP_H__ */ diff --git a/ext/metadata/metadatatags.c b/ext/metadata/metadatatags.c new file mode 100644 index 00000000..91544b77 --- /dev/null +++ b/ext/metadata/metadatatags.c @@ -0,0 +1,91 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#include "metadatatags.h" + +/* + * EXIF tags + */ + +static void +metadata_tags_exif_register (void) +{ + gst_tag_register (GST_TAG_EXIF, GST_TAG_FLAG_META, + GST_TYPE_BUFFER, GST_TAG_EXIF, "exif metadata chunk", NULL); +} + +/* + * IPTC tags + */ + +static void +metadata_tags_iptc_register (void) +{ + gst_tag_register (GST_TAG_IPTC, GST_TAG_FLAG_META, + GST_TYPE_BUFFER, GST_TAG_IPTC, "iptc metadata chunk", NULL); +} + +/* + * XMP tags + */ + +static void +metadata_tags_xmp_register (void) +{ + gst_tag_register (GST_TAG_XMP, GST_TAG_FLAG_META, + GST_TYPE_BUFFER, GST_TAG_XMP, "xmp metadata chunk", NULL); +} + +/* + * + */ + +void +metadata_tags_register (void) +{ + + metadata_tags_exif_register (); + metadata_tags_iptc_register (); + metadata_tags_xmp_register (); + +} diff --git a/ext/metadata/metadatatags.h b/ext/metadata/metadatatags.h new file mode 100644 index 00000000..094161ee --- /dev/null +++ b/ext/metadata/metadatatags.h @@ -0,0 +1,62 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#ifndef __GST_METADATA_TAGS_H__ +#define __GST_METADATA_TAGS_H__ + +#include +#include + +G_BEGIN_DECLS + +#define GST_TAG_EXIF "exif" + +#define GST_TAG_IPTC "iptc" + +#define GST_TAG_XMP "xmp" + +extern void +metadata_tags_register (void); + +G_END_DECLS +#endif /* __GST_METADATA_TAGS_H__ */ diff --git a/ext/metadata/metadataxmp.c b/ext/metadata/metadataxmp.c new file mode 100644 index 00000000..900a454a --- /dev/null +++ b/ext/metadata/metadataxmp.c @@ -0,0 +1,261 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#include "metadataxmp.h" +#include "metadataparseutil.h" +#include "metadatatags.h" + +GST_DEBUG_CATEGORY (gst_metadata_xmp_debug); +#define GST_CAT_DEFAULT gst_metadata_xmp_debug + +#ifndef HAVE_XMP + +void +metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + + GST_LOG ("XMP not defined, here I should send just one tag as whole chunk"); + + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_XMP, adapter); + +} + +gboolean +metadataparse_xmp_init (void) +{ + return TRUE; +} + +void +metadataparse_xmp_dispose (void) +{ + return; +} + +void +metadatamux_xmp_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + /* do nothing */ +} + +#else /* ifndef HAVE_XMP */ + +#include + +#define XMP_SCHEMA_NODE 0x80000000UL + +void +metadataparse_xmp_iter_array (XmpPtr xmp, const char *schema, const char *path); + +static void +metadataparse_xmp_iter_simple (const char *schema, const char *path, + const char *value); + +static void metadataparse_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter); + +gboolean +metadataparse_xmp_init (void) +{ + return xmp_init (); +} + +void +metadataparse_xmp_dispose (void) +{ + xmp_terminate (); +} + +void +metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter) +{ + const guint8 *buf; + guint32 size; + XmpPtr xmp = NULL; + XmpIteratorPtr xmp_iter = NULL; + + if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { + goto done; + } + + /* add chunk tag */ + metadataparse_util_tag_list_add_chunk (taglist, mode, GST_TAG_XMP, adapter); + + buf = gst_adapter_peek (adapter, size); + + xmp = xmp_new (buf, size); + if (!xmp) + goto done; + + xmp_iter = xmp_iterator_new (xmp, NULL, NULL, XMP_ITER_JUSTCHILDREN); + + if (!xmp_iter) + goto done; + + metadataparse_xmp_iter (xmp, xmp_iter); + +done: + + if (xmp_iter) { + xmp_iterator_free (xmp_iter); + } + + if (xmp) { + xmp_free (xmp); + } + + return; + +} + +void +metadataparse_xmp_iter_simple_qual (const char *schema, const char *path, + const char *value) +{ + GString *string = g_string_new (path); + gchar *ch; + + ch = string->str + string->len - 3; + while (ch != string->str) { + if (*ch == '[') { + *ch = '\0'; + } + --ch; + } + + GST_LOG (" %s = %s\n", string->str, value); + g_string_free (string, TRUE); +} + +void +metadataparse_xmp_iter_simple (const char *schema, const char *path, + const char *value) +{ + GST_LOG (" %s = %s\n", path, value); +} + +void +metadataparse_xmp_iter_array (XmpPtr xmp, const char *schema, const char *path) +{ + + XmpIteratorPtr xmp_iter = NULL; + + xmp_iter = xmp_iterator_new (xmp, schema, path, XMP_ITER_JUSTCHILDREN); + + if (xmp_iter) { + metadataparse_xmp_iter (xmp, xmp_iter); + + xmp_iterator_free (xmp_iter); + } + +} + +void +metadataparse_xmp_iter (XmpPtr xmp, XmpIteratorPtr iter) +{ + XmpStringPtr xstr_schema = xmp_string_new (); + XmpStringPtr xstr_path = xmp_string_new (); + XmpStringPtr xstr_prop = xmp_string_new (); + uint32_t opt = 0; + + while (xmp_iterator_next (iter, xstr_schema, xstr_path, xstr_prop, &opt)) { + const char *schema = xmp_string_cstr (xstr_schema); + const char *path = xmp_string_cstr (xstr_path); + const char *value = xmp_string_cstr (xstr_prop); + + if (XMP_IS_NODE_SCHEMA (opt)) { + GST_LOG ("%s\n", schema); + metadataparse_xmp_iter_array (xmp, schema, path); + } else if (XMP_IS_PROP_SIMPLE (opt)) { + if (strcmp (path, "") != 0) { + if (XMP_HAS_PROP_QUALIFIERS (opt)) { + metadataparse_xmp_iter_simple_qual (schema, path, value); + } else { + metadataparse_xmp_iter_simple (schema, path, value); + } + } + } else if (XMP_IS_PROP_ARRAY (opt)) { + if (XMP_IS_ARRAY_ALTTEXT (opt)) { + metadataparse_xmp_iter_array (xmp, schema, path); + xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE); + } else { + metadataparse_xmp_iter_array (xmp, schema, path); + xmp_iterator_skip (iter, XMP_ITER_SKIPSUBTREE); + } + } + + + + } + + if (xstr_prop) { + xmp_string_free (xstr_prop); + } + if (xstr_path) { + xmp_string_free (xstr_path); + } + if (xstr_schema) { + xmp_string_free (xstr_schema); + } +} + +void +metadatamux_xmp_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist) +{ + if (adapter == NULL) + goto done; + + if (*adapter) + g_object_unref (*adapter); + + *adapter = gst_adapter_new (); + +done: + + return; +} + +#endif /* else (ifndef HAVE_XMP) */ diff --git a/ext/metadata/metadataxmp.h b/ext/metadata/metadataxmp.h new file mode 100644 index 00000000..8c3ef19d --- /dev/null +++ b/ext/metadata/metadataxmp.h @@ -0,0 +1,65 @@ +/* + * GStreamer + * Copyright 2007 Edgard Lima + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * 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. + */ + +#ifndef __GST_METADATAPARSE_XMP_H__ +#define __GST_METADATAPARSE_XMP_H__ + +#include +#include + +G_BEGIN_DECLS + +extern void +metadataparse_xmp_tag_list_add (GstTagList * taglist, GstTagMergeMode mode, + GstAdapter * adapter); + +extern gboolean metadataparse_xmp_init (void); + +extern void metadataparse_xmp_dispose (void); + +extern void +metadatamux_xmp_create_chunk_from_tag_list (GstAdapter ** adapter, + GstTagList * taglist); + +G_END_DECLS +#endif /* __GST_METADATAPARSE_XMP_H__ */ -- cgit v1.2.1