From 6836fdea8367cdcaea53505a5a9ff93909b103d8 Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Tue, 30 Oct 2007 12:49:04 +0000 Subject: Created new plugin ('medadata') and element ('metadataparse') that extract metadata from images (look at bug #486659). Original commit message from CVS: Created new plugin ('medadata') and element ('metadataparse') that extract metadata from images (look at bug #486659). --- ext/metadata/Makefile.am | 21 + ext/metadata/gstmetadata.c | 63 +++ ext/metadata/gstmetadataparse.c | 914 +++++++++++++++++++++++++++++++++++++++ ext/metadata/gstmetadataparse.h | 113 +++++ ext/metadata/metadataparse.c | 194 +++++++++ ext/metadata/metadataparse.h | 112 +++++ ext/metadata/metadataparseexif.c | 129 ++++++ ext/metadata/metadataparseexif.h | 57 +++ ext/metadata/metadataparseiptc.c | 108 +++++ ext/metadata/metadataparseiptc.h | 57 +++ ext/metadata/metadataparsejpeg.c | 374 ++++++++++++++++ ext/metadata/metadataparsejpeg.h | 85 ++++ ext/metadata/metadataparsexmp.c | 69 +++ ext/metadata/metadataparsexmp.h | 57 +++ 14 files changed, 2353 insertions(+) create mode 100644 ext/metadata/Makefile.am create mode 100644 ext/metadata/gstmetadata.c create mode 100644 ext/metadata/gstmetadataparse.c create mode 100644 ext/metadata/gstmetadataparse.h create mode 100644 ext/metadata/metadataparse.c create mode 100644 ext/metadata/metadataparse.h create mode 100644 ext/metadata/metadataparseexif.c create mode 100644 ext/metadata/metadataparseexif.h create mode 100644 ext/metadata/metadataparseiptc.c create mode 100644 ext/metadata/metadataparseiptc.h create mode 100644 ext/metadata/metadataparsejpeg.c create mode 100644 ext/metadata/metadataparsejpeg.h create mode 100644 ext/metadata/metadataparsexmp.c create mode 100644 ext/metadata/metadataparsexmp.h (limited to 'ext/metadata') diff --git a/ext/metadata/Makefile.am b/ext/metadata/Makefile.am new file mode 100644 index 00000000..fd27b6e4 --- /dev/null +++ b/ext/metadata/Makefile.am @@ -0,0 +1,21 @@ +plugin_LTLIBRARIES = libgstmetadata.la + +libgstmetadata_la_SOURCES = gstmetadata.c \ + gstmetadataparse.c \ + metadataparse.c \ + metadataparsejpeg.c \ + metadataparseexif.c \ + metadataparseiptc.c \ + metadataparsexmp.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 \ + metadataparsejpeg.h \ + metadataparseexif.h \ + metadataparseiptc.h \ + metadataparsexmp.h + diff --git a/ext/metadata/gstmetadata.c b/ext/metadata/gstmetadata.c new file mode 100644 index 00000000..263c8b37 --- /dev/null +++ b/ext/metadata/gstmetadata.c @@ -0,0 +1,63 @@ +/* + * 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstmetadataparse.h" +/* #include "gstmetadatamux.h" ...soon.. */ + +static gboolean +plugin_init (GstPlugin * plugin) +{ + + return gst_metadata_parse_plugin_init (plugin); + +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "metadata", + "Metadata (EXIF, IPTC and XMP) image (JPEG, TIFF) parser and muxer", + plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN) diff --git a/ext/metadata/gstmetadataparse.c b/ext/metadata/gstmetadataparse.c new file mode 100644 index 00000000..d40384c8 --- /dev/null +++ b/ext/metadata/gstmetadataparse.c @@ -0,0 +1,914 @@ +/* + * 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. + */ + +/** + * SECTION:metadataparse-metadata + * + * + * Example launch line + * + * + * gst-launch -v -m filesrc location=./test.jpeg ! metadataparse ! fakesink silent=TRUE + * + * + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "gstmetadataparse.h" + + +#include "metadataparseexif.h" + +#include "metadataparseiptc.h" + +#include "metadataparsexmp.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) + +/* Filter signals and args */ +enum +{ + /* FILL ME */ + LAST_SIGNAL +}; + +enum +{ + ARG_0, + ARG_EXIF, + ARG_IPTC, + ARG_XMP +}; + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("image/jpeg;" "image/png") + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS ("image/jpeg-metadata;" "image/png-metadata") + ); + +GST_BOILERPLATE (GstMetadataParse, gst_metadata_parse, GstElement, + GST_TYPE_ELEMENT); + +static GstMetadataParseClass *metadata_parent_class = NULL; + +static void gst_metadata_parse_dispose (GObject * object); + +static void gst_metadata_parse_finalize (GObject * object); + +static void gst_metadata_parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_metadata_parse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static GstStateChangeReturn +gst_metadata_parse_change_state (GstElement * element, + GstStateChange transition); + +static GstCaps *gst_metadata_parse_get_caps (GstPad * pad); +static gboolean gst_metadata_parse_set_caps (GstPad * pad, GstCaps * caps); +static gboolean gst_metadata_parse_src_event (GstPad * pad, GstEvent * event); +static gboolean gst_metadata_parse_sink_event (GstPad * pad, GstEvent * event); + +static GstFlowReturn gst_metadata_parse_chain (GstPad * pad, GstBuffer * buf); + +static gboolean +gst_metadata_parse_get_range (GstPad * pad, guint64 offset, guint size, + GstBuffer ** buf); + +static gboolean gst_metadata_parse_activate (GstPad * pad); + +static void gst_metadata_parse_init_members (GstMetadataParse * filter); +static void gst_metadata_parse_dispose_members (GstMetadataParse * filter); + +static gboolean +gst_metadata_parse_configure_srccaps (GstMetadataParse * filter); +static gboolean gst_metadata_parse_configure_caps (GstMetadataParse * filter); + +static int +gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf, + guint32 size); + +static void +gst_metadata_parse_base_init (gpointer gclass) +{ + static GstElementDetails element_details = { + "Metadata parser", + "Image/Extracter/Metadata", + "Send metadata tags (EXIF, IPTC and XMP) while passing throught the contents", + "Edgard Lima " + }; + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); + gst_element_class_set_details (element_class, &element_details); +} + +/* initialize the plugin's class */ +static void +gst_metadata_parse_class_init (GstMetadataParseClass * klass) +{ + GObjectClass *gobject_class; + GstElementClass *gstelement_class; + + 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_parse_dispose); + gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_metadata_parse_finalize); + + gobject_class->set_property = gst_metadata_parse_set_property; + gobject_class->get_property = gst_metadata_parse_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_parse_change_state; + +} + +/* initialize the new element + * instantiate pads and add them to element + * set functions + * initialize structure + */ +static void +gst_metadata_parse_init (GstMetadataParse * filter, + GstMetadataParseClass * 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_parse_set_caps)); + gst_pad_set_getcaps_function (filter->sinkpad, + GST_DEBUG_FUNCPTR (gst_metadata_parse_get_caps)); + gst_pad_set_event_function (filter->sinkpad, gst_metadata_parse_sink_event); + gst_pad_set_chain_function (filter->sinkpad, + GST_DEBUG_FUNCPTR (gst_metadata_parse_chain)); + gst_pad_set_activate_function (filter->sinkpad, gst_metadata_parse_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_metadata_parse_get_caps)); + gst_pad_set_event_function (filter->srcpad, gst_metadata_parse_src_event); + gst_pad_use_fixed_caps (filter->srcpad); + gst_pad_set_getrange_function (filter->srcpad, gst_metadata_parse_get_range); + + /* addind pads */ + + gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); + gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); + + /* init members */ + + gst_metadata_parse_init_members (filter); + +} + +static void +gst_metadata_parse_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstMetadataParse *filter = GST_METADATA_PARSE (object); + + switch (prop_id) { + case ARG_EXIF: + if (g_value_get_boolean (value)) + set_parse_option (filter->parse_data, PARSE_OPT_EXIF); + else + unset_parse_option (filter->parse_data, PARSE_OPT_EXIF); + break; + case ARG_IPTC: + if (g_value_get_boolean (value)) + set_parse_option (filter->parse_data, PARSE_OPT_IPTC); + else + unset_parse_option (filter->parse_data, PARSE_OPT_IPTC); + break; + case ARG_XMP: + if (g_value_get_boolean (value)) + set_parse_option (filter->parse_data, PARSE_OPT_XMP); + else + unset_parse_option (filter->parse_data, PARSE_OPT_XMP); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_metadata_parse_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + GstMetadataParse *filter = GST_METADATA_PARSE (object); + + switch (prop_id) { + case ARG_EXIF: + g_value_set_boolean (value, + PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_EXIF); + break; + case ARG_IPTC: + g_value_set_boolean (value, + PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_IPTC); + break; + case ARG_XMP: + g_value_set_boolean (value, + PARSE_DATA_OPTION (filter->parse_data) & PARSE_OPT_XMP); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +static GstCaps * +gst_metadata_parse_get_caps (GstPad * pad) +{ + GstMetadataParse *filter = NULL; + GstPad *otherpad; + GstCaps *caps_new = NULL; + GstCaps *caps_otherpad_peer = NULL; + + filter = GST_METADATA_PARSE (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; + GString *mime = NULL; + + structure = gst_caps_get_structure (caps_otherpad_peer, i); + + mime = g_string_new (gst_structure_get_name (structure)); + if (otherpad == filter->sinkpad) { + g_string_append (mime, "-metadata"); + } else { + /* strip ou "-metadata" */ + mime->str[mime->len - 9] = '\0'; + } + + structure_new = gst_structure_empty_new (mime->str); + + gst_caps_append_structure (caps_new, structure_new); + + g_string_free (mime, TRUE); + + } + + } + +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_parse_src_event (GstPad * pad, GstEvent * event) +{ + GstMetadataParse *filter = NULL; + gboolean ret = FALSE; + + filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_SEEK: + if (filter->state != MT_STATE_PARSED) { + /* FIXME: What to do here */ + ret = TRUE; + goto done; + } + 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_parse_sink_event (GstPad * pad, GstEvent * event) +{ + GstMetadataParse *filter = NULL; + gboolean ret = FALSE; + + filter = GST_METADATA_PARSE (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_parse_dispose (GObject * object) +{ + GstMetadataParse *filter = NULL; + + filter = GST_METADATA_PARSE (object); + + gst_metadata_parse_dispose_members (filter); + + G_OBJECT_CLASS (metadata_parent_class)->dispose (object); +} + +static void +gst_metadata_parse_finalize (GObject * object) +{ + G_OBJECT_CLASS (metadata_parent_class)->finalize (object); +} + +static void +gst_metadata_parse_dispose_members (GstMetadataParse * filter) +{ + metadataparse_dispose (&filter->parse_data); + if (filter->adapter) { + gst_object_unref (filter->adapter); + filter->adapter = NULL; + } +} + +static void +gst_metadata_parse_init_members (GstMetadataParse * filter) +{ + filter->need_send_tag = TRUE; + filter->exif = TRUE; + filter->iptc = TRUE; + filter->xmp = TRUE; + filter->adapter = NULL; + filter->next_offset = 0; + filter->next_size = 0; + filter->img_type = IMG_NONE; + filter->state = MT_STATE_NULL; + filter->need_more_data = FALSE; + metadataparse_init (&filter->parse_data); +} + +static gboolean +gst_metadata_parse_configure_srccaps (GstMetadataParse * filter) +{ + GstCaps *caps = NULL; + gboolean ret = FALSE; + gchar *mime = NULL; + + switch (filter->img_type) { + case IMG_JPEG: + mime = "image/jpeg-metadata"; + break; + case IMG_PNG: + mime = "image/png-metadata"; + break; + default: + goto done; + break; + } + + caps = gst_caps_new_simple (mime, NULL); + + ret = gst_pad_set_caps (filter->srcpad, caps); + +done: + + if (caps) { + gst_caps_unref (caps); + caps = NULL; + } + + return ret; + +} + +static gboolean +gst_metadata_parse_configure_caps (GstMetadataParse * 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_parse_set_caps (GstPad * pad, GstCaps * caps) +{ + GstMetadataParse *filter = NULL; + GstStructure *structure = NULL; + const gchar *mime = NULL; + gboolean ret = FALSE; + + filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); + + 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 { + goto done; + } + + ret = gst_metadata_parse_configure_srccaps (filter); + +done: + + gst_object_unref (filter); + + return ret; +} + +static const gchar * +gst_metadata_parse_get_type_name (int img_type) +{ + gchar *type_name = NULL; + + 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; +} + +/* + * return: + * -1 -> error + * 0 -> succeded + * 1 -> need more data + */ + +static int +gst_metadata_parse_parse (GstMetadataParse * filter, const guint8 * buf, + guint32 size) +{ + + int ret = -1; + + filter->next_offset = 0; + filter->next_size = 0; + + ret = metadataparse_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) { + /* 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 { + filter->state = MT_STATE_PARSED; + filter->need_more_data = FALSE; + } + + if (filter->img_type != PARSE_DATA_IMG_TYPE (filter->parse_data)) { + filter->img_type = PARSE_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", + gst_metadata_parse_get_type_name (filter->img_type))); + ret = -1; + goto done; + } + } + +done: + + return ret; + +} + +/* chain function + * this function does the actual processing + */ + +static GstFlowReturn +gst_metadata_parse_chain (GstPad * pad, GstBuffer * buf) +{ + GstMetadataParse *filter = NULL; + GstFlowReturn ret = GST_FLOW_ERROR; + + filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); + + if (filter->state != MT_STATE_PARSED) { + guint32 adpt_size = gst_adapter_available (filter->adapter); + + if (filter->next_offset) { + if (filter->next_offset >= adpt_size) { + /* clean adapter */ + gst_adapter_clear (filter->adapter); + 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), + GST_BUFFER_SIZE (buf) - filter->next_offset); + filter->next_offset = 0; + gst_adapter_push (filter->adapter, new_buf); + } + } else { + /* remove first bytes and add buffer */ + gst_adapter_flush (filter->adapter, filter->next_offset); + filter->next_offset = 0; + gst_adapter_push (filter->adapter, gst_buffer_copy (buf)); + } + } else { + /* just push buffer */ + gst_adapter_push (filter->adapter, gst_buffer_copy (buf)); + } + + adpt_size = gst_adapter_available (filter->adapter); + + if (adpt_size && filter->next_size <= adpt_size) { + const guint8 *new_buf = gst_adapter_peek (filter->adapter, adpt_size); + + if (gst_metadata_parse_parse (filter, new_buf, adpt_size) < 0) + goto done; + } + } + + if (filter->need_send_tag) { + metadataparse_exif_dump (filter->parse_data.adpt_exif); + metadataparse_iptc_dump (filter->parse_data.adpt_iptc); + metadataparse_xmp_dump (filter->parse_data.adpt_xmp); + + filter->need_send_tag = FALSE; + } + + gst_buffer_set_caps (buf, GST_PAD_CAPS (filter->srcpad)); + + ret = gst_pad_push (filter->srcpad, buf); + buf = NULL; /* this function don't owner it anymore */ + +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_parse_activate (GstPad * pad) +{ + GstMetadataParse *filter = NULL; + gboolean ret = TRUE; + gint64 duration = 0; + GstFormat format = GST_FORMAT_BYTES; + int res; + guint32 offset = 0; + + filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); + + if (!gst_pad_check_pull_range (pad) || + !gst_pad_activate_pull (filter->sinkpad, TRUE)) { + /* nothing to be done by now, activate push mode */ + goto done; + } + + 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; + } + + /* try to parse */ + 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_parse_parse (filter, GST_BUFFER_DATA (buf), + GST_BUFFER_SIZE (buf)); + if (res < 0) { + ret = FALSE; + goto done; + } + + gst_buffer_unref (buf); + + } while (res > 0); + +done: + + if (ret) { + do { + if (!(ret = gst_pad_activate_pull (filter->sinkpad, FALSE))) + break; + + if (!gst_pad_is_active (filter->sinkpad)) { + ret = gst_pad_activate_push (filter->srcpad, TRUE); + ret &= gst_pad_activate_push (filter->sinkpad, TRUE); + } + + } while (FALSE); + } + + return ret; + +} + +static gboolean +gst_metadata_parse_get_range (GstPad * pad, + guint64 offset, guint size, GstBuffer ** buf) +{ + GstMetadataParse *filter = NULL; + gboolean ret; + + filter = GST_METADATA_PARSE (gst_pad_get_parent (pad)); + + if (filter->need_send_tag) { + metadataparse_exif_dump (filter->parse_data.adpt_exif); + metadataparse_iptc_dump (filter->parse_data.adpt_iptc); + metadataparse_xmp_dump (filter->parse_data.adpt_xmp); + + filter->need_send_tag = FALSE; + } + + ret = gst_pad_pull_range (filter->sinkpad, offset, size, buf); + + gst_object_unref (filter); + + return ret; + +} + +static GstStateChangeReturn +gst_metadata_parse_change_state (GstElement * element, + GstStateChange transition) +{ + GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS; + GstMetadataParse *filter = GST_METADATA_PARSE (element); + + switch (transition) { + case GST_STATE_CHANGE_NULL_TO_READY: + gst_metadata_parse_init_members (filter); + filter->adapter = gst_adapter_new (); + 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_READY_TO_NULL: + gst_metadata_parse_dispose_members (filter); + break; + default: + break; + } + +done: + + return ret; +} + +/* + * element plugin init function + */ + +gboolean +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"); + + + return gst_element_register (plugin, "metadataparse", + GST_RANK_PRIMARY, GST_TYPE_METADATA_PARSE); +} diff --git a/ext/metadata/gstmetadataparse.h b/ext/metadata/gstmetadataparse.h new file mode 100644 index 00000000..adffa702 --- /dev/null +++ b/ext/metadata/gstmetadataparse.h @@ -0,0 +1,113 @@ +/* + * 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_PARSE_H__ +#define __GST_METADATA_PARSE_H__ + +#include + +#include "metadataparse.h" + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_METADATA_PARSE \ + (gst_metadata_parse_get_type()) +#define GST_METADATA_PARSE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_METADATA_PARSE,GstMetadataParse)) +#define GST_METADATA_PARSE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_METADATA_PARSE,GstMetadataParseClass)) +#define GST_IS_METADATA_PARSE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_METADATA_PARSE)) +#define GST_IS_METADATA_PARSE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_METADATA_PARSE)) + +typedef struct _GstMetadataParse GstMetadataParse; +typedef struct _GstMetadataParseClass GstMetadataParseClass; + +typedef enum _tag_MetadataState { + MT_STATE_NULL, /* still need to check media type */ + MT_STATE_READING, + MT_STATE_PARSED +} MetadataState; + +struct _GstMetadataParse +{ + GstElement element; + + GstPad *sinkpad, *srcpad; + + gboolean exif; + gboolean iptc; + gboolean xmp; + + gboolean need_send_tag; + + ParseData parse_data; + GstAdapter * adapter; + guint32 next_offset; + guint32 next_size; + ImageType img_type; + + MetadataState state; + + gboolean need_more_data; + + + +}; + +struct _GstMetadataParseClass +{ + GstElementClass parent_class; +}; + +extern GType +gst_metadata_parse_get_type (void); + +extern gboolean +gst_metadata_parse_plugin_init (GstPlugin * plugin); + +G_END_DECLS + +#endif /* __GST_METADATA_PARSE_H__ */ diff --git a/ext/metadata/metadataparse.c b/ext/metadata/metadataparse.c new file mode 100644 index 00000000..50fdbaba --- /dev/null +++ b/ext/metadata/metadataparse.c @@ -0,0 +1,194 @@ +/* + * 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 "metadataparse.h" + +#include "metadataparsejpeg.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->adpt_exif = NULL; + parse_data->adpt_iptc = NULL; + parse_data->adpt_xmp = NULL; +} + +/* + * 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, &next_start, next_size); + break; + case IMG_PNG: + break; + default: + /* unexpected */ + ret = -1; + goto done; + break; + } + + *next_offset = next_start - buf; + +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; + } + + if (parse_data->adpt_xmp) { + gst_object_unref (parse_data->adpt_xmp); + parse_data->adpt_xmp = NULL; + } + + if (parse_data->adpt_iptc) { + gst_object_unref (parse_data->adpt_iptc); + parse_data->adpt_iptc = NULL; + } + + if (parse_data->adpt_exif) { + gst_object_unref (parse_data->adpt_exif); + parse_data->adpt_exif = 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 **adpt_exif = NULL; + GstAdapter **adpt_iptc = NULL; + GstAdapter **adpt_xmp = NULL; + + *next_start = buf; + + parse_data->img_type = IMG_NONE; + + if (*bufsize < 4) { + *next_size = 4; + ret = 1; + goto done; + } + + ret = 0; + if (parse_data->option & PARSE_OPT_EXIF) + adpt_exif = &parse_data->adpt_exif; + if (parse_data->option & PARSE_OPT_IPTC) + adpt_iptc = &parse_data->adpt_iptc; + if (parse_data->option & PARSE_OPT_XMP) + adpt_xmp = &parse_data->adpt_xmp; + + if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF) { + metadataparse_jpeg_init (&parse_data->format_data.jpeg, adpt_exif, + adpt_iptc, adpt_xmp); + parse_data->img_type = IMG_JPEG; + } else if (buf[0] == 0x89 && buf[1] == 0x50 && buf[2] == 0x4e + && buf[3] == 0x47) { + parse_data->img_type = IMG_PNG; + } else + ret = -1; + +done: + + return ret; +} diff --git a/ext/metadata/metadataparse.h b/ext/metadata/metadataparse.h new file mode 100644 index 00000000..661bb31d --- /dev/null +++ b/ext/metadata/metadataparse.h @@ -0,0 +1,112 @@ +/* + * 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 "metadataparsejpeg.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_EXIF, + STATE_IPTC, + STATE_XMP, + 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; + union { + JpegData jpeg; + } format_data; + GstAdapter *adpt_exif; + GstAdapter *adpt_iptc; + GstAdapter *adpt_xmp; +} 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 to jump (just a hint to jump a chunk) + * 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 new file mode 100644 index 00000000..abd9f50a --- /dev/null +++ b/ext/metadata/metadataparseexif.c @@ -0,0 +1,129 @@ +/* + * 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" + +GST_DEBUG_CATEGORY (gst_metadata_parse_exif_debug); +#define GST_CAT_DEFAULT gst_metadata_parse_exif_debug + +#ifndef HAVE_EXIF + +void +metadataparse_exif_dump (GstAdapter * adapter) +{ + + GST_LOG ("EXIF not defined, here I should send just one tag as whole chunk"); + +} + +#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_dump (GstAdapter * adapter) +{ + const guint8 *buf; + guint32 size; + ExifData *exif = NULL; + + if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { + goto done; + } + + 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 *) NULL /* app data */ ); + +done: + + if (exif) + exif_data_unref (exif); + + return; + +} + +static void +exif_data_foreach_content_func (ExifContent * content, void *callback_data) +{ + ExifIfd ifd = exif_content_get_ifd (content); + + 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, + callback_data); +} + +static void +exif_content_foreach_entry_func (ExifEntry * entry, void *unused) +{ + char buf[2048]; + + 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 new file mode 100644 index 00000000..fdbed28d --- /dev/null +++ b/ext/metadata/metadataparseexif.h @@ -0,0 +1,57 @@ +/* + * 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_dump(GstAdapter *adapter); + +G_END_DECLS + +#endif /* __GST_METADATAPARSE_EXIF_H__ */ diff --git a/ext/metadata/metadataparseiptc.c b/ext/metadata/metadataparseiptc.c new file mode 100644 index 00000000..b6d0e4cf --- /dev/null +++ b/ext/metadata/metadataparseiptc.c @@ -0,0 +1,108 @@ +/* + * 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" + +GST_DEBUG_CATEGORY (gst_metadata_parse_iptc_debug); +#define GST_CAT_DEFAULT gst_metadata_parse_iptc_debug + +#ifndef HAVE_IPTC + +void +metadataparse_iptc_dump (GstAdapter * adapter) +{ + + GST_LOG ("IPTC not defined, here I should send just one tag as whole chunk"); + +} + +#else /* ifndef HAVE_IPTC */ + +#include + +static void +iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data); + +void +metadataparse_iptc_dump (GstAdapter * adapter) +{ + const guint8 *buf; + guint32 size; + IptcData *iptc = NULL; + + if (adapter == NULL || (size = gst_adapter_available (adapter)) == 0) { + goto done; + } + + 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, NULL); + +done: + + if (iptc) + iptc_data_unref (iptc); + + return; + +} + +static void +iptc_data_foreach_dataset_func (IptcDataSet * dataset, void *user_data) +{ + + char *buf[256]; + + 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 new file mode 100644 index 00000000..4bba6e4f --- /dev/null +++ b/ext/metadata/metadataparseiptc.h @@ -0,0 +1,57 @@ +/* + * 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_dump(GstAdapter *adapter); + +G_END_DECLS + +#endif /* __GST_METADATAPARSE_IPTC_H__ */ diff --git a/ext/metadata/metadataparsejpeg.c b/ext/metadata/metadataparsejpeg.c new file mode 100644 index 00000000..bf453a12 --- /dev/null +++ b/ext/metadata/metadataparsejpeg.c @@ -0,0 +1,374 @@ +/* + * 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 "metadataparsejpeg.h" + +#include + +#include + +static int +metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size); + + +static int +metadataparse_jpeg_hold_chunk (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, + guint32 * next_size, GstAdapter ** adapter); + +static int +metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size); + +static int +metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size); + +static int +metadataparse_jpeg_jump (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size); + +#define READ(buf, size) ( (size)--, *((buf)++) ) + +void +metadataparse_jpeg_init (JpegData * jpeg_data, GstAdapter ** adpt_exif, + GstAdapter ** adpt_iptc, GstAdapter ** adpt_xmp) +{ + jpeg_data->state = JPEG_NULL; + jpeg_data->adpt_exif = adpt_exif; + jpeg_data->adpt_iptc = adpt_iptc; + jpeg_data->adpt_xmp = adpt_xmp; + jpeg_data->read = 0; +} + +void +metadataparse_jpeg_dispose (JpegData * jpeg_data) +{ + + jpeg_data->adpt_exif = NULL; + jpeg_data->adpt_iptc = NULL; + jpeg_data->adpt_xmp = NULL; +} + +int +metadataparse_jpeg_parse (JpegData * jpeg_data, guint8 * buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + + int ret = 0; + guint8 mark[2] = { 0x00, 0x00 }; + + *next_start = buf; + + if (jpeg_data->state == JPEG_NULL) { + + if (*bufsize < 2) { + *next_size = (buf - *next_start) + 2; + ret = 1; + goto done; + } + + mark[0] = READ (buf, *bufsize); + mark[1] = READ (buf, *bufsize); + + if (mark[0] != 0xFF || mark[1] != 0xD8) { + ret = -1; + goto done; + } + + jpeg_data->state = JPEG_READING; + + } + + while (ret == 0) { + switch (jpeg_data->state) { + case JPEG_READING: + ret = + metadataparse_jpeg_reading (jpeg_data, &buf, bufsize, next_start, + next_size); + break; + case JPEG_JUMPING: + ret = + metadataparse_jpeg_jump (jpeg_data, &buf, bufsize, next_start, + next_size); + break; + case JPEG_EXIF: + ret = + metadataparse_jpeg_exif (jpeg_data, &buf, bufsize, next_start, + next_size); + break; + case JPEG_IPTC: + ret = + metadataparse_jpeg_iptc (jpeg_data, &buf, bufsize, next_start, + next_size); + break; + case JPEG_DONE: + goto done; + break; + default: + ret = -1; + break; + } + } + +done: + + return ret; + +} + + +/* look for markers */ +static int +metadataparse_jpeg_reading (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + + int ret = -1; + guint8 mark[2] = { 0x00, 0x00 }; + guint16 chunk_size = 0; + + static const unsigned char ExifHeader[] = + { 0x45, 0x78, 0x69, 0x66, 0x00, 0x00 }; + static const char IptcHeader[] = "Photoshop 3.0"; + + *next_start = *buf; + + if (*bufsize < 2) { + *next_size = (*buf - *next_start) + 2; + ret = 1; + goto done; + } + + mark[0] = READ (*buf, *bufsize); + mark[1] = READ (*buf, *bufsize); + + if (mark[0] == 0xFF) { + if (mark[1] == 0xD9) { /* end of image */ + ret = 0; + jpeg_data->state = JPEG_DONE; + goto done; + } else if (mark[1] == 0xDA) { /* start of scan, lets not look behinf of this */ + ret = 0; + jpeg_data->state = JPEG_DONE; + goto done; + } + + if (*bufsize < 2) { + *next_size = (*buf - *next_start) + 2; + ret = 1; + goto done; + } + + chunk_size = READ (*buf, *bufsize) << 8; + chunk_size += READ (*buf, *bufsize); + + if (mark[1] == 0xE1) { /* may be it is Exif */ + if (chunk_size >= 8) { /* size2 'EXIF' 0x00 0x00 */ + guint8 ch; + + if (*bufsize < 6) { + *next_size = (*buf - *next_start) + 6; + ret = 1; + goto done; + } + + if (jpeg_data->adpt_exif) { + if (0 == memcmp (ExifHeader, *buf, 6)) { + jpeg_data->read = chunk_size - 2; + ret = 0; + jpeg_data->state = JPEG_EXIF; + goto done; + } + } + } + } else if (mark[1] == 0xED) { /* may be it is photoshop and may be there is iptc */ + if (chunk_size >= 16) { /* size2 "Photoshop 3.0" */ + + if (*bufsize < 14) { + *next_size = (*buf - *next_start) + 14; + ret = 1; + goto done; + } + + if (jpeg_data->adpt_iptc) { + if (0 == memcmp (IptcHeader, *buf, 14)) { + jpeg_data->read = chunk_size - 2; + ret = 0; + jpeg_data->state = JPEG_IPTC; + goto done; + } + } + } + } + + /* just set jump sise */ + jpeg_data->read = chunk_size - 2; + jpeg_data->state = JPEG_JUMPING; + ret = 0; + + } else { + /* invalid JPEG chunk */ + ret = -1; + } + + +done: + + return ret; + + +} + +static int +metadataparse_jpeg_hold_chunk (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, + guint32 * next_size, GstAdapter ** adapter) +{ + int ret; + + if (jpeg_data->read > *bufsize) { + *next_start = *buf; + *next_size = jpeg_data->read; + ret = 1; + } else { + GstBuffer *gst_buf; + + if (NULL == *adapter) { + *adapter = gst_adapter_new (); + } + gst_buf = gst_buffer_new_and_alloc (jpeg_data->read); + memcpy (GST_BUFFER_DATA (gst_buf), *buf, jpeg_data->read); + gst_adapter_push (*adapter, gst_buf); + + *next_start = *buf + jpeg_data->read; + *buf += jpeg_data->read; + *bufsize -= jpeg_data->read; + jpeg_data->state = JPEG_READING; + ret = 0; + } + + return ret; +} + +static int +metadataparse_jpeg_exif (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + + return metadataparse_jpeg_hold_chunk (jpeg_data, buf, + bufsize, next_start, next_size, jpeg_data->adpt_exif); + +} + +static int +metadataparse_jpeg_iptc (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + + int ret; + + ret = metadataparse_jpeg_hold_chunk (jpeg_data, buf, + bufsize, next_start, next_size, jpeg_data->adpt_iptc); + + + if (ret == 0) { + + const guint8 *buf; + guint32 size; + unsigned int iptc_len; + int res; + + size = gst_adapter_available (*jpeg_data->adpt_iptc); + buf = gst_adapter_peek (*jpeg_data->adpt_iptc, size); + + res = iptc_jpeg_ps3_find_iptc (buf, size, &iptc_len); + + if (res < 0) { + /* error */ + ret = -1; + } else if (res == 0) { + /* no iptc data found */ + gst_adapter_clear (*jpeg_data->adpt_iptc); + } else { + gst_adapter_flush (*jpeg_data->adpt_iptc, res); + size = gst_adapter_available (*jpeg_data->adpt_iptc); + if (size > iptc_len) { + GstBuffer *buf; + + buf = gst_adapter_take_buffer (*jpeg_data->adpt_iptc, iptc_len); + gst_adapter_clear (*jpeg_data->adpt_iptc); + gst_adapter_push (*jpeg_data->adpt_iptc, buf); + } + } + + } + + return ret; + +} + +static int +metadataparse_jpeg_jump (JpegData * jpeg_data, guint8 ** buf, + guint32 * bufsize, guint8 ** next_start, guint32 * next_size) +{ + int ret; + + if (jpeg_data->read > *bufsize) { + jpeg_data->read -= *bufsize; + *next_size = 2; + *next_start = *buf + *bufsize + jpeg_data->read; + jpeg_data->read = 0; + *bufsize = 0; + jpeg_data->state = JPEG_READING; + ret = 1; + } else { + *next_start = *buf + jpeg_data->read; + *buf += jpeg_data->read; + *bufsize -= jpeg_data->read; + jpeg_data->state = JPEG_READING; + ret = 0; + } + return ret; +} diff --git a/ext/metadata/metadataparsejpeg.h b/ext/metadata/metadataparsejpeg.h new file mode 100644 index 00000000..67e5ac0e --- /dev/null +++ b/ext/metadata/metadataparsejpeg.h @@ -0,0 +1,85 @@ +/* + * 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_JPEG_H__ +#define __METADATAPARSE_JPEG_H__ + +#include + +G_BEGIN_DECLS + +typedef enum _tag_JpegState { + JPEG_NULL, + JPEG_READING, + JPEG_JUMPING, + JPEG_EXIF, + JPEG_IPTC, + JPEG_XMP, + JPEG_DONE +} JpegState; + + +typedef struct _tag_JpegData { + JpegState state; + GstAdapter **adpt_exif; + GstAdapter **adpt_iptc; + GstAdapter **adpt_xmp; + guint32 read; +} JpegData; + + +extern void +metadataparse_jpeg_init(JpegData *jpeg_data, GstAdapter **adpt_exif, GstAdapter **adpt_iptc, GstAdapter **adpt_xmp); + +extern void +metadataparse_jpeg_dispose(JpegData *jpeg_data); + + +int +metadataparse_jpeg_parse(JpegData *jpeg_data, guint8 *buf, + guint32 *bufsize, guint8 ** next_start, + guint32 * next_size); + +G_END_DECLS + +#endif /* __METADATAPARSE_JPEG_H__ */ diff --git a/ext/metadata/metadataparsexmp.c b/ext/metadata/metadataparsexmp.c new file mode 100644 index 00000000..7aee17f2 --- /dev/null +++ b/ext/metadata/metadataparsexmp.c @@ -0,0 +1,69 @@ +/* + * 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" + +GST_DEBUG_CATEGORY (gst_metadata_parse_xmp_debug); +#define GST_CAT_DEFAULT gst_metadata_parse_xmp_debug + +#ifndef HAVE_XMP + +void +metadataparse_xmp_dump (GstAdapter * adapter) +{ + + GST_LOG ("XMP not defined, here I should send just one tag as whole chunk"); + +} + +#else /* ifndef HAVE_XMP */ + +void +metadataparse_xmp_dump (GstAdapter * adapter) +{ + + GST_LOG ("XMP still not implemented"); + +} + +#endif /* else (ifndef HAVE_XMP) */ diff --git a/ext/metadata/metadataparsexmp.h b/ext/metadata/metadataparsexmp.h new file mode 100644 index 00000000..6e988a23 --- /dev/null +++ b/ext/metadata/metadataparsexmp.h @@ -0,0 +1,57 @@ +/* + * 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_dump(GstAdapter *adapter); + +G_END_DECLS + +#endif /* __GST_METADATAPARSE_XMP_H__ */ -- cgit v1.2.1