2007-11-23 17:35:21 +00:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2008-01-23 16:35:34 +00:00
|
|
|
* SECTION: element-metadatamux
|
2007-11-23 17:35:21 +00:00
|
|
|
*
|
|
|
|
* <refsect2>
|
2008-01-23 16:35:34 +00:00
|
|
|
* <para>
|
|
|
|
* This element writes tags into metadata (EXIF, IPTC and XMP) chunks, and
|
|
|
|
* writes the chunks into image files (JPEG, PNG). Tags the are received as
|
|
|
|
* GST_EVENT_TAG event or set by the application using #GstTagSetter interface.
|
|
|
|
* </para>
|
2007-11-23 17:35:21 +00:00
|
|
|
* <title>Example launch line</title>
|
|
|
|
* <para>
|
|
|
|
* <programlisting>
|
2008-01-23 16:35:34 +00:00
|
|
|
* gst-launch -v -m filesrc location=orig.jpeg ! metadatamux ! filesink
|
|
|
|
* location=dest.jpeg
|
2007-11-23 17:35:21 +00:00
|
|
|
* </programlisting>
|
2008-01-23 16:35:34 +00:00
|
|
|
* <programlisting>
|
|
|
|
* gst-launch -v -m filesrc location=orig.png ! metadatademux ! pngdec !
|
|
|
|
* ffmpegcolorspace ! jpegenc ! metadatamux ! filesink location=dest.jpeg
|
|
|
|
* </programlisting>
|
|
|
|
* </para>
|
|
|
|
* <title>How it works</title>
|
|
|
|
* <para>
|
|
|
|
* If this element receives a GST_TAG_EXIF, GST_TAG_IPTC or GST_TAG_XMP which
|
|
|
|
* are whole chunk metadata tags, then this whole chunk will be modified by
|
|
|
|
* individual tags received and written to the file. Otherwise, a new chunk
|
|
|
|
* will be created from the scratch and then modified in same way.
|
2007-11-23 17:35:21 +00:00
|
|
|
* </para>
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* includes
|
|
|
|
*/
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
|
|
|
#include "gstmetadatamux.h"
|
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
#include "metadataexif.h"
|
|
|
|
|
|
|
|
#include "metadataiptc.h"
|
|
|
|
|
|
|
|
#include "metadataxmp.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* enum and types
|
|
|
|
*/
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
};
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* defines and static global vars
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_metadata_mux_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_metadata_mux_debug
|
|
|
|
|
|
|
|
#define GOTO_DONE_IF_NULL(ptr) \
|
|
|
|
do { if ( NULL == (ptr) ) goto done; } while(FALSE)
|
|
|
|
|
|
|
|
#define GOTO_DONE_IF_NULL_AND_FAIL(ptr, ret) \
|
|
|
|
do { if ( NULL == (ptr) ) { (ret) = FALSE; goto done; } } while(FALSE)
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("image/jpeg, tags-extracted = (bool) true;"
|
|
|
|
"image/png, tags-extracted = (bool) true")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("image/jpeg; " "image/png")
|
|
|
|
);
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
static GstMetadataMuxClass *metadata_parent_class = NULL;
|
2007-12-03 16:14:01 +00:00
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* static helper functions declaration
|
|
|
|
*/
|
2007-12-03 16:14:01 +00:00
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
static gboolean gst_metadata_mux_configure_srccaps (GstMetadataMux * filter);
|
2007-12-03 16:14:01 +00:00
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* GObject callback functions declaration
|
|
|
|
*/
|
2007-11-23 17:35:21 +00:00
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
static void gst_metadata_mux_base_init (gpointer gclass);
|
|
|
|
|
|
|
|
static void gst_metadata_mux_class_init (GstMetadataMuxClass * klass);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_init (GstMetadataMux * filter, GstMetadataMuxClass * gclass);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
static void gst_metadata_mux_dispose (GObject * object);
|
|
|
|
|
|
|
|
static void gst_metadata_mux_finalize (GObject * object);
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static void gst_metadata_mux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2008-01-23 16:35:34 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static void gst_metadata_mux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* GstBaseMetadata virtual functions declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void gst_metadata_mux_create_chunks_from_tags (GstBaseMetadata * base);
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static gboolean gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps);
|
2008-01-23 16:35:34 +00:00
|
|
|
|
|
|
|
static GstCaps *gst_metadata_mux_get_caps (GstPad * pad);
|
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
static gboolean gst_metadata_mux_sink_event (GstPad * pad, GstEvent * event);
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
/*
|
|
|
|
* GST BOILERPLATE
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_add_interfaces (GType type)
|
|
|
|
{
|
|
|
|
static const GInterfaceInfo tag_setter_info = { NULL, NULL, NULL };
|
|
|
|
|
|
|
|
g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, &tag_setter_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GST_BOILERPLATE_FULL (GstMetadataMux, gst_metadata_mux, GstBaseMetadata,
|
|
|
|
GST_TYPE_BASE_METADATA, gst_metadata_mux_add_interfaces);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* static helper functions implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_metadata_mux_configure_srccaps (GstMetadataMux * filter)
|
|
|
|
{
|
|
|
|
GstCaps *caps = NULL;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
gchar *mime = NULL;
|
|
|
|
|
|
|
|
switch (GST_BASE_METADATA_IMG_TYPE (filter)) {
|
|
|
|
case IMG_JPEG:
|
|
|
|
mime = "image/jpeg";
|
|
|
|
break;
|
|
|
|
case IMG_PNG:
|
|
|
|
mime = "image/png";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
caps = gst_caps_new_simple (mime, NULL);
|
|
|
|
|
|
|
|
ret = gst_pad_set_caps (GST_BASE_METADATA_SRC_PAD (filter), caps);
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
if (caps) {
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
caps = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GObject callback functions declaration
|
|
|
|
*/
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static void
|
|
|
|
gst_metadata_mux_base_init (gpointer gclass)
|
|
|
|
{
|
2008-01-23 16:35:34 +00:00
|
|
|
/* *INDENT-OFF* */
|
2007-11-23 17:35:21 +00:00
|
|
|
static GstElementDetails element_details = {
|
2008-01-23 16:35:34 +00:00
|
|
|
"Metadata muxer",
|
|
|
|
"Muxer/Extracter/Metadata",
|
|
|
|
"Write metadata (EXIF, IPTC and XMP) into a image stream",
|
2007-11-28 08:13:52 +00:00
|
|
|
"Edgard Lima <edgard.lima@indt.org.br>"
|
2007-11-23 17:35:21 +00:00
|
|
|
};
|
2008-01-23 16:35:34 +00:00
|
|
|
/* *INDENT-ON* */
|
2007-11-23 17:35:21 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&src_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sink_factory));
|
|
|
|
gst_element_class_set_details (element_class, &element_details);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_class_init (GstMetadataMuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2007-12-19 09:50:47 +00:00
|
|
|
GstBaseMetadataClass *gstbasemetadata_class;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2007-12-19 09:50:47 +00:00
|
|
|
gstbasemetadata_class = (GstBaseMetadataClass *) klass;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
metadata_parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_metadata_mux_dispose);
|
|
|
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_metadata_mux_finalize);
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
gobject_class->set_property = gst_metadata_mux_set_property;
|
|
|
|
gobject_class->get_property = gst_metadata_mux_get_property;
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
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);
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_init (GstMetadataMux * filter, GstMetadataMuxClass * gclass)
|
|
|
|
{
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_base_metadata_set_option_flag (GST_BASE_METADATA (filter),
|
|
|
|
META_OPT_EXIF | META_OPT_IPTC | META_OPT_XMP | META_OPT_MUX);
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gst_metadata_mux_dispose (GObject * object)
|
2007-11-28 08:13:52 +00:00
|
|
|
{
|
2007-12-19 09:50:47 +00:00
|
|
|
G_OBJECT_CLASS (metadata_parent_class)->dispose (object);
|
|
|
|
}
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
static void
|
|
|
|
gst_metadata_mux_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (metadata_parent_class)->finalize (object);
|
2007-11-28 08:13:52 +00:00
|
|
|
}
|
|
|
|
|
2008-01-23 16:35:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GstBaseMetadata virtual functions implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gst_metadata_mux_create_chunks_from_tags:
|
|
|
|
* @base: the base metadata instance
|
|
|
|
*
|
|
|
|
* This function creates new metadata (EXIF, IPTC, XMP) chunks with the tags
|
|
|
|
* received and add it to the list of segments that will be injected to the
|
|
|
|
* resulting file by #GstBaseMetadata.
|
|
|
|
*
|
|
|
|
* Returns: nothing
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2007-12-14 18:18:37 +00:00
|
|
|
static void
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_metadata_mux_create_chunks_from_tags (GstBaseMetadata * base)
|
2007-12-14 18:18:37 +00:00
|
|
|
{
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
GstMetadataMux *filter = GST_METADATA_MUX (base);
|
2007-12-14 18:18:37 +00:00
|
|
|
GstTagSetter *setter = GST_TAG_SETTER (filter);
|
|
|
|
const GstTagList *taglist = gst_tag_setter_get_tag_list (setter);
|
|
|
|
guint8 *buf = NULL;
|
|
|
|
guint32 size = 0;
|
|
|
|
|
|
|
|
if (taglist) {
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (gst_base_metadata_get_option_flag (base) & META_OPT_EXIF) {
|
2007-12-14 18:18:37 +00:00
|
|
|
metadatamux_exif_create_chunk_from_tag_list (&buf, &size, taglist);
|
2008-01-23 16:35:34 +00:00
|
|
|
gst_base_metadata_update_inject_segment_with_new_data (base, &buf, &size,
|
2007-12-19 09:50:47 +00:00
|
|
|
MD_CHUNK_EXIF);
|
2007-12-14 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (gst_base_metadata_get_option_flag (base) & META_OPT_IPTC) {
|
2007-12-14 18:18:37 +00:00
|
|
|
metadatamux_iptc_create_chunk_from_tag_list (&buf, &size, taglist);
|
2008-01-23 16:35:34 +00:00
|
|
|
gst_base_metadata_update_inject_segment_with_new_data (base, &buf, &size,
|
2007-12-19 09:50:47 +00:00
|
|
|
MD_CHUNK_IPTC);
|
2007-12-14 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (gst_base_metadata_get_option_flag (base) & META_OPT_XMP) {
|
2007-12-14 18:18:37 +00:00
|
|
|
metadatamux_xmp_create_chunk_from_tag_list (&buf, &size, taglist);
|
2008-01-23 16:35:34 +00:00
|
|
|
gst_base_metadata_update_inject_segment_with_new_data (base, &buf, &size,
|
2007-12-19 09:50:47 +00:00
|
|
|
MD_CHUNK_XMP);
|
2007-12-14 18:18:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf) {
|
|
|
|
g_free (buf);
|
|
|
|
}
|
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
static gboolean
|
|
|
|
gst_metadata_mux_set_caps (GstPad * pad, GstCaps * caps)
|
|
|
|
{
|
2007-11-28 08:13:52 +00:00
|
|
|
GstMetadataMux *filter = NULL;
|
|
|
|
GstStructure *structure = NULL;
|
|
|
|
const gchar *mime = NULL;
|
|
|
|
gboolean ret = FALSE;
|
2007-12-19 09:50:47 +00:00
|
|
|
gboolean based = TRUE;
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
|
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
|
|
|
|
|
|
mime = gst_structure_get_name (structure);
|
|
|
|
|
|
|
|
if (strcmp (mime, "image/jpeg") == 0) {
|
2007-12-19 09:50:47 +00:00
|
|
|
GST_BASE_METADATA_IMG_TYPE (filter) = IMG_JPEG;
|
2007-11-28 08:13:52 +00:00
|
|
|
} else if (strcmp (mime, "image/png") == 0) {
|
2007-12-19 09:50:47 +00:00
|
|
|
GST_BASE_METADATA_IMG_TYPE (filter) = IMG_PNG;
|
2007-11-28 08:13:52 +00:00
|
|
|
} else {
|
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (gst_structure_get_boolean (structure, "tags-extracted", &based)) {
|
|
|
|
if (based == FALSE) {
|
2007-11-28 08:13:52 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = gst_metadata_mux_configure_srccaps (filter);
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
gst_object_unref (filter);
|
|
|
|
|
|
|
|
return ret;
|
2007-11-23 17:35:21 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
static GstCaps *
|
|
|
|
gst_metadata_mux_get_caps (GstPad * pad)
|
2007-11-28 08:13:52 +00:00
|
|
|
{
|
|
|
|
GstMetadataMux *filter = NULL;
|
2007-12-19 09:50:47 +00:00
|
|
|
GstPad *otherpad;
|
|
|
|
GstCaps *caps_new = NULL;
|
|
|
|
GstCaps *caps_otherpad_peer = NULL;
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
(GST_BASE_METADATA_SRC_PAD (filter) == pad) ?
|
|
|
|
(otherpad = GST_BASE_METADATA_SINK_PAD (filter)) :
|
|
|
|
(otherpad = GST_BASE_METADATA_SRC_PAD (filter));
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
caps_new = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
caps_otherpad_peer = gst_pad_get_allowed_caps (otherpad);
|
|
|
|
GOTO_DONE_IF_NULL (caps_otherpad_peer);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (gst_caps_is_empty (caps_otherpad_peer)
|
|
|
|
|| gst_caps_is_any (caps_otherpad_peer)) {
|
|
|
|
goto done;
|
2007-11-28 08:13:52 +00:00
|
|
|
} else {
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
guint i;
|
|
|
|
guint caps_size = 0;
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
caps_size = gst_caps_get_size (caps_otherpad_peer);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_caps_unref (caps_new);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
caps_new = gst_caps_new_empty ();
|
2007-11-30 12:53:13 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
for (i = 0; i < caps_size; ++i) {
|
|
|
|
GstStructure *structure = NULL;
|
|
|
|
GstStructure *structure_new = NULL;
|
|
|
|
const gchar *mime = NULL;
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
structure = gst_caps_get_structure (caps_otherpad_peer, i);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
mime = gst_structure_get_name (structure);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (pad == GST_BASE_METADATA_SINK_PAD (filter)) {
|
|
|
|
structure_new =
|
|
|
|
gst_structure_new (mime, "tags-extracted", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
NULL);
|
2007-11-28 08:13:52 +00:00
|
|
|
} else {
|
2007-12-19 09:50:47 +00:00
|
|
|
structure_new = gst_structure_new (mime, NULL);
|
2007-11-28 08:13:52 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_caps_append_structure (caps_new, structure_new);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
if (caps_otherpad_peer) {
|
|
|
|
gst_caps_unref (caps_otherpad_peer);
|
|
|
|
caps_otherpad_peer = NULL;
|
2007-11-28 08:13:52 +00:00
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_object_unref (filter);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
return caps_new;
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_metadata_mux_sink_event (GstPad * pad, GstEvent * event)
|
2007-11-28 08:13:52 +00:00
|
|
|
{
|
|
|
|
GstMetadataMux *filter = NULL;
|
2007-12-19 09:50:47 +00:00
|
|
|
gboolean ret = FALSE;
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
filter = GST_METADATA_MUX (gst_pad_get_parent (pad));
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
{
|
|
|
|
GstTagList *taglist = NULL;
|
|
|
|
GstTagSetter *setter = GST_TAG_SETTER (filter);
|
2008-02-02 20:22:19 +00:00
|
|
|
const GstTagMergeMode mode = gst_tag_setter_get_tag_merge_mode (setter);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_event_parse_tag (event, &taglist);
|
2008-02-02 20:22:19 +00:00
|
|
|
gst_tag_setter_merge_tags (setter, taglist, mode);
|
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
}
|
2007-11-28 08:13:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
ret = gst_pad_event_default (pad, event);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
2007-12-19 09:50:47 +00:00
|
|
|
gst_object_unref (filter);
|
2007-11-28 08:13:52 +00:00
|
|
|
|
|
|
|
return ret;
|
2007-12-19 09:50:47 +00:00
|
|
|
|
2007-11-28 08:13:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* element plugin init function
|
|
|
|
*/
|
|
|
|
|
2007-11-23 17:35:21 +00:00
|
|
|
gboolean
|
|
|
|
gst_metadata_mux_plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
2007-11-28 08:13:52 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_metadata_mux_debug, "metadatamux", 0,
|
2007-12-19 09:50:47 +00:00
|
|
|
"Metadata muxer");
|
2007-11-23 17:35:21 +00:00
|
|
|
|
|
|
|
return gst_element_register (plugin, "metadatamux",
|
|
|
|
GST_RANK_NONE, GST_TYPE_METADATA_MUX);
|
|
|
|
}
|