mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-25 01:30:38 +00:00
mxf: Start implementing a central UL database and add some helper functions and use them
This commit is contained in:
parent
a19f0375ec
commit
b409f71f49
6 changed files with 394 additions and 208 deletions
|
@ -16,7 +16,8 @@ libgstmxf_la_SOURCES = \
|
|||
mxfmetadata.c \
|
||||
mxfdms1.c \
|
||||
mxfwrite.c \
|
||||
mxfmux.c
|
||||
mxfmux.c \
|
||||
mxful.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) \
|
||||
|
@ -39,5 +40,6 @@ noinst_HEADERS = \
|
|||
mxfmetadata.h \
|
||||
mxfdms1.h \
|
||||
mxfwrite.h \
|
||||
mxfmux.h
|
||||
mxfmux.h \
|
||||
mxful.h
|
||||
|
||||
|
|
|
@ -33,57 +33,20 @@ GST_DEBUG_CATEGORY_EXTERN (mxf_debug);
|
|||
static const MXFTimestamp mxf_timestamp_unknown = { 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
static const MXFUMID umid_zero = { {0,} };
|
||||
static const MXFUL key_zero = { {0,} };
|
||||
|
||||
/* UL common to all MXF UL */
|
||||
static const guint8 mxf_key[] = { 0x06, 0x0e, 0x2b, 0x34 };
|
||||
|
||||
/* SMPTE 377M 6.1 */
|
||||
static const guint8 partition_pack_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
|
||||
0x01
|
||||
};
|
||||
|
||||
/* SMPTE 336M */
|
||||
static const guint8 fill_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x01, 0x03, 0x01, 0x02, 0x10,
|
||||
0x01, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
/* SMPTE 377M 8.1 */
|
||||
static const guint8 primer_pack_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
|
||||
0x01, 0x05, 0x01, 0x00
|
||||
};
|
||||
|
||||
/* SMPTE 377M 8.6 */
|
||||
static const guint8 metadata_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x01, 0x01,
|
||||
0x01
|
||||
};
|
||||
|
||||
static const guint8 random_index_pack_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
|
||||
0x01, 0x11, 0x01, 0x00
|
||||
};
|
||||
|
||||
static const guint8 index_table_segment_key[] =
|
||||
{ 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
|
||||
0x01, 0x10, 0x01, 0x00
|
||||
};
|
||||
|
||||
gboolean
|
||||
mxf_is_mxf_packet (const MXFUL * key)
|
||||
mxf_is_mxf_packet (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, mxf_key, 4) == 0);
|
||||
return mxf_ul_is_subclass (MXF_UL (SMPTE), ul);
|
||||
}
|
||||
|
||||
/* SMPTE 377M 6.1: Check if this is a valid partition pack */
|
||||
gboolean
|
||||
mxf_is_partition_pack (const MXFUL * key)
|
||||
mxf_is_partition_pack (const MXFUL * ul)
|
||||
{
|
||||
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] >= 0x02
|
||||
&& key->u[13] <= 0x04 && key->u[14] < 0x05 && key->u[15] == 0x00)
|
||||
if (mxf_ul_is_subclass (MXF_UL (PARTITION_PACK), ul) &&
|
||||
ul->u[13] >= 0x02 && ul->u[13] <= 0x04 &&
|
||||
ul->u[14] < 0x05 && ul->u[15] == 0x00)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -91,10 +54,9 @@ mxf_is_partition_pack (const MXFUL * key)
|
|||
|
||||
/* SMPTE 377M 6.2: header partition pack has byte 14 == 0x02 */
|
||||
gboolean
|
||||
mxf_is_header_partition_pack (const MXFUL * key)
|
||||
mxf_is_header_partition_pack (const MXFUL * ul)
|
||||
{
|
||||
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x02 &&
|
||||
key->u[14] < 0x05 && key->u[15] == 0x00)
|
||||
if (mxf_is_partition_pack (ul) && ul->u[13] == 0x02)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -102,10 +64,9 @@ mxf_is_header_partition_pack (const MXFUL * key)
|
|||
|
||||
/* SMPTE 377M 6.3: body partition pack has byte 14 == 0x03 */
|
||||
gboolean
|
||||
mxf_is_body_partition_pack (const MXFUL * key)
|
||||
mxf_is_body_partition_pack (const MXFUL * ul)
|
||||
{
|
||||
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x03 &&
|
||||
key->u[14] < 0x05 && key->u[15] == 0x00)
|
||||
if (mxf_is_partition_pack (ul) && ul->u[13] == 0x03)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
|
@ -113,159 +74,92 @@ mxf_is_body_partition_pack (const MXFUL * key)
|
|||
|
||||
/* SMPTE 377M 6.4: footer partition pack has byte 14 == 0x04 */
|
||||
gboolean
|
||||
mxf_is_footer_partition_pack (const MXFUL * key)
|
||||
mxf_is_footer_partition_pack (const MXFUL * ul)
|
||||
{
|
||||
if (memcmp (key, partition_pack_key, 13) == 0 && key->u[13] == 0x04 &&
|
||||
key->u[14] < 0x05 && key->u[15] == 0x00)
|
||||
if (mxf_is_partition_pack (ul) && ul->u[13] == 0x04)
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_is_fill (const MXFUL * key)
|
||||
mxf_is_fill (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, fill_key, 16) == 0);
|
||||
return (mxf_ul_is_subclass (MXF_UL (FILL), ul));
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_is_primer_pack (const MXFUL * key)
|
||||
mxf_is_primer_pack (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, primer_pack_key, 16) == 0);
|
||||
return (mxf_ul_is_subclass (MXF_UL (PRIMER_PACK), ul));
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_is_metadata (const MXFUL * key)
|
||||
mxf_is_metadata (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, metadata_key, 13) == 0 && key->u[15] == 0x00);
|
||||
return (mxf_ul_is_subclass (MXF_UL (METADATA), ul));
|
||||
}
|
||||
|
||||
/* SMPTE 377M 8.7.3 */
|
||||
gboolean
|
||||
mxf_is_descriptive_metadata (const MXFUL * key)
|
||||
mxf_is_descriptive_metadata (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, mxf_key, 4) == 0 &&
|
||||
key->u[4] == 0x02 &&
|
||||
key->u[6] == 0x01 &&
|
||||
key->u[7] == 0x01 &&
|
||||
key->u[8] == 0x0d &&
|
||||
key->u[9] == 0x01 && key->u[10] == 0x04 && key->u[11] == 0x01);
|
||||
return (mxf_ul_is_subclass (MXF_UL (DESCRIPTIVE_METADATA), ul));
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_is_random_index_pack (const MXFUL * key)
|
||||
mxf_is_random_index_pack (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, random_index_pack_key, 16) == 0);
|
||||
return (mxf_ul_is_subclass (MXF_UL (RANDOM_INDEX_PACK), ul));
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_is_index_table_segment (const MXFUL * key)
|
||||
mxf_is_index_table_segment (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, index_table_segment_key, 16) == 0);
|
||||
return (mxf_ul_is_subclass (MXF_UL (INDEX_TABLE_SEGMENT), ul));
|
||||
}
|
||||
|
||||
/* SMPTE 379M 6.2.1 */
|
||||
gboolean
|
||||
mxf_is_generic_container_system_item (const MXFUL * key)
|
||||
mxf_is_generic_container_system_item (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, mxf_key, 4) == 0 && key->u[4] == 0x02
|
||||
&& key->u[6] == 0x01 && key->u[8] == 0x0d && key->u[9] == 0x01
|
||||
&& key->u[10] == 0x03 && key->u[11] == 0x01 && (key->u[12] == 0x04
|
||||
|| key->u[12] == 0x14));
|
||||
return (mxf_ul_is_subclass (MXF_UL (GENERIC_CONTAINER_SYSTEM_ITEM), ul) &&
|
||||
(ul->u[12] == 0x04 || ul->u[12] == 0x14));
|
||||
}
|
||||
|
||||
/* SMPTE 379M 7.1 */
|
||||
gboolean
|
||||
mxf_is_generic_container_essence_element (const MXFUL * key)
|
||||
mxf_is_generic_container_essence_element (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (key, mxf_key, 4) == 0 && key->u[4] == 0x01
|
||||
&& key->u[5] == 0x02 && key->u[6] == 0x01 && key->u[8] == 0x0d
|
||||
&& key->u[9] == 0x01 && key->u[10] == 0x03 && key->u[11] == 0x01
|
||||
&& (key->u[12] == 0x05 || key->u[12] == 0x06 || key->u[12] == 0x07
|
||||
|| key->u[12] == 0x15 || key->u[12] == 0x16 || key->u[12] == 0x17
|
||||
|| key->u[12] == 0x18));
|
||||
return (mxf_ul_is_subclass (MXF_UL (GENERIC_CONTAINER_ESSENCE_ELEMENT), ul)
|
||||
&& (ul->u[12] == 0x05 || ul->u[12] == 0x06
|
||||
|| ul->u[12] == 0x07 || ul->u[12] == 0x15
|
||||
|| ul->u[12] == 0x16 || ul->u[12] == 0x17 || ul->u[12] == 0x18));
|
||||
}
|
||||
|
||||
/* SMPTE 379M 8 */
|
||||
gboolean
|
||||
mxf_is_generic_container_essence_container_label (const MXFUL * key)
|
||||
mxf_is_generic_container_essence_container_label (const MXFUL * ul)
|
||||
{
|
||||
return (key->u[0] == 0x06 &&
|
||||
key->u[1] == 0x0e &&
|
||||
key->u[2] == 0x2b &&
|
||||
key->u[3] == 0x34 &&
|
||||
key->u[4] == 0x04 &&
|
||||
key->u[5] == 0x01 &&
|
||||
key->u[6] == 0x01 &&
|
||||
key->u[8] == 0x0d &&
|
||||
key->u[9] == 0x01 &&
|
||||
key->u[10] == 0x03 &&
|
||||
key->u[11] == 0x01 && (key->u[12] == 0x01 || key->u[12] == 0x02));
|
||||
return (mxf_ul_is_subclass (MXF_UL
|
||||
(GENERIC_CONTAINER_ESSENCE_CONTAINER_LABEL), ul) && (ul->u[12] == 0x01
|
||||
|| ul->u[12] == 0x02));
|
||||
}
|
||||
|
||||
/* Essence container label found in files generated by Avid */
|
||||
static const guint8 avid_essence_container_label[] = {
|
||||
0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0xff, 0x4b, 0x46, 0x41, 0x41, 0x00,
|
||||
0x0d, 0x4d, 0x4f
|
||||
};
|
||||
|
||||
gboolean
|
||||
mxf_is_avid_essence_container_label (const MXFUL * key)
|
||||
mxf_is_avid_essence_container_label (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (&key->u, avid_essence_container_label, 16) == 0);
|
||||
return (mxf_ul_is_subclass (MXF_UL (AVID_ESSENCE_CONTAINER_ESSENCE_LABEL),
|
||||
ul));
|
||||
}
|
||||
|
||||
/* Essence element key found in files generated by Avid */
|
||||
static const guint8 avid_essence_element_ul[] = {
|
||||
0x06, 0x0e, 0x2b, 0x34, 0x01, 0x02, 0x01, 0x01, 0x0e, 0x04, 0x03, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
gboolean
|
||||
mxf_is_avid_essence_container_essence_element (const MXFUL * key)
|
||||
mxf_is_avid_essence_container_essence_element (const MXFUL * ul)
|
||||
{
|
||||
return (memcmp (&key->u, avid_essence_element_ul, 12) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_equal (const MXFUL * a, const MXFUL * b)
|
||||
{
|
||||
return (memcmp (a, b, 16) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_zero (const MXFUL * key)
|
||||
{
|
||||
return (memcmp (key, &key_zero, 16) == 0);
|
||||
}
|
||||
|
||||
guint
|
||||
mxf_ul_hash (const MXFUL * key)
|
||||
{
|
||||
guint32 ret = 0;
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
ret ^=
|
||||
(key->u[i * 4 + 0] << 24) | (key->u[i * 4 + 1] << 16) | (key->u[i * 4 +
|
||||
2] << 8) | (key->u[i * 4 + 3] << 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar *
|
||||
mxf_ul_to_string (const MXFUL * key, gchar str[48])
|
||||
{
|
||||
g_return_val_if_fail (key != NULL, NULL);
|
||||
g_return_val_if_fail (str != NULL, NULL);
|
||||
|
||||
g_snprintf (str, 48,
|
||||
"%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x",
|
||||
key->u[0], key->u[1], key->u[2], key->u[3], key->u[4], key->u[5],
|
||||
key->u[6], key->u[7], key->u[8], key->u[9], key->u[10], key->u[11],
|
||||
key->u[12], key->u[13], key->u[14], key->u[15]);
|
||||
|
||||
return str;
|
||||
return (mxf_ul_is_subclass (MXF_UL (AVID_ESSENCE_CONTAINER_ESSENCE_ELEMENT),
|
||||
ul));
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -476,57 +370,6 @@ mxf_product_version_is_valid (const MXFProductVersion * version)
|
|||
return (memcmp (version, &null, sizeof (MXFProductVersion)) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_array_parse (MXFUL ** array, guint32 * count, const guint8 * data,
|
||||
guint size)
|
||||
{
|
||||
guint32 element_count, element_size;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (array != NULL, FALSE);
|
||||
g_return_val_if_fail (count != NULL, FALSE);
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
if (size < 8)
|
||||
return FALSE;
|
||||
|
||||
element_count = GST_READ_UINT32_BE (data);
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
if (element_count == 0) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
element_size = GST_READ_UINT32_BE (data);
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
if (element_size != 16) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (16 * element_count < size) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*array = g_new (MXFUL, element_count);
|
||||
*count = element_count;
|
||||
|
||||
for (i = 0; i < element_count; i++) {
|
||||
memcpy (&((*array)[i]), data, 16);
|
||||
data += 16;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* SMPTE 377M 6.1, Table 2 */
|
||||
gboolean
|
||||
mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack,
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "mxftypes.h"
|
||||
#include "mxful.h"
|
||||
#include "mxfmetadata.h"
|
||||
|
||||
typedef GstFlowReturn (*MXFEssenceElementHandleFunc) (const MXFUL *key, GstBuffer *buffer, GstCaps *caps, MXFMetadataTimelineTrack *track, gpointer mapping_data, GstBuffer **outbuf);
|
||||
|
@ -34,11 +35,6 @@ typedef struct {
|
|||
GstCaps * (*create_caps) (MXFMetadataTimelineTrack *track, GstTagList **tags, MXFEssenceElementHandleFunc *handler, gpointer *mapping_data);
|
||||
} MXFEssenceElementHandler;
|
||||
|
||||
gchar * mxf_ul_to_string (const MXFUL *ul, gchar str[48]);
|
||||
gboolean mxf_ul_is_equal (const MXFUL *a, const MXFUL *b);
|
||||
gboolean mxf_ul_is_zero (const MXFUL *ul);
|
||||
guint mxf_ul_hash (const MXFUL *ul);
|
||||
|
||||
gchar *mxf_umid_to_string (const MXFUMID * umid, gchar str[96]);
|
||||
MXFUMID *mxf_umid_from_string (const gchar *str, MXFUMID * umid);
|
||||
gboolean mxf_umid_is_equal (const MXFUMID *a, const MXFUMID *b);
|
||||
|
@ -82,8 +78,6 @@ gboolean mxf_timestamp_is_unknown (const MXFTimestamp *a);
|
|||
gint mxf_timestamp_compare (const MXFTimestamp *a, const MXFTimestamp *b);
|
||||
gchar *mxf_timestamp_to_string (const MXFTimestamp *t, gchar str[32]);
|
||||
|
||||
gboolean mxf_ul_array_parse (MXFUL **array, guint32 *count, const guint8 *data, guint size);
|
||||
|
||||
gboolean mxf_partition_pack_parse (const MXFUL *key, MXFPartitionPack *pack, const guint8 *data, guint size);
|
||||
void mxf_partition_pack_reset (MXFPartitionPack *pack);
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ typedef struct {
|
|||
guint8 u[16];
|
||||
} MXFUL;
|
||||
|
||||
typedef struct {
|
||||
guint8 u[16];
|
||||
} MXFUUID;
|
||||
|
||||
/* SMPTE 377M 3.2 */
|
||||
typedef struct {
|
||||
guint8 u[32];
|
||||
|
|
284
gst/mxf/mxful.c
Normal file
284
gst/mxf/mxful.c
Normal file
|
@ -0,0 +1,284 @@
|
|||
/* 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 <string.h>
|
||||
|
||||
#include "mxful.h"
|
||||
|
||||
const MXFUL _mxf_ul_table[] = {
|
||||
/* SMPTE */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x00,}},
|
||||
/* FILL, SMPTE 336M */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0x01,
|
||||
0x03, 0x01, 0x02, 0x10, 0x01, 0x00,}},
|
||||
/* PARTITION_PACK, SMPTE 377M 6.1 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01, 0x00,}},
|
||||
/* PRIMER_PACK, SMPTE 377M 8.1 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01, 0x05, 0x01, 0x00}},
|
||||
/* METADATA, SMPTE 377M 8.6 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x01, 0x01, 0x01, 0x00,}},
|
||||
/* DESCRIPTIVE_METADATA, SMPTE 377M 8.7.3 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x00, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x04, 0x01, 0x00,}},
|
||||
/* RANDOM_INDEX_PACK, SMPTE 377M 11.1 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01, 0x11, 0x01, 0x00}},
|
||||
/* INDEX_TABLE_SEGMENT, SMPTE 377M 10.2.2 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x53, 0x01, 0x01,
|
||||
0x0d, 0x01, 0x02, 0x01, 0x01, 0x10, 0x01, 0x00}},
|
||||
/* GENERIC_CONTAINER_SYSTEM_ITEM, SMPTE 379M 6.2.1 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x02, 0x00, 0x01, 0x00,
|
||||
0x0d, 0x01, 0x03, 0x01, 0x00}},
|
||||
/* GENERIC_CONTAINER_ESSENCE_ELEMENT, SMPTE 379M 7.1 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x01, 0x02, 0x01, 0x00,
|
||||
0x0d, 0x01, 0x03, 0x01, 0x00,}},
|
||||
/* GENERIC_CONTAINER_ESSENCE_CONTAINER_LABEL, SMPTE 379M 8 */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x04, 0x01, 0x01, 0x00,
|
||||
0x0d, 0x01, 0x03, 0x01, 0x00,}},
|
||||
/* AVID_ESSENCE_CONTAINER_ESSENCE_ELEMENT, undocumented */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x01, 0x02, 0x01, 0x01,
|
||||
0x0e, 0x04, 0x03, 0x01, 0x00,}},
|
||||
/* AVID_ESSENCE_CONTAINER_ESSENCE_LABEL, undocumented */
|
||||
{{0x06, 0x0e, 0x2b, 0x34, 0x01, 0x01, 0x01, 0xff,
|
||||
0x4b, 0x46, 0x41, 0x41, 0x00, 0x0d, 0x4d, 0x4f}},
|
||||
};
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_equal (const MXFUL * a, const MXFUL * b)
|
||||
{
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (a != NULL, FALSE);
|
||||
g_return_val_if_fail (b != NULL, FALSE);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
/* registry version */
|
||||
if (i == 7)
|
||||
continue;
|
||||
|
||||
if (a->u[i] != b->u[i])
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_subclass (const MXFUL * class, const MXFUL * subclass)
|
||||
{
|
||||
guint i, j;
|
||||
|
||||
g_return_val_if_fail (class != NULL, FALSE);
|
||||
g_return_val_if_fail (subclass != NULL, FALSE);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (i == 7)
|
||||
/* registry version */
|
||||
continue;
|
||||
|
||||
if (class->u[i] == 0x00) {
|
||||
gboolean terminated = TRUE;
|
||||
|
||||
for (j = i; j < 16; j++) {
|
||||
if (class->u[j] != 0x00) {
|
||||
terminated = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (terminated)
|
||||
return TRUE;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (class->u[i] != subclass->u[i])
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_zero (const MXFUL * ul)
|
||||
{
|
||||
static const guint8 zero[16] = { 0, };
|
||||
|
||||
g_return_val_if_fail (ul != NULL, FALSE);
|
||||
|
||||
return (memcmp (ul, &zero, 16) == 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_is_valid (const MXFUL * ul)
|
||||
{
|
||||
guint i, j;
|
||||
|
||||
g_return_val_if_fail (ul != NULL, FALSE);
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
if (ul->u[i] == 0x00) {
|
||||
for (j = i; j < 16; j++) {
|
||||
if (ul->u[j] != 0x00)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (ul->u[i] > 0x7f)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
guint
|
||||
mxf_ul_hash (const MXFUL * ul)
|
||||
{
|
||||
guint32 ret = 0;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (ul != NULL, 0);
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
ret ^= (ul->u[i * 4 + 0] << 24) |
|
||||
(ul->u[i * 4 + 1] << 16) |
|
||||
(ul->u[i * 4 + 2] << 8) | (ul->u[i * 4 + 3] << 0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar *
|
||||
mxf_ul_to_string (const MXFUL * ul, gchar str[48])
|
||||
{
|
||||
gchar *ret = str;
|
||||
|
||||
g_return_val_if_fail (ul != NULL, NULL);
|
||||
|
||||
if (ret == NULL)
|
||||
ret = g_malloc (48);
|
||||
|
||||
g_snprintf (ret, 48,
|
||||
"%02x.%02x.%02x.%02x."
|
||||
"%02x.%02x.%02x.%02x."
|
||||
"%02x.%02x.%02x.%02x."
|
||||
"%02x.%02x.%02x.%02x",
|
||||
ul->u[0], ul->u[1], ul->u[2], ul->u[3],
|
||||
ul->u[4], ul->u[5], ul->u[6], ul->u[7],
|
||||
ul->u[8], ul->u[9], ul->u[10], ul->u[11],
|
||||
ul->u[12], ul->u[13], ul->u[14], ul->u[15]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
MXFUL *
|
||||
mxf_ul_from_string (const gchar * str, MXFUL * ul)
|
||||
{
|
||||
MXFUL *ret = ul;
|
||||
gint len;
|
||||
guint i, j;
|
||||
|
||||
g_return_val_if_fail (str != NULL, NULL);
|
||||
|
||||
len = strlen (str);
|
||||
if (len != 47) {
|
||||
GST_ERROR ("Invalid UL string length %d, should be 47", len);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ret == NULL)
|
||||
ret = g_new0 (MXFUL, 1);
|
||||
|
||||
memset (ret, 0, 16);
|
||||
|
||||
for (i = 0, j = 0; i < 16; i++) {
|
||||
if (!g_ascii_isxdigit (str[j]) ||
|
||||
!g_ascii_isxdigit (str[j + 1]) ||
|
||||
(str[j + 2] != '.' && str[j + 2] != '\0')) {
|
||||
GST_ERROR ("Invalid UL string '%s'", str);
|
||||
if (ul == NULL)
|
||||
g_free (ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->u[i] = (g_ascii_xdigit_value (str[j]) << 4) |
|
||||
(g_ascii_xdigit_value (str[j + 1]));
|
||||
j += 3;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean
|
||||
mxf_ul_array_parse (MXFUL ** array, guint32 * count, const guint8 * data,
|
||||
guint size)
|
||||
{
|
||||
guint32 element_count, element_size;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (array != NULL, FALSE);
|
||||
g_return_val_if_fail (count != NULL, FALSE);
|
||||
g_return_val_if_fail (data != NULL, FALSE);
|
||||
|
||||
if (size < 8)
|
||||
return FALSE;
|
||||
|
||||
element_count = GST_READ_UINT32_BE (data);
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
if (element_count == 0) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
element_size = GST_READ_UINT32_BE (data);
|
||||
data += 4;
|
||||
size -= 4;
|
||||
|
||||
if (element_size != 16) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (16 * element_count < size) {
|
||||
*array = NULL;
|
||||
*count = 0;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*array = g_new (MXFUL, element_count);
|
||||
*count = element_count;
|
||||
|
||||
for (i = 0; i < element_count; i++) {
|
||||
memcpy (&((*array)[i]), data, 16);
|
||||
data += 16;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
59
gst/mxf/mxful.h
Normal file
59
gst/mxf/mxful.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
/* 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_UL_H__
|
||||
#define __MXF_UL_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "mxftypes.h"
|
||||
|
||||
typedef enum {
|
||||
MXF_UL_SMPTE = 0,
|
||||
MXF_UL_FILL,
|
||||
MXF_UL_PARTITION_PACK,
|
||||
MXF_UL_PRIMER_PACK,
|
||||
MXF_UL_METADATA,
|
||||
MXF_UL_DESCRIPTIVE_METADATA,
|
||||
MXF_UL_RANDOM_INDEX_PACK,
|
||||
MXF_UL_INDEX_TABLE_SEGMENT,
|
||||
MXF_UL_GENERIC_CONTAINER_SYSTEM_ITEM,
|
||||
MXF_UL_GENERIC_CONTAINER_ESSENCE_ELEMENT,
|
||||
MXF_UL_GENERIC_CONTAINER_ESSENCE_CONTAINER_LABEL,
|
||||
MXF_UL_AVID_ESSENCE_CONTAINER_ESSENCE_ELEMENT,
|
||||
MXF_UL_AVID_ESSENCE_CONTAINER_ESSENCE_LABEL,
|
||||
MXF_UL_MAX
|
||||
} MXFULId;
|
||||
|
||||
extern const MXFUL _mxf_ul_table[MXF_UL_MAX];
|
||||
|
||||
#define MXF_UL(id) (&_mxf_ul_table[MXF_UL_##id])
|
||||
|
||||
gboolean mxf_ul_is_equal (const MXFUL *a, const MXFUL *b);
|
||||
gboolean mxf_ul_is_subclass (const MXFUL *class, const MXFUL *subclass);
|
||||
gboolean mxf_ul_is_zero (const MXFUL *ul);
|
||||
gboolean mxf_ul_is_valid (const MXFUL *ul);
|
||||
guint mxf_ul_hash (const MXFUL *ul);
|
||||
|
||||
gchar * mxf_ul_to_string (const MXFUL *ul, gchar str[48]);
|
||||
MXFUL * mxf_ul_from_string (const gchar *str, MXFUL *ul);
|
||||
|
||||
gboolean mxf_ul_array_parse (MXFUL **array, guint32 *count, const guint8 *data, guint size);
|
||||
|
||||
#endif /* __MXF_UL_H__ */
|
Loading…
Reference in a new issue