mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-26 17:18:15 +00:00
mxf: Add MXF muxer
This muxer currently only supports OP1a and is probably not yet 100% complying to the standards.
This commit is contained in:
parent
86719f194f
commit
e50039897b
12 changed files with 4435 additions and 10 deletions
|
@ -160,6 +160,10 @@ fi
|
|||
AM_CONDITIONAL(HAVE_GCC_ASM, test "x$HAVE_GCC_ASM" = "xyes")
|
||||
|
||||
dnl *** checks for library functions ***
|
||||
AC_CHECK_FUNCS([gmtime_r])
|
||||
|
||||
dnl *** checks for headers ***
|
||||
AC_CHECK_HEADERS([sys/utsname.h])
|
||||
|
||||
dnl *** checks for dependency libraries ***
|
||||
|
||||
|
|
|
@ -14,7 +14,9 @@ libgstmxf_la_SOURCES = \
|
|||
mxfup.c \
|
||||
mxfvc3.c \
|
||||
mxfmetadata.c \
|
||||
mxfdms1.c
|
||||
mxfdms1.c \
|
||||
mxfwrite.c \
|
||||
mxfmux.c
|
||||
|
||||
libgstmxf_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
|
||||
libgstmxf_la_LIBADD = $(GST_LIBS) $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \
|
||||
|
@ -35,5 +37,7 @@ noinst_HEADERS = \
|
|||
mxfvc3.h \
|
||||
mxftypes.h \
|
||||
mxfmetadata.h \
|
||||
mxfdms1.h
|
||||
mxfdms1.h \
|
||||
mxfwrite.h \
|
||||
mxfmux.h
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include "mxfquark.h"
|
||||
#include "mxfdemux.h"
|
||||
#include "mxfmux.h"
|
||||
#include "mxfaes-bwf.h"
|
||||
#include "mxfmpeg.h"
|
||||
#include "mxfdv-dif.h"
|
||||
|
@ -53,6 +54,8 @@ mxf_init (void)
|
|||
static gboolean
|
||||
plugin_init (GstPlugin * plugin)
|
||||
{
|
||||
GST_DEBUG_CATEGORY_INIT (mxf_debug, "mxf", 0, "MXF");
|
||||
|
||||
mxf_init ();
|
||||
mxf_quark_initialize ();
|
||||
mxf_metadata_init_types ();
|
||||
|
@ -67,11 +70,10 @@ plugin_init (GstPlugin * plugin)
|
|||
mxf_dms1_initialize ();
|
||||
|
||||
if (!gst_element_register (plugin, "mxfdemux", GST_RANK_PRIMARY,
|
||||
GST_TYPE_MXF_DEMUX))
|
||||
GST_TYPE_MXF_DEMUX) ||
|
||||
!gst_element_register (plugin, "mxfmux", GST_RANK_NONE, GST_TYPE_MXF_MUX))
|
||||
return FALSE;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (mxf_debug, "mxf", 0, "MXF");
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -386,6 +386,7 @@ struct _MXFMetadataBaseClass {
|
|||
gboolean (*handle_tag) (MXFMetadataBase *self, MXFPrimerPack *primer, guint16 tag, const guint8 *tag_data, guint tag_size);
|
||||
gboolean (*resolve) (MXFMetadataBase *self, GHashTable *metadata);
|
||||
GstStructure * (*to_structure) (MXFMetadataBase *self);
|
||||
GList * (*write_tags) (MXFMetadataBase *self, MXFPrimerPack *primer);
|
||||
|
||||
GQuark name_quark;
|
||||
};
|
||||
|
@ -751,15 +752,20 @@ struct _MXFDescriptiveMetadataFrameworkInterface {
|
|||
gboolean mxf_metadata_base_parse (MXFMetadataBase *self, MXFPrimerPack *primer, const guint8 *data, guint size);
|
||||
gboolean mxf_metadata_base_resolve (MXFMetadataBase *self, GHashTable *metadata);
|
||||
GstStructure * mxf_metadata_base_to_structure (MXFMetadataBase *self);
|
||||
GstBuffer * mxf_metadata_base_to_buffer (MXFMetadataBase *self, MXFPrimerPack *primer);
|
||||
|
||||
MXFMetadata *mxf_metadata_new (guint16 type, MXFPrimerPack *primer, guint64 offset, const guint8 *data, guint size);
|
||||
void mxf_metadata_register (GType type);
|
||||
void mxf_metadata_init_types (void);
|
||||
|
||||
MXFMetadataTrackType mxf_metadata_track_identifier_parse (const MXFUL * track_identifier);
|
||||
const MXFUL * mxf_metadata_track_identifier_get (MXFMetadataTrackType type);
|
||||
|
||||
void mxf_metadata_generic_picture_essence_descriptor_set_caps (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps);
|
||||
void mxf_metadata_generic_picture_essence_descriptor_from_caps (MXFMetadataGenericPictureEssenceDescriptor * self, GstCaps * caps);
|
||||
|
||||
void mxf_metadata_generic_sound_essence_descriptor_set_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps);
|
||||
void mxf_metadata_generic_sound_essence_descriptor_from_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps);
|
||||
|
||||
void mxf_descriptive_metadata_register (guint8 scheme, GType *types);
|
||||
MXFDescriptiveMetadata * mxf_descriptive_metadata_new (guint8 scheme, guint32 type, MXFPrimerPack * primer, guint64 offset, const guint8 * data, guint size);
|
||||
|
|
1327
gst/mxf/mxfmux.c
Normal file
1327
gst/mxf/mxfmux.c
Normal file
File diff suppressed because it is too large
Load diff
100
gst/mxf/mxfmux.h
Normal file
100
gst/mxf/mxfmux.h
Normal file
|
@ -0,0 +1,100 @@
|
|||
/* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __MXF_MUX_H__
|
||||
#define __MXF_MUX_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
#include <gst/base/gstcollectpads.h>
|
||||
|
||||
#include "mxfwrite.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_MXF_MUX \
|
||||
(gst_mxf_mux_get_type ())
|
||||
#define GST_MXF_MUX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_MXF_MUX, GstMXFMux))
|
||||
#define GST_MXF_MUX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_MXF_MUX, GstMXFMuxClass))
|
||||
#define GST_IS_MXF_MUX(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_MXF_MUX))
|
||||
#define GST_IS_MXF_MUX_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_MXF_MUX))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GstCollectData collect;
|
||||
|
||||
guint64 pos;
|
||||
GstClockTime last_timestamp;
|
||||
|
||||
MXFMetadataFileDescriptor *descriptor;
|
||||
|
||||
GstAdapter *adapter;
|
||||
|
||||
gpointer mapping_data;
|
||||
const MXFEssenceElementWriter *writer;
|
||||
MXFEssenceElementWriteFunc write_func;
|
||||
|
||||
MXFMetadataSourcePackage *source_package;
|
||||
MXFMetadataTimelineTrack *source_track;
|
||||
} GstMXFMuxPad;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GST_MXF_MUX_STATE_HEADER,
|
||||
GST_MXF_MUX_STATE_DATA
|
||||
} GstMXFMuxState;
|
||||
|
||||
typedef struct _GstMXFMux {
|
||||
GstElement element;
|
||||
|
||||
GstPad *srcpad;
|
||||
GstCollectPads *collect;
|
||||
GstPadEventFunction collect_event;
|
||||
|
||||
GstMXFMuxState state;
|
||||
guint n_pads;
|
||||
|
||||
guint64 offset;
|
||||
|
||||
MXFPartitionPack partition;
|
||||
MXFPrimerPack primer;
|
||||
|
||||
GHashTable *metadata;
|
||||
MXFMetadataPreface *preface;
|
||||
|
||||
MXFFraction min_edit_rate;
|
||||
guint64 last_gc_position;
|
||||
GstClockTime last_gc_timestamp;
|
||||
|
||||
gchar *application;
|
||||
} GstMXFMux;
|
||||
|
||||
typedef struct _GstMXFMuxClass {
|
||||
GstElementClass parent;
|
||||
} GstMXFMuxClass;
|
||||
|
||||
GType gst_mxf_mux_get_type (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MXF_MUX_H__ */
|
|
@ -468,6 +468,14 @@ mxf_product_version_parse (MXFProductVersion * product_version,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_product_version_is_valid (const MXFProductVersion * version)
|
||||
{
|
||||
static const guint8 null[sizeof (MXFProductVersion)] = { 0, };
|
||||
|
||||
return (memcmp (version, &null, sizeof (MXFProductVersion)) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_array_parse (MXFUL ** array, guint32 * count, const guint8 * data,
|
||||
guint size)
|
||||
|
@ -1023,7 +1031,12 @@ mxf_primer_pack_reset (MXFPrimerPack * pack)
|
|||
|
||||
if (pack->mappings)
|
||||
g_hash_table_destroy (pack->mappings);
|
||||
if (pack->reverse_mappings)
|
||||
g_hash_table_destroy (pack->reverse_mappings);
|
||||
|
||||
memset (pack, 0, sizeof (MXFPrimerPack));
|
||||
|
||||
pack->next_free_tag = 0x8000;
|
||||
}
|
||||
|
||||
/* structural metadata parsing */
|
||||
|
@ -1051,7 +1064,10 @@ mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
|
|||
void
|
||||
mxf_local_tag_free (MXFLocalTag * tag)
|
||||
{
|
||||
g_free (tag->data);
|
||||
if (tag->g_slice)
|
||||
g_slice_free1 (tag->size, tag->data);
|
||||
else
|
||||
g_free (tag->data);
|
||||
g_slice_free (MXFLocalTag, tag);
|
||||
}
|
||||
|
||||
|
@ -1100,6 +1116,32 @@ mxf_local_tag_add_to_hash_table (const MXFPrimerPack * primer,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_local_tag_insert (MXFLocalTag * tag, GHashTable ** hash_table)
|
||||
{
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
gchar str[48];
|
||||
#endif
|
||||
|
||||
g_return_val_if_fail (tag != NULL, FALSE);
|
||||
g_return_val_if_fail (hash_table != NULL, FALSE);
|
||||
|
||||
if (*hash_table == NULL)
|
||||
*hash_table =
|
||||
g_hash_table_new_full ((GHashFunc) mxf_ul_hash,
|
||||
(GEqualFunc) mxf_ul_is_equal, (GDestroyNotify) NULL,
|
||||
(GDestroyNotify) mxf_local_tag_free);
|
||||
|
||||
g_return_val_if_fail (*hash_table != NULL, FALSE);
|
||||
|
||||
GST_DEBUG ("Adding local tag 0x%04x with UL %s and size %u", tag,
|
||||
mxf_ul_to_string (&tag->key, str), tag->size);
|
||||
|
||||
g_hash_table_insert (*hash_table, &tag->key, tag);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GSList *_mxf_essence_element_handler_registry = NULL;
|
||||
|
||||
void
|
||||
|
|
|
@ -72,6 +72,7 @@ gchar * mxf_utf16_to_utf8 (const guint8 * data, guint size);
|
|||
|
||||
gboolean mxf_product_version_parse (MXFProductVersion * product_version,
|
||||
const guint8 * data, guint size);
|
||||
gboolean mxf_product_version_is_valid (const MXFProductVersion *version);
|
||||
|
||||
gboolean mxf_fraction_parse (MXFFraction *fraction, const guint8 *data, guint size);
|
||||
gdouble mxf_fraction_to_double (const MXFFraction *fraction);
|
||||
|
@ -96,11 +97,12 @@ void mxf_index_table_segment_reset (MXFIndexTableSegment *segment);
|
|||
|
||||
gboolean mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag,
|
||||
guint16 * tag_size, const guint8 ** tag_data);
|
||||
void gst_mxf_local_tag_free (MXFLocalTag *tag);
|
||||
void mxf_local_tag_free (MXFLocalTag *tag);
|
||||
|
||||
gboolean mxf_local_tag_add_to_hash_table (const MXFPrimerPack *primer,
|
||||
guint16 tag, const guint8 *tag_data, guint16 tag_size,
|
||||
GHashTable **hash_table);
|
||||
gboolean mxf_local_tag_insert (MXFLocalTag *tag, GHashTable **hash_table);
|
||||
|
||||
void mxf_essence_element_handler_register (const MXFEssenceElementHandler *handler);
|
||||
const MXFEssenceElementHandler * mxf_essence_element_handler_find (const MXFMetadataTimelineTrack *track);
|
||||
|
|
|
@ -65,6 +65,8 @@ typedef struct {
|
|||
MXFUL key;
|
||||
guint16 size;
|
||||
guint8 *data;
|
||||
|
||||
gboolean g_slice; /* TRUE if data was allocated by GSlice */
|
||||
} MXFLocalTag;
|
||||
|
||||
/* SMPTE 377M 11.1 */
|
||||
|
@ -114,6 +116,8 @@ typedef struct {
|
|||
typedef struct {
|
||||
guint64 offset;
|
||||
GHashTable *mappings;
|
||||
GHashTable *reverse_mappings;
|
||||
guint16 next_free_tag;
|
||||
} MXFPrimerPack;
|
||||
|
||||
/* SMPTE 377M 10.2.3 */
|
||||
|
|
567
gst/mxf/mxfwrite.c
Normal file
567
gst/mxf/mxfwrite.c
Normal file
|
@ -0,0 +1,567 @@
|
|||
/* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mxfwrite.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
|
||||
#define GST_CAT_DEFAULT mxf_debug
|
||||
|
||||
static GList *_essence_element_writer_registry = NULL;
|
||||
static GPtrArray *_essence_element_writer_pad_templates = NULL;
|
||||
|
||||
void
|
||||
mxf_essence_element_writer_register (const MXFEssenceElementWriter * writer)
|
||||
{
|
||||
_essence_element_writer_registry =
|
||||
g_list_prepend (_essence_element_writer_registry, (gpointer) writer);
|
||||
|
||||
if (!_essence_element_writer_pad_templates)
|
||||
_essence_element_writer_pad_templates = g_ptr_array_new ();
|
||||
|
||||
if (_essence_element_writer_pad_templates->len > 0 &&
|
||||
g_ptr_array_index (_essence_element_writer_pad_templates,
|
||||
_essence_element_writer_pad_templates->len - 1) == NULL)
|
||||
g_ptr_array_remove_index (_essence_element_writer_pad_templates,
|
||||
_essence_element_writer_pad_templates->len - 1);
|
||||
|
||||
g_ptr_array_add (_essence_element_writer_pad_templates,
|
||||
(gpointer) writer->pad_template);
|
||||
}
|
||||
|
||||
const GstPadTemplate **
|
||||
mxf_essence_element_writer_get_pad_templates (void)
|
||||
{
|
||||
if (!_essence_element_writer_pad_templates
|
||||
|| _essence_element_writer_pad_templates->len == 0)
|
||||
return NULL;
|
||||
|
||||
if (g_ptr_array_index (_essence_element_writer_pad_templates,
|
||||
_essence_element_writer_pad_templates->len - 1))
|
||||
g_ptr_array_add (_essence_element_writer_pad_templates, NULL);
|
||||
|
||||
return (const GstPadTemplate **) _essence_element_writer_pad_templates->pdata;
|
||||
}
|
||||
|
||||
const MXFEssenceElementWriter *
|
||||
mxf_essence_element_writer_find (const GstPadTemplate * templ)
|
||||
{
|
||||
GList *l = _essence_element_writer_registry;
|
||||
|
||||
for (; l; l = l->next) {
|
||||
MXFEssenceElementWriter *writer = l->data;
|
||||
|
||||
if (writer->pad_template == templ)
|
||||
return writer;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_ul_set (MXFUL * ul, GHashTable * hashtable)
|
||||
{
|
||||
guint i;
|
||||
|
||||
next_try:
|
||||
for (i = 0; i < 4; i++)
|
||||
GST_WRITE_UINT32_BE (&ul->u[i * 4], g_random_int ());
|
||||
|
||||
if (hashtable && g_hash_table_lookup_extended (hashtable, ul, NULL, NULL))
|
||||
goto next_try;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_umid_set (MXFUMID * umid)
|
||||
{
|
||||
guint i;
|
||||
guint32 tmp;
|
||||
|
||||
/* SMPTE S330M 5.1.1:
|
||||
* UMID Identifier
|
||||
*/
|
||||
umid->u[0] = 0x06;
|
||||
umid->u[1] = 0x0a;
|
||||
umid->u[2] = 0x2b;
|
||||
umid->u[3] = 0x34;
|
||||
umid->u[4] = 0x01;
|
||||
umid->u[5] = 0x01;
|
||||
umid->u[6] = 0x01;
|
||||
umid->u[7] = 0x05; /* version, see RP210 */
|
||||
umid->u[8] = 0x01;
|
||||
umid->u[9] = 0x01;
|
||||
umid->u[10] = 0x0d; /* mixed group of components in a single container */
|
||||
|
||||
/* - UUID/UL method for material number
|
||||
* - 24 bit PRG for instance number
|
||||
*/
|
||||
umid->u[11] = 0x20 | 0x02;
|
||||
|
||||
/* Length of remaining data */
|
||||
umid->u[12] = 0x13;
|
||||
|
||||
/* Instance number */
|
||||
tmp = g_random_int ();
|
||||
umid->u[13] = (tmp >> 24) & 0xff;
|
||||
umid->u[14] = (tmp >> 16) & 0xff;
|
||||
umid->u[15] = (tmp >> 8) & 0xff;
|
||||
|
||||
/* Material number: ISO UUID Version 4 */
|
||||
for (i = 16; i < 32; i += 4)
|
||||
GST_WRITE_UINT32_BE (&umid->u[i], g_random_int ());
|
||||
|
||||
umid->u[16 + 6] &= 0x0f;
|
||||
umid->u[16 + 6] |= 0x40;
|
||||
|
||||
umid->u[16 + 8] &= 0x3f;
|
||||
umid->u[16 + 8] |= 0x80;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_timestamp_set_now (MXFTimestamp * timestamp)
|
||||
{
|
||||
GTimeVal tv;
|
||||
time_t t;
|
||||
struct tm *tm;
|
||||
|
||||
#ifdef HAVE_GMTIME_R
|
||||
struct tm tm_;
|
||||
#endif
|
||||
|
||||
g_get_current_time (&tv);
|
||||
t = (time_t) tv.tv_sec;
|
||||
|
||||
#ifdef HAVE_GMTIME_R
|
||||
tm = gmtime_r (&t, &tm_);
|
||||
#else
|
||||
tm = gmtime (&t);
|
||||
#endif
|
||||
|
||||
timestamp->year = tm->tm_year + 1900;
|
||||
timestamp->month = tm->tm_mon;
|
||||
timestamp->day = tm->tm_mday;
|
||||
timestamp->hour = tm->tm_hour;
|
||||
timestamp->minute = tm->tm_min;
|
||||
timestamp->second = tm->tm_sec;
|
||||
timestamp->msecond = tv.tv_usec / 1000;
|
||||
}
|
||||
|
||||
static guint8 mxf_op_identification_ul[] = {
|
||||
0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01
|
||||
};
|
||||
|
||||
void
|
||||
mxf_op_set_atom (MXFUL * ul, gboolean single_sourceclip,
|
||||
gboolean single_essence_track)
|
||||
{
|
||||
memcpy (&ul->u, &mxf_op_identification_ul, 12);
|
||||
ul->u[12] = 0x10;
|
||||
ul->u[13] = 0;
|
||||
|
||||
if (!single_sourceclip)
|
||||
ul->u[13] |= 0x80;
|
||||
|
||||
if (!single_essence_track)
|
||||
ul->u[13] |= 0x40;
|
||||
|
||||
ul->u[14] = 0;
|
||||
ul->u[15] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_op_set_generalized (MXFUL * ul, MXFOperationalPattern pattern,
|
||||
gboolean internal_essence, gboolean streamable, gboolean single_track)
|
||||
{
|
||||
g_return_if_fail (pattern >= MXF_OP_1a);
|
||||
|
||||
memcpy (&ul->u, &mxf_op_identification_ul, 12);
|
||||
|
||||
if (pattern == MXF_OP_1a || pattern == MXF_OP_1b || pattern == MXF_OP_1c)
|
||||
ul->u[12] = 0x01;
|
||||
else if (pattern == MXF_OP_2a || pattern == MXF_OP_2b || pattern == MXF_OP_2c)
|
||||
ul->u[12] = 0x02;
|
||||
else if (pattern == MXF_OP_3a || pattern == MXF_OP_3b || pattern == MXF_OP_3c)
|
||||
ul->u[12] = 0x03;
|
||||
|
||||
if (pattern == MXF_OP_1a || pattern == MXF_OP_2a || pattern == MXF_OP_3a)
|
||||
ul->u[13] = 0x01;
|
||||
else if (pattern == MXF_OP_1b || pattern == MXF_OP_2b || pattern == MXF_OP_3b)
|
||||
ul->u[13] = 0x02;
|
||||
else if (pattern == MXF_OP_1c || pattern == MXF_OP_2c || pattern == MXF_OP_3c)
|
||||
ul->u[13] = 0x02;
|
||||
|
||||
ul->u[14] = 0x80;
|
||||
if (!internal_essence)
|
||||
ul->u[14] |= 0x40;
|
||||
if (!streamable)
|
||||
ul->u[14] |= 0x20;
|
||||
if (!single_track)
|
||||
ul->u[14] |= 0x10;
|
||||
|
||||
ul->u[15] = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
_mxf_mapping_ul_free (MXFUL * ul)
|
||||
{
|
||||
g_slice_free (MXFUL, ul);
|
||||
}
|
||||
|
||||
guint16
|
||||
mxf_primer_pack_add_mapping (MXFPrimerPack * primer, guint16 local_tag,
|
||||
const MXFUL * ul)
|
||||
{
|
||||
MXFUL *uid;
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
gchar str[48];
|
||||
#endif
|
||||
|
||||
if (primer->mappings == NULL) {
|
||||
primer->mappings = g_hash_table_new_full (g_direct_hash, g_direct_equal,
|
||||
(GDestroyNotify) NULL, (GDestroyNotify) _mxf_mapping_ul_free);
|
||||
}
|
||||
|
||||
if (primer->reverse_mappings == NULL) {
|
||||
primer->reverse_mappings = g_hash_table_new_full ((GHashFunc) mxf_ul_hash,
|
||||
(GEqualFunc) mxf_ul_is_equal, (GDestroyNotify) _mxf_mapping_ul_free,
|
||||
(GDestroyNotify) NULL);
|
||||
}
|
||||
|
||||
if (primer->next_free_tag == 0xffff && local_tag == 0) {
|
||||
GST_ERROR ("Used too many dynamic tags");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (local_tag == 0) {
|
||||
guint16 tmp;
|
||||
|
||||
tmp = GPOINTER_TO_UINT (g_hash_table_lookup (primer->reverse_mappings, ul));
|
||||
if (tmp == 0) {
|
||||
local_tag = primer->next_free_tag;
|
||||
primer->next_free_tag++;
|
||||
}
|
||||
} else {
|
||||
if (g_hash_table_lookup (primer->mappings, GUINT_TO_POINTER (local_tag)))
|
||||
return local_tag;
|
||||
}
|
||||
|
||||
g_assert (local_tag != 0);
|
||||
|
||||
uid = g_slice_new (MXFUL);
|
||||
memcpy (uid, ul, 16);
|
||||
|
||||
GST_DEBUG ("Adding mapping = 0x%04x -> %s", local_tag,
|
||||
mxf_ul_to_string (uid, str));
|
||||
g_hash_table_insert (primer->mappings, GUINT_TO_POINTER (local_tag), uid);
|
||||
uid = g_slice_dup (MXFUL, uid);
|
||||
g_hash_table_insert (primer->reverse_mappings, uid,
|
||||
GUINT_TO_POINTER (local_tag));
|
||||
|
||||
return local_tag;
|
||||
}
|
||||
|
||||
guint
|
||||
mxf_ber_encode_size (guint size, guint8 ber[9])
|
||||
{
|
||||
guint8 slen, i;
|
||||
guint8 tmp[8];
|
||||
|
||||
memset (ber, 0, 9);
|
||||
|
||||
if (size <= 127) {
|
||||
ber[0] = size;
|
||||
return 1;
|
||||
} else if (size > G_MAXUINT) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
slen = 0;
|
||||
while (size > 0) {
|
||||
tmp[slen] = size & 0xff;
|
||||
size >>= 8;
|
||||
slen++;
|
||||
}
|
||||
|
||||
ber[0] = 0x80 | slen;
|
||||
for (i = 0; i < slen; i++) {
|
||||
ber[i + 1] = tmp[slen - i - 1];
|
||||
}
|
||||
|
||||
return slen + 1;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_timestamp_write (const MXFTimestamp * timestamp, guint8 * data)
|
||||
{
|
||||
GST_WRITE_UINT16_BE (data, timestamp->year);
|
||||
GST_WRITE_UINT8 (data + 2, timestamp->month);
|
||||
GST_WRITE_UINT8 (data + 3, timestamp->day);
|
||||
GST_WRITE_UINT8 (data + 4, timestamp->hour);
|
||||
GST_WRITE_UINT8 (data + 5, timestamp->minute);
|
||||
GST_WRITE_UINT8 (data + 6, timestamp->second);
|
||||
GST_WRITE_UINT8 (data + 7, (timestamp->msecond * 256) / 1000);
|
||||
}
|
||||
|
||||
guint8 *
|
||||
mxf_utf8_to_utf16 (const gchar * str, guint16 * size)
|
||||
{
|
||||
guint8 *ret;
|
||||
GError *error = NULL;
|
||||
gsize s;
|
||||
|
||||
g_return_val_if_fail (size != NULL, NULL);
|
||||
|
||||
if (str == NULL) {
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = (guint8 *)
|
||||
g_convert_with_fallback (str, -1, "UTF-16BE", "UTF-8", "*", NULL, &s,
|
||||
&error);
|
||||
|
||||
if (ret == NULL) {
|
||||
GST_WARNING ("UTF-16-BE to UTF-8 conversion failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
*size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*size = s;
|
||||
return (guint8 *) ret;
|
||||
}
|
||||
|
||||
void
|
||||
mxf_product_version_write (const MXFProductVersion * version, guint8 * data)
|
||||
{
|
||||
GST_WRITE_UINT16_BE (data, version->major);
|
||||
GST_WRITE_UINT16_BE (data + 2, version->minor);
|
||||
GST_WRITE_UINT16_BE (data + 4, version->patch);
|
||||
GST_WRITE_UINT16_BE (data + 6, version->build);
|
||||
GST_WRITE_UINT16_BE (data + 8, version->release);
|
||||
}
|
||||
|
||||
GstBuffer *
|
||||
mxf_partition_pack_to_buffer (const MXFPartitionPack * pack)
|
||||
{
|
||||
static const guint8 partition_pack_ul[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01
|
||||
};
|
||||
guint slen;
|
||||
guint8 ber[9];
|
||||
GstBuffer *ret;
|
||||
guint8 *data;
|
||||
guint i;
|
||||
guint size =
|
||||
8 + 16 * pack->n_essence_containers + 16 + 4 + 8 + 4 + 8 + 8 + 8 + 8 + 8 +
|
||||
4 + 2 + 2;
|
||||
|
||||
slen = mxf_ber_encode_size (size, ber);
|
||||
|
||||
ret = gst_buffer_new_and_alloc (16 + slen + size);
|
||||
memcpy (GST_BUFFER_DATA (ret), &partition_pack_ul, 13);
|
||||
if (pack->type == MXF_PARTITION_PACK_HEADER)
|
||||
GST_BUFFER_DATA (ret)[13] = 0x02;
|
||||
else if (pack->type == MXF_PARTITION_PACK_BODY)
|
||||
GST_BUFFER_DATA (ret)[13] = 0x03;
|
||||
else if (pack->type == MXF_PARTITION_PACK_FOOTER)
|
||||
GST_BUFFER_DATA (ret)[13] = 0x04;
|
||||
GST_BUFFER_DATA (ret)[14] = 0;
|
||||
if (pack->complete)
|
||||
GST_BUFFER_DATA (ret)[14] |= 0x02;
|
||||
if (pack->closed)
|
||||
GST_BUFFER_DATA (ret)[14] |= 0x01;
|
||||
GST_BUFFER_DATA (ret)[14] += 1;
|
||||
GST_BUFFER_DATA (ret)[15] = 0;
|
||||
memcpy (GST_BUFFER_DATA (ret) + 16, &ber, slen);
|
||||
|
||||
data = GST_BUFFER_DATA (ret) + 16 + slen;
|
||||
|
||||
GST_WRITE_UINT16_BE (data, pack->major_version);
|
||||
GST_WRITE_UINT16_BE (data + 2, pack->minor_version);
|
||||
data += 4;
|
||||
|
||||
GST_WRITE_UINT32_BE (data, pack->kag_size);
|
||||
data += 4;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->this_partition);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->prev_partition);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->footer_partition);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->header_byte_count);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->index_byte_count);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT32_BE (data, pack->index_sid);
|
||||
data += 4;
|
||||
|
||||
GST_WRITE_UINT64_BE (data, pack->body_offset);
|
||||
data += 8;
|
||||
|
||||
GST_WRITE_UINT32_BE (data, pack->body_sid);
|
||||
data += 4;
|
||||
|
||||
memcpy (data, &pack->operational_pattern, 16);
|
||||
data += 16;
|
||||
|
||||
GST_WRITE_UINT32_BE (data, pack->n_essence_containers);
|
||||
GST_WRITE_UINT32_BE (data + 4, 16);
|
||||
data += 8;
|
||||
|
||||
for (i = 0; i < pack->n_essence_containers; i++)
|
||||
memcpy (data + 16 * i, &pack->essence_containers[i], 16);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GstBuffer *
|
||||
mxf_primer_pack_to_buffer (const MXFPrimerPack * pack)
|
||||
{
|
||||
static const guint8 primer_pack_ul[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
|
||||
0x01, 0x05, 0x01, 0x00
|
||||
};
|
||||
guint slen;
|
||||
guint8 ber[9];
|
||||
GstBuffer *ret;
|
||||
guint n;
|
||||
guint8 *data;
|
||||
|
||||
if (pack->mappings)
|
||||
n = g_hash_table_size (pack->mappings);
|
||||
else
|
||||
n = 0;
|
||||
|
||||
slen = mxf_ber_encode_size (8 + 18 * n, ber);
|
||||
|
||||
ret = gst_buffer_new_and_alloc (16 + slen + 8 + 18 * n);
|
||||
memcpy (GST_BUFFER_DATA (ret), &primer_pack_ul, 16);
|
||||
memcpy (GST_BUFFER_DATA (ret) + 16, &ber, slen);
|
||||
|
||||
data = GST_BUFFER_DATA (ret) + 16 + slen;
|
||||
|
||||
GST_WRITE_UINT32_BE (data, n);
|
||||
GST_WRITE_UINT32_BE (data + 4, 18);
|
||||
data += 8;
|
||||
|
||||
if (pack->mappings) {
|
||||
guint16 local_tag;
|
||||
MXFUL *ul;
|
||||
#if GLIB_CHECK_VERSION (2, 16, 0)
|
||||
GHashTableIter iter;
|
||||
|
||||
g_hash_table_iter_init (&iter, pack->mappings);
|
||||
#else
|
||||
GList *l, *values;
|
||||
|
||||
keys = g_hash_table_get_keys (pack->mappings);
|
||||
#endif
|
||||
|
||||
#if GLIB_CHECK_VERSION (2, 16, 0)
|
||||
while (g_hash_table_iter_next (&iter, (gpointer) & local_tag,
|
||||
(gpointer) & ul)) {
|
||||
#else
|
||||
for (l = keys l; l = l->next) {
|
||||
local_tag = GPOINTER_TO_GUINT (l->data);
|
||||
ul = g_hash_table_lookup (pack->mappings, GUINT_TO_POINTER (local_tag));
|
||||
#endif
|
||||
GST_WRITE_UINT16_BE (data, local_tag);
|
||||
memcpy (data + 2, ul, 16);
|
||||
data += 18;
|
||||
}
|
||||
|
||||
#if !GLIB_CHECK_VERSION (2, 16, 0)
|
||||
g_list_free (keys);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GstBuffer *
|
||||
mxf_fill_new (guint size)
|
||||
{
|
||||
static const guint8 fill_ul[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x01,
|
||||
0x03, 0x01, 0x02, 0x10, 0x01, 0x00, 0x00, 0x00
|
||||
};
|
||||
GstBuffer *ret;
|
||||
guint slen;
|
||||
guint8 ber[9];
|
||||
|
||||
slen = mxf_ber_encode_size (size, ber);
|
||||
|
||||
ret = gst_buffer_new_and_alloc (16 + slen + size);
|
||||
memcpy (GST_BUFFER_DATA (ret), &fill_ul, 16);
|
||||
memcpy (GST_BUFFER_DATA (ret) + 16, &ber, slen);
|
||||
memset (GST_BUFFER_DATA (ret) + slen, 0, size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const guint8 random_index_pack_ul[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01, 0x11, 0x01, 0x00
|
||||
};
|
||||
|
||||
GstBuffer *
|
||||
mxf_random_index_pack_to_buffer (const GArray * array)
|
||||
{
|
||||
MXFRandomIndexPackEntry *entry;
|
||||
guint i;
|
||||
GstBuffer *ret;
|
||||
guint8 slen, ber[9];
|
||||
guint size;
|
||||
guint8 *data;
|
||||
|
||||
if (array->len == 0)
|
||||
return NULL;
|
||||
|
||||
size = array->len * 12 + 4;
|
||||
slen = mxf_ber_encode_size (size, ber);
|
||||
ret = gst_buffer_new_and_alloc (16 + slen + size);
|
||||
memcpy (GST_BUFFER_DATA (ret), random_index_pack_ul, 16);
|
||||
memcpy (GST_BUFFER_DATA (ret) + 16, ber, slen);
|
||||
|
||||
data = GST_BUFFER_DATA (ret) + 16 + slen;
|
||||
|
||||
for (i = 0; i < array->len; i++) {
|
||||
entry = &g_array_index (array, MXFRandomIndexPackEntry, i);
|
||||
GST_WRITE_UINT32_BE (data, entry->body_sid);
|
||||
GST_WRITE_UINT64_BE (data + 4, entry->offset);
|
||||
data += 12;
|
||||
}
|
||||
GST_WRITE_UINT32_BE (data, GST_BUFFER_SIZE (ret));
|
||||
|
||||
return ret;
|
||||
}
|
85
gst/mxf/mxfwrite.h
Normal file
85
gst/mxf/mxfwrite.h
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* 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
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Handling of the basic MXF types */
|
||||
|
||||
#ifndef __MXF_WRITE_H__
|
||||
#define __MXF_WRITE_H__
|
||||
|
||||
#include <string.h>
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstadapter.h>
|
||||
|
||||
#include "mxfmetadata.h"
|
||||
#include "mxftypes.h"
|
||||
#include "mxfparse.h"
|
||||
|
||||
typedef GstFlowReturn (*MXFEssenceElementWriteFunc) (GstBuffer *buffer, GstCaps *caps, gpointer mapping_data, GstAdapter *adapter, GstBuffer **outbuf, gboolean flush);
|
||||
|
||||
typedef struct {
|
||||
MXFMetadataFileDescriptor * (*get_descriptor) (GstPadTemplate *tmpl, GstCaps *caps, MXFEssenceElementWriteFunc *handler, gpointer *mapping_data);
|
||||
void (*update_descriptor) (MXFMetadataFileDescriptor *d, GstCaps *caps, gpointer mapping_data, GstBuffer *buf);
|
||||
void (*get_edit_rate) (MXFMetadataFileDescriptor *a, GstCaps *caps, gpointer mapping_data, GstBuffer *buf, MXFMetadataSourcePackage *package, MXFMetadataTimelineTrack *track, MXFFraction *edit_rate);
|
||||
guint32 (*get_track_number_template) (MXFMetadataFileDescriptor *a, GstCaps *caps, gpointer mapping_data);
|
||||
const GstPadTemplate *pad_template;
|
||||
MXFUL data_definition;
|
||||
} MXFEssenceElementWriter;
|
||||
|
||||
typedef enum {
|
||||
MXF_OP_UNKNOWN = 0,
|
||||
MXF_OP_ATOM,
|
||||
MXF_OP_1a,
|
||||
MXF_OP_1b,
|
||||
MXF_OP_1c,
|
||||
MXF_OP_2a,
|
||||
MXF_OP_2b,
|
||||
MXF_OP_2c,
|
||||
MXF_OP_3a,
|
||||
MXF_OP_3b,
|
||||
MXF_OP_3c,
|
||||
} MXFOperationalPattern;
|
||||
|
||||
void mxf_essence_element_writer_register (const MXFEssenceElementWriter *writer);
|
||||
const GstPadTemplate ** mxf_essence_element_writer_get_pad_templates (void);
|
||||
const MXFEssenceElementWriter *mxf_essence_element_writer_find (const GstPadTemplate *templ);
|
||||
|
||||
void mxf_ul_set (MXFUL *ul, GHashTable *hashtable);
|
||||
void mxf_umid_set (MXFUMID *umid);
|
||||
|
||||
void mxf_timestamp_set_now (MXFTimestamp *timestamp);
|
||||
void mxf_timestamp_write (const MXFTimestamp *timestamp, guint8 *data);
|
||||
|
||||
void mxf_op_set_atom (MXFUL *ul, gboolean single_sourceclip, gboolean single_essence_track);
|
||||
void mxf_op_set_generalized (MXFUL *ul, MXFOperationalPattern pattern, gboolean internal_essence, gboolean streamable, gboolean single_track);
|
||||
|
||||
guint16 mxf_primer_pack_add_mapping (MXFPrimerPack *primer, guint16 local_tag, const MXFUL *ul);
|
||||
|
||||
guint mxf_ber_encode_size (guint size, guint8 ber[9]);
|
||||
|
||||
guint8 * mxf_utf8_to_utf16 (const gchar *str, guint16 *size);
|
||||
|
||||
void mxf_product_version_write (const MXFProductVersion *version, guint8 *data);
|
||||
|
||||
GstBuffer * mxf_partition_pack_to_buffer (const MXFPartitionPack *pack);
|
||||
GstBuffer * mxf_primer_pack_to_buffer (const MXFPrimerPack *pack);
|
||||
GstBuffer * mxf_fill_new (guint size);
|
||||
|
||||
GstBuffer * mxf_random_index_pack_to_buffer (const GArray *array);
|
||||
|
||||
#endif /* __MXF_WRITE_H__ */
|
Loading…
Reference in a new issue