summaryrefslogtreecommitdiffstats
path: root/gst/mxf/mxfparse.c
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2009-01-22 11:42:24 +0100
committerSebastian Dröge <slomo@circular-chaos.org>2009-01-22 13:13:00 +0100
commit100dfc34d63e1d7991265412ddb36b1d6653904f (patch)
treee756975c1f9ecd50f97c175fe368594e95e3f521 /gst/mxf/mxfparse.c
parentcd80f534f5c22faefd191c8b9f716b4d4b34a64d (diff)
downloadgst-plugins-bad-100dfc34d63e1d7991265412ddb36b1d6653904f.tar.gz
gst-plugins-bad-100dfc34d63e1d7991265412ddb36b1d6653904f.tar.bz2
gst-plugins-bad-100dfc34d63e1d7991265412ddb36b1d6653904f.zip
Simplify parsing of UL/UUID arrays
Simplify parsing of UL/UUID arrays by abstracting it into a separate function.
Diffstat (limited to 'gst/mxf/mxfparse.c')
-rw-r--r--gst/mxf/mxfparse.c72
1 files changed, 57 insertions, 15 deletions
diff --git a/gst/mxf/mxfparse.c b/gst/mxf/mxfparse.c
index a3a4aa3d..6c2eb44c 100644
--- a/gst/mxf/mxfparse.c
+++ b/gst/mxf/mxfparse.c
@@ -435,13 +435,64 @@ mxf_product_version_parse (MXFProductVersion * product_version,
return TRUE;
}
+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,
const guint8 * data, guint size)
{
- guint i;
#ifndef GST_DISABLE_GST_DEBUG
+ guint i;
gchar str[48];
#endif
@@ -544,28 +595,19 @@ mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack,
GST_DEBUG (" operational pattern = %s",
mxf_ul_to_string (&pack->operational_pattern, str));
- pack->n_essence_containers = GST_READ_UINT32_BE (data);
- data += 4;
- size -= 4;
-
- GST_DEBUG (" number of essence containers = %u", pack->n_essence_containers);
-
- if (GST_READ_UINT32_BE (data) != 16)
- goto error;
- data += 4;
- size -= 4;
-
- if (size < 16 * pack->n_essence_containers)
+ if (!mxf_ul_array_parse (&pack->essence_containers,
+ &pack->n_essence_containers, data, size))
goto error;
+#ifndef GST_DISABLE_GST_DEBUG
+ GST_DEBUG (" number of essence containers = %u", pack->n_essence_containers);
if (pack->n_essence_containers) {
- pack->essence_containers = g_new (MXFUL, pack->n_essence_containers);
for (i = 0; i < pack->n_essence_containers; i++) {
- memcpy (&pack->essence_containers[i], data + i * 16, 16);
GST_DEBUG (" essence container %u = %s", i,
mxf_ul_to_string (&pack->essence_containers[i], str));
}
}
+#endif
pack->valid = TRUE;