2009-03-11 18:32:16 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* 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
|
2012-11-03 20:38:00 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2009-03-11 18:32:16 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-22 17:24:43 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-mxfmux
|
|
|
|
*
|
|
|
|
* mxfmux muxes different streams into an MXF file.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example launch line</title>
|
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 -v filesrc location=/path/to/audio ! decodebin ! queue ! mxfmux name=m ! filesink location=file.mxf filesrc location=/path/to/video ! decodebin ! queue ! m.
|
2009-04-22 17:24:43 +00:00
|
|
|
* ]| This pipeline muxes an audio and video file into a single MXF file.
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mxfmux.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (mxfmux_debug);
|
|
|
|
#define GST_CAT_DEFAULT mxfmux_debug
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
#define GST_TYPE_MXF_MUX_PAD (gst_mxf_mux_pad_get_type())
|
|
|
|
#define GST_MXF_MUX_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MXF_MUX_PAD, GstMXFMuxPad))
|
|
|
|
#define GST_MXF_MUX_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MXF_MUX_PAD, GstMXFMuxPadClass))
|
|
|
|
#define GST_MXF_MUX_PAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),GST_TYPE_MXF_MUX_PAD, GstMXFMuxPadClass))
|
|
|
|
#define GST_IS_MXF_MUX_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MXF_MUX_PAD))
|
|
|
|
#define GST_IS_MXF_MUX_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MXF_MUX_PAD))
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstAggregatorPad parent;
|
|
|
|
|
|
|
|
guint64 pos;
|
|
|
|
GstClockTime last_timestamp;
|
|
|
|
|
|
|
|
MXFMetadataFileDescriptor *descriptor;
|
|
|
|
|
|
|
|
GstAdapter *adapter;
|
|
|
|
gboolean have_complete_edit_unit;
|
|
|
|
|
|
|
|
gpointer mapping_data;
|
|
|
|
const MXFEssenceElementWriter *writer;
|
|
|
|
MXFEssenceElementWriteFunc write_func;
|
|
|
|
|
|
|
|
MXFMetadataSourcePackage *source_package;
|
|
|
|
MXFMetadataTimelineTrack *source_track;
|
|
|
|
} GstMXFMuxPad;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstAggregatorPadClass parent_class;
|
|
|
|
} GstMXFMuxPadClass;
|
|
|
|
|
|
|
|
GType gst_mxf_mux_pad_get_type (void);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstMXFMuxPad, gst_mxf_mux_pad, GST_TYPE_AGGREGATOR_PAD);
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_pad_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstMXFMuxPad *pad = GST_MXF_MUX_PAD (object);
|
|
|
|
|
|
|
|
g_object_unref (pad->adapter);
|
|
|
|
g_free (pad->mapping_data);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_mxf_mux_pad_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_pad_class_init (GstMXFMuxPadClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = (GObjectClass *) klass;
|
|
|
|
|
|
|
|
object_class->finalize = gst_mxf_mux_pad_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_pad_init (GstMXFMuxPad * pad)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("application/mxf")
|
|
|
|
);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0
|
|
|
|
};
|
|
|
|
|
2012-10-26 20:48:06 +00:00
|
|
|
#define gst_mxf_mux_parent_class parent_class
|
2015-10-23 15:38:33 +00:00
|
|
|
G_DEFINE_TYPE (GstMXFMux, gst_mxf_mux, GST_TYPE_AGGREGATOR);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
static void gst_mxf_mux_finalize (GObject * object);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
static GstFlowReturn gst_mxf_mux_aggregate (GstAggregator * aggregator,
|
|
|
|
gboolean timeout);
|
|
|
|
static gboolean gst_mxf_mux_stop (GstAggregator * aggregator);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
static gboolean gst_mxf_mux_src_event (GstAggregator * aggregator,
|
2012-10-26 20:48:06 +00:00
|
|
|
GstEvent * event);
|
2015-10-23 15:38:33 +00:00
|
|
|
static gboolean gst_mxf_mux_sink_event (GstAggregator * aggregator,
|
|
|
|
GstAggregatorPad * aggpad, GstEvent * event);
|
|
|
|
static GstAggregatorPad *gst_mxf_mux_create_new_pad (GstAggregator * aggregator,
|
2012-10-26 20:48:06 +00:00
|
|
|
GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
static void gst_mxf_mux_reset (GstMXFMux * mux);
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mxf_mux_push (GstMXFMux * mux, GstBuffer * buf)
|
|
|
|
{
|
2012-10-26 20:48:06 +00:00
|
|
|
guint size = gst_buffer_get_size (buf);
|
2009-03-11 18:32:16 +00:00
|
|
|
GstFlowReturn ret;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
ret = gst_aggregator_finish_buffer (GST_AGGREGATOR (mux), buf);
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->offset += size;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_class_init (GstMXFMuxClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
2015-10-23 15:38:33 +00:00
|
|
|
GstAggregatorClass *gstaggregator_class;
|
2012-10-26 20:48:06 +00:00
|
|
|
const GstPadTemplate **p;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY_INIT (mxfmux_debug, "mxfmux", 0, "MXF muxer");
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2015-10-23 15:38:33 +00:00
|
|
|
gstaggregator_class = (GstAggregatorClass *) klass;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
gobject_class->finalize = gst_mxf_mux_finalize;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
gstaggregator_class->create_new_pad =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mxf_mux_create_new_pad);
|
|
|
|
gstaggregator_class->src_event = GST_DEBUG_FUNCPTR (gst_mxf_mux_src_event);
|
|
|
|
gstaggregator_class->sink_event = GST_DEBUG_FUNCPTR (gst_mxf_mux_sink_event);
|
|
|
|
gstaggregator_class->stop = GST_DEBUG_FUNCPTR (gst_mxf_mux_stop);
|
|
|
|
gstaggregator_class->aggregate = GST_DEBUG_FUNCPTR (gst_mxf_mux_aggregate);
|
|
|
|
gstaggregator_class->sinkpads_type = GST_TYPE_MXF_MUX_PAD;
|
2012-10-26 20:48:06 +00:00
|
|
|
|
2016-03-04 06:50:26 +00:00
|
|
|
gst_element_class_add_static_pad_template (gstelement_class, &src_templ);
|
2012-10-26 20:48:06 +00:00
|
|
|
|
|
|
|
p = mxf_essence_element_writer_get_pad_templates ();
|
|
|
|
while (p && *p) {
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
(GstPadTemplate *) gst_object_ref (GST_OBJECT (*p)));
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_class_set_static_metadata (gstelement_class, "MXF muxer",
|
|
|
|
"Codec/Muxer",
|
|
|
|
"Muxes video/audio streams into a MXF stream",
|
|
|
|
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_mxf_mux_init (GstMXFMux * mux)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-12-07 18:27:23 +00:00
|
|
|
mux->index_table = g_array_new (FALSE, FALSE, sizeof (MXFIndexTableSegment));
|
2009-03-11 18:32:16 +00:00
|
|
|
gst_mxf_mux_reset (mux);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstMXFMux *mux = GST_MXF_MUX (object);
|
|
|
|
|
|
|
|
gst_mxf_mux_reset (mux);
|
|
|
|
|
|
|
|
if (mux->metadata) {
|
|
|
|
g_hash_table_destroy (mux->metadata);
|
|
|
|
mux->metadata = NULL;
|
2009-05-09 13:48:54 +00:00
|
|
|
g_list_free (mux->metadata_list);
|
|
|
|
mux->metadata_list = NULL;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 18:27:23 +00:00
|
|
|
if (mux->index_table) {
|
|
|
|
g_array_free (mux->index_table, TRUE);
|
|
|
|
mux->index_table = NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mxf_mux_reset (GstMXFMux * mux)
|
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GList *l;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
2016-03-18 11:35:37 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
|
|
|
|
|
|
|
gst_adapter_clear (pad->adapter);
|
|
|
|
g_free (pad->mapping_data);
|
|
|
|
pad->mapping_data = NULL;
|
|
|
|
|
|
|
|
pad->pos = 0;
|
|
|
|
pad->last_timestamp = 0;
|
|
|
|
pad->descriptor = NULL;
|
|
|
|
pad->have_complete_edit_unit = FALSE;
|
|
|
|
|
|
|
|
pad->source_package = NULL;
|
|
|
|
pad->source_track = NULL;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
mux->state = GST_MXF_MUX_STATE_HEADER;
|
|
|
|
|
|
|
|
if (mux->metadata) {
|
|
|
|
g_hash_table_destroy (mux->metadata);
|
|
|
|
mux->preface = NULL;
|
2009-05-09 13:48:54 +00:00
|
|
|
g_list_free (mux->metadata_list);
|
|
|
|
mux->metadata_list = NULL;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
mux->metadata = mxf_metadata_hash_table_new ();
|
|
|
|
|
|
|
|
mxf_partition_pack_reset (&mux->partition);
|
|
|
|
mxf_primer_pack_reset (&mux->primer);
|
|
|
|
memset (&mux->min_edit_rate, 0, sizeof (MXFFraction));
|
|
|
|
mux->last_gc_timestamp = 0;
|
|
|
|
mux->last_gc_position = 0;
|
|
|
|
mux->offset = 0;
|
2015-12-07 18:27:23 +00:00
|
|
|
|
|
|
|
g_array_set_size (mux->index_table, 0);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_mxf_mux_src_event (GstAggregator * aggregator, GstEvent * event)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2009-03-11 18:32:16 +00:00
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
/* disable seeking for now */
|
2015-10-21 14:47:00 +00:00
|
|
|
gst_event_unref (event);
|
2009-03-11 18:32:16 +00:00
|
|
|
return FALSE;
|
|
|
|
default:
|
2015-10-23 15:38:33 +00:00
|
|
|
return GST_AGGREGATOR_CLASS (parent_class)->src_event (aggregator, event);
|
2009-03-11 18:32:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
g_assert_not_reached ();
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_mxf_mux_set_caps (GstMXFMux * mux, GstMXFMuxPad * pad, GstCaps * caps)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
|
|
|
gboolean ret = TRUE;
|
2009-03-26 12:11:07 +00:00
|
|
|
MXFUUID d_instance_uid = { {0,} };
|
2015-10-23 15:38:33 +00:00
|
|
|
MXFMetadataFileDescriptor *old_descriptor = pad->descriptor;
|
2009-05-09 13:48:54 +00:00
|
|
|
GList *l;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-15 14:27:03 +00:00
|
|
|
GST_DEBUG_OBJECT (pad, "Setting caps %" GST_PTR_FORMAT, caps);
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
if (old_descriptor) {
|
|
|
|
memcpy (&d_instance_uid, &MXF_METADATA_BASE (old_descriptor)->instance_uid,
|
|
|
|
16);
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->descriptor = NULL;
|
|
|
|
g_free (pad->mapping_data);
|
|
|
|
pad->mapping_data = NULL;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->descriptor =
|
|
|
|
pad->writer->get_descriptor (GST_PAD_PAD_TEMPLATE (pad), caps,
|
|
|
|
&pad->write_func, &pad->mapping_data);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (!pad->descriptor) {
|
2009-03-11 18:32:16 +00:00
|
|
|
GST_ERROR_OBJECT (mux,
|
|
|
|
"Couldn't get descriptor for pad '%s' with caps %" GST_PTR_FORMAT,
|
|
|
|
GST_PAD_NAME (pad), caps);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
if (mxf_uuid_is_zero (&d_instance_uid))
|
|
|
|
mxf_uuid_init (&d_instance_uid, mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
memcpy (&MXF_METADATA_BASE (pad->descriptor)->instance_uid, &d_instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
16);
|
|
|
|
|
2009-05-09 13:48:54 +00:00
|
|
|
if (old_descriptor) {
|
|
|
|
for (l = mux->metadata_list; l; l = l->next) {
|
|
|
|
MXFMetadataBase *tmp = l->data;
|
|
|
|
|
|
|
|
if (mxf_uuid_is_equal (&d_instance_uid, &tmp->instance_uid)) {
|
2015-10-23 15:38:33 +00:00
|
|
|
l->data = pad->descriptor;
|
2009-05-09 13:48:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-23 15:38:33 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, pad->descriptor);
|
2009-05-09 13:48:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_replace (mux->metadata,
|
2015-10-23 15:38:33 +00:00
|
|
|
&MXF_METADATA_BASE (pad->descriptor)->instance_uid, pad->descriptor);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
if (old_descriptor) {
|
|
|
|
if (mux->preface && mux->preface->content_storage &&
|
|
|
|
mux->preface->content_storage->packages) {
|
|
|
|
guint i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < mux->preface->content_storage->n_packages; i++) {
|
|
|
|
MXFMetadataSourcePackage *package;
|
|
|
|
|
2014-04-21 09:07:06 +00:00
|
|
|
if (!MXF_IS_METADATA_SOURCE_PACKAGE (mux->preface->
|
|
|
|
content_storage->packages[i]))
|
2009-03-11 18:32:16 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
package =
|
2014-04-21 09:07:06 +00:00
|
|
|
MXF_METADATA_SOURCE_PACKAGE (mux->preface->
|
|
|
|
content_storage->packages[i]);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
if (!package->descriptor)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (MXF_IS_METADATA_MULTIPLE_DESCRIPTOR (package->descriptor)) {
|
|
|
|
MXFMetadataMultipleDescriptor *tmp =
|
|
|
|
MXF_METADATA_MULTIPLE_DESCRIPTOR (package->descriptor);
|
|
|
|
|
|
|
|
for (j = 0; j < tmp->n_sub_descriptors; j++) {
|
|
|
|
if (tmp->sub_descriptors[j] ==
|
|
|
|
MXF_METADATA_GENERIC_DESCRIPTOR (old_descriptor)) {
|
|
|
|
tmp->sub_descriptors[j] =
|
2015-10-23 15:38:33 +00:00
|
|
|
MXF_METADATA_GENERIC_DESCRIPTOR (pad->descriptor);
|
2009-03-11 18:32:16 +00:00
|
|
|
memcpy (&tmp->sub_descriptors_uids[j], &d_instance_uid, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (package->descriptor ==
|
|
|
|
MXF_METADATA_GENERIC_DESCRIPTOR (old_descriptor)) {
|
|
|
|
package->descriptor =
|
2015-10-23 15:38:33 +00:00
|
|
|
MXF_METADATA_GENERIC_DESCRIPTOR (pad->descriptor);
|
2009-03-11 18:32:16 +00:00
|
|
|
memcpy (&package->descriptor_uid, &d_instance_uid, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-26 20:48:06 +00:00
|
|
|
static gboolean
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_mxf_mux_sink_event (GstAggregator * aggregator,
|
|
|
|
GstAggregatorPad * aggpad, GstEvent * event)
|
2012-10-26 20:48:06 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GstMXFMux *mux = GST_MXF_MUX (aggregator);
|
2012-10-26 20:48:06 +00:00
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_TAG:
|
|
|
|
/* TODO: do something with the tags */
|
|
|
|
break;
|
2015-10-23 15:38:33 +00:00
|
|
|
case GST_EVENT_CAPS:{
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_event_parse_caps (event, &caps);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
ret = gst_mxf_mux_set_caps (mux, GST_MXF_MUX_PAD (aggpad), caps);
|
|
|
|
|
2012-10-26 20:48:06 +00:00
|
|
|
break;
|
2015-10-23 15:38:33 +00:00
|
|
|
}
|
2012-10-26 20:48:06 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
/* now GstAggregator can take care of the rest, e.g. EOS */
|
2012-10-26 20:48:06 +00:00
|
|
|
if (ret)
|
2015-10-23 15:38:33 +00:00
|
|
|
ret =
|
|
|
|
GST_AGGREGATOR_CLASS (parent_class)->sink_event (aggregator, aggpad,
|
|
|
|
event);
|
2012-10-26 20:48:06 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-22 15:21:31 +00:00
|
|
|
static char *
|
|
|
|
gst_mxf_mux_create_pad_name (GstPadTemplate * templ, guint id)
|
|
|
|
{
|
|
|
|
GString *string;
|
|
|
|
|
|
|
|
string = g_string_new (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
|
|
|
|
g_string_truncate (string, string->len - 2);
|
|
|
|
g_string_append_printf (string, "%u", id);
|
|
|
|
|
|
|
|
return g_string_free (string, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
static GstAggregatorPad *
|
|
|
|
gst_mxf_mux_create_new_pad (GstAggregator * aggregator,
|
2012-10-26 20:48:06 +00:00
|
|
|
GstPadTemplate * templ, const gchar * pad_name, const GstCaps * caps)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GstMXFMux *mux = GST_MXF_MUX (aggregator);
|
|
|
|
GstMXFMuxPad *pad;
|
2009-03-11 18:32:16 +00:00
|
|
|
guint pad_number;
|
|
|
|
gchar *name = NULL;
|
|
|
|
const MXFEssenceElementWriter *writer;
|
|
|
|
|
|
|
|
if (mux->state != GST_MXF_MUX_STATE_HEADER) {
|
|
|
|
GST_WARNING_OBJECT (mux, "Can't request pads after writing header");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
writer = mxf_essence_element_writer_find (templ);
|
|
|
|
if (!writer) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Not our template");
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-06-04 21:04:44 +00:00
|
|
|
pad_number = g_atomic_int_add ((gint *) & mux->n_pads, 1);
|
2010-03-22 15:21:31 +00:00
|
|
|
name = gst_mxf_mux_create_pad_name (templ, pad_number);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-15 14:27:03 +00:00
|
|
|
GST_DEBUG_OBJECT (mux, "Creating pad '%s'", name);
|
2015-10-23 15:38:33 +00:00
|
|
|
pad =
|
|
|
|
g_object_new (GST_TYPE_MXF_MUX_PAD, "name", name, "direction",
|
|
|
|
GST_PAD_SINK, "template", templ, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_free (name);
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->last_timestamp = 0;
|
|
|
|
pad->adapter = gst_adapter_new ();
|
|
|
|
pad->writer = writer;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_pad_use_fixed_caps (GST_PAD_CAST (pad));
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
return GST_AGGREGATOR_PAD (pad);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mxf_mux_create_metadata (GstMXFMux * mux)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
2015-10-23 15:38:33 +00:00
|
|
|
GList *l;
|
2009-03-11 18:32:16 +00:00
|
|
|
GArray *tmp;
|
|
|
|
|
2009-03-15 14:27:03 +00:00
|
|
|
GST_DEBUG_OBJECT (mux, "Creating MXF metadata");
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
|
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2012-10-26 20:48:06 +00:00
|
|
|
GstCaps *caps;
|
2015-10-23 15:38:33 +00:00
|
|
|
GstBuffer *buffer;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (!pad || !pad->descriptor) {
|
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2012-10-26 20:48:06 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2015-10-23 15:38:33 +00:00
|
|
|
}
|
2012-10-26 20:48:06 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
caps = gst_pad_get_current_caps (GST_PAD_CAST (pad));
|
|
|
|
if (!caps) {
|
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-15 14:27:03 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2015-10-23 15:38:33 +00:00
|
|
|
}
|
2009-03-15 14:27:03 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
|
|
|
if (pad->writer->update_descriptor)
|
|
|
|
pad->writer->update_descriptor (pad->descriptor,
|
|
|
|
caps, pad->mapping_data, buffer);
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_caps_unref (caps);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Preface */
|
|
|
|
mux->preface =
|
2011-02-26 12:39:01 +00:00
|
|
|
(MXFMetadataPreface *) g_object_new (MXF_TYPE_METADATA_PREFACE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (mux->preface)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (mux->preface)->instance_uid, mux->preface);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, mux->preface);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
mxf_timestamp_set_now (&mux->preface->last_modified_date);
|
|
|
|
mux->preface->version = 258;
|
|
|
|
mux->preface->object_model_version = 1;
|
|
|
|
|
|
|
|
mxf_op_set_generalized (&mux->preface->operational_pattern, MXF_OP_1a, TRUE,
|
|
|
|
TRUE, FALSE);
|
|
|
|
|
|
|
|
tmp = g_array_new (FALSE, FALSE, sizeof (MXFUL));
|
2015-10-23 15:38:33 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2009-03-16 11:15:46 +00:00
|
|
|
guint i;
|
|
|
|
gboolean found = FALSE;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (!pad || !pad->descriptor ||
|
|
|
|
mxf_ul_is_zero (&pad->descriptor->essence_container)) {
|
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2015-10-23 15:38:33 +00:00
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-16 11:15:46 +00:00
|
|
|
for (i = 0; i < tmp->len; i++) {
|
2015-10-23 15:38:33 +00:00
|
|
|
if (mxf_ul_is_equal (&pad->descriptor->essence_container,
|
2009-03-16 11:15:46 +00:00
|
|
|
&g_array_index (tmp, MXFUL, i))) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
continue;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
g_array_append_val (tmp, pad->descriptor->essence_container);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
mux->preface->n_essence_containers = tmp->len;
|
|
|
|
mux->preface->essence_containers = (MXFUL *) g_array_free (tmp, FALSE);
|
|
|
|
|
|
|
|
/* This will later be used as UID for the material package */
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&mux->preface->primary_package_uid, mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Identifications */
|
|
|
|
{
|
|
|
|
MXFMetadataIdentification *identification;
|
|
|
|
static const guint8 gst_uid[] = {
|
|
|
|
0xe5, 0xde, 0xcd, 0x04, 0x24, 0x90, 0x69, 0x18,
|
|
|
|
0x8a, 0xc9, 0xb5, 0xd7, 0x02, 0x58, 0x46, 0x78
|
|
|
|
};
|
|
|
|
guint major, minor, micro, nano;
|
|
|
|
|
|
|
|
mux->preface->n_identifications = 1;
|
|
|
|
mux->preface->identifications = g_new0 (MXFMetadataIdentification *, 1);
|
|
|
|
identification = mux->preface->identifications[0] =
|
|
|
|
(MXFMetadataIdentification *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_IDENTIFICATION, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (identification)->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (identification)->instance_uid, identification);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, identification);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&identification->this_generation_uid, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
identification->company_name = g_strdup ("GStreamer");
|
|
|
|
identification->product_name = g_strdup ("GStreamer Multimedia Framework");
|
|
|
|
|
|
|
|
gst_version (&major, &minor, µ, &nano);
|
|
|
|
identification->product_version.major = major;
|
|
|
|
identification->product_version.minor = minor;
|
|
|
|
identification->product_version.patch = micro;
|
|
|
|
identification->product_version.build = nano;
|
|
|
|
identification->product_version.release =
|
|
|
|
(nano == 0) ? 1 : (nano == 1) ? 2 : 4;
|
|
|
|
|
|
|
|
identification->version_string =
|
|
|
|
g_strdup_printf ("%u.%u.%u.%u", major, minor, micro, nano);
|
|
|
|
memcpy (&identification->product_uid, &gst_uid, 16);
|
|
|
|
|
|
|
|
memcpy (&identification->modification_date,
|
|
|
|
&mux->preface->last_modified_date, sizeof (MXFTimestamp));
|
|
|
|
memcpy (&identification->toolkit_version, &identification->product_version,
|
|
|
|
sizeof (MXFProductVersion));
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
{
|
|
|
|
struct utsname sys_details;
|
|
|
|
|
|
|
|
if (uname (&sys_details) == 0) {
|
|
|
|
identification->platform = g_strdup_printf ("%s %s %s",
|
|
|
|
sys_details.sysname, sys_details.release, sys_details.machine);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(G_OS_WIN32)
|
|
|
|
if (identification->platform == NULL)
|
|
|
|
identification->platform = g_strdup ("Microsoft Windows");
|
|
|
|
#elif defined(G_OS_BEOS)
|
|
|
|
if (identification->platform == NULL)
|
|
|
|
identification->platform = g_strdup ("BEOS");
|
|
|
|
#elif defined(G_OS_UNIX)
|
|
|
|
if (identification->platform == NULL)
|
|
|
|
identification->platform = g_strdup ("Unix");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Content storage */
|
|
|
|
{
|
|
|
|
MXFMetadataContentStorage *cstorage;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
cstorage = mux->preface->content_storage = (MXFMetadataContentStorage *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_CONTENT_STORAGE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (cstorage)->instance_uid, mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (cstorage)->instance_uid, cstorage);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, cstorage);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
cstorage->n_packages = 2;
|
2009-03-26 07:11:20 +00:00
|
|
|
cstorage->packages = g_new0 (MXFMetadataGenericPackage *, 2);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Source package */
|
|
|
|
{
|
|
|
|
MXFMetadataSourcePackage *p;
|
|
|
|
|
|
|
|
cstorage->packages[1] = (MXFMetadataGenericPackage *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SOURCE_PACKAGE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (cstorage->packages[1])->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (cstorage->packages[1])->instance_uid,
|
|
|
|
cstorage->packages[1]);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list =
|
|
|
|
g_list_prepend (mux->metadata_list, cstorage->packages[1]);
|
2009-03-11 18:32:16 +00:00
|
|
|
p = (MXFMetadataSourcePackage *) cstorage->packages[1];
|
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_umid_init (&p->parent.package_uid);
|
2009-03-11 18:32:16 +00:00
|
|
|
p->parent.name = g_strdup ("Source package");
|
|
|
|
memcpy (&p->parent.package_creation_date,
|
|
|
|
&mux->preface->last_modified_date, sizeof (MXFTimestamp));
|
|
|
|
memcpy (&p->parent.package_modified_date,
|
|
|
|
&mux->preface->last_modified_date, sizeof (MXFTimestamp));
|
|
|
|
|
2016-01-28 15:32:34 +00:00
|
|
|
p->parent.n_tracks = GST_ELEMENT_CAST (mux)->numsinkpads + 1;
|
2009-03-26 07:11:20 +00:00
|
|
|
p->parent.tracks = g_new0 (MXFMetadataTrack *, p->parent.n_tracks);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2016-01-28 15:32:34 +00:00
|
|
|
if (p->parent.n_tracks > 2) {
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataMultipleDescriptor *d;
|
|
|
|
|
|
|
|
p->descriptor = (MXFMetadataGenericDescriptor *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_MULTIPLE_DESCRIPTOR, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
d = (MXFMetadataMultipleDescriptor *) p->descriptor;
|
2016-01-28 15:32:34 +00:00
|
|
|
d->n_sub_descriptors = p->parent.n_tracks - 1;
|
2009-03-11 18:32:16 +00:00
|
|
|
d->sub_descriptors =
|
2016-01-28 15:32:34 +00:00
|
|
|
g_new0 (MXFMetadataGenericDescriptor *, p->parent.n_tracks - 1);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (d)->instance_uid, mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (d)->instance_uid, d);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, d);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tracks */
|
|
|
|
{
|
2016-01-28 15:32:34 +00:00
|
|
|
guint n;
|
|
|
|
|
|
|
|
n = 1;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Essence tracks */
|
2015-10-23 15:38:33 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataTimelineTrack *track;
|
|
|
|
MXFMetadataSequence *sequence;
|
|
|
|
MXFMetadataSourceClip *clip;
|
2012-10-26 20:48:06 +00:00
|
|
|
GstCaps *caps;
|
2015-10-23 15:38:33 +00:00
|
|
|
GstBuffer *buffer;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
p->parent.tracks[n] = (MXFMetadataTrack *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
track = (MXFMetadataTimelineTrack *) p->parent.tracks[n];
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (track)->instance_uid, track);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, track);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
caps = gst_pad_get_current_caps (GST_PAD_CAST (pad));
|
|
|
|
buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
2009-03-11 18:32:16 +00:00
|
|
|
track->parent.track_id = n + 1;
|
|
|
|
track->parent.track_number =
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->writer->get_track_number_template (pad->descriptor,
|
|
|
|
caps, pad->mapping_data);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-12-08 14:45:33 +00:00
|
|
|
/* FIXME: All tracks in a source package must have the same edit
|
|
|
|
* rate! This means that if we have different edit rates, we need to
|
|
|
|
* make them different source packages and essence containers with
|
|
|
|
* a different BodySID */
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->writer->get_edit_rate (pad->descriptor,
|
|
|
|
caps, pad->mapping_data, buffer, p, track, &track->edit_rate);
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_caps_unref (caps);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
sequence = track->parent.sequence = (MXFMetadataSequence *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (sequence)->instance_uid, sequence);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, sequence);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
memcpy (&sequence->data_definition, &pad->writer->data_definition,
|
2009-03-11 18:32:16 +00:00
|
|
|
16);
|
|
|
|
|
|
|
|
sequence->n_structural_components = 1;
|
|
|
|
sequence->structural_components =
|
2009-03-26 07:11:20 +00:00
|
|
|
g_new0 (MXFMetadataStructuralComponent *, 1);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
clip = (MXFMetadataSourceClip *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SOURCE_CLIP, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
sequence->structural_components[0] =
|
|
|
|
(MXFMetadataStructuralComponent *) clip;
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (clip)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (clip)->instance_uid, clip);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, clip);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
memcpy (&clip->parent.data_definition, &sequence->data_definition,
|
|
|
|
16);
|
|
|
|
clip->start_position = 0;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_package = p;
|
|
|
|
pad->source_track = track;
|
|
|
|
pad->descriptor->linked_track_id = n + 1;
|
2016-01-28 15:32:34 +00:00
|
|
|
if (p->parent.n_tracks == 2) {
|
2015-10-23 15:38:33 +00:00
|
|
|
p->descriptor = (MXFMetadataGenericDescriptor *) pad->descriptor;
|
2009-03-11 18:32:16 +00:00
|
|
|
} else {
|
2014-04-21 09:07:06 +00:00
|
|
|
MXF_METADATA_MULTIPLE_DESCRIPTOR (p->
|
2016-01-28 15:32:34 +00:00
|
|
|
descriptor)->sub_descriptors[n - 1] =
|
2015-10-23 15:38:33 +00:00
|
|
|
(MXFMetadataGenericDescriptor *) pad->descriptor;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Material package */
|
|
|
|
{
|
|
|
|
MXFMetadataMaterialPackage *p;
|
|
|
|
MXFFraction min_edit_rate = { 0, 0 };
|
|
|
|
gdouble min_edit_rate_d = G_MAXDOUBLE;
|
|
|
|
|
|
|
|
cstorage->packages[0] = (MXFMetadataGenericPackage *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_MATERIAL_PACKAGE, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
memcpy (&MXF_METADATA_BASE (cstorage->packages[0])->instance_uid,
|
|
|
|
&mux->preface->primary_package_uid, 16);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (cstorage->packages[0])->instance_uid,
|
|
|
|
cstorage->packages[0]);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list =
|
|
|
|
g_list_prepend (mux->metadata_list, cstorage->packages[0]);
|
2009-03-11 18:32:16 +00:00
|
|
|
p = (MXFMetadataMaterialPackage *) cstorage->packages[0];
|
|
|
|
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_umid_init (&p->package_uid);
|
2009-03-11 18:32:16 +00:00
|
|
|
p->name = g_strdup ("Material package");
|
|
|
|
memcpy (&p->package_creation_date, &mux->preface->last_modified_date,
|
|
|
|
sizeof (MXFTimestamp));
|
|
|
|
memcpy (&p->package_modified_date, &mux->preface->last_modified_date,
|
|
|
|
sizeof (MXFTimestamp));
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
p->n_tracks = GST_ELEMENT_CAST (mux)->numsinkpads + 1;
|
2009-03-26 07:11:20 +00:00
|
|
|
p->tracks = g_new0 (MXFMetadataTrack *, p->n_tracks);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Tracks */
|
|
|
|
{
|
|
|
|
guint n;
|
|
|
|
|
|
|
|
n = 1;
|
|
|
|
/* Essence tracks */
|
2015-10-23 15:38:33 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2012-10-26 20:48:06 +00:00
|
|
|
GstCaps *caps;
|
2015-10-23 15:38:33 +00:00
|
|
|
GstBuffer *buffer;
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataSourcePackage *source_package;
|
|
|
|
MXFMetadataTimelineTrack *track, *source_track;
|
|
|
|
MXFMetadataSequence *sequence;
|
|
|
|
MXFMetadataSourceClip *clip;
|
|
|
|
|
|
|
|
source_package = MXF_METADATA_SOURCE_PACKAGE (cstorage->packages[1]);
|
|
|
|
source_track =
|
2016-01-28 15:32:34 +00:00
|
|
|
MXF_METADATA_TIMELINE_TRACK (source_package->parent.tracks[n]);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
p->tracks[n] = (MXFMetadataTrack *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
track = (MXFMetadataTimelineTrack *) p->tracks[n];
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (track)->instance_uid, track);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, track);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
track->parent.track_id = n + 1;
|
|
|
|
track->parent.track_number = 0;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
caps = gst_pad_get_current_caps (GST_PAD_CAST (pad));
|
|
|
|
buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
|
|
|
pad->writer->get_edit_rate (pad->descriptor,
|
|
|
|
caps, pad->mapping_data,
|
|
|
|
buffer, source_package, source_track, &track->edit_rate);
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_caps_unref (caps);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
if (track->edit_rate.n != source_track->edit_rate.n ||
|
|
|
|
track->edit_rate.d != source_track->edit_rate.d) {
|
|
|
|
memcpy (&source_track->edit_rate, &track->edit_rate,
|
|
|
|
sizeof (MXFFraction));
|
|
|
|
}
|
|
|
|
|
2009-03-15 14:27:03 +00:00
|
|
|
if (track->edit_rate.d <= 0 || track->edit_rate.n <= 0) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Invalid edit rate");
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-15 14:27:03 +00:00
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
if (min_edit_rate_d >
|
|
|
|
((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d)) {
|
|
|
|
min_edit_rate_d =
|
|
|
|
((gdouble) track->edit_rate.n) / ((gdouble) track->edit_rate.d);
|
|
|
|
memcpy (&min_edit_rate, &track->edit_rate, sizeof (MXFFraction));
|
|
|
|
}
|
|
|
|
|
|
|
|
sequence = track->parent.sequence = (MXFMetadataSequence *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (sequence)->instance_uid, sequence);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, sequence);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
memcpy (&sequence->data_definition, &pad->writer->data_definition,
|
2009-03-11 18:32:16 +00:00
|
|
|
16);
|
|
|
|
sequence->n_structural_components = 1;
|
|
|
|
sequence->structural_components =
|
2009-03-26 07:11:20 +00:00
|
|
|
g_new0 (MXFMetadataStructuralComponent *, 1);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
clip = (MXFMetadataSourceClip *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SOURCE_CLIP, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
sequence->structural_components[0] =
|
|
|
|
(MXFMetadataStructuralComponent *) clip;
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (clip)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (clip)->instance_uid, clip);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, clip);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
memcpy (&clip->parent.data_definition, &sequence->data_definition,
|
|
|
|
16);
|
|
|
|
clip->start_position = 0;
|
|
|
|
|
|
|
|
memcpy (&clip->source_package_id, &cstorage->packages[1]->package_uid,
|
|
|
|
32);
|
2016-01-28 15:32:34 +00:00
|
|
|
clip->source_track_id = n + 1;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
|
|
|
/* Timecode track */
|
|
|
|
{
|
|
|
|
MXFMetadataTimelineTrack *track;
|
|
|
|
MXFMetadataSequence *sequence;
|
|
|
|
MXFMetadataTimecodeComponent *component;
|
|
|
|
|
|
|
|
p->tracks[n] = (MXFMetadataTrack *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
track = (MXFMetadataTimelineTrack *) p->tracks[n];
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid,
|
|
|
|
mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (track)->instance_uid, track);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, track);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
track->parent.track_id = n + 1;
|
|
|
|
track->parent.track_number = 0;
|
|
|
|
track->parent.track_name = g_strdup ("Timecode track");
|
|
|
|
/* FIXME: Is this correct? */
|
|
|
|
memcpy (&track->edit_rate, &min_edit_rate, sizeof (MXFFraction));
|
|
|
|
|
|
|
|
sequence = track->parent.sequence = (MXFMetadataSequence *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL);
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (sequence)->instance_uid, sequence);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, sequence);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
memcpy (&sequence->data_definition,
|
|
|
|
mxf_metadata_track_identifier_get
|
|
|
|
(MXF_METADATA_TRACK_TIMECODE_12M_INACTIVE), 16);
|
|
|
|
|
|
|
|
sequence->n_structural_components = 1;
|
|
|
|
sequence->structural_components =
|
2009-03-26 07:11:20 +00:00
|
|
|
g_new0 (MXFMetadataStructuralComponent *, 1);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
component = (MXFMetadataTimecodeComponent *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMECODE_COMPONENT, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
sequence->structural_components[0] =
|
|
|
|
(MXFMetadataStructuralComponent *) component;
|
2009-03-26 12:11:07 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (component)->instance_uid,
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (component)->instance_uid, component);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, component);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
memcpy (&component->parent.data_definition,
|
|
|
|
&sequence->data_definition, 16);
|
|
|
|
|
|
|
|
component->start_timecode = 0;
|
2014-04-21 09:07:06 +00:00
|
|
|
if (track->edit_rate.d == 0)
|
|
|
|
component->rounded_timecode_base = 1;
|
|
|
|
else
|
|
|
|
component->rounded_timecode_base =
|
|
|
|
(((gdouble) track->edit_rate.n) /
|
|
|
|
((gdouble) track->edit_rate.d) + 0.5);
|
2009-03-11 18:32:16 +00:00
|
|
|
/* TODO: drop frame */
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (&mux->min_edit_rate, &min_edit_rate, sizeof (MXFFraction));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-28 15:32:34 +00:00
|
|
|
/* Timecode track */
|
|
|
|
{
|
|
|
|
MXFMetadataSourcePackage *p;
|
|
|
|
MXFMetadataTimelineTrack *track;
|
|
|
|
MXFMetadataSequence *sequence;
|
|
|
|
MXFMetadataTimecodeComponent *component;
|
|
|
|
guint n = 0;
|
|
|
|
|
|
|
|
p = (MXFMetadataSourcePackage *) cstorage->packages[1];
|
|
|
|
|
|
|
|
p->parent.tracks[n] = (MXFMetadataTrack *)
|
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMELINE_TRACK, NULL);
|
|
|
|
track = (MXFMetadataTimelineTrack *) p->parent.tracks[n];
|
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (track)->instance_uid, mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (track)->instance_uid, track);
|
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, track);
|
|
|
|
|
|
|
|
track->parent.track_id = n + 1;
|
|
|
|
track->parent.track_number = 0;
|
|
|
|
track->parent.track_name = g_strdup ("Timecode track");
|
|
|
|
/* FIXME: Is this correct? */
|
|
|
|
memcpy (&track->edit_rate, &mux->min_edit_rate, sizeof (MXFFraction));
|
|
|
|
|
|
|
|
sequence = track->parent.sequence = (MXFMetadataSequence *)
|
|
|
|
g_object_new (MXF_TYPE_METADATA_SEQUENCE, NULL);
|
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (sequence)->instance_uid,
|
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (sequence)->instance_uid, sequence);
|
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, sequence);
|
|
|
|
|
|
|
|
memcpy (&sequence->data_definition,
|
|
|
|
mxf_metadata_track_identifier_get
|
|
|
|
(MXF_METADATA_TRACK_TIMECODE_12M_INACTIVE), 16);
|
|
|
|
|
|
|
|
sequence->n_structural_components = 1;
|
|
|
|
sequence->structural_components =
|
|
|
|
g_new0 (MXFMetadataStructuralComponent *, 1);
|
|
|
|
|
|
|
|
component = (MXFMetadataTimecodeComponent *)
|
|
|
|
g_object_new (MXF_TYPE_METADATA_TIMECODE_COMPONENT, NULL);
|
|
|
|
sequence->structural_components[0] =
|
|
|
|
(MXFMetadataStructuralComponent *) component;
|
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (component)->instance_uid,
|
|
|
|
mux->metadata);
|
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (component)->instance_uid, component);
|
|
|
|
mux->metadata_list = g_list_prepend (mux->metadata_list, component);
|
|
|
|
|
|
|
|
memcpy (&component->parent.data_definition,
|
|
|
|
&sequence->data_definition, 16);
|
|
|
|
|
|
|
|
component->start_timecode = 0;
|
|
|
|
if (track->edit_rate.d == 0)
|
|
|
|
component->rounded_timecode_base = 1;
|
|
|
|
else
|
|
|
|
component->rounded_timecode_base =
|
|
|
|
(((gdouble) track->edit_rate.n) /
|
|
|
|
((gdouble) track->edit_rate.d) + 0.5);
|
|
|
|
/* TODO: drop frame */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < cstorage->packages[1]->n_tracks; i++) {
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataTrack *track = cstorage->packages[1]->tracks[i];
|
|
|
|
guint j;
|
|
|
|
guint32 templ;
|
|
|
|
guint8 n_type, n;
|
|
|
|
|
|
|
|
if ((track->track_number & 0x00ff00ff) != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
templ = track->track_number;
|
|
|
|
n_type = 0;
|
|
|
|
|
2016-01-28 15:32:34 +00:00
|
|
|
for (j = 1; j < cstorage->packages[1]->n_tracks; j++) {
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataTrack *tmp = cstorage->packages[1]->tracks[j];
|
|
|
|
|
|
|
|
if (tmp->track_number == templ) {
|
|
|
|
n_type++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
n = 0;
|
2016-01-28 15:32:34 +00:00
|
|
|
for (j = 1; j < cstorage->packages[1]->n_tracks; j++) {
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataTrack *tmp = cstorage->packages[1]->tracks[j];
|
|
|
|
|
|
|
|
if (tmp->track_number == templ) {
|
|
|
|
n++;
|
|
|
|
tmp->track_number |= (n_type << 16) | (n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cstorage->n_essence_container_data = 1;
|
|
|
|
cstorage->essence_container_data =
|
2009-03-26 07:11:20 +00:00
|
|
|
g_new0 (MXFMetadataEssenceContainerData *, 1);
|
2009-03-11 18:32:16 +00:00
|
|
|
cstorage->essence_container_data[0] = (MXFMetadataEssenceContainerData *)
|
2011-02-26 12:39:01 +00:00
|
|
|
g_object_new (MXF_TYPE_METADATA_ESSENCE_CONTAINER_DATA, NULL);
|
2014-04-21 09:07:06 +00:00
|
|
|
mxf_uuid_init (&MXF_METADATA_BASE (cstorage->essence_container_data[0])->
|
|
|
|
instance_uid, mux->metadata);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_hash_table_insert (mux->metadata,
|
|
|
|
&MXF_METADATA_BASE (cstorage->essence_container_data[0])->instance_uid,
|
|
|
|
cstorage->essence_container_data[0]);
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list =
|
|
|
|
g_list_prepend (mux->metadata_list,
|
|
|
|
cstorage->essence_container_data[0]);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
cstorage->essence_container_data[0]->linked_package =
|
|
|
|
MXF_METADATA_SOURCE_PACKAGE (cstorage->packages[1]);
|
2016-01-29 16:02:01 +00:00
|
|
|
cstorage->essence_container_data[0]->index_sid = 2;
|
2009-03-11 18:32:16 +00:00
|
|
|
cstorage->essence_container_data[0]->body_sid = 1;
|
|
|
|
}
|
|
|
|
|
2009-05-09 13:48:54 +00:00
|
|
|
/* Sort descriptors at the correct places */
|
|
|
|
{
|
|
|
|
GList *l;
|
2009-05-10 08:40:36 +00:00
|
|
|
GList *descriptors = NULL;
|
2009-05-09 13:48:54 +00:00
|
|
|
|
|
|
|
for (l = mux->metadata_list; l; l = l->next) {
|
|
|
|
MXFMetadataBase *m = l->data;
|
|
|
|
|
|
|
|
if (MXF_IS_METADATA_GENERIC_DESCRIPTOR (m)
|
|
|
|
&& !MXF_IS_METADATA_MULTIPLE_DESCRIPTOR (m)) {
|
|
|
|
descriptors = l;
|
|
|
|
l->prev->next = NULL;
|
|
|
|
l->prev = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-10 08:40:36 +00:00
|
|
|
g_assert (descriptors != NULL);
|
|
|
|
|
2009-05-09 13:48:54 +00:00
|
|
|
for (l = mux->metadata_list; l; l = l->next) {
|
|
|
|
MXFMetadataBase *m = l->data;
|
|
|
|
GList *s;
|
|
|
|
|
|
|
|
if (MXF_IS_METADATA_MULTIPLE_DESCRIPTOR (m) ||
|
|
|
|
MXF_IS_METADATA_SOURCE_PACKAGE (m)) {
|
|
|
|
s = l->prev;
|
|
|
|
l->prev = g_list_last (descriptors);
|
|
|
|
s->next = descriptors;
|
|
|
|
descriptors->prev = s;
|
|
|
|
l->prev->next = l;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
|
|
|
|
2009-05-09 13:48:54 +00:00
|
|
|
mux->metadata_list = g_list_reverse (mux->metadata_list);
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2009-04-13 11:32:34 +00:00
|
|
|
gst_mxf_mux_init_partition_pack (GstMXFMux * mux)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GList *l;
|
2009-03-11 18:32:16 +00:00
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
mxf_partition_pack_reset (&mux->partition);
|
|
|
|
mux->partition.type = MXF_PARTITION_PACK_HEADER;
|
|
|
|
mux->partition.closed = mux->partition.complete = FALSE;
|
|
|
|
mux->partition.major_version = 0x0001;
|
|
|
|
mux->partition.minor_version = 0x0002;
|
2015-10-21 16:00:41 +00:00
|
|
|
mux->partition.kag_size = 1;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->partition.this_partition = 0;
|
|
|
|
mux->partition.prev_partition = 0;
|
|
|
|
mux->partition.footer_partition = 0;
|
|
|
|
mux->partition.header_byte_count = 0;
|
|
|
|
mux->partition.index_byte_count = 0;
|
|
|
|
mux->partition.index_sid = 0;
|
|
|
|
mux->partition.body_offset = 0;
|
|
|
|
mux->partition.body_sid = 0;
|
|
|
|
|
|
|
|
memcpy (&mux->partition.operational_pattern,
|
|
|
|
&mux->preface->operational_pattern, 16);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
mux->partition.n_essence_containers = GST_ELEMENT_CAST (mux)->numsinkpads;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->partition.essence_containers =
|
|
|
|
g_new0 (MXFUL, mux->partition.n_essence_containers);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2009-03-11 18:32:16 +00:00
|
|
|
guint j;
|
2009-03-16 11:15:46 +00:00
|
|
|
gboolean found = FALSE;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-16 11:15:46 +00:00
|
|
|
for (j = 0; j <= i; j++) {
|
2015-10-23 15:38:33 +00:00
|
|
|
if (mxf_ul_is_equal (&pad->descriptor->essence_container,
|
2009-03-16 11:15:46 +00:00
|
|
|
&mux->partition.essence_containers[j])) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 11:15:46 +00:00
|
|
|
if (found)
|
|
|
|
continue;
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
memcpy (&mux->partition.essence_containers[i],
|
2015-10-23 15:38:33 +00:00
|
|
|
&pad->descriptor->essence_container, 16);
|
2009-03-11 18:32:16 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
mux->partition.n_essence_containers = i;
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mxf_mux_write_header_metadata (GstMXFMux * mux)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GList *buffers = NULL;
|
|
|
|
GList *l;
|
2009-05-09 13:48:54 +00:00
|
|
|
MXFMetadataBase *m;
|
2009-03-11 18:32:16 +00:00
|
|
|
guint64 header_byte_count = 0;
|
|
|
|
|
2009-05-09 13:48:54 +00:00
|
|
|
for (l = mux->metadata_list; l; l = l->next) {
|
2009-03-11 18:32:16 +00:00
|
|
|
m = l->data;
|
|
|
|
buf = mxf_metadata_base_to_buffer (m, &mux->primer);
|
2012-10-26 20:48:06 +00:00
|
|
|
header_byte_count += gst_buffer_get_size (buf);
|
2009-03-11 18:32:16 +00:00
|
|
|
buffers = g_list_prepend (buffers, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
buffers = g_list_reverse (buffers);
|
|
|
|
buf = mxf_primer_pack_to_buffer (&mux->primer);
|
2012-10-26 20:48:06 +00:00
|
|
|
header_byte_count += gst_buffer_get_size (buf);
|
2009-03-11 18:32:16 +00:00
|
|
|
buffers = g_list_prepend (buffers, buf);
|
|
|
|
|
|
|
|
mux->partition.header_byte_count = header_byte_count;
|
|
|
|
buf = mxf_partition_pack_to_buffer (&mux->partition);
|
|
|
|
if ((ret = gst_mxf_mux_push (mux, buf)) != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Failed pushing partition: %s",
|
|
|
|
gst_flow_get_name (ret));
|
|
|
|
g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (buffers);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = buffers; l; l = l->next) {
|
|
|
|
buf = l->data;
|
|
|
|
l->data = NULL;
|
|
|
|
if ((ret = gst_mxf_mux_push (mux, buf)) != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Failed pushing buffer: %s",
|
|
|
|
gst_flow_get_name (ret));
|
2009-05-09 13:48:01 +00:00
|
|
|
g_list_foreach (l, (GFunc) gst_mini_object_unref, NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
g_list_free (buffers);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (buffers);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const guint8 _gc_essence_element_ul[] = {
|
2015-10-22 16:20:24 +00:00
|
|
|
0x06, 0x0e, 0x2b, 0x34, 0x01, 0x02, 0x01, 0x01,
|
2009-03-11 18:32:16 +00:00
|
|
|
0x0d, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_mxf_mux_handle_buffer (GstMXFMux * mux, GstMXFMuxPad * pad)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GstBuffer *buf = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
2009-03-11 18:32:16 +00:00
|
|
|
GstBuffer *outbuf = NULL;
|
2012-10-26 20:48:06 +00:00
|
|
|
GstMapInfo map;
|
2015-12-04 16:05:58 +00:00
|
|
|
gsize buf_size;
|
2009-03-11 18:32:16 +00:00
|
|
|
GstFlowReturn ret = GST_FLOW_OK;
|
|
|
|
guint8 slen, ber[9];
|
2015-10-23 15:38:33 +00:00
|
|
|
gboolean flush = gst_aggregator_pad_is_eos (GST_AGGREGATOR_PAD (pad))
|
|
|
|
&& !pad->have_complete_edit_unit && buf == NULL;
|
2015-12-08 16:23:02 +00:00
|
|
|
gboolean is_keyframe = buf ?
|
|
|
|
!GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT) : TRUE;
|
2009-03-26 07:11:20 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (pad->have_complete_edit_unit) {
|
|
|
|
GST_DEBUG_OBJECT (pad,
|
2009-03-26 07:11:20 +00:00
|
|
|
"Handling remaining buffer for track %u at position %" G_GINT64_FORMAT,
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id, pad->pos);
|
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
2009-03-26 07:11:20 +00:00
|
|
|
buf = NULL;
|
|
|
|
} else if (!flush) {
|
2015-10-23 15:38:33 +00:00
|
|
|
if (buf)
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
buf = gst_aggregator_pad_steal_buffer (GST_AGGREGATOR_PAD (pad));
|
2009-03-26 07:11:20 +00:00
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
if (buf) {
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
2012-12-18 15:50:37 +00:00
|
|
|
"Handling buffer of size %" G_GSIZE_FORMAT " for track %u at position %"
|
|
|
|
G_GINT64_FORMAT, gst_buffer_get_size (buf),
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id, pad->pos);
|
2009-03-26 07:11:20 +00:00
|
|
|
} else {
|
|
|
|
flush = TRUE;
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
2009-03-26 07:11:20 +00:00
|
|
|
"Flushing for track %u at position %" G_GINT64_FORMAT,
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id, pad->pos);
|
2009-03-26 07:11:20 +00:00
|
|
|
}
|
2009-03-15 14:27:03 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
ret = pad->write_func (buf, pad->mapping_data, pad->adapter, &outbuf, flush);
|
2009-03-26 07:11:20 +00:00
|
|
|
if (ret != GST_FLOW_OK && ret != GST_FLOW_CUSTOM_SUCCESS) {
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_ERROR_OBJECT (pad,
|
2009-03-26 07:11:20 +00:00
|
|
|
"Failed handling buffer for track %u, reason %s",
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id, gst_flow_get_name (ret));
|
2009-03-11 18:32:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
if (ret == GST_FLOW_CUSTOM_SUCCESS) {
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->have_complete_edit_unit = TRUE;
|
2009-03-26 07:11:20 +00:00
|
|
|
ret = GST_FLOW_OK;
|
|
|
|
} else {
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->have_complete_edit_unit = FALSE;
|
2009-03-26 07:11:20 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
buf = outbuf;
|
|
|
|
if (buf == NULL)
|
|
|
|
return ret;
|
|
|
|
|
2015-12-07 18:27:23 +00:00
|
|
|
/* We currently only index the first essence stream */
|
|
|
|
if (pad == (GstMXFMuxPad *) GST_ELEMENT_CAST (mux)->sinkpads->data) {
|
|
|
|
MXFIndexTableSegment *segment;
|
|
|
|
const gint max_segment_size = G_MAXUINT16 / 11;
|
|
|
|
|
|
|
|
if (mux->index_table->len == 0 ||
|
|
|
|
g_array_index (mux->index_table, MXFIndexTableSegment,
|
|
|
|
mux->index_table->len - 1).index_duration >= max_segment_size) {
|
|
|
|
MXFIndexTableSegment s;
|
|
|
|
|
|
|
|
memset (&segment, 0, sizeof (segment));
|
|
|
|
|
|
|
|
mxf_uuid_init (&s.instance_id, mux->metadata);
|
|
|
|
memcpy (&s.index_edit_rate, &pad->source_track->edit_rate,
|
|
|
|
sizeof (s.index_edit_rate));
|
|
|
|
s.index_start_position = pad->pos;
|
|
|
|
s.index_duration = 0;
|
|
|
|
s.edit_unit_byte_count = 0;
|
|
|
|
s.index_sid =
|
|
|
|
mux->preface->content_storage->essence_container_data[0]->index_sid;
|
|
|
|
s.body_sid =
|
|
|
|
mux->preface->content_storage->essence_container_data[0]->body_sid;
|
|
|
|
s.slice_count = 0;
|
|
|
|
s.pos_table_count = 0;
|
|
|
|
s.n_delta_entries = 0;
|
|
|
|
s.delta_entries = NULL;
|
|
|
|
s.n_index_entries = 0;
|
|
|
|
s.index_entries = g_new0 (MXFIndexEntry, max_segment_size);
|
|
|
|
g_array_append_val (mux->index_table, s);
|
|
|
|
}
|
|
|
|
segment =
|
|
|
|
&g_array_index (mux->index_table, MXFIndexTableSegment,
|
|
|
|
mux->index_table->len - 1);
|
|
|
|
|
|
|
|
segment->index_entries[segment->n_index_entries].temporal_offset = 0;
|
|
|
|
segment->index_entries[segment->n_index_entries].key_frame_offset = 0;
|
|
|
|
segment->index_entries[segment->n_index_entries].flags = is_keyframe ? 0x80 : 0x20; /* FIXME: Need to distinguish all the cases */
|
|
|
|
segment->index_entries[segment->n_index_entries].stream_offset =
|
|
|
|
mux->partition.body_offset;
|
|
|
|
|
|
|
|
segment->n_index_entries++;
|
|
|
|
segment->index_duration++;
|
|
|
|
}
|
|
|
|
|
2015-12-04 16:05:58 +00:00
|
|
|
buf_size = gst_buffer_get_size (buf);
|
|
|
|
slen = mxf_ber_encode_size (buf_size, ber);
|
|
|
|
outbuf = gst_buffer_new_and_alloc (16 + slen);
|
|
|
|
gst_buffer_map (outbuf, &map, GST_MAP_WRITE);
|
2012-10-26 20:48:06 +00:00
|
|
|
memcpy (map.data, _gc_essence_element_ul, 16);
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_WRITE_UINT32_BE (map.data + 12, pad->source_track->parent.track_number);
|
2012-10-26 20:48:06 +00:00
|
|
|
memcpy (map.data + 16, ber, slen);
|
2015-12-04 16:05:58 +00:00
|
|
|
gst_buffer_unmap (outbuf, &map);
|
|
|
|
outbuf = gst_buffer_append (outbuf, buf);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_DEBUG_OBJECT (pad,
|
2015-12-04 16:05:58 +00:00
|
|
|
"Pushing buffer of size %" G_GSIZE_FORMAT " for track %u",
|
|
|
|
gst_buffer_get_size (outbuf), pad->source_track->parent.track_id);
|
2009-03-26 07:11:20 +00:00
|
|
|
|
2015-12-07 18:27:23 +00:00
|
|
|
mux->partition.body_offset += gst_buffer_get_size (outbuf);
|
2015-12-04 16:05:58 +00:00
|
|
|
if ((ret = gst_mxf_mux_push (mux, outbuf)) != GST_FLOW_OK) {
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_ERROR_OBJECT (pad,
|
2009-03-26 07:11:20 +00:00
|
|
|
"Failed pushing buffer for track %u, reason %s",
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id, gst_flow_get_name (ret));
|
2009-03-11 18:32:16 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->pos++;
|
|
|
|
pad->last_timestamp =
|
|
|
|
gst_util_uint64_scale (GST_SECOND * pad->pos,
|
|
|
|
pad->source_track->edit_rate.d, pad->source_track->edit_rate.n);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mxf_mux_write_body_partition (GstMXFMux * mux)
|
|
|
|
{
|
|
|
|
GstBuffer *buf;
|
|
|
|
|
|
|
|
mux->partition.type = MXF_PARTITION_PACK_BODY;
|
2016-01-29 16:07:08 +00:00
|
|
|
mux->partition.closed = TRUE;
|
|
|
|
mux->partition.complete = TRUE;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->partition.this_partition = mux->offset;
|
|
|
|
mux->partition.prev_partition = 0;
|
|
|
|
mux->partition.footer_partition = 0;
|
|
|
|
mux->partition.header_byte_count = 0;
|
|
|
|
mux->partition.index_byte_count = 0;
|
|
|
|
mux->partition.index_sid = 0;
|
|
|
|
mux->partition.body_offset = 0;
|
|
|
|
mux->partition.body_sid =
|
|
|
|
mux->preface->content_storage->essence_container_data[0]->body_sid;
|
|
|
|
|
|
|
|
buf = mxf_partition_pack_to_buffer (&mux->partition);
|
|
|
|
return gst_mxf_mux_push (mux, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mxf_mux_handle_eos (GstMXFMux * mux)
|
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GList *l;
|
2009-03-26 07:11:20 +00:00
|
|
|
gboolean have_data = FALSE;
|
|
|
|
GstBuffer *packet;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
do {
|
|
|
|
GstMXFMuxPad *best = NULL;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
have_data = FALSE;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
|
|
|
GstBuffer *buffer =
|
|
|
|
gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
GstClockTime next_gc_timestamp =
|
|
|
|
gst_util_uint64_scale ((mux->last_gc_position + 1) * GST_SECOND,
|
|
|
|
mux->min_edit_rate.d, mux->min_edit_rate.n);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (pad->have_complete_edit_unit ||
|
|
|
|
gst_adapter_available (pad->adapter) > 0 || buffer) {
|
2009-03-26 07:11:20 +00:00
|
|
|
have_data = TRUE;
|
2015-10-23 15:38:33 +00:00
|
|
|
if (pad->last_timestamp < next_gc_timestamp) {
|
|
|
|
best = gst_object_ref (pad);
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2009-03-26 07:11:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-05-09 13:48:41 +00:00
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2009-05-09 13:48:41 +00:00
|
|
|
|
|
|
|
if (have_data && !l->next) {
|
2009-03-26 07:11:20 +00:00
|
|
|
mux->last_gc_position++;
|
|
|
|
mux->last_gc_timestamp = next_gc_timestamp;
|
|
|
|
break;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
if (best) {
|
|
|
|
gst_mxf_mux_handle_buffer (mux, best);
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_object_unref (best);
|
2009-03-26 07:11:20 +00:00
|
|
|
have_data = TRUE;
|
|
|
|
}
|
|
|
|
} while (have_data);
|
|
|
|
|
|
|
|
mux->last_gc_position++;
|
|
|
|
mux->last_gc_timestamp =
|
|
|
|
gst_util_uint64_scale (mux->last_gc_position * GST_SECOND,
|
|
|
|
mux->min_edit_rate.d, mux->min_edit_rate.n);
|
|
|
|
|
|
|
|
/* Update essence track durations */
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
|
|
|
GstMXFMuxPad *pad = l->data;
|
2009-03-26 07:11:20 +00:00
|
|
|
guint i;
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
/* Update durations */
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.sequence->duration = pad->pos;
|
|
|
|
MXF_METADATA_SOURCE_CLIP (pad->source_track->parent.
|
|
|
|
sequence->structural_components[0])->parent.duration = pad->pos;
|
2009-03-11 18:32:16 +00:00
|
|
|
for (i = 0; i < mux->preface->content_storage->packages[0]->n_tracks; i++) {
|
|
|
|
MXFMetadataTimelineTrack *track;
|
|
|
|
|
2014-04-21 09:07:06 +00:00
|
|
|
if (!MXF_IS_METADATA_TIMELINE_TRACK (mux->preface->
|
|
|
|
content_storage->packages[0]->tracks[i])
|
|
|
|
|| !MXF_IS_METADATA_SOURCE_CLIP (mux->preface->
|
|
|
|
content_storage->packages[0]->tracks[i]->sequence->
|
|
|
|
structural_components[0]))
|
2009-03-11 18:32:16 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
track =
|
2014-04-21 09:07:06 +00:00
|
|
|
MXF_METADATA_TIMELINE_TRACK (mux->preface->
|
|
|
|
content_storage->packages[0]->tracks[i]);
|
|
|
|
if (MXF_METADATA_SOURCE_CLIP (track->parent.
|
|
|
|
sequence->structural_components[0])->source_track_id ==
|
2015-10-23 15:38:33 +00:00
|
|
|
pad->source_track->parent.track_id) {
|
|
|
|
track->parent.sequence->structural_components[0]->duration = pad->pos;
|
|
|
|
track->parent.sequence->duration = pad->pos;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Update timecode track duration */
|
|
|
|
{
|
|
|
|
MXFMetadataTimelineTrack *track =
|
2014-04-21 09:07:06 +00:00
|
|
|
MXF_METADATA_TIMELINE_TRACK (mux->preface->
|
|
|
|
content_storage->packages[0]->tracks[0]);
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFMetadataSequence *sequence = track->parent.sequence;
|
|
|
|
MXFMetadataTimecodeComponent *component =
|
|
|
|
MXF_METADATA_TIMECODE_COMPONENT (sequence->structural_components[0]);
|
|
|
|
|
|
|
|
sequence->duration = mux->last_gc_position;
|
|
|
|
component->parent.duration = mux->last_gc_position;
|
|
|
|
}
|
|
|
|
|
2016-01-28 15:32:34 +00:00
|
|
|
{
|
|
|
|
MXFMetadataTimelineTrack *track =
|
|
|
|
MXF_METADATA_TIMELINE_TRACK (mux->preface->
|
|
|
|
content_storage->packages[1]->tracks[0]);
|
|
|
|
MXFMetadataSequence *sequence = track->parent.sequence;
|
|
|
|
MXFMetadataTimecodeComponent *component =
|
|
|
|
MXF_METADATA_TIMECODE_COMPONENT (sequence->structural_components[0]);
|
|
|
|
|
|
|
|
sequence->duration = mux->last_gc_position;
|
|
|
|
component->parent.duration = mux->last_gc_position;
|
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
|
|
|
guint64 body_partition = mux->partition.this_partition;
|
|
|
|
guint32 body_sid = mux->partition.body_sid;
|
|
|
|
guint64 footer_partition = mux->offset;
|
|
|
|
GArray *rip;
|
|
|
|
GstFlowReturn ret;
|
2012-10-26 20:48:06 +00:00
|
|
|
GstSegment segment;
|
2009-03-11 18:32:16 +00:00
|
|
|
MXFRandomIndexPackEntry entry;
|
2015-12-07 18:27:23 +00:00
|
|
|
GList *index_entries = NULL, *l;
|
|
|
|
guint index_byte_count = 0;
|
|
|
|
guint i;
|
2016-01-29 15:38:23 +00:00
|
|
|
GstBuffer *buf;
|
2015-12-07 18:27:23 +00:00
|
|
|
|
|
|
|
for (i = 0; i < mux->index_table->len; i++) {
|
|
|
|
MXFIndexTableSegment *segment =
|
|
|
|
&g_array_index (mux->index_table, MXFIndexTableSegment, i);
|
|
|
|
GstBuffer *segment_buffer = mxf_index_table_segment_to_buffer (segment);
|
|
|
|
|
|
|
|
index_byte_count += gst_buffer_get_size (segment_buffer);
|
|
|
|
index_entries = g_list_prepend (index_entries, segment_buffer);
|
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
mux->partition.type = MXF_PARTITION_PACK_FOOTER;
|
|
|
|
mux->partition.closed = TRUE;
|
|
|
|
mux->partition.complete = TRUE;
|
|
|
|
mux->partition.this_partition = mux->offset;
|
|
|
|
mux->partition.prev_partition = body_partition;
|
|
|
|
mux->partition.footer_partition = mux->offset;
|
|
|
|
mux->partition.header_byte_count = 0;
|
2015-12-07 18:27:23 +00:00
|
|
|
mux->partition.index_byte_count = index_byte_count;
|
|
|
|
mux->partition.index_sid =
|
|
|
|
mux->preface->content_storage->essence_container_data[0]->index_sid;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->partition.body_offset = 0;
|
|
|
|
mux->partition.body_sid = 0;
|
|
|
|
|
|
|
|
gst_mxf_mux_write_header_metadata (mux);
|
|
|
|
|
2015-12-07 18:27:23 +00:00
|
|
|
index_entries = g_list_reverse (index_entries);
|
|
|
|
for (l = index_entries; l; l = l->next) {
|
|
|
|
if ((ret = gst_mxf_mux_push (mux, l->data)) != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Failed pushing index table segment");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_list_free (index_entries);
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
rip = g_array_sized_new (FALSE, FALSE, sizeof (MXFRandomIndexPackEntry), 3);
|
|
|
|
entry.offset = 0;
|
|
|
|
entry.body_sid = 0;
|
|
|
|
g_array_append_val (rip, entry);
|
|
|
|
entry.offset = body_partition;
|
|
|
|
entry.body_sid = body_sid;
|
|
|
|
g_array_append_val (rip, entry);
|
|
|
|
entry.offset = footer_partition;
|
|
|
|
entry.body_sid = 0;
|
|
|
|
g_array_append_val (rip, entry);
|
|
|
|
|
|
|
|
packet = mxf_random_index_pack_to_buffer (rip);
|
|
|
|
if ((ret = gst_mxf_mux_push (mux, packet)) != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Failed pushing random index pack");
|
|
|
|
}
|
|
|
|
g_array_free (rip, TRUE);
|
|
|
|
|
|
|
|
/* Rewrite header partition with updated values */
|
2012-10-26 20:48:06 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_BYTES);
|
2015-10-23 15:38:33 +00:00
|
|
|
if (gst_pad_push_event (GST_AGGREGATOR_SRC_PAD (mux),
|
|
|
|
gst_event_new_segment (&segment))) {
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->offset = 0;
|
|
|
|
mux->partition.type = MXF_PARTITION_PACK_HEADER;
|
|
|
|
mux->partition.closed = TRUE;
|
|
|
|
mux->partition.complete = TRUE;
|
|
|
|
mux->partition.this_partition = 0;
|
2015-10-21 15:58:06 +00:00
|
|
|
mux->partition.prev_partition = 0;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->partition.footer_partition = footer_partition;
|
|
|
|
mux->partition.header_byte_count = 0;
|
|
|
|
mux->partition.index_byte_count = 0;
|
|
|
|
mux->partition.index_sid = 0;
|
|
|
|
mux->partition.body_offset = 0;
|
|
|
|
mux->partition.body_sid = 0;
|
|
|
|
|
|
|
|
ret = gst_mxf_mux_write_header_metadata (mux);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Rewriting header partition failed");
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-29 15:38:23 +00:00
|
|
|
|
|
|
|
g_assert (mux->offset == body_partition);
|
|
|
|
|
|
|
|
mux->partition.type = MXF_PARTITION_PACK_BODY;
|
|
|
|
mux->partition.closed = TRUE;
|
|
|
|
mux->partition.complete = TRUE;
|
|
|
|
mux->partition.this_partition = mux->offset;
|
|
|
|
mux->partition.prev_partition = 0;
|
|
|
|
mux->partition.footer_partition = footer_partition;
|
|
|
|
mux->partition.header_byte_count = 0;
|
|
|
|
mux->partition.index_byte_count = 0;
|
|
|
|
mux->partition.index_sid = 0;
|
|
|
|
mux->partition.body_offset = 0;
|
|
|
|
mux->partition.body_sid =
|
|
|
|
mux->preface->content_storage->essence_container_data[0]->body_sid;
|
|
|
|
|
|
|
|
buf = mxf_partition_pack_to_buffer (&mux->partition);
|
|
|
|
ret = gst_mxf_mux_push (mux, buf);
|
|
|
|
if (ret != GST_FLOW_OK) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Rewriting body partition failed");
|
|
|
|
return ret;
|
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
} else {
|
|
|
|
GST_WARNING_OBJECT (mux, "Can't rewrite header partition");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
_sort_mux_pads (gconstpointer a, gconstpointer b)
|
|
|
|
{
|
|
|
|
const GstMXFMuxPad *pa = a, *pb = b;
|
|
|
|
MXFMetadataTrackType ta =
|
|
|
|
mxf_metadata_track_identifier_parse (&pa->writer->data_definition);
|
|
|
|
MXFMetadataTrackType tb =
|
|
|
|
mxf_metadata_track_identifier_parse (&pb->writer->data_definition);
|
|
|
|
|
|
|
|
if (ta != tb)
|
|
|
|
return ta - tb;
|
|
|
|
|
|
|
|
return pa->source_track->parent.track_number -
|
|
|
|
pa->source_track->parent.track_number;
|
|
|
|
}
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_mxf_mux_stop (GstAggregator * aggregator)
|
|
|
|
{
|
|
|
|
GstMXFMux *mux = GST_MXF_MUX (aggregator);
|
|
|
|
|
|
|
|
gst_mxf_mux_reset (mux);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
static GstFlowReturn
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_mxf_mux_aggregate (GstAggregator * aggregator, gboolean timeout)
|
2009-03-11 18:32:16 +00:00
|
|
|
{
|
2015-10-23 15:38:33 +00:00
|
|
|
GstMXFMux *mux = GST_MXF_MUX (aggregator);
|
2009-03-11 18:32:16 +00:00
|
|
|
GstMXFMuxPad *best = NULL;
|
|
|
|
GstFlowReturn ret;
|
2015-10-23 15:38:33 +00:00
|
|
|
GList *l;
|
2009-03-11 18:32:16 +00:00
|
|
|
gboolean eos = TRUE;
|
|
|
|
|
2015-11-20 15:50:30 +00:00
|
|
|
if (timeout) {
|
|
|
|
GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
|
|
|
|
("Live mixing and got a timeout. This is not supported yet"));
|
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2009-03-22 14:35:42 +00:00
|
|
|
if (mux->state == GST_MXF_MUX_STATE_ERROR) {
|
|
|
|
GST_ERROR_OBJECT (mux, "Had an error before -- returning");
|
|
|
|
return GST_FLOW_ERROR;
|
2009-03-26 07:11:20 +00:00
|
|
|
} else if (mux->state == GST_MXF_MUX_STATE_EOS) {
|
|
|
|
GST_WARNING_OBJECT (mux, "EOS");
|
2012-10-26 20:48:06 +00:00
|
|
|
return GST_FLOW_EOS;
|
2009-03-22 14:35:42 +00:00
|
|
|
}
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
if (mux->state == GST_MXF_MUX_STATE_HEADER) {
|
2015-10-20 22:02:46 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (GST_ELEMENT_CAST (mux)->sinkpads == NULL) {
|
2009-03-11 18:32:16 +00:00
|
|
|
GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
|
|
|
|
("No input streams configured"));
|
2009-03-22 14:35:42 +00:00
|
|
|
ret = GST_FLOW_ERROR;
|
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
|
|
|
|
2015-10-20 22:02:46 +00:00
|
|
|
caps = gst_caps_new_empty_simple ("application/mxf");
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_aggregator_set_src_caps (GST_AGGREGATOR (mux), caps);
|
2015-10-20 22:02:46 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if ((ret = gst_mxf_mux_create_metadata (mux)) != GST_FLOW_OK)
|
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if ((ret = gst_mxf_mux_init_partition_pack (mux)) != GST_FLOW_OK)
|
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if ((ret = gst_mxf_mux_write_header_metadata (mux)) != GST_FLOW_OK)
|
2009-03-22 14:35:42 +00:00
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Sort pads, we will always write in that order */
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
GST_ELEMENT_CAST (mux)->sinkpads =
|
|
|
|
g_list_sort (GST_ELEMENT_CAST (mux)->sinkpads, _sort_mux_pads);
|
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
/* Write body partition */
|
|
|
|
ret = gst_mxf_mux_write_body_partition (mux);
|
|
|
|
if (ret != GST_FLOW_OK)
|
2009-03-22 14:35:42 +00:00
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
mux->state = GST_MXF_MUX_STATE_DATA;
|
|
|
|
}
|
|
|
|
|
2009-03-15 14:27:03 +00:00
|
|
|
g_return_val_if_fail (g_hash_table_size (mux->metadata) > 0, GST_FLOW_ERROR);
|
|
|
|
|
2009-03-26 07:11:20 +00:00
|
|
|
do {
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_LOCK (mux);
|
|
|
|
for (l = GST_ELEMENT_CAST (mux)->sinkpads; l; l = l->next) {
|
2011-12-15 13:39:41 +00:00
|
|
|
gboolean pad_eos;
|
2015-10-23 15:38:33 +00:00
|
|
|
GstMXFMuxPad *pad = l->data;
|
|
|
|
GstBuffer *buffer;
|
2009-03-26 07:11:20 +00:00
|
|
|
GstClockTime next_gc_timestamp =
|
|
|
|
gst_util_uint64_scale ((mux->last_gc_position + 1) * GST_SECOND,
|
|
|
|
mux->min_edit_rate.d, mux->min_edit_rate.n);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
pad_eos = gst_aggregator_pad_is_eos (GST_AGGREGATOR_PAD (pad));
|
2011-12-15 13:39:41 +00:00
|
|
|
if (!pad_eos)
|
|
|
|
eos = FALSE;
|
2009-03-11 18:32:16 +00:00
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
buffer = gst_aggregator_pad_get_buffer (GST_AGGREGATOR_PAD (pad));
|
|
|
|
|
|
|
|
if ((!pad_eos || pad->have_complete_edit_unit ||
|
|
|
|
gst_adapter_available (pad->adapter) > 0 || buffer)
|
|
|
|
&& pad->last_timestamp < next_gc_timestamp) {
|
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
best = gst_object_ref (pad);
|
2009-03-26 07:11:20 +00:00
|
|
|
break;
|
2015-10-23 15:38:33 +00:00
|
|
|
} else if (!eos && !l->next) {
|
2009-03-26 07:11:20 +00:00
|
|
|
mux->last_gc_position++;
|
|
|
|
mux->last_gc_timestamp = next_gc_timestamp;
|
|
|
|
eos = FALSE;
|
2015-10-23 15:38:33 +00:00
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2009-03-26 07:11:20 +00:00
|
|
|
best = NULL;
|
|
|
|
break;
|
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
if (buffer)
|
|
|
|
gst_buffer_unref (buffer);
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
2015-10-23 15:38:33 +00:00
|
|
|
GST_OBJECT_UNLOCK (mux);
|
2009-03-26 07:11:20 +00:00
|
|
|
} while (!eos && best == NULL);
|
2009-03-11 18:32:16 +00:00
|
|
|
|
|
|
|
if (!eos && best) {
|
2009-03-22 14:35:42 +00:00
|
|
|
ret = gst_mxf_mux_handle_buffer (mux, best);
|
2015-10-23 15:38:33 +00:00
|
|
|
gst_object_unref (best);
|
2009-03-22 14:35:42 +00:00
|
|
|
if (ret != GST_FLOW_OK)
|
|
|
|
goto error;
|
2009-03-11 18:32:16 +00:00
|
|
|
} else if (eos) {
|
2009-03-22 14:35:42 +00:00
|
|
|
GST_DEBUG_OBJECT (mux, "Handling EOS");
|
|
|
|
|
2015-10-23 15:38:33 +00:00
|
|
|
if (best)
|
|
|
|
gst_object_unref (best);
|
|
|
|
|
2009-03-11 18:32:16 +00:00
|
|
|
gst_mxf_mux_handle_eos (mux);
|
2009-03-26 07:11:20 +00:00
|
|
|
mux->state = GST_MXF_MUX_STATE_EOS;
|
2012-10-26 20:48:06 +00:00
|
|
|
return GST_FLOW_EOS;
|
2015-10-23 15:38:33 +00:00
|
|
|
} else {
|
2015-10-27 14:32:48 +00:00
|
|
|
g_assert_not_reached ();
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|
2009-03-22 14:35:42 +00:00
|
|
|
|
2009-03-22 14:58:50 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2009-03-22 14:35:42 +00:00
|
|
|
error:
|
|
|
|
{
|
|
|
|
mux->state = GST_MXF_MUX_STATE_ERROR;
|
|
|
|
return ret;
|
|
|
|
}
|
2009-03-11 18:32:16 +00:00
|
|
|
}
|