summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog22
-rw-r--r--ext/metadata/Makefile.am6
-rw-r--r--ext/metadata/TODO5
-rw-r--r--ext/metadata/gstbasemetadata.c1123
-rw-r--r--ext/metadata/gstbasemetadata.h164
-rw-r--r--ext/metadata/gstmetadatacommon.c5
-rw-r--r--ext/metadata/gstmetadatacommon.h2
-rw-r--r--ext/metadata/gstmetadatademux.c1056
-rw-r--r--ext/metadata/gstmetadatademux.h30
-rw-r--r--ext/metadata/gstmetadatamux.c1037
-rw-r--r--ext/metadata/gstmetadatamux.h28
-rw-r--r--ext/metadata/metadata.c23
-rw-r--r--ext/metadata/metadata.h14
-rw-r--r--ext/metadata/metadatatags.h2
-rw-r--r--ext/metadata/test/metadata_editor.c1
15 files changed, 1574 insertions, 1944 deletions
diff --git a/ChangeLog b/ChangeLog
index b7cd68bb..e5856804 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2007-12-19 Edgard Lima <edgard.lima@indt.org.br>
+
+ * ext/metadata/Makefile.am:
+ * ext/metadata/TODO:
+ * ext/metadata/gstbasemetadata.c:
+ * ext/metadata/gstbasemetadata.h:
+ * ext/metadata/gstmetadatacommon.c:
+ * ext/metadata/gstmetadatacommon.h:
+ * ext/metadata/gstmetadatademux.c:
+ * ext/metadata/gstmetadatademux.h:
+ * ext/metadata/gstmetadatamux.c:
+ * ext/metadata/gstmetadatamux.h:
+ * ext/metadata/metadata.c:
+ * ext/metadata/metadata.h:
+ * ext/metadata/metadataexif.c:
+ * ext/metadata/metadataparsejpeg.c:
+ * ext/metadata/metadataparsepng.c:
+ * ext/metadata/metadatatags.c:
+ * ext/metadata/metadatatags.h:
+ * ext/metadata/test/metadata_editor.c:
+ New base class for metadata elements.
+
2007-12-18 Andy Wingo <wingo@pobox.com>
* gst/switch/gstswitch-marshal.list:
diff --git a/ext/metadata/Makefile.am b/ext/metadata/Makefile.am
index aa6fac48..5123c2ae 100644
--- a/ext/metadata/Makefile.am
+++ b/ext/metadata/Makefile.am
@@ -14,7 +14,8 @@ libgstmetadata_la_SOURCES = gstmetadata.c \
metadataparseutil.c \
metadatatypes.c \
gstmetadatamux.c \
- metadatatags.c
+ metadatatags.c \
+ gstbasemetadata.c
libgstmetadata_ladir = $(includedir)/gstreamer-@GST_MAJORMINOR@/metadata
libgstmetadata_la_HEADERS = metadatatags.h
@@ -35,5 +36,6 @@ noinst_HEADERS = gstmetadatademux.h \
metadataxmp.h \
metadataparseutil.h \
metadatatypes.h \
- gstmetadatamux.h
+ gstmetadatamux.h \
+ gstbasemetadata.h
diff --git a/ext/metadata/TODO b/ext/metadata/TODO
index b85e38dc..bdd228b9 100644
--- a/ext/metadata/TODO
+++ b/ext/metadata/TODO
@@ -3,6 +3,7 @@ This file contains a list of things to be done as well some open issues (questio
TODO:
+0- Remove "common" file (put inside class)
1- Add individual tags IPTC and XMP (and more for EXIF)
2- Get properties like 'width' and 'height' from caps
3- Review the code (in order to move to gst-plugins-good)
@@ -17,3 +18,7 @@ OPEN ISSUES:
3- Add GST_TYPE_FRACTION support for GStreamer TAGS
4- After decided issue (4) put more things to gstmetadatacommon (or else create a Class)
+KNOWN BUGS
+
+1- exposure-time, exposure-program and fnumber can't be read from a file saved from scratch (whithout WHOLE_CHUNK from previous file)
+
diff --git a/ext/metadata/gstbasemetadata.c b/ext/metadata/gstbasemetadata.c
new file mode 100644
index 00000000..962edd3b
--- /dev/null
+++ b/ext/metadata/gstbasemetadata.c
@@ -0,0 +1,1123 @@
+/*
+ * GStreamer
+ * Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
+ *
+ * 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:metadatabase-metadata
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * <para>
+ * <programlisting>
+ * gst-launch -v -m filesrc location=./test.jpeg ! metadatabase ! fakesink silent=TRUE
+ * </programlisting>
+ * </para>
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gst/gst.h>
+
+#include "gstbasemetadata.h"
+
+#include "metadataexif.h"
+
+#include "metadataiptc.h"
+
+#include "metadataxmp.h"
+
+#include <string.h>
+
+GST_DEBUG_CATEGORY_STATIC (gst_base_metadata_debug);
+#define GST_CAT_DEFAULT gst_base_metadata_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 GstBaseMetadataClass *parent_class = NULL;
+
+static void gst_base_metadata_dispose (GObject * object);
+
+static void gst_base_metadata_finalize (GObject * object);
+
+static void gst_base_metadata_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_base_metadata_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+static GstStateChangeReturn
+gst_base_metadata_change_state (GstElement * element,
+ GstStateChange transition);
+
+static gboolean gst_base_metadata_src_event (GstPad * pad, GstEvent * event);
+static gboolean gst_base_metadata_sink_event (GstPad * pad, GstEvent * event);
+
+static GstFlowReturn gst_base_metadata_chain (GstPad * pad, GstBuffer * buf);
+
+static gboolean gst_base_metadata_checkgetrange (GstPad * srcpad);
+
+static GstFlowReturn
+gst_base_metadata_get_range (GstPad * pad, guint64 offset_orig, guint size,
+ GstBuffer ** buf);
+
+static gboolean gst_base_metadata_sink_activate (GstPad * pad);
+
+static gboolean
+gst_base_metadata_src_activate_pull (GstPad * pad, gboolean active);
+
+static gboolean gst_base_metadata_pull_range_base (GstBaseMetadata * filter);
+
+static void gst_base_metadata_init_members (GstBaseMetadata * filter);
+static void gst_base_metadata_dispose_members (GstBaseMetadata * filter);
+
+static gboolean gst_base_metadata_configure_caps (GstBaseMetadata * filter);
+
+static int
+gst_base_metadata_parse (GstBaseMetadata * filter, const guint8 * buf,
+ guint32 size);
+
+static const GstQueryType *gst_base_metadata_get_query_types (GstPad * pad);
+
+static gboolean gst_base_metadata_src_query (GstPad * pad, GstQuery * query);
+
+static void gst_base_metadata_base_init (gpointer gclass);
+static void gst_base_metadata_class_init (GstBaseMetadataClass * klass);
+static void
+gst_base_metadata_init (GstBaseMetadata * filter,
+ GstBaseMetadataClass * gclass);
+
+GType
+gst_base_metadata_get_type (void)
+{
+ static GType base_metadata_type = 0;
+
+ if (G_UNLIKELY (base_metadata_type == 0)) {
+ static const GTypeInfo base_metadata_info = {
+ sizeof (GstBaseMetadataClass),
+ (GBaseInitFunc) gst_base_metadata_base_init,
+ NULL,
+ (GClassInitFunc) gst_base_metadata_class_init,
+ NULL,
+ NULL,
+ sizeof (GstBaseMetadata),
+ 0,
+ (GInstanceInitFunc) gst_base_metadata_init,
+ };
+
+ base_metadata_type = g_type_register_static (GST_TYPE_ELEMENT,
+ "GstBaseMetadata", &base_metadata_info, G_TYPE_FLAG_ABSTRACT);
+ }
+ return base_metadata_type;
+}
+
+
+static void
+gst_base_metadata_base_init (gpointer gclass)
+{
+ GST_DEBUG_CATEGORY_INIT (gst_base_metadata_debug, "basemetadata", 0,
+ "basemetadata element");
+}
+
+/* initialize the plugin's class */
+static void
+gst_base_metadata_class_init (GstBaseMetadataClass * klass)
+{
+ GObjectClass *gobject_class;
+ GstElementClass *gstelement_class;
+
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_base_metadata_dispose);
+ gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_base_metadata_finalize);
+
+ gobject_class->set_property = gst_base_metadata_set_property;
+ gobject_class->get_property = gst_base_metadata_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_base_metadata_change_state;
+
+}
+
+/* initialize the new element
+ * instantiate pads and add them to element
+ * set functions
+ * initialize structure
+ */
+static void
+gst_base_metadata_init (GstBaseMetadata * filter, GstBaseMetadataClass * gclass)
+{
+ /* sink pad */
+
+ filter->sinkpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (gclass), "sink"), "sink");
+ gst_pad_set_setcaps_function (filter->sinkpad,
+ GST_DEBUG_FUNCPTR (gclass->set_caps));
+ gst_pad_set_getcaps_function (filter->sinkpad,
+ GST_DEBUG_FUNCPTR (gclass->get_sink_caps));
+ gst_pad_set_event_function (filter->sinkpad, gst_base_metadata_sink_event);
+ gst_pad_set_chain_function (filter->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_base_metadata_chain));
+ gst_pad_set_activate_function (filter->sinkpad,
+ gst_base_metadata_sink_activate);
+
+ /* source pad */
+
+ filter->srcpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_CLASS (gclass), "src"), "src");
+ gst_pad_set_getcaps_function (filter->srcpad,
+ GST_DEBUG_FUNCPTR (gclass->get_src_caps));
+ gst_pad_set_event_function (filter->srcpad, gst_base_metadata_src_event);
+ gst_pad_set_query_function (filter->srcpad,
+ GST_DEBUG_FUNCPTR (gst_base_metadata_src_query));
+ gst_pad_set_query_type_function (filter->srcpad,
+ GST_DEBUG_FUNCPTR (gst_base_metadata_get_query_types));
+ gst_pad_use_fixed_caps (filter->srcpad);
+
+ gst_pad_set_checkgetrange_function (filter->srcpad,
+ GST_DEBUG_FUNCPTR (gst_base_metadata_checkgetrange));
+ gst_pad_set_getrange_function (filter->srcpad, gst_base_metadata_get_range);
+
+ gst_pad_set_activatepull_function (filter->srcpad,
+ GST_DEBUG_FUNCPTR (gst_base_metadata_src_activate_pull));
+ /* addind pads */
+
+ gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
+ gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
+
+ metadataparse_xmp_init ();
+ /* init members */
+
+ filter->options = META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP;
+
+ gst_base_metadata_init_members (filter);
+
+}
+
+static void
+gst_base_metadata_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstBaseMetadata *filter = GST_BASE_METADATA (object);
+
+ switch (prop_id) {
+ case ARG_EXIF:
+ if (g_value_get_boolean (value))
+ filter->options |= META_OPT_EXIF;
+ else
+ filter->options &= ~META_OPT_EXIF;
+ break;
+ case ARG_IPTC:
+ if (g_value_get_boolean (value))
+ filter->options |= META_OPT_IPTC;
+ else
+ filter->options &= ~META_OPT_IPTC;
+ break;
+ case ARG_XMP:
+ if (g_value_get_boolean (value))
+ filter->options |= META_OPT_XMP;
+ else
+ filter->options &= ~META_OPT_XMP;
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gst_base_metadata_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstBaseMetadata *filter = GST_BASE_METADATA (object);
+
+ switch (prop_id) {
+ case ARG_EXIF:
+ g_value_set_boolean (value, filter->options & META_OPT_EXIF);
+ break;
+ case ARG_IPTC:
+ g_value_set_boolean (value, filter->options & META_OPT_IPTC);
+ break;
+ case ARG_XMP:
+ g_value_set_boolean (value, filter->options & META_OPT_XMP);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+/* GstElement vmethod implementations */
+
+static gboolean
+gst_base_metadata_processing (GstBaseMetadata * filter)
+{
+ gboolean ret = TRUE;
+ GstBaseMetadataClass *bclass = GST_BASE_METADATA_GET_CLASS (filter);
+
+ if (filter->need_processing) {
+ bclass->processing (filter);
+ if (gst_metadata_common_calculate_offsets (&filter->common)) {
+ filter->need_processing = FALSE;
+ } else {
+ ret = FALSE;
+ }
+ }
+
+ return ret;
+
+}
+
+static gboolean
+gst_base_metadata_sink_event (GstPad * pad, GstEvent * event)
+{
+ GstBaseMetadata *filter = NULL;
+ gboolean ret = FALSE;
+ GstBaseMetadataClass *bclass;
+
+ filter = GST_BASE_METADATA (gst_pad_get_parent (pad));
+ bclass = GST_BASE_METADATA_GET_CLASS (filter);
+
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_EOS:
+ if (filter->need_more_data) {
+ GST_ELEMENT_WARNING (filter, STREAM, DECODE, (NULL),
+ ("Need more data. Unexpected EOS"));
+ }
+ break;
+ case GST_EVENT_TAG:
+ break;
+ default:
+ break;
+ }
+
+ ret = bclass->sink_event (pad, event);
+
+ gst_object_unref (filter);
+
+ return ret;
+
+}
+
+
+static gboolean
+gst_base_metadata_src_event (GstPad * pad, GstEvent * event)
+{
+ GstBaseMetadata *filter = NULL;
+ gboolean ret = FALSE;
+
+ filter = GST_BASE_METADATA (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 base */
+ if (!gst_base_metadata_processing (filter)) {
+ ret = FALSE;
+ 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->common.duration < 0)
+ goto done;
+ start = start * filter->common.duration / 100;
+ stop = stop * filter->common.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->common.duration < 0)
+ goto done;
+ start = filter->common.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_common_translate_pos_to_orig (&filter->common, 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->common.duration < 0)
+ goto done;
+ stop = filter->common.duration + stop;
+ }
+ stop_type == GST_SEEK_TYPE_SET;
+
+ gst_metadata_common_translate_pos_to_orig (&filter->common, 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 void
+gst_base_metadata_dispose (GObject * object)
+{
+ GstBaseMetadata *filter = NULL;
+
+ filter = GST_BASE_METADATA (object);
+
+ gst_base_metadata_dispose_members (filter);
+
+ metadataparse_xmp_dispose ();
+
+ G_OBJECT_CLASS (parent_class)->dispose (object);
+}
+
+static void
+gst_base_metadata_finalize (GObject * object)
+{
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+gst_base_metadata_dispose_members (GstBaseMetadata * filter)
+{
+ gst_metadata_common_dispose (&filter->common);
+
+ 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->prepend_buffer) {
+ gst_buffer_unref (filter->prepend_buffer);
+ filter->prepend_buffer = NULL;
+ }
+}
+
+static void
+gst_base_metadata_init_members (GstBaseMetadata * filter)
+{
+ filter->need_processing = FALSE;
+
+ 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->offset = 0;
+ filter->need_more_data = FALSE;
+
+ filter->prepend_buffer = NULL;
+
+ memset (&filter->common, 0x00, sizeof (filter->common));
+
+}
+
+static gboolean
+gst_base_metadata_configure_caps (GstBaseMetadata * 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;
+
+}
+
+static const GstQueryType *
+gst_base_metadata_get_query_types (GstPad * pad)
+{
+ static const GstQueryType gst_base_metadata_src_query_types[] = {
+ GST_QUERY_POSITION,
+ GST_QUERY_DURATION,
+ GST_QUERY_FORMATS,
+ 0
+ };
+
+ return gst_base_metadata_src_query_types;
+}
+
+static gboolean
+gst_base_metadata_src_query (GstPad * pad, GstQuery * query)
+{
+ gboolean ret = FALSE;
+ GstFormat format;
+ GstBaseMetadata *filter = GST_BASE_METADATA (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 (!gst_base_metadata_processing (filter)) {
+ ret = FALSE;
+ goto done;
+ }
+
+ gst_query_parse_duration (query, &format, NULL);
+
+ if (format == GST_FORMAT_BYTES) {
+ if (filter->common.duration >= 0) {
+ gst_query_set_duration (query, GST_FORMAT_BYTES,
+ filter->common.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;
+
+}
+
+/*
+ * Do parsing step-by-step and reconfigure caps if need
+ * return:
+ * META_PARSING_ERROR
+ * META_PARSING_DONE
+ * META_PARSING_NEED_MORE_DATA
+ */
+
+static int
+gst_base_metadata_parse (GstBaseMetadata * filter, const guint8 * buf,
+ guint32 size)
+{
+
+ int ret = META_PARSING_ERROR;
+
+ filter->next_offset = 0;
+ filter->next_size = 0;
+
+ ret = metadata_parse (&filter->common.metadata, buf, size,
+ &filter->next_offset, &filter->next_size);
+
+ if (ret == META_PARSING_ERROR) {
+ if (META_DATA_IMG_TYPE (filter->common.metadata) == 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 == META_PARSING_NEED_MORE_DATA) {
+ filter->need_more_data = TRUE;
+ } else {
+ filter->common.state = MT_STATE_PARSED;
+ filter->need_more_data = FALSE;
+ filter->need_processing = TRUE;
+ }
+
+ /* reconfigure caps if it is different from type detected by 'base_metadata' function */
+ if (filter->img_type != META_DATA_IMG_TYPE (filter->common.metadata)) {
+ filter->img_type = META_DATA_IMG_TYPE (filter->common.metadata);
+ if (!gst_base_metadata_configure_caps (filter)) {
+ GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL),
+ ("Couldn't reconfigure caps for %s",
+ gst_metadata_common_get_type_name (filter->img_type)));
+ ret = META_PARSING_ERROR;
+ goto done;
+ }
+ }
+
+done:
+
+ return ret;
+
+}
+
+/* chain function
+ * this function does the actual processing
+ */
+
+/* FIXME */
+/* Current base is just done before is pull mode could be activated */
+/* may be it is possible to base 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 ! metadatabase ! filesink location=gen3.jpg */
+
+static GstFlowReturn
+gst_base_metadata_chain (GstPad * pad, GstBuffer * buf)
+{
+ GstBaseMetadata *filter = NULL;
+ GstFlowReturn ret = GST_FLOW_ERROR;
+ guint32 buf_size = 0;
+ guint32 new_buf_size = 0;
+ gboolean append = FALSE;
+
+ filter = GST_BASE_METADATA (gst_pad_get_parent (pad));
+
+ if (filter->common.state != MT_STATE_PARSED) {
+ 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_base_metadata_parse (filter, new_buf,
+ adpt_size) == META_PARSING_ERROR) {
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+ }
+ }
+
+ if (filter->common.state == MT_STATE_PARSED) {
+
+ if (!gst_base_metadata_processing (filter)) {
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+
+ 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->offset_orig + GST_BUFFER_SIZE (buf) ==
+ filter->common.duration_orig)
+ append = TRUE;
+
+ buf_size = GST_BUFFER_SIZE (buf);
+
+ gst_metadata_common_strip_push_buffer (&filter->common, 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->common.append_buffer) {
+ gst_buffer_set_caps (filter->common.append_buffer,
+ GST_PAD_CAPS (filter->srcpad));
+ gst_buffer_ref (filter->common.append_buffer);
+ ret = gst_pad_push (filter->srcpad, filter->common.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 based */
+ 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_base_metadata_pull_range_base (GstBaseMetadata * 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;
+ }
+ filter->common.duration_orig = duration;
+
+ 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;
+
+ /* 'filter->next_size' only says the minimum required number of bytes.
+ We try provided more bytes (4096) just to avoid a lot of calls to 'metadata_parse'
+ returning META_PARSING_NEED_MORE_DATA */
+ if (filter->next_size < 4096) {
+ if (duration - offset < 4096) {
+ /* In case there is no 4096 bytes available upstream.
+ It should be done upstream but we do here for safety */
+ 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_base_metadata_parse (filter, GST_BUFFER_DATA (buf),
+ GST_BUFFER_SIZE (buf));
+ if (res == META_PARSING_ERROR) {
+ ret = FALSE;
+ goto done;
+ }
+
+ gst_buffer_unref (buf);
+
+ } while (res == META_PARSING_NEED_MORE_DATA);
+
+done:
+
+ return ret;
+
+}
+
+static gboolean
+gst_base_metadata_sink_activate (GstPad * pad)
+{
+ GstBaseMetadata *filter = NULL;
+ gboolean ret = TRUE;
+
+
+ filter = GST_BASE_METADATA (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 base in chain. Fail here ? */
+ /* nothing to be done by now, activate push mode */
+ return gst_pad_activate_push (pad, TRUE);
+ }
+
+ /* try to base */
+ if (filter->common.state == MT_STATE_NULL) {
+ ret = gst_base_metadata_pull_range_base (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;
+
+}
+
+static gboolean
+gst_base_metadata_checkgetrange (GstPad * srcpad)
+{
+ GstBaseMetadata *filter = NULL;
+
+ filter = GST_BASE_METADATA (GST_PAD_PARENT (srcpad));
+
+ return gst_pad_check_pull_range (filter->sinkpad);
+}
+
+static GstFlowReturn
+gst_base_metadata_get_range (GstPad * pad,
+ guint64 offset, guint size, GstBuffer ** buf)
+{
+ GstBaseMetadata *filter = NULL;
+ GstFlowReturn ret = GST_FLOW_OK;
+ gint64 offset_orig = 0;
+ guint size_orig;
+ GstBuffer *prepend = NULL;
+ gboolean need_append = FALSE;
+
+ filter = GST_BASE_METADATA (GST_PAD_PARENT (pad));
+
+ if (!gst_base_metadata_processing (filter)) {
+ ret = GST_FLOW_ERROR;
+ goto done;
+ }
+
+ if (offset + size > filter->common.duration) {
+ size = filter->common.duration - offset;
+ }
+
+ size_orig = size;
+
+ gst_metadata_common_translate_pos_to_orig (&filter->common, offset,
+ &offset_orig, &prepend);
+
+ if (size > 1) {
+ gint64 pos;
+
+ pos = offset + size - 1;
+ gst_metadata_common_translate_pos_to_orig (&filter->common, 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_common_strip_push_buffer (&filter->common, 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_common_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_base_metadata_src_activate_pull (GstPad * pad, gboolean active)
+{
+ GstBaseMetadata *filter = NULL;
+ gboolean ret;
+
+ filter = GST_BASE_METADATA (gst_pad_get_parent (pad));
+
+ ret = gst_pad_activate_pull (filter->sinkpad, active);
+
+ if (ret && filter->common.state == MT_STATE_NULL) {
+ ret = gst_base_metadata_pull_range_base (filter);
+ }
+
+ gst_object_unref (filter);
+
+ return ret;
+}
+
+
+static GstStateChangeReturn
+gst_base_metadata_change_state (GstElement * element, GstStateChange transition)
+{
+ GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
+ GstBaseMetadata *filter = GST_BASE_METADATA (element);
+
+ switch (transition) {
+ case GST_STATE_CHANGE_NULL_TO_READY:
+ gst_base_metadata_init_members (filter);
+ filter->adapter_parsing = gst_adapter_new ();
+ gst_metadata_common_init (&filter->common, filter->options);
+ 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->common.state != MT_STATE_PARSED) {
+ /* cleanup parser */
+ gst_metadata_common_dispose (&filter->common);
+ gst_metadata_common_init (&filter->common, filter->options);
+ }
+ break;
+ case GST_STATE_CHANGE_READY_TO_NULL:
+ gst_base_metadata_dispose_members (filter);
+ break;
+ default:
+ break;
+ }
+
+done:
+
+ return ret;
+}
+
+void
+gst_base_metadata_set_option_flag (GstBaseMetadata * metadata,
+ MetaOptions options)
+{
+ metadata->options |= options;
+}
+
+void
+gst_base_metadata_unset_option_flag (GstBaseMetadata * metadata,
+ MetaOptions options)
+{
+ metadata->options &= ~options;
+}
+
+MetaOptions
+gst_base_metadata_get_option_flag (const GstBaseMetadata * metadata)
+{
+ return metadata->options;
+}
+
+void
+gst_base_metadata_update_segment_with_new_buffer (GstBaseMetadata * metadata,
+ guint8 ** buf, guint32 * size, MetadataChunkType type)
+{
+ gst_metadata_common_update_segment_with_new_buffer (&metadata->common, buf,
+ size, type);
+}
+
+void
+gst_base_metadata_chunk_array_remove_zero_size (GstBaseMetadata * metadata)
+{
+ metadata_chunk_array_remove_zero_size (&metadata->common.metadata.
+ inject_chunks);
+}
diff --git a/ext/metadata/gstbasemetadata.h b/ext/metadata/gstbasemetadata.h
new file mode 100644
index 00000000..4389cf90
--- /dev/null
+++ b/ext/metadata/gstbasemetadata.h
@@ -0,0 +1,164 @@
+/*
+ * GStreamer
+ * Copyright 2007 Edgard Lima <edgard.lima@indt.org.br>
+ *
+ * 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_BASE_METADATA_H__
+#define __GST_BASE_METADATA_H__
+
+#include <gst/gst.h>
+
+#include "gstmetadatacommon.h"
+
+G_BEGIN_DECLS
+
+/* #defines don't like whitespacey bits */
+#define GST_TYPE_BASE_METADATA (gst_base_metadata_get_type())
+#define GST_BASE_METADATA(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BASE_METADATA,GstBaseMetadata))
+#define GST_BASE_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BASE_METADATA,GstBaseMetadataClass))
+#define GST_BASE_METADATA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_BASE_METADATA, GstBaseMetadataClass))
+#define GST_IS_BASE_METADATA(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BASE_METADATA))
+#define GST_IS_BASE_METADATA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BASE_METADATA))
+#define GST_BASE_METADATA_CAST(obj) ((GstBaseMetadata *)(obj))
+
+typedef struct _GstBaseMetadata GstBaseMetadata;
+typedef struct _GstBaseMetadataClass GstBaseMetadataClass;
+
+typedef enum _tag_BaseMetadataType {
+ BASE_METADATA_DEMUXING,
+ BASE_METADATA_MUXING
+} BaseMetadataType;
+
+
+/**
+ * GST_BASE_METADATA_SRC_PAD:
+ * @obj: base metadata instance
+ *
+ * Gives the pointer to the #GstPad object of the element.
+ */
+#define GST_BASE_METADATA_SRC_PAD(obj) (GST_BASE_METADATA_CAST (obj)->srcpad)
+
+/**
+ * GST_BASE_METADATA_SINK_PAD:
+ * @obj: base metadata instance
+ *
+ * Gives the pointer to the #GstPad object of the element.
+ */
+#define GST_BASE_METADATA_SINK_PAD(obj) (GST_BASE_METADATA_CAST (obj)->sinkpad)
+
+#define GST_BASE_METADATA_EXIF_ADAPTER(obj) (GST_BASE_METADATA_CAST (obj)->common.metadata.exif_adapter)
+#define GST_BASE_METADATA_IPTC_ADAPTER(obj) (GST_BASE_METADATA_CAST (obj)->common.metadata.iptc_adapter)
+#define GST_BASE_METADATA_XMP_ADAPTER(obj) (GST_BASE_METADATA_CAST (obj)->common.metadata.xmp_adapter)
+
+#define GST_BASE_METADATA_IMG_TYPE(obj) (GST_BASE_METADATA_CAST (obj)->img_type)
+
+
+/**
+ * GstBaseMetadata:
+ * @element: the parent element.
+ *
+ * The opaque #GstBaseMetadata data structure.
+ */
+struct _GstBaseMetadata
+{
+ GstElement element;
+
+ /*< protected >*/
+ GstPad *sinkpad, *srcpad;
+
+ /*< private >*/
+ GstMetadataCommon common;
+
+ MetaOptions options;
+
+ gboolean need_processing;
+
+ GstAdapter *adapter_parsing;
+ GstAdapter *adapter_holding;
+ guint32 next_offset;
+ guint32 next_size;
+ ImageType img_type;
+
+ gint64 offset_orig; /* offset in original stream */
+ gint64 offset; /* offset in current stream */
+
+ GstBuffer * prepend_buffer;
+
+ gboolean need_more_data;
+
+};
+
+struct _GstBaseMetadataClass
+{
+ GstElementClass parent_class;
+
+ void (*processing) (GstBaseMetadata *basemetadata);
+
+ gboolean (*set_caps) (GstPad * pad, GstCaps * caps);
+
+ GstCaps* (*get_src_caps) (GstPad * pad);
+ GstCaps* (*get_sink_caps) (GstPad * pad);
+
+ gboolean (*sink_event) (GstPad * pad, GstEvent * event);
+
+};
+
+extern GType
+gst_base_metadata_get_type (void);
+
+extern void
+gst_base_metadata_set_option_flag(GstBaseMetadata *metadata, const MetaOptions options);
+
+extern void
+gst_base_metadata_unset_option_flag(GstBaseMetadata *metadata, const MetaOptions options);
+
+extern MetaOptions
+gst_base_metadata_get_option_flag(const GstBaseMetadata *metadata);
+
+extern void
+gst_base_metadata_update_segment_with_new_buffer (GstBaseMetadata *metadata,
+ guint8 ** buf, guint32 * size, MetadataChunkType type);
+
+extern void
+gst_base_metadata_chunk_array_remove_zero_size (GstBaseMetadata *metadata);
+
+G_END_DECLS
+#endif /* __GST_BASE_METADATA_H__ */
diff --git a/ext/metadata/gstmetadatacommon.c b/ext/metadata/gstmetadatacommon.c
index 07704ce4..7fbb2cdd 100644
--- a/ext/metadata/gstmetadatacommon.c
+++ b/ext/metadata/gstmetadatacommon.c
@@ -150,10 +150,9 @@ done:
*/
void
-gst_metadata_common_init (GstMetadataCommon * common, gboolean parse,
- guint8 options)
+gst_metadata_common_init (GstMetadataCommon * common, MetaOptions options)
{
- metadata_init (&common->metadata, parse, options);
+ metadata_init (&common->metadata, options);
}
void
diff --git a/ext/metadata/gstmetadatacommon.h b/ext/metadata/gstmetadatacommon.h
index 7f2169c0..7f195dc9 100644
--- a/ext/metadata/gstmetadatacommon.h
+++ b/ext/metadata/gstmetadatacommon.h
@@ -69,7 +69,7 @@ struct _GstMetadataCommon {
};
extern void
-gst_metadata_common_init(GstMetadataCommon *common, gboolean parse, guint8 options);
+gst_metadata_common_init(GstMetadataCommon *common, MetaOptions options);
extern void
gst_metadata_common_dispose(GstMetadataCommon *common);
diff --git a/ext/metadata/gstmetadatademux.c b/ext/metadata/gstmetadatademux.c
index b0d09950..6393319e 100644
--- a/ext/metadata/gstmetadatademux.c
+++ b/ext/metadata/gstmetadatademux.c
@@ -86,9 +86,6 @@ enum
enum
{
ARG_0,
- ARG_EXIF,
- ARG_IPTC,
- ARG_XMP,
ARG_PARSE_ONLY
};
@@ -108,8 +105,8 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
"image/png, " "tags-extracted = (bool) true")
);
-GST_BOILERPLATE (GstMetadataDemux, gst_metadata_demux, GstElement,
- GST_TYPE_ELEMENT);
+GST_BOILERPLATE (GstMetadataDemux, gst_metadata_demux, GstBaseMetadata,
+ GST_TYPE_BASE_METADATA);
static GstMetadataDemuxClass *metadata_parent_class = NULL;
@@ -122,47 +119,11 @@ static void gst_metadata_demux_set_property (GObject * object, guint prop_id,
static void gst_metadata_demux_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);
-static GstStateChangeReturn
-gst_metadata_demux_change_state (GstElement * element,
- GstStateChange transition);
-
static GstCaps *gst_metadata_demux_get_caps (GstPad * pad);
static gboolean gst_metadata_demux_set_caps (GstPad * pad, GstCaps * caps);
-static gboolean gst_metadata_demux_src_event (GstPad * pad, GstEvent * event);
static gboolean gst_metadata_demux_sink_event (GstPad * pad, GstEvent * event);
-static GstFlowReturn gst_metadata_demux_chain (GstPad * pad, GstBuffer * buf);
-
-static gboolean gst_metadata_demux_checkgetrange (GstPad * srcpad);
-
-static GstFlowReturn
-gst_metadata_demux_get_range (GstPad * pad, guint64 offset_orig, guint size,
- GstBuffer ** buf);
-
-static gboolean gst_metadata_demux_sink_activate (GstPad * pad);
-
-static gboolean
-gst_metadata_demux_src_activate_pull (GstPad * pad, gboolean active);
-
-static gboolean gst_metadata_demux_pull_range_demux (GstMetadataDemux * filter);
-
-static void gst_metadata_demux_init_members (GstMetadataDemux * filter);
-static void gst_metadata_demux_dispose_members (GstMetadataDemux * filter);
-
-static gboolean
-gst_metadata_demux_configure_srccaps (GstMetadataDemux * filter);
-
-static gboolean gst_metadata_demux_configure_caps (GstMetadataDemux * filter);
-
-static int
-gst_metadata_demux_parse (GstMetadataDemux * filter, const guint8 * buf,
- guint32 size);
-
-static void gst_metadata_demux_send_tags (GstMetadataDemux * filter);
-
-static const GstQueryType *gst_metadata_demux_get_query_types (GstPad * pad);
-
-static gboolean gst_metadata_demux_src_query (GstPad * pad, GstQuery * query);
+static void gst_metadata_demux_send_tags (GstBaseMetadata * base);
static void
gst_metadata_demux_base_init (gpointer gclass)
@@ -188,9 +149,11 @@ gst_metadata_demux_class_init (GstMetadataDemuxClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
+ GstBaseMetadataClass *gstbasemetadata_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
+ gstbasemetadata_class = (GstBaseMetadataClass *) klass;
metadata_parent_class = g_type_class_peek_parent (klass);
@@ -200,23 +163,20 @@ gst_metadata_demux_class_init (GstMetadataDemuxClass * klass)
gobject_class->set_property = gst_metadata_demux_set_property;
gobject_class->get_property = gst_metadata_demux_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));
-
g_object_class_install_property (gobject_class, ARG_PARSE_ONLY,
g_param_spec_boolean ("parse-only", "parse-only",
"If TRUE, don't strip out any chunk", FALSE, G_PARAM_READWRITE));
- gstelement_class->change_state = gst_metadata_demux_change_state;
+ gstbasemetadata_class->processing =
+ GST_DEBUG_FUNCPTR (gst_metadata_demux_send_tags);
+ gstbasemetadata_class->set_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_demux_set_caps);
+ gstbasemetadata_class->get_sink_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_demux_get_caps);
+ gstbasemetadata_class->get_src_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_demux_get_caps);
+ gstbasemetadata_class->sink_event =
+ GST_DEBUG_FUNCPTR (gst_metadata_demux_sink_event);
}
@@ -231,52 +191,8 @@ gst_metadata_demux_init (GstMetadataDemux * filter,
{
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_demux_set_caps));
- gst_pad_set_getcaps_function (filter->sinkpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_get_caps));
- gst_pad_set_event_function (filter->sinkpad, gst_metadata_demux_sink_event);
- gst_pad_set_chain_function (filter->sinkpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_chain));
- gst_pad_set_activate_function (filter->sinkpad,
- gst_metadata_demux_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_metadata_demux_get_caps));
- gst_pad_set_event_function (filter->srcpad, gst_metadata_demux_src_event);
- gst_pad_set_query_function (filter->srcpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_src_query));
- gst_pad_set_query_type_function (filter->srcpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_get_query_types));
- gst_pad_use_fixed_caps (filter->srcpad);
-
- gst_pad_set_checkgetrange_function (filter->srcpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_checkgetrange));
- gst_pad_set_getrange_function (filter->srcpad, gst_metadata_demux_get_range);
-
- gst_pad_set_activatepull_function (filter->srcpad,
- GST_DEBUG_FUNCPTR (gst_metadata_demux_src_activate_pull));
- /* addind pads */
-
- gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad);
- gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
-
- metadataparse_xmp_init ();
- /* init members */
-
- filter->options = META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP;
-
- gst_metadata_demux_init_members (filter);
+ gst_base_metadata_set_option_flag (GST_BASE_METADATA (filter),
+ META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP | META_OPT_DEMUX);
}
@@ -287,29 +203,13 @@ gst_metadata_demux_set_property (GObject * object, guint prop_id,
GstMetadataDemux *filter = GST_METADATA_DEMUX (object);
switch (prop_id) {
- case ARG_EXIF:
- if (g_value_get_boolean (value))
- filter->options |= META_OPT_EXIF;
- else
- filter->options &= ~META_OPT_EXIF;
- break;
- case ARG_IPTC:
- if (g_value_get_boolean (value))
- filter->options |= META_OPT_IPTC;
- else
- filter->options &= ~META_OPT_IPTC;
- break;
- case ARG_XMP:
- if (g_value_get_boolean (value))
- filter->options |= META_OPT_XMP;
- else
- filter->options &= ~META_OPT_XMP;
- break;
case ARG_PARSE_ONLY:
if (g_value_get_boolean (value))
- filter->options |= META_OPT_PARSE_ONLY;
+ gst_base_metadata_set_option_flag (GST_BASE_METADATA (object),
+ META_OPT_PARSE_ONLY);
else
- filter->options &= ~META_OPT_PARSE_ONLY;
+ gst_base_metadata_unset_option_flag (GST_BASE_METADATA (object),
+ META_OPT_PARSE_ONLY);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -321,20 +221,12 @@ static void
gst_metadata_demux_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- GstMetadataDemux *filter = GST_METADATA_DEMUX (object);
+ guint8 option =
+ gst_base_metadata_get_option_flag (GST_BASE_METADATA (object));
switch (prop_id) {
- case ARG_EXIF:
- g_value_set_boolean (value, filter->options & META_OPT_EXIF);
- break;
- case ARG_IPTC:
- g_value_set_boolean (value, filter->options & META_OPT_IPTC);
- break;
- case ARG_XMP:
- g_value_set_boolean (value, filter->options & META_OPT_XMP);
- break;
case ARG_PARSE_ONLY:
- g_value_set_boolean (value, filter->options & META_OPT_PARSE_ONLY);
+ g_value_set_boolean (value, option & META_OPT_PARSE_ONLY);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -342,215 +234,13 @@ gst_metadata_demux_get_property (GObject * object, guint prop_id,
}
}
-/* GstElement vmethod implementations */
-
-static GstCaps *
-gst_metadata_demux_get_caps (GstPad * pad)
-{
- GstMetadataDemux *filter = NULL;
- GstPad *otherpad;
- GstCaps *caps_new = NULL;
- GstCaps *caps_otherpad_peer = NULL;
-
- filter = GST_METADATA_DEMUX (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_demux_src_event (GstPad * pad, GstEvent * event)
-{
- GstMetadataDemux *filter = NULL;
- gboolean ret = FALSE;
-
- filter = GST_METADATA_DEMUX (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 demux */
- if (filter->common.state != MT_STATE_PARSED)
- 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->common.duration < 0)
- goto done;
- start = start * filter->common.duration / 100;
- stop = stop * filter->common.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->common.duration < 0)
- goto done;
- start = filter->common.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_common_translate_pos_to_orig (&filter->common, 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->common.duration < 0)
- goto done;
- stop = filter->common.duration + stop;
- }
- stop_type == GST_SEEK_TYPE_SET;
-
- gst_metadata_common_translate_pos_to_orig (&filter->common, 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_demux_sink_event (GstPad * pad, GstEvent * event)
-{
- GstMetadataDemux *filter = NULL;
- gboolean ret = FALSE;
- filter = GST_METADATA_DEMUX (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_demux_dispose (GObject * object)
{
GstMetadataDemux *filter = NULL;
- filter = GST_METADATA_DEMUX (object);
-
- gst_metadata_demux_dispose_members (filter);
-
- metadataparse_xmp_dispose ();
-
G_OBJECT_CLASS (metadata_parent_class)->dispose (object);
}
@@ -561,43 +251,58 @@ gst_metadata_demux_finalize (GObject * object)
}
static void
-gst_metadata_demux_dispose_members (GstMetadataDemux * filter)
+gst_metadata_demux_send_tags (GstBaseMetadata * base)
{
- gst_metadata_common_dispose (&filter->common);
- if (filter->adapter_parsing) {
- gst_object_unref (filter->adapter_parsing);
- filter->adapter_parsing = NULL;
- }
+ GstMetadataDemux *filter = GST_METADATA_DEMUX (base);
+ GstMessage *msg;
+ GstTagList *taglist = gst_tag_list_new ();
+ GstEvent *event;
+ GstPad *srcpad = GST_BASE_METADATA_SRC_PAD (filter);
- if (filter->adapter_holding) {
- gst_object_unref (filter->adapter_holding);
- filter->adapter_holding = NULL;
- }
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_EXIF)
+ metadataparse_exif_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_EXIF_ADAPTER (base), METADATA_TAG_MAP_WHOLECHUNK);
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_IPTC)
+ metadataparse_iptc_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_IPTC_ADAPTER (base), METADATA_TAG_MAP_WHOLECHUNK);
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_XMP)
+ metadataparse_xmp_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_XMP_ADAPTER (base), METADATA_TAG_MAP_WHOLECHUNK);
+
+ if (taglist && !gst_tag_list_is_empty (taglist)) {
+
+ msg =
+ gst_message_new_tag (GST_OBJECT (filter), gst_tag_list_copy (taglist));
+ gst_element_post_message (GST_ELEMENT (filter), msg);
- if (filter->prepend_buffer) {
- gst_buffer_unref (filter->prepend_buffer);
- filter->prepend_buffer = NULL;
+ event = gst_event_new_tag (taglist);
+ gst_pad_push_event (srcpad, event);
+ taglist = NULL;
}
-}
-static void
-gst_metadata_demux_init_members (GstMetadataDemux * filter)
-{
- filter->need_send_tag = FALSE;
+ if (!taglist)
+ taglist = gst_tag_list_new ();
- 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->offset = 0;
- filter->need_more_data = FALSE;
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_EXIF)
+ metadataparse_exif_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_EXIF_ADAPTER (base), METADATA_TAG_MAP_INDIVIDUALS);
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_IPTC)
+ metadataparse_iptc_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_IPTC_ADAPTER (base), METADATA_TAG_MAP_INDIVIDUALS);
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_XMP)
+ metadataparse_xmp_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
+ GST_BASE_METADATA_XMP_ADAPTER (base), METADATA_TAG_MAP_INDIVIDUALS);
- filter->prepend_buffer = NULL;
+ if (taglist && !gst_tag_list_is_empty (taglist)) {
- memset (&filter->common, 0x00, sizeof (filter->common));
+ msg = gst_message_new_tag (GST_OBJECT (filter), taglist);
+ gst_element_post_message (GST_ELEMENT (filter), msg);
+ taglist = NULL;
+ }
+
+ if (taglist)
+ gst_tag_list_free (taglist);
}
@@ -608,7 +313,7 @@ gst_metadata_demux_configure_srccaps (GstMetadataDemux * filter)
gboolean ret = FALSE;
gchar *mime = NULL;
- switch (filter->img_type) {
+ switch (GST_BASE_METADATA_IMG_TYPE (filter)) {
case IMG_JPEG:
mime = "image/jpeg";
break;
@@ -624,7 +329,7 @@ gst_metadata_demux_configure_srccaps (GstMetadataDemux * filter)
caps =
gst_caps_new_simple (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE, NULL);
- ret = gst_pad_set_caps (filter->srcpad, caps);
+ ret = gst_pad_set_caps (GST_BASE_METADATA_SRC_PAD (filter), caps);
done:
@@ -637,51 +342,6 @@ done:
}
-static gboolean
-gst_metadata_demux_configure_caps (GstMetadataDemux * 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
@@ -691,7 +351,7 @@ gst_metadata_demux_set_caps (GstPad * pad, GstCaps * caps)
GstStructure *structure = NULL;
const gchar *mime = NULL;
gboolean ret = FALSE;
- gboolean demuxd = TRUE;
+ gboolean based = TRUE;
filter = GST_METADATA_DEMUX (gst_pad_get_parent (pad));
@@ -700,16 +360,16 @@ gst_metadata_demux_set_caps (GstPad * pad, GstCaps * caps)
mime = gst_structure_get_name (structure);
if (strcmp (mime, "image/jpeg") == 0) {
- filter->img_type = IMG_JPEG;
+ GST_BASE_METADATA_IMG_TYPE (filter) = IMG_JPEG;
} else if (strcmp (mime, "image/png") == 0) {
- filter->img_type = IMG_PNG;
+ GST_BASE_METADATA_IMG_TYPE (filter) = IMG_PNG;
} else {
ret = FALSE;
goto done;
}
- if (gst_structure_get_boolean (structure, "tags-extracted", &demuxd)) {
- if (demuxd == TRUE) {
+ if (gst_structure_get_boolean (structure, "tags-extracted", &based)) {
+ if (based == TRUE) {
ret = FALSE;
goto done;
}
@@ -724,572 +384,84 @@ done:
return ret;
}
-static void
-gst_metadata_demux_send_tags (GstMetadataDemux * filter)
-{
-
- GstMessage *msg;
- GstTagList *taglist = gst_tag_list_new ();
- GstEvent *event;
-
- if (filter->options & META_OPT_EXIF)
- metadataparse_exif_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.exif_adapter, METADATA_TAG_MAP_WHOLECHUNK);
- if (filter->options & META_OPT_IPTC)
- metadataparse_iptc_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.iptc_adapter, METADATA_TAG_MAP_WHOLECHUNK);
- if (filter->options & META_OPT_XMP)
- metadataparse_xmp_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.xmp_adapter, METADATA_TAG_MAP_WHOLECHUNK);
-
- if (taglist && !gst_tag_list_is_empty (taglist)) {
-
- msg =
- gst_message_new_tag (GST_OBJECT (filter), gst_tag_list_copy (taglist));
- gst_element_post_message (GST_ELEMENT (filter), msg);
-
- event = gst_event_new_tag (taglist);
- gst_pad_push_event (filter->srcpad, event);
- taglist = NULL;
- }
-
- if (!taglist)
- taglist = gst_tag_list_new ();
-
- if (filter->options & META_OPT_EXIF)
- metadataparse_exif_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.exif_adapter, METADATA_TAG_MAP_INDIVIDUALS);
- if (filter->options & META_OPT_IPTC)
- metadataparse_iptc_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.iptc_adapter, METADATA_TAG_MAP_INDIVIDUALS);
- if (filter->options & META_OPT_XMP)
- metadataparse_xmp_tag_list_add (taglist, GST_TAG_MERGE_KEEP,
- filter->common.metadata.xmp_adapter, METADATA_TAG_MAP_INDIVIDUALS);
-
- if (taglist && !gst_tag_list_is_empty (taglist)) {
-
- msg = gst_message_new_tag (GST_OBJECT (filter), taglist);
- gst_element_post_message (GST_ELEMENT (filter), msg);
- taglist = NULL;
- }
-
- if (taglist)
- gst_tag_list_free (taglist);
-
- filter->need_send_tag = FALSE;
-}
-
-static const GstQueryType *
-gst_metadata_demux_get_query_types (GstPad * pad)
-{
- static const GstQueryType gst_metadata_demux_src_query_types[] = {
- GST_QUERY_POSITION,
- GST_QUERY_DURATION,
- GST_QUERY_FORMATS,
- 0
- };
-
- return gst_metadata_demux_src_query_types;
-}
-
-static gboolean
-gst_metadata_demux_src_query (GstPad * pad, GstQuery * query)
-{
- gboolean ret = FALSE;
- GstFormat format;
- GstMetadataDemux *filter = GST_METADATA_DEMUX (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->common.state != MT_STATE_PARSED)
- goto done;
-
- gst_query_parse_duration (query, &format, NULL);
-
- if (format == GST_FORMAT_BYTES) {
- if (filter->common.duration >= 0) {
- gst_query_set_duration (query, GST_FORMAT_BYTES,
- filter->common.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;
-
-}
-
-/*
- * Do parsing step-by-step and reconfigure caps if need
- * return:
- * META_PARSING_ERROR
- * META_PARSING_DONE
- * META_PARSING_NEED_MORE_DATA
- */
-
-static int
-gst_metadata_demux_parse (GstMetadataDemux * filter, const guint8 * buf,
- guint32 size)
-{
-
- int ret = META_PARSING_ERROR;
-
- filter->next_offset = 0;
- filter->next_size = 0;
-
- ret = metadata_parse (&filter->common.metadata, buf, size,
- &filter->next_offset, &filter->next_size);
-
- if (ret == META_PARSING_ERROR) {
- if (META_DATA_IMG_TYPE (filter->common.metadata) == 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 == META_PARSING_NEED_MORE_DATA) {
- filter->need_more_data = TRUE;
- } else {
- filter->common.state = MT_STATE_PARSED;
- gst_metadata_common_calculate_offsets (&filter->common);
- filter->need_more_data = FALSE;
- filter->need_send_tag = TRUE;
- }
-
- /* reconfigure caps if it is different from type detected by 'metadata_demux' function */
- if (filter->img_type != META_DATA_IMG_TYPE (filter->common.metadata)) {
- filter->img_type = META_DATA_IMG_TYPE (filter->common.metadata);
- if (!gst_metadata_demux_configure_caps (filter)) {
- GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL),
- ("Couldn't reconfigure caps for %s",
- gst_metadata_common_get_type_name (filter->img_type)));
- ret = META_PARSING_ERROR;
- goto done;
- }
- }
-
-done:
-
- return ret;
-
-}
-
-/* chain function
- * this function does the actual processing
- */
-
-/* FIXME */
-/* Current demux is just done before is pull mode could be activated */
-/* may be it is possible to demux 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 ! metadatademux ! filesink location=gen3.jpg */
-
-static GstFlowReturn
-gst_metadata_demux_chain (GstPad * pad, GstBuffer * buf)
+static GstCaps *
+gst_metadata_demux_get_caps (GstPad * pad)
{
GstMetadataDemux *filter = NULL;
- GstFlowReturn ret = GST_FLOW_ERROR;
- guint32 buf_size = 0;
- guint32 new_buf_size = 0;
- gboolean append = FALSE;
+ GstPad *otherpad;
+ GstCaps *caps_new = NULL;
+ GstCaps *caps_otherpad_peer = NULL;
filter = GST_METADATA_DEMUX (gst_pad_get_parent (pad));
- if (filter->common.state != MT_STATE_PARSED) {
- 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_demux_parse (filter, new_buf,
- adpt_size) == META_PARSING_ERROR) {
- ret = GST_FLOW_ERROR;
- goto done;
- }
- }
- }
-
- if (filter->common.state == MT_STATE_PARSED) {
-
- 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_demux_send_tags (filter);
- }
-
- if (filter->offset_orig + GST_BUFFER_SIZE (buf) ==
- filter->common.duration_orig)
- append = TRUE;
-
- buf_size = GST_BUFFER_SIZE (buf);
-
- gst_metadata_common_strip_push_buffer (&filter->common, filter->offset_orig,
- &filter->prepend_buffer, &buf);
+ (GST_BASE_METADATA_SRC_PAD (filter) == pad) ?
+ (otherpad = GST_BASE_METADATA_SINK_PAD (filter)) :
+ (otherpad = GST_BASE_METADATA_SRC_PAD (filter));
- 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->common.append_buffer) {
- gst_buffer_set_caps (filter->common.append_buffer,
- GST_PAD_CAPS (filter->srcpad));
- gst_buffer_ref (filter->common.append_buffer);
- ret = gst_pad_push (filter->srcpad, filter->common.append_buffer);
- if (ret != GST_FLOW_OK)
- goto done;
- }
+ caps_new = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
- filter->offset_orig += buf_size;
- filter->offset += new_buf_size;
+ 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 {
- /* just store while still not demuxd */
- 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;
-
-}
+ guint i;
+ guint caps_size = 0;
-static gboolean
-gst_metadata_demux_pull_range_demux (GstMetadataDemux * filter)
-{
+ caps_size = gst_caps_get_size (caps_otherpad_peer);
- int res;
- gboolean ret = TRUE;
- guint32 offset = 0;
- gint64 duration = 0;
- GstFormat format = GST_FORMAT_BYTES;
+ gst_caps_unref (caps_new);
- if (!(ret =
- gst_pad_query_peer_duration (filter->sinkpad, &format, &duration))) {
- /* this should never happen, but try chain anyway */
- ret = TRUE;
- goto done;
- }
- filter->common.duration_orig = duration;
+ caps_new = gst_caps_new_empty ();
- if (format != GST_FORMAT_BYTES) {
- /* this should never happen, but try chain anyway */
- ret = TRUE;
- goto done;
- }
+ for (i = 0; i < caps_size; ++i) {
+ GstStructure *structure = NULL;
+ GstStructure *structure_new = NULL;
+ const gchar *mime = NULL;
- do {
- GstFlowReturn flow;
- GstBuffer *buf = NULL;
+ structure = gst_caps_get_structure (caps_otherpad_peer, i);
- offset += filter->next_offset;
+ mime = gst_structure_get_name (structure);
- /* 'filter->next_size' only says the minimum required number of bytes.
- We try provided more bytes (4096) just to avoid a lot of calls to 'metadata_demux'
- returning META_PARSING_NEED_MORE_DATA */
- if (filter->next_size < 4096) {
- if (duration - offset < 4096) {
- /* In case there is no 4096 bytes available upstream.
- It should be done upstream but we do here for safety */
- filter->next_size = duration - offset;
+ if (pad == GST_BASE_METADATA_SINK_PAD (filter)) {
+ structure_new =
+ gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, FALSE,
+ NULL);
} else {
- filter->next_size = 4096;
+ structure_new =
+ gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE,
+ NULL);
}
- }
- flow =
- gst_pad_pull_range (filter->sinkpad, offset, filter->next_size, &buf);
- if (GST_FLOW_OK != flow) {
- ret = FALSE;
- goto done;
- }
+ gst_caps_append_structure (caps_new, structure_new);
- res =
- gst_metadata_demux_parse (filter, GST_BUFFER_DATA (buf),
- GST_BUFFER_SIZE (buf));
- if (res == META_PARSING_ERROR) {
- ret = FALSE;
- goto done;
}
- gst_buffer_unref (buf);
-
- } while (res == META_PARSING_NEED_MORE_DATA);
-
-done:
-
- return ret;
-
-}
-
-static gboolean
-gst_metadata_demux_sink_activate (GstPad * pad)
-{
- GstMetadataDemux *filter = NULL;
- gboolean ret = TRUE;
-
-
- filter = GST_METADATA_DEMUX (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 demux in chain. Fail here ? */
- /* nothing to be done by now, activate push mode */
- return gst_pad_activate_push (pad, TRUE);
- }
-
- /* try to demux */
- if (filter->common.state == MT_STATE_NULL) {
- ret = gst_metadata_demux_pull_range_demux (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;
-
-}
-
-static gboolean
-gst_metadata_demux_checkgetrange (GstPad * srcpad)
-{
- GstMetadataDemux *filter = NULL;
-
- filter = GST_METADATA_DEMUX (GST_PAD_PARENT (srcpad));
-
- return gst_pad_check_pull_range (filter->sinkpad);
-}
-
-static GstFlowReturn
-gst_metadata_demux_get_range (GstPad * pad,
- guint64 offset, guint size, GstBuffer ** buf)
-{
- GstMetadataDemux *filter = NULL;
- GstFlowReturn ret = GST_FLOW_OK;
- gint64 offset_orig = 0;
- guint size_orig;
- GstBuffer *prepend = NULL;
- gboolean need_append = FALSE;
-
- filter = GST_METADATA_DEMUX (GST_PAD_PARENT (pad));
-
- if (filter->common.state != MT_STATE_PARSED) {
- ret = GST_FLOW_ERROR;
- goto done;
- }
-
- if (offset + size > filter->common.duration) {
- size = filter->common.duration - offset;
- }
-
- size_orig = size;
-
- if (filter->need_send_tag) {
- gst_metadata_demux_send_tags (filter);
- }
-
- gst_metadata_common_translate_pos_to_orig (&filter->common, offset,
- &offset_orig, &prepend);
-
- if (size > 1) {
- gint64 pos;
-
- pos = offset + size - 1;
- gst_metadata_common_translate_pos_to_orig (&filter->common, 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_common_strip_push_buffer (&filter->common, offset_orig,
- &prepend, buf);
-
- if (GST_BUFFER_SIZE (*buf) < size) {
- /* need append */
- need_append = TRUE;
- }
-
- }
- } else {
- *buf = prepend;
+ if (caps_otherpad_peer) {
+ gst_caps_unref (caps_otherpad_peer);
+ caps_otherpad_peer = NULL;
}
-done:
-
- if (need_append) {
- /* FIXME: together with SEEK and
- * gst_metadata_common_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
- */
- }
+ gst_object_unref (filter);
- return ret;
+ return caps_new;
}
static gboolean
-gst_metadata_demux_src_activate_pull (GstPad * pad, gboolean active)
+gst_metadata_demux_sink_event (GstPad * pad, GstEvent * event)
{
- GstMetadataDemux *filter = NULL;
- gboolean ret;
-
- filter = GST_METADATA_DEMUX (gst_pad_get_parent (pad));
-
- ret = gst_pad_activate_pull (filter->sinkpad, active);
-
- if (ret && filter->common.state == MT_STATE_NULL) {
- ret = gst_metadata_demux_pull_range_demux (filter);
- }
-
- gst_object_unref (filter);
-
- return ret;
+ return gst_pad_event_default (pad, event);
}
-static GstStateChangeReturn
-gst_metadata_demux_change_state (GstElement * element,
- GstStateChange transition)
-{
- GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
- GstMetadataDemux *filter = GST_METADATA_DEMUX (element);
-
- switch (transition) {
- case GST_STATE_CHANGE_NULL_TO_READY:
- gst_metadata_demux_init_members (filter);
- filter->adapter_parsing = gst_adapter_new ();
- gst_metadata_common_init (&filter->common, TRUE, filter->options);
- 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->common.state != MT_STATE_PARSED) {
- /* cleanup demuxr */
- gst_metadata_common_dispose (&filter->common);
- gst_metadata_common_init (&filter->common, TRUE, filter->options);
- }
- break;
- case GST_STATE_CHANGE_READY_TO_NULL:
- gst_metadata_demux_dispose_members (filter);
- break;
- default:
- break;
- }
-
-done:
-
- return ret;
-}
-
/*
* element plugin init function
*/
diff --git a/ext/metadata/gstmetadatademux.h b/ext/metadata/gstmetadatademux.h
index 2170a871..df1c42df 100644
--- a/ext/metadata/gstmetadatademux.h
+++ b/ext/metadata/gstmetadatademux.h
@@ -46,7 +46,7 @@
#include <gst/gst.h>
-#include "gstmetadatacommon.h"
+#include "gstbasemetadata.h"
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */
@@ -65,36 +65,12 @@ typedef struct _GstMetadataDemuxClass GstMetadataDemuxClass;
struct _GstMetadataDemux
{
- GstElement element;
-
- GstPad *sinkpad, *srcpad;
-
- GstMetadataCommon common;
-
- guint8 options;
-
- gboolean need_send_tag;
-
- GstAdapter *adapter_parsing;
- GstAdapter *adapter_holding;
- guint32 next_offset;
- guint32 next_size;
- ImageType img_type;
-
- gint64 offset_orig; /* offset in original stream */
- gint64 offset; /* offset in current stream */
-
- GstBuffer * prepend_buffer;
-
- gboolean need_more_data;
-
-
-
+ GstBaseMetadata element;
};
struct _GstMetadataDemuxClass
{
- GstElementClass parent_class;
+ GstBaseMetadataClass parent_class;
};
extern GType gst_metadata_demux_get_type (void);
diff --git a/ext/metadata/gstmetadatamux.c b/ext/metadata/gstmetadatamux.c
index f2c2a895..8175e7c6 100644
--- a/ext/metadata/gstmetadatamux.c
+++ b/ext/metadata/gstmetadatamux.c
@@ -86,11 +86,10 @@ enum
enum
{
ARG_0,
- ARG_EXIF,
- ARG_IPTC,
- ARG_XMP
+ ARG_PARSE_ONLY
};
+
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
@@ -113,8 +112,8 @@ gst_metadata_mux_add_interfaces (GType type)
}
-GST_BOILERPLATE_FULL (GstMetadataMux, gst_metadata_mux, GstElement,
- GST_TYPE_ELEMENT, gst_metadata_mux_add_interfaces);
+GST_BOILERPLATE_FULL (GstMetadataMux, gst_metadata_mux, GstBaseMetadata,
+ GST_TYPE_BASE_METADATA, gst_metadata_mux_add_interfaces);
static GstMetadataMuxClass *metadata_parent_class = NULL;
@@ -127,53 +126,19 @@ static void gst_metadata_mux_set_property (GObject * object, guint prop_id,
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_parse (GstMetadataMux * filter, const guint8 * buf,
- guint32 size);
-
-static void gst_metadata_mux_create_chunks_from_tags (GstMetadataMux * filter);
-
-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_create_chunks_from_tags (GstBaseMetadata * base);
static void
gst_metadata_mux_base_init (gpointer gclass)
{
static GstElementDetails element_details = {
- "Metadata muxer",
- "Muxer/Metadata",
- "Convert tags to metadata (EXIF, IPTC and XMP) and insert into the stream",
+ "Metadata muxr",
+ "Muxr/Extracter/Metadata",
+ "Send metadata tags (EXIF, IPTC and XMP) and remove metadata chunks from stream",
"Edgard Lima <edgard.lima@indt.org.br>"
};
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
@@ -191,9 +156,11 @@ gst_metadata_mux_class_init (GstMetadataMuxClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
+ GstBaseMetadataClass *gstbasemetadata_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
+ gstbasemetadata_class = (GstBaseMetadataClass *) klass;
metadata_parent_class = g_type_class_peek_parent (klass);
@@ -203,19 +170,20 @@ gst_metadata_mux_class_init (GstMetadataMuxClass * klass)
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 ?",
- FALSE, G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, ARG_XMP,
- g_param_spec_boolean ("xmp", "XMP", "Send XMP metadata ?",
- FALSE, G_PARAM_READWRITE));
-
- gstelement_class->change_state = gst_metadata_mux_change_state;
+ g_object_class_install_property (gobject_class, ARG_PARSE_ONLY,
+ g_param_spec_boolean ("parse-only", "parse-only",
+ "If TRUE, don't strip out any chunk", FALSE, G_PARAM_READWRITE));
+
+ gstbasemetadata_class->processing =
+ GST_DEBUG_FUNCPTR (gst_metadata_mux_create_chunks_from_tags);
+ gstbasemetadata_class->set_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_mux_set_caps);
+ gstbasemetadata_class->get_sink_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_mux_get_caps);
+ gstbasemetadata_class->get_src_caps =
+ GST_DEBUG_FUNCPTR (gst_metadata_mux_get_caps);
+ gstbasemetadata_class->sink_event =
+ GST_DEBUG_FUNCPTR (gst_metadata_mux_sink_event);
}
@@ -229,52 +197,8 @@ 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_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_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);
-
- metadataparse_xmp_init ();
- /* init members */
-
- filter->options = META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP;
-
- gst_metadata_mux_init_members (filter);
+ gst_base_metadata_set_option_flag (GST_BASE_METADATA (filter),
+ META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP | META_OPT_MUX);
}
@@ -285,23 +209,13 @@ 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))
- filter->options |= META_OPT_EXIF;
- else
- filter->options &= ~META_OPT_EXIF;
- break;
- case ARG_IPTC:
- if (g_value_get_boolean (value))
- filter->options |= META_OPT_IPTC;
- else
- filter->options &= ~META_OPT_IPTC;
- break;
- case ARG_XMP:
+ case ARG_PARSE_ONLY:
if (g_value_get_boolean (value))
- filter->options |= META_OPT_XMP;
+ gst_base_metadata_set_option_flag (GST_BASE_METADATA (object),
+ META_OPT_PARSE_ONLY);
else
- filter->options &= ~META_OPT_XMP;
+ gst_base_metadata_unset_option_flag (GST_BASE_METADATA (object),
+ META_OPT_PARSE_ONLY);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -313,17 +227,12 @@ static void
gst_metadata_mux_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec)
{
- GstMetadataMux *filter = GST_METADATA_MUX (object);
+ guint8 option =
+ gst_base_metadata_get_option_flag (GST_BASE_METADATA (object));
switch (prop_id) {
- case ARG_EXIF:
- g_value_set_boolean (value, filter->options & META_OPT_EXIF);
- break;
- case ARG_IPTC:
- g_value_set_boolean (value, filter->options & META_OPT_IPTC);
- break;
- case ARG_XMP:
- g_value_set_boolean (value, filter->options & META_OPT_XMP);
+ case ARG_PARSE_ONLY:
+ g_value_set_boolean (value, option & META_OPT_PARSE_ONLY);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -331,80 +240,27 @@ gst_metadata_mux_get_property (GObject * object, guint prop_id,
}
}
-/* GstElement vmethod implementations */
-static GstCaps *
-gst_metadata_mux_get_caps (GstPad * pad)
+
+static void
+gst_metadata_mux_dispose (GObject * object)
{
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, TRUE,
- NULL);
- } else {
- structure_new = gst_structure_new (mime, 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;
+ 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_create_chunks_from_tags (GstMetadataMux * filter)
+gst_metadata_mux_create_chunks_from_tags (GstBaseMetadata * base)
{
+ GstMetadataMux *filter = GST_METADATA_MUX (base);
GstMessage *msg;
GstTagSetter *setter = GST_TAG_SETTER (filter);
const GstTagList *taglist = gst_tag_setter_get_tag_list (setter);
@@ -414,22 +270,22 @@ gst_metadata_create_chunks_from_tags (GstMetadataMux * filter)
if (taglist) {
- if (filter->options & META_OPT_EXIF) {
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_EXIF) {
metadatamux_exif_create_chunk_from_tag_list (&buf, &size, taglist);
- gst_metadata_common_update_segment_with_new_buffer (&filter->common, &buf,
- &size, MD_CHUNK_EXIF);
+ gst_base_metadata_update_segment_with_new_buffer (base, &buf, &size,
+ MD_CHUNK_EXIF);
}
- if (filter->options & META_OPT_IPTC) {
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_IPTC) {
metadatamux_iptc_create_chunk_from_tag_list (&buf, &size, taglist);
- gst_metadata_common_update_segment_with_new_buffer (&filter->common, &buf,
- &size, MD_CHUNK_IPTC);
+ gst_base_metadata_update_segment_with_new_buffer (base, &buf, &size,
+ MD_CHUNK_IPTC);
}
- if (filter->options & META_OPT_XMP) {
+ if (gst_base_metadata_get_option_flag (base) & META_OPT_XMP) {
metadatamux_xmp_create_chunk_from_tag_list (&buf, &size, taglist);
- gst_metadata_common_update_segment_with_new_buffer (&filter->common, &buf,
- &size, MD_CHUNK_XMP);
+ gst_base_metadata_update_segment_with_new_buffer (base, &buf, &size,
+ MD_CHUNK_XMP);
}
}
@@ -438,208 +294,7 @@ gst_metadata_create_chunks_from_tags (GstMetadataMux * filter)
g_free (buf);
}
- metadata_chunk_array_remove_zero_size (&filter->common.metadata.
- inject_chunks);
-
-}
-
-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->need_calculate_offset) {
- gst_metadata_create_chunks_from_tags (filter);
- if (gst_metadata_common_calculate_offsets (&filter->common))
- filter->need_calculate_offset = FALSE;
- else
- 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->common.duration < 0)
- goto done;
- start = start * filter->common.duration / 100;
- stop = stop * filter->common.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->common.duration < 0)
- goto done;
- start = filter->common.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_common_translate_pos_to_orig (&filter->common, 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->common.duration < 0)
- goto done;
- stop = filter->common.duration + stop;
- }
- stop_type == GST_SEEK_TYPE_SET;
-
- gst_metadata_common_translate_pos_to_orig (&filter->common, 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:
- {
- GstTagList *taglist = NULL;
- GstTagSetter *setter = GST_TAG_SETTER (filter);
-
- gst_event_parse_tag (event, &taglist);
- gst_tag_setter_merge_tags (setter, taglist, GST_TAG_MERGE_REPLACE);
-
- }
- 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);
-
- metadataparse_xmp_dispose ();
-
- 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)
-{
- gst_metadata_common_dispose (&filter->common);
-
- 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->prepend_buffer) {
- gst_buffer_unref (filter->prepend_buffer);
- filter->prepend_buffer = NULL;
- }
-}
-
-static void
-gst_metadata_mux_init_members (GstMetadataMux * filter)
-{
- filter->need_calculate_offset = FALSE;
-
- 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->offset = 0;
- filter->need_more_data = FALSE;
-
- filter->prepend_buffer = NULL;
-
- memset (&filter->common, 0x00, sizeof (filter->common));
+ gst_base_metadata_chunk_array_remove_zero_size (base);
}
@@ -650,7 +305,7 @@ gst_metadata_mux_configure_srccaps (GstMetadataMux * filter)
gboolean ret = FALSE;
gchar *mime = NULL;
- switch (filter->img_type) {
+ switch (GST_BASE_METADATA_IMG_TYPE (filter)) {
case IMG_JPEG:
mime = "image/jpeg";
break;
@@ -665,7 +320,7 @@ gst_metadata_mux_configure_srccaps (GstMetadataMux * filter)
caps = gst_caps_new_simple (mime, NULL);
- ret = gst_pad_set_caps (filter->srcpad, caps);
+ ret = gst_pad_set_caps (GST_BASE_METADATA_SRC_PAD (filter), caps);
done:
@@ -678,51 +333,6 @@ done:
}
-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
@@ -732,7 +342,7 @@ gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps)
GstStructure *structure = NULL;
const gchar *mime = NULL;
gboolean ret = FALSE;
- gboolean muxd = TRUE;
+ gboolean based = TRUE;
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
@@ -741,16 +351,16 @@ gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps)
mime = gst_structure_get_name (structure);
if (strcmp (mime, "image/jpeg") == 0) {
- filter->img_type = IMG_JPEG;
+ GST_BASE_METADATA_IMG_TYPE (filter) = IMG_JPEG;
} else if (strcmp (mime, "image/png") == 0) {
- filter->img_type = IMG_PNG;
+ GST_BASE_METADATA_IMG_TYPE (filter) = IMG_PNG;
} else {
ret = FALSE;
goto done;
}
- if (gst_structure_get_boolean (structure, "tags-extracted", &muxd)) {
- if (muxd == FALSE) {
+ if (gst_structure_get_boolean (structure, "tags-extracted", &based)) {
+ if (based == FALSE) {
ret = FALSE;
goto done;
}
@@ -765,525 +375,104 @@ done:
return ret;
}
-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
- };
-
- 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->need_calculate_offset) {
- gst_metadata_create_chunks_from_tags (filter);
- if (gst_metadata_common_calculate_offsets (&filter->common))
- filter->need_calculate_offset = FALSE;
- else
- goto done;
- }
-
- gst_query_parse_duration (query, &format, NULL);
-
- if (format == GST_FORMAT_BYTES) {
- if (filter->common.duration >= 0) {
- gst_query_set_duration (query, GST_FORMAT_BYTES,
- filter->common.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;
-
-}
-
-/*
- * Do parsing step-by-step and reconfigure caps if need
- * return:
- * META_PARSING_ERROR
- * META_PARSING_DONE
- * META_PARSING_NEED_MORE_DATA
- */
-
-static int
-gst_metadata_mux_parse (GstMetadataMux * filter, const guint8 * buf,
- guint32 size)
-{
-
- int ret = META_PARSING_ERROR;
-
- filter->next_offset = 0;
- filter->next_size = 0;
-
- ret = metadata_parse (&filter->common.metadata, buf, size,
- &filter->next_offset, &filter->next_size);
-
- if (ret == META_PARSING_ERROR) {
- if (META_DATA_IMG_TYPE (filter->common.metadata) == 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 == META_PARSING_NEED_MORE_DATA) {
- filter->need_more_data = TRUE;
- } else {
- filter->common.state = MT_STATE_PARSED;
- filter->need_more_data = FALSE;
- filter->need_calculate_offset = TRUE;
- }
-
- /* reconfigure caps if it is different from type detected by 'metadata_mux' function */
- if (filter->img_type != META_DATA_IMG_TYPE (filter->common.metadata)) {
- filter->img_type = META_DATA_IMG_TYPE (filter->common.metadata);
- if (!gst_metadata_mux_configure_caps (filter)) {
- GST_ELEMENT_ERROR (filter, STREAM, FORMAT, (NULL),
- ("Couldn't reconfigure caps for %s",
- gst_metadata_common_get_type_name (filter->img_type)));
- ret = META_PARSING_ERROR;
- 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)
+static GstCaps *
+gst_metadata_mux_get_caps (GstPad * pad)
{
GstMetadataMux *filter = NULL;
- GstFlowReturn ret = GST_FLOW_ERROR;
- guint32 buf_size = 0;
- guint32 new_buf_size = 0;
- gboolean append = FALSE;
+ GstPad *otherpad;
+ GstCaps *caps_new = NULL;
+ GstCaps *caps_otherpad_peer = NULL;
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
- if (filter->common.state != MT_STATE_PARSED) {
- 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_parse (filter, new_buf,
- adpt_size) == META_PARSING_ERROR) {
- ret = GST_FLOW_ERROR;
- goto done;
- }
- }
- }
-
- if (filter->common.state == MT_STATE_PARSED) {
-
- 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_calculate_offset) {
- gst_metadata_create_chunks_from_tags (filter);
- if (gst_metadata_common_calculate_offsets (&filter->common)) {
- filter->need_calculate_offset = FALSE;
- } else {
- ret = GST_FLOW_ERROR;
- goto done;
- }
- }
-
- if (filter->offset_orig + GST_BUFFER_SIZE (buf) ==
- filter->common.duration_orig)
- append = TRUE;
-
- buf_size = GST_BUFFER_SIZE (buf);
+ (GST_BASE_METADATA_SRC_PAD (filter) == pad) ?
+ (otherpad = GST_BASE_METADATA_SINK_PAD (filter)) :
+ (otherpad = GST_BASE_METADATA_SRC_PAD (filter));
- gst_metadata_common_strip_push_buffer (&filter->common, 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->common.append_buffer) {
- gst_buffer_set_caps (filter->common.append_buffer,
- GST_PAD_CAPS (filter->srcpad));
- gst_buffer_ref (filter->common.append_buffer);
- ret = gst_pad_push (filter->srcpad, filter->common.append_buffer);
- if (ret != GST_FLOW_OK)
- goto done;
- }
+ caps_new = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
- filter->offset_orig += buf_size;
- filter->offset += new_buf_size;
+ 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 {
- /* 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:
+ guint i;
+ guint caps_size = 0;
- 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)
-{
+ caps_size = gst_caps_get_size (caps_otherpad_peer);
- int res;
- gboolean ret = TRUE;
- guint32 offset = 0;
- gint64 duration = 0;
- GstFormat format = GST_FORMAT_BYTES;
+ gst_caps_unref (caps_new);
- if (!(ret =
- gst_pad_query_peer_duration (filter->sinkpad, &format, &duration))) {
- /* this should never happen, but try chain anyway */
- ret = TRUE;
- goto done;
- }
- filter->common.duration_orig = duration;
+ caps_new = gst_caps_new_empty ();
- if (format != GST_FORMAT_BYTES) {
- /* this should never happen, but try chain anyway */
- ret = TRUE;
- goto done;
- }
+ for (i = 0; i < caps_size; ++i) {
+ GstStructure *structure = NULL;
+ GstStructure *structure_new = NULL;
+ const gchar *mime = NULL;
- do {
- GstFlowReturn flow;
- GstBuffer *buf = NULL;
+ structure = gst_caps_get_structure (caps_otherpad_peer, i);
- offset += filter->next_offset;
+ mime = gst_structure_get_name (structure);
- /* 'filter->next_size' only says the minimum required number of bytes.
- We try provided more bytes (4096) just to avoid a lot of calls to 'metadata_parse'
- returning META_PARSING_NEED_MORE_DATA */
- if (filter->next_size < 4096) {
- if (duration - offset < 4096) {
- /* In case there is no 4096 bytes available upstream.
- It should be done upstream but we do here for safety */
- filter->next_size = duration - offset;
+ if (pad == GST_BASE_METADATA_SINK_PAD (filter)) {
+ structure_new =
+ gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE,
+ NULL);
} else {
- filter->next_size = 4096;
+ structure_new = gst_structure_new (mime, NULL);
}
- }
- flow =
- gst_pad_pull_range (filter->sinkpad, offset, filter->next_size, &buf);
- if (GST_FLOW_OK != flow) {
- ret = FALSE;
- goto done;
- }
+ gst_caps_append_structure (caps_new, structure_new);
- res =
- gst_metadata_mux_parse (filter, GST_BUFFER_DATA (buf),
- GST_BUFFER_SIZE (buf));
- if (res == META_PARSING_ERROR) {
- ret = FALSE;
- goto done;
}
- gst_buffer_unref (buf);
-
- } while (res == META_PARSING_NEED_MORE_DATA);
-
-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->common.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;
-
-}
-
-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->need_calculate_offset) {
- gst_metadata_create_chunks_from_tags (filter);
- if (gst_metadata_common_calculate_offsets (&filter->common)) {
- filter->need_calculate_offset = FALSE;
- } else {
- ret = GST_FLOW_ERROR;
- goto done;
- }
- }
-
- if (offset + size > filter->common.duration) {
- size = filter->common.duration - offset;
- }
-
- size_orig = size;
-
- gst_metadata_common_translate_pos_to_orig (&filter->common, offset,
- &offset_orig, &prepend);
-
- if (size > 1) {
- gint64 pos;
-
- pos = offset + size - 1;
- gst_metadata_common_translate_pos_to_orig (&filter->common, 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_common_strip_push_buffer (&filter->common, offset_orig,
- &prepend, buf);
-
- if (GST_BUFFER_SIZE (*buf) < size) {
- /* need append */
- need_append = TRUE;
- }
-
- }
- } else {
- *buf = prepend;
+ if (caps_otherpad_peer) {
+ gst_caps_unref (caps_otherpad_peer);
+ caps_otherpad_peer = NULL;
}
-done:
-
- if (need_append) {
- /* FIXME: together with SEEK and
- * gst_metadata_common_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
- */
- }
+ gst_object_unref (filter);
- return ret;
+ return caps_new;
}
static gboolean
-gst_metadata_mux_src_activate_pull (GstPad * pad, gboolean active)
+gst_metadata_mux_sink_event (GstPad * pad, GstEvent * event)
{
GstMetadataMux *filter = NULL;
- gboolean ret;
+ gboolean ret = FALSE;
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
- ret = gst_pad_activate_pull (filter->sinkpad, active);
-
- if (ret && filter->common.state == MT_STATE_NULL) {
- ret = gst_metadata_mux_pull_range_mux (filter);
- }
-
- gst_object_unref (filter);
-
- return ret;
-}
+ switch (GST_EVENT_TYPE (event)) {
+ case GST_EVENT_TAG:
+ {
+ GstTagList *taglist = NULL;
+ GstTagSetter *setter = GST_TAG_SETTER (filter);
+ gst_event_parse_tag (event, &taglist);
+ gst_tag_setter_merge_tags (setter, taglist, GST_TAG_MERGE_REPLACE);
-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 ();
- gst_metadata_common_init (&filter->common, FALSE, filter->options);
+ }
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->common.state != MT_STATE_PARSED) {
- /* cleanup parser */
- gst_metadata_common_dispose (&filter->common);
- gst_metadata_common_init (&filter->common, FALSE, filter->options);
- }
- break;
- case GST_STATE_CHANGE_READY_TO_NULL:
- gst_metadata_mux_dispose_members (filter);
- break;
- default:
- break;
- }
+ ret = gst_pad_event_default (pad, event);
-done:
+ gst_object_unref (filter);
return ret;
+
}
/*
@@ -1294,7 +483,7 @@ gboolean
gst_metadata_mux_plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_metadata_mux_debug, "metadatamux", 0,
- "Metadata demuxer");
+ "Metadata muxer");
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 8b123f51..cafd6e08 100644
--- a/ext/metadata/gstmetadatamux.h
+++ b/ext/metadata/gstmetadatamux.h
@@ -46,7 +46,7 @@
#include <gst/gst.h>
-#include "gstmetadatacommon.h"
+#include "gstbasemetadata.h"
G_BEGIN_DECLS
/* #defines don't like whitespacey bits */
@@ -65,34 +65,12 @@ typedef struct _GstMetadataMuxClass GstMetadataMuxClass;
struct _GstMetadataMux
{
- GstElement element;
-
- GstPad *sinkpad, *srcpad;
-
- GstMetadataCommon common;
-
- guint8 options;
-
- GstAdapter *adapter_parsing;
- GstAdapter *adapter_holding;
- guint32 next_offset;
- guint32 next_size;
- ImageType img_type;
-
- gint64 offset_orig; /* offset in original stream */
- gint64 offset; /* offset in current stream */
-
- GstBuffer * prepend_buffer;
-
- gboolean need_more_data;
-
- gboolean need_calculate_offset; /* mux need to calculate offsets of insert chunks */
-
+ GstBaseMetadata element;
};
struct _GstMetadataMuxClass
{
- GstElementClass parent_class;
+ GstBaseMetadataClass parent_class;
};
extern GType gst_metadata_mux_get_type (void);
diff --git a/ext/metadata/metadata.c b/ext/metadata/metadata.c
index 7909db23..8e0c06b2 100644
--- a/ext/metadata/metadata.c
+++ b/ext/metadata/metadata.c
@@ -65,10 +65,10 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
* meta_data [in]: metadata handler to be inited
* parse [in]: pass TRUE for demuxing and FALSE for muxing
* options [in]: which types of metadata will be processed (EXIF, IPTC and/or XMP).
- * Look at 'MetaOption' to see the available options.
+ * Look at 'MetaOptions' to see the available options.
*/
void
-metadata_init (MetaData * meta_data, const gboolean parse, const guint8 options)
+metadata_init (MetaData * meta_data, const MetaOptions options)
{
meta_data->state = STATE_NULL;
meta_data->img_type = IMG_NONE;
@@ -77,9 +77,8 @@ metadata_init (MetaData * meta_data, const gboolean parse, const guint8 options)
meta_data->exif_adapter = NULL;
meta_data->iptc_adapter = NULL;
meta_data->xmp_adapter = NULL;
- meta_data->parse = parse;
- if (parse) {
+ if (meta_data->options & META_OPT_DEMUX) {
/* when parsing we will probably strip only 3 chunk (exif, iptc and xmp)
so we use 4 just in case there is more than one chunk of them.
But this is just for convinience, 'cause the chunk_array incriases dinamically */
@@ -105,13 +104,13 @@ metadata_dispose (MetaData * meta_data)
switch (meta_data->img_type) {
case IMG_JPEG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_jpeg_dispose (&meta_data->format_data.jpeg_parse);
else
metadatamux_jpeg_dispose (&meta_data->format_data.jpeg_mux);
break;
case IMG_PNG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_png_dispose (&meta_data->format_data.png_parse);
else
metadatamux_png_dispose (&meta_data->format_data.png_mux);
@@ -176,7 +175,7 @@ metadata_parse (MetaData * meta_data, const guint8 * buf,
switch (meta_data->img_type) {
case IMG_JPEG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
ret =
metadataparse_jpeg_parse (&meta_data->format_data.jpeg_parse,
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
@@ -188,7 +187,7 @@ metadata_parse (MetaData * meta_data, const guint8 * buf,
next_size);
break;
case IMG_PNG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
ret =
metadataparse_png_parse (&meta_data->format_data.png_parse,
(guint8 *) buf, &bufsize, meta_data->offset_orig, &next_start,
@@ -233,13 +232,13 @@ metadata_lazy_update (MetaData * meta_data)
{
switch (meta_data->img_type) {
case IMG_JPEG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_jpeg_lazy_update (&meta_data->format_data.jpeg_parse);
else
metadatamux_jpeg_lazy_update (&meta_data->format_data.jpeg_mux);
break;
case IMG_PNG:
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_png_lazy_update (&meta_data->format_data.png_parse);
else
metadatamux_png_lazy_update (&meta_data->format_data.png_mux);
@@ -293,7 +292,7 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
xmp = &meta_data->xmp_adapter;
if (buf[0] == 0xFF && buf[1] == 0xD8 && buf[2] == 0xFF) {
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_jpeg_init (&meta_data->format_data.jpeg_parse, exif, iptc,
xmp, &meta_data->strip_chunks, &meta_data->inject_chunks,
meta_data->options & META_OPT_PARSE_ONLY);
@@ -314,7 +313,7 @@ metadata_parse_none (MetaData * meta_data, const guint8 * buf,
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) {
- if (G_LIKELY (meta_data->parse))
+ if (G_LIKELY (meta_data->options & META_OPT_DEMUX))
metadataparse_png_init (&meta_data->format_data.png_parse, exif, iptc,
xmp, &meta_data->strip_chunks, &meta_data->inject_chunks,
meta_data->options & META_OPT_PARSE_ONLY);
diff --git a/ext/metadata/metadata.h b/ext/metadata/metadata.h
index 2853136d..6150cc8e 100644
--- a/ext/metadata/metadata.h
+++ b/ext/metadata/metadata.h
@@ -56,14 +56,16 @@ G_BEGIN_DECLS
/* *INDENT-OFF* */
-typedef enum _tag_MetaOption
+typedef enum _tag_MetaOptions
{
META_OPT_EXIF = (1 << 0),
META_OPT_IPTC = (1 << 1),
META_OPT_XMP = (1 << 2),
- META_OPT_PARSE_ONLY = (1 << 3),
- META_OPT_ALL = (1 << 4) - 1
-} MetaOption;
+ META_OPT_PARSE_ONLY = (1 << 3), /* only makes sense with META_OPT_DEMUX */
+ META_OPT_DEMUX = (1 << 4),
+ META_OPT_MUX = (1 << 5),
+ META_OPT_ALL = (1 << 6) - 1
+} MetaOptions;
/* *INDENT-ON* */
typedef enum _tag_MetaState
@@ -100,13 +102,11 @@ typedef struct _tag_MetaData
MetadataChunkArray strip_chunks;
MetadataChunkArray inject_chunks;
- gboolean parse; /* true - parsing, false - muxing */
-
} MetaData;
#define META_DATA_IMG_TYPE(p) (p).img_type
-extern void metadata_init (MetaData * meta_data, const gboolean parse, const guint8 options);
+extern void metadata_init (MetaData * meta_data, const MetaOptions options);
extern void metadata_dispose (MetaData * meta_data);
diff --git a/ext/metadata/metadatatags.h b/ext/metadata/metadatatags.h
index 77a6c306..a5ee914e 100644
--- a/ext/metadata/metadatatags.h
+++ b/ext/metadata/metadatatags.h
@@ -69,7 +69,7 @@ typedef enum {
#define GST_TAG_IMAGE_XRESOLUTION "image-xresolution"
#define GST_TAG_IMAGE_YRESOLUTION "image-yresolution"
-#define GST_TAG_CAPTURE_EXPOSURE_TIME "capture-exposute-time"
+#define GST_TAG_CAPTURE_EXPOSURE_TIME "capture-exposure-time"
#define GST_TAG_CAPTURE_FNUMBER "captute-fnumber"
#define GST_TAG_CAPTURE_EXPOSURE_PROGRAM "capture-exposure-program"
#define GST_TAG_CAPTURE_BRIGHTNESS "capture-brightness"
diff --git a/ext/metadata/test/metadata_editor.c b/ext/metadata/test/metadata_editor.c
index 0479e785..f24f9994 100644
--- a/ext/metadata/test/metadata_editor.c
+++ b/ext/metadata/test/metadata_editor.c
@@ -928,6 +928,7 @@ me_gst_setup_view_pipeline (const gchar * filename, GdkWindow * window)
/* set elements's properties */
g_object_set (gst_source, "location", filename, NULL);
+ g_object_set (gst_metadata_demux, "parse-only", TRUE, NULL);
g_object_set (gst_video_sink, "force-aspect-ratio", TRUE, NULL);