Simplify parsing of UL/UUID arrays

Simplify parsing of UL/UUID arrays by abstracting it
into a separate function.
This commit is contained in:
Sebastian Dröge 2009-01-22 11:42:24 +01:00
parent cd80f534f5
commit 100dfc34d6
6 changed files with 640 additions and 1138 deletions

View file

@ -816,24 +816,24 @@ mxf_aes_bwf_create_caps (MXFMetadataTimelineTrack * track, GstTagList ** tags,
if (!track->parent.descriptor[i]) if (!track->parent.descriptor[i])
continue; continue;
if (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (track-> if (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (track->parent.
parent.descriptor[i]) descriptor[i])
&& (track->parent.descriptor[i]->essence_container.u[14] == 0x01 && (track->parent.descriptor[i]->essence_container.u[14] == 0x01
|| track->parent.descriptor[i]->essence_container.u[14] == 0x02 || track->parent.descriptor[i]->essence_container.u[14] == 0x02
|| track->parent.descriptor[i]->essence_container.u[14] == 0x08)) { || track->parent.descriptor[i]->essence_container.u[14] == 0x08)) {
s = (MXFMetadataGenericSoundEssenceDescriptor *) track-> s = (MXFMetadataGenericSoundEssenceDescriptor *) track->parent.
parent.descriptor[i]; descriptor[i];
bwf = TRUE; bwf = TRUE;
break; break;
} else } else
if (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (track-> if (MXF_IS_METADATA_GENERIC_SOUND_ESSENCE_DESCRIPTOR (track->parent.
parent.descriptor[i]) descriptor[i])
&& (track->parent.descriptor[i]->essence_container.u[14] == 0x03 && (track->parent.descriptor[i]->essence_container.u[14] == 0x03
|| track->parent.descriptor[i]->essence_container.u[14] == 0x04 || track->parent.descriptor[i]->essence_container.u[14] == 0x04
|| track->parent.descriptor[i]->essence_container.u[14] == 0x09)) { || track->parent.descriptor[i]->essence_container.u[14] == 0x09)) {
s = (MXFMetadataGenericSoundEssenceDescriptor *) track-> s = (MXFMetadataGenericSoundEssenceDescriptor *) track->parent.
parent.descriptor[i]; descriptor[i];
bwf = FALSE; bwf = FALSE;
break; break;
} }

File diff suppressed because it is too large Load diff

View file

@ -439,9 +439,9 @@ struct _MXFDMS1Framework {
MXFUL *titles_sets_uids; MXFUL *titles_sets_uids;
MXFDMS1Titles **titles_sets; MXFDMS1Titles **titles_sets;
guint32 n_annotations_sets; guint32 n_annotation_sets;
MXFUL *annotations_sets_uids; MXFUL *annotation_sets_uids;
MXFDMS1Annotation **annotations_sets; MXFDMS1Annotation **annotation_sets;
guint32 n_participant_sets; guint32 n_participant_sets;
MXFUL *participant_sets_uids; MXFUL *participant_sets_uids;

View file

@ -364,31 +364,22 @@ mxf_metadata_preface_handle_tag (MXFMetadataBase * metadata,
GST_DEBUG (" primary package = %s", GST_DEBUG (" primary package = %s",
mxf_ul_to_string (&self->primary_package_uid, str)); mxf_ul_to_string (&self->primary_package_uid, str));
break; break;
case 0x3b06:{ case 0x3b06:
guint32 len; if (!mxf_ul_array_parse (&self->identifications_uids,
guint i; &self->n_identifications, tag_data, tag_size))
if (tag_size < 8)
goto error;
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of identifications = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
self->n_identifications = len; GST_DEBUG (" number of identifications = %u", self->n_identifications);
self->identifications_uids = g_new (MXFUL, len); #ifndef GST_DISABLE_GST_DEBUG
for (i = 0; i < len; i++) { {
memcpy (&self->identifications_uids[i], tag_data + 8 + i * 16, 16); guint i;
GST_DEBUG (" identification %u = %s", i, for (i = 0; i < self->n_identifications; i++) {
mxf_ul_to_string (&self->identifications_uids[i], str)); GST_DEBUG (" identification %u = %s", i,
mxf_ul_to_string (&self->identifications_uids[i], str));
}
} }
#endif
break; break;
}
case 0x3b03: case 0x3b03:
if (tag_size != 16) if (tag_size != 16)
goto error; goto error;
@ -403,56 +394,39 @@ mxf_metadata_preface_handle_tag (MXFMetadataBase * metadata,
GST_DEBUG (" operational pattern = %s", GST_DEBUG (" operational pattern = %s",
mxf_ul_to_string (&self->operational_pattern, str)); mxf_ul_to_string (&self->operational_pattern, str));
break; break;
case 0x3b0a:{ case 0x3b0a:
guint32 len; if (!mxf_ul_array_parse (&self->essence_containers,
guint i; &self->n_essence_containers, tag_data, tag_size))
if (tag_size < 8)
goto error;
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of essence containers = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
self->n_essence_containers = len; GST_DEBUG (" number of essence containers = %u",
self->essence_containers = g_new (MXFUL, len); self->n_essence_containers);
for (i = 0; i < len; i++) { #ifndef GST_DISABLE_GST_DEBUG
memcpy (&self->essence_containers[i], tag_data + 8 + i * 16, 16); {
GST_DEBUG (" essence container %u = %s", i, guint i;
mxf_ul_to_string (&self->essence_containers[i], str)); for (i = 0; i < self->n_essence_containers; i++) {
GST_DEBUG (" essence container %u = %s", i,
mxf_ul_to_string (&self->essence_containers[i], str));
}
} }
#endif
break; break;
} case 0x3b0b:
case 0x3b0b:{ if (!mxf_ul_array_parse (&self->dm_schemes, &self->n_dm_schemes, tag_data,
guint32 len; tag_size))
guint i;
if (tag_size < 8)
goto error;
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of DM schemes = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
GST_DEBUG (" number of DM schemes = %u", self->n_dm_schemes);
self->n_dm_schemes = len; #ifndef GST_DISABLE_GST_DEBUG
self->dm_schemes = g_new (MXFUL, len); {
for (i = 0; i < len; i++) { guint i;
memcpy (&self->dm_schemes[i], tag_data + 8 + i * 16, 16); for (i = 0; i < self->n_dm_schemes; i++) {
GST_DEBUG (" DM schemes %u = %s", i, GST_DEBUG (" DM schemes %u = %s", i,
mxf_ul_to_string (&self->dm_schemes[i], str)); mxf_ul_to_string (&self->dm_schemes[i], str));
}
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS
@ -701,53 +675,38 @@ mxf_metadata_content_storage_handle_tag (MXFMetadataBase * metadata,
#endif #endif
switch (tag) { switch (tag) {
case 0x1901:{ case 0x1901:
guint32 len; if (!mxf_ul_array_parse (&self->packages_uids, &self->n_packages,
guint i; tag_data, tag_size))
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of packages = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error; goto error;
if (tag_size < 8 + len * 16) GST_DEBUG (" number of packages = %u", self->n_packages);
goto error; #ifndef GST_DISABLE_GST_DEBUG
{
self->packages_uids = g_new (MXFUL, len); guint i;
self->n_packages = len; for (i = 0; i < self->n_packages; i++) {
for (i = 0; i < len; i++) { GST_DEBUG (" package %u = %s", i,
memcpy (&self->packages_uids[i], tag_data + 8 + i * 16, 16); mxf_ul_to_string (&self->packages_uids[i], str));
GST_DEBUG (" package %u = %s", i, }
mxf_ul_to_string (&self->packages_uids[i], str));
} }
#endif
break; break;
} case 0x1902:
case 0x1902:{ if (!mxf_ul_array_parse (&self->essence_container_data_uids,
guint32 len; &self->n_essence_container_data, tag_data, tag_size))
guint i;
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of essence container data = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
self->essence_container_data_uids = g_new (MXFUL, len); GST_DEBUG (" number of essence container data = %u",
self->n_essence_container_data = len; self->n_essence_container_data);
for (i = 0; i < len; i++) { #ifndef GST_DISABLE_GST_DEBUG
memcpy (&self->essence_container_data_uids[i], {
tag_data + 8 + i * 16, 16); guint i;
GST_DEBUG (" essence container data %u = %s", i, for (i = 0; i < self->n_essence_container_data; i++) {
mxf_ul_to_string (&self->essence_container_data_uids[i], str)); GST_DEBUG (" essence container data %u = %s", i,
mxf_ul_to_string (&self->essence_container_data_uids[i], str));
}
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS
@ -1018,29 +977,22 @@ mxf_metadata_generic_package_handle_tag (MXFMetadataBase * metadata,
self->package_modified_date.second, self->package_modified_date.second,
(self->package_modified_date.quarter_msecond * 1000) / 256); (self->package_modified_date.quarter_msecond * 1000) / 256);
break; break;
case 0x4403:{ case 0x4403:
guint32 len; if (!mxf_ul_array_parse (&self->tracks_uids, &self->n_tracks, tag_data,
guint i; tag_size))
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of tracks = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
self->tracks_uids = g_new (MXFUL, len); GST_DEBUG (" number of tracks = %u", self->n_tracks);
self->n_tracks = len; #ifndef GST_DISABLE_GST_DEBUG
for (i = 0; i < len; i++) { {
memcpy (&self->tracks_uids[i], tag_data + 8 + i * 16, 16); guint i;
GST_DEBUG (" track %u = %s", i, for (i = 0; i < self->n_tracks; i++) {
mxf_ul_to_string (&self->tracks_uids[i], str)); GST_DEBUG (" track %u = %s", i,
mxf_ul_to_string (&self->tracks_uids[i], str));
}
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS
@ -1687,30 +1639,23 @@ mxf_metadata_sequence_handle_tag (MXFMetadataBase * metadata,
self->duration = GST_READ_UINT64_BE (tag_data); self->duration = GST_READ_UINT64_BE (tag_data);
GST_DEBUG (" duration = %" G_GINT64_FORMAT, self->duration); GST_DEBUG (" duration = %" G_GINT64_FORMAT, self->duration);
break; break;
case 0x1001:{ case 0x1001:
guint32 len; if (!mxf_ul_array_parse (&self->structural_components_uids,
guint i; &self->n_structural_components, tag_data, tag_size))
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of structural components = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error;
if (tag_size < 8 + len * 16)
goto error; goto error;
self->structural_components_uids = g_new (MXFUL, len); GST_DEBUG (" number of structural components = %u",
self->n_structural_components = len; self->n_structural_components);
for (i = 0; i < len; i++) { #ifndef GST_DISABLE_GST_DEBUG
memcpy (&self->structural_components_uids[i], {
tag_data + 8 + i * 16, 16); guint i;
GST_DEBUG (" structural component %u = %s", i, for (i = 0; i < self->n_structural_components; i++) {
mxf_ul_to_string (&self->structural_components_uids[i], str)); GST_DEBUG (" structural component %u = %s", i,
mxf_ul_to_string (&self->structural_components_uids[i], str));
}
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS
@ -2276,30 +2221,22 @@ mxf_metadata_generic_descriptor_handle_tag (MXFMetadataBase * metadata,
#endif #endif
switch (tag) { switch (tag) {
case 0x2f01:{ case 0x2f01:
guint32 len; if (!mxf_ul_array_parse (&self->locators_uids, &self->n_locators,
guint i; tag_data, tag_size))
if (tag_size < 8)
goto error; goto error;
len = GST_READ_UINT32_BE (tag_data); GST_DEBUG (" number of locators = %u", self->n_locators);
GST_DEBUG (" number of locators = %u", len); #ifndef GST_DISABLE_GST_DEBUG
if (len == 0) {
return TRUE; guint i;
for (i = 0; i < self->n_locators; i++) {
if (GST_READ_UINT32_BE (tag_data + 4) != 16) GST_DEBUG (" locator %u = %s", i,
goto error; mxf_ul_to_string (&self->locators_uids[i], str));
}
self->locators_uids = g_new (MXFUL, len);
self->n_locators = len;
for (i = 0; i < len; i++) {
memcpy (&self->locators_uids[i], tag_data + 8 + i * 16, 16);
GST_DEBUG (" locator %u = %s", i,
mxf_ul_to_string (&self->locators_uids[i], str));
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS
@ -3175,37 +3112,23 @@ mxf_metadata_multiple_descriptor_handle_tag (MXFMetadataBase * metadata,
#endif #endif
switch (tag) { switch (tag) {
case 0x3f01:{ case 0x3f01:
guint32 len; if (!mxf_ul_array_parse (&self->sub_descriptors_uids,
guint i; &self->n_sub_descriptors, tag_data, tag_size))
if (tag_size < 8)
goto error;
len = GST_READ_UINT32_BE (tag_data);
GST_DEBUG (" number of sub descriptors = %u", len);
if (len == 0)
return TRUE;
if (GST_READ_UINT32_BE (tag_data + 4) != 16)
goto error; goto error;
tag_data += 8; GST_DEBUG (" number of sub descriptors = %u", self->n_sub_descriptors);
tag_size -= 8; #ifndef GST_DISABLE_GST_DEBUG
if (tag_size < len * 16) {
goto error; guint i;
for (i = 0; i < self->n_sub_descriptors; i++) {
self->n_sub_descriptors = len; GST_DEBUG (" sub descriptor %u = %s", i,
self->sub_descriptors_uids = g_new (MXFUL, len); mxf_ul_to_string (&self->sub_descriptors_uids[i], str));
for (i = 0; i < len; i++) { }
memcpy (&self->sub_descriptors_uids[i], tag_data, 16);
tag_data += 16;
tag_size -= 16;
GST_DEBUG (" sub descriptor %u = %s", i,
mxf_ul_to_string (&self->sub_descriptors_uids[i], str));
} }
#endif
break; break;
}
default: default:
ret = ret =
MXF_METADATA_BASE_CLASS MXF_METADATA_BASE_CLASS

View file

@ -435,13 +435,64 @@ mxf_product_version_parse (MXFProductVersion * product_version,
return TRUE; 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 */ /* SMPTE 377M 6.1, Table 2 */
gboolean gboolean
mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack, mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack,
const guint8 * data, guint size) const guint8 * data, guint size)
{ {
guint i;
#ifndef GST_DISABLE_GST_DEBUG #ifndef GST_DISABLE_GST_DEBUG
guint i;
gchar str[48]; gchar str[48];
#endif #endif
@ -544,28 +595,19 @@ mxf_partition_pack_parse (const MXFUL * key, MXFPartitionPack * pack,
GST_DEBUG (" operational pattern = %s", GST_DEBUG (" operational pattern = %s",
mxf_ul_to_string (&pack->operational_pattern, str)); mxf_ul_to_string (&pack->operational_pattern, str));
pack->n_essence_containers = GST_READ_UINT32_BE (data); if (!mxf_ul_array_parse (&pack->essence_containers,
data += 4; &pack->n_essence_containers, data, size))
size -= 4; goto error;
#ifndef GST_DISABLE_GST_DEBUG
GST_DEBUG (" number of essence containers = %u", pack->n_essence_containers); 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)
goto error;
if (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++) { 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, GST_DEBUG (" essence container %u = %s", i,
mxf_ul_to_string (&pack->essence_containers[i], str)); mxf_ul_to_string (&pack->essence_containers[i], str));
} }
} }
#endif
pack->valid = TRUE; pack->valid = TRUE;

View file

@ -76,6 +76,8 @@ gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, gui
gboolean mxf_timestamp_is_unknown (const MXFTimestamp *a); gboolean mxf_timestamp_is_unknown (const MXFTimestamp *a);
gint mxf_timestamp_compare (const MXFTimestamp *a, const MXFTimestamp *b); gint mxf_timestamp_compare (const MXFTimestamp *a, const MXFTimestamp *b);
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); gboolean mxf_partition_pack_parse (const MXFUL *key, MXFPartitionPack *pack, const guint8 *data, guint size);
void mxf_partition_pack_reset (MXFPartitionPack *pack); void mxf_partition_pack_reset (MXFPartitionPack *pack);