diff --git a/gst/mxf/mxfdemux.c b/gst/mxf/mxfdemux.c index e798365adf..1033f08fef 100644 --- a/gst/mxf/mxfdemux.c +++ b/gst/mxf/mxfdemux.c @@ -216,17 +216,10 @@ gst_mxf_demux_reset_mxf_state (GstMXFDemux * demux) } static void -gst_mxf_demux_reset_metadata (GstMXFDemux * demux) +gst_mxf_demux_reset_track_metadata (GstMXFDemux *demux) { guint i; - GST_DEBUG_OBJECT (demux, "Resetting metadata"); - - demux->update_metadata = TRUE; - demux->metadata_resolved = FALSE; - - demux->current_package = NULL; - if (demux->src) { for (i = 0; i < demux->src->len; i++) { GstMXFDemuxPad *pad = g_ptr_array_index (demux->src, i); @@ -241,19 +234,24 @@ gst_mxf_demux_reset_metadata (GstMXFDemux * demux) pad->source_package = NULL; } } +} + +static void +gst_mxf_demux_reset_metadata (GstMXFDemux * demux) +{ + GST_DEBUG_OBJECT (demux, "Resetting metadata"); + + demux->update_metadata = TRUE; + demux->metadata_resolved = FALSE; + + gst_mxf_demux_reset_track_metadata (demux); + + demux->current_package = NULL; demux->preface = NULL; if (demux->metadata) { - guint i; - - for (i = 0; i < demux->metadata->len; i++) { - GstMiniObject *o = g_ptr_array_index (demux->metadata, i); - - if (o) - gst_mini_object_unref (o); - } - g_ptr_array_free (demux->metadata, TRUE); + g_hash_table_destroy (demux->metadata); demux->metadata = NULL; } } @@ -476,8 +474,9 @@ gst_mxf_demux_handle_primer_pack (GstMXFDemux * demux, const MXFUL * key, static GstFlowReturn gst_mxf_demux_handle_header_metadata_resolve_references (GstMXFDemux * demux) { - guint i; GstFlowReturn ret = GST_FLOW_OK; + GHashTableIter iter; + MXFMetadataBase *m = NULL; GST_DEBUG_OBJECT (demux, "Resolve metadata references"); demux->update_metadata = FALSE; @@ -487,17 +486,16 @@ gst_mxf_demux_handle_header_metadata_resolve_references (GstMXFDemux * demux) return GST_FLOW_ERROR; } - /* Append NULL terminator */ - g_ptr_array_add (demux->metadata, NULL); + g_hash_table_iter_init (&iter, demux->metadata); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) & m)) { + m->resolved = MXF_METADATA_BASE_RESOLVE_STATE_NONE; + } - for (i = 0; i < demux->metadata->len - 1; i++) { - MXFMetadataBase *m = - MXF_METADATA_BASE (g_ptr_array_index (demux->metadata, i)); + g_hash_table_iter_init (&iter, demux->metadata); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) & m)) { gboolean resolved; - resolved = - mxf_metadata_base_resolve (m, - (MXFMetadataBase **) demux->metadata->pdata); + resolved = mxf_metadata_base_resolve (m, demux->metadata); /* Resolving can fail for anything but the preface, as the preface * will resolve everything required */ @@ -865,7 +863,7 @@ gst_mxf_demux_handle_metadata (GstMXFDemux * demux, const MXFUL * key, GstBuffer * buffer) { guint16 type; - MXFMetadata *metadata = NULL; + MXFMetadata *metadata = NULL, *old = NULL; GstFlowReturn ret = GST_FLOW_OK; type = GST_READ_UINT16_BE (key->u + 13); @@ -886,44 +884,43 @@ gst_mxf_demux_handle_metadata (GstMXFDemux * demux, const MXFUL * key, } metadata = - mxf_metadata_new (type, &demux->primer, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); - - if (metadata && !MXF_IS_METADATA_PREFACE (metadata) - && !demux->update_metadata) { - GST_DEBUG_OBJECT (demux, - "Skipping parsing of metadata because it's older than what we have"); - gst_mini_object_unref ((GstMiniObject *) metadata); - return GST_FLOW_OK; - } + mxf_metadata_new (type, &demux->primer, demux->offset, + GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); if (!metadata) { GST_ERROR_OBJECT (demux, "Parsing metadata failed"); return GST_FLOW_ERROR; } - if (MXF_IS_METADATA_PREFACE (metadata)) { - MXFMetadataPreface *preface = MXF_METADATA_PREFACE (metadata); + if (!demux->metadata) + demux->metadata = mxf_metadata_hash_table_new (); - if (!demux->preface - || (!mxf_timestamp_is_unknown (&preface->last_modified_date) - && mxf_timestamp_compare (&demux->preface->last_modified_date, - &preface->last_modified_date) < 0)) { - GST_DEBUG_OBJECT (demux, - "Timestamp of new preface is newer than old, updating metadata"); - gst_mxf_demux_reset_metadata (demux); - demux->preface = preface; - } else { - GST_DEBUG_OBJECT (demux, "Preface is older than already parsed preface"); - gst_mini_object_unref ((GstMiniObject *) metadata); - return GST_FLOW_OK; - } + old = + g_hash_table_lookup (demux->metadata, + &MXF_METADATA_BASE (metadata)->instance_uid); + if (old + && MXF_METADATA_BASE (old)->offset >= + MXF_METADATA_BASE (metadata)->offset) { +#ifndef GST_DISABLE_GST_DEBUG + gchar str[48]; +#endif + + GST_DEBUG_OBJECT (demux, + "Metadata with instance uid %s already exists and is newer", + mxf_ul_to_string (&MXF_METADATA_BASE (metadata)->instance_uid, str)); + gst_mini_object_unref (GST_MINI_OBJECT (metadata)); + return GST_FLOW_OK; } - if (!demux->metadata) - demux->metadata = g_ptr_array_new (); + if (MXF_IS_METADATA_PREFACE (metadata)) { + demux->preface = MXF_METADATA_PREFACE (metadata); + } - g_ptr_array_add (demux->metadata, metadata); + demux->update_metadata = TRUE; + gst_mxf_demux_reset_track_metadata (demux); + + g_hash_table_replace (demux->metadata, + &MXF_METADATA_BASE (metadata)->instance_uid, metadata); return ret; } @@ -935,7 +932,7 @@ gst_mxf_demux_handle_descriptive_metadata (GstMXFDemux * demux, guint32 type; guint8 scheme; GstFlowReturn ret = GST_FLOW_OK; - MXFDescriptiveMetadata *m = NULL; + MXFDescriptiveMetadata *m = NULL, *old = NULL; scheme = GST_READ_UINT8 (key->u + 12); type = GST_READ_UINT24_BE (key->u + 13); @@ -955,14 +952,7 @@ gst_mxf_demux_handle_descriptive_metadata (GstMXFDemux * demux, return GST_FLOW_ERROR; } - if (!demux->update_metadata) { - GST_DEBUG_OBJECT (demux, - "Skipping parsing of metadata because it's older than what we have"); - return GST_FLOW_OK; - } - - - m = mxf_descriptive_metadata_new (scheme, type, &demux->primer, + m = mxf_descriptive_metadata_new (scheme, type, &demux->primer, demux->offset, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer)); if (!m) { @@ -973,10 +963,28 @@ gst_mxf_demux_handle_descriptive_metadata (GstMXFDemux * demux, } if (!demux->metadata) - demux->metadata = g_ptr_array_new (); + demux->metadata = mxf_metadata_hash_table_new (); - g_ptr_array_add (demux->metadata, m); + old = + g_hash_table_lookup (demux->metadata, + &MXF_METADATA_BASE (m)->instance_uid); + if (old && MXF_METADATA_BASE (old)->offset >= MXF_METADATA_BASE (m)->offset) { +#ifndef GST_DISABLE_GST_DEBUG + gchar str[48]; +#endif + GST_DEBUG_OBJECT (demux, + "Metadata with instance uid %s already exists and is newer", + mxf_ul_to_string (&MXF_METADATA_BASE (m)->instance_uid, str)); + gst_mini_object_unref (GST_MINI_OBJECT (m)); + return GST_FLOW_OK; + } + + demux->update_metadata = TRUE; + gst_mxf_demux_reset_track_metadata (demux); + + g_hash_table_replace (demux->metadata, &MXF_METADATA_BASE (m)->instance_uid, + m); return ret; } @@ -1502,7 +1510,7 @@ gst_mxf_demux_parse_footer_metadata (GstMXFDemux * demux) { MXFPartitionPack partition; MXFPrimerPack primer; - guint64 offset, old_offset = demux->offset; + guint64 old_offset = demux->offset; MXFUL key; GstBuffer *buffer = NULL; guint read = 0; @@ -1516,21 +1524,23 @@ gst_mxf_demux_parse_footer_metadata (GstMXFDemux * demux) gst_mxf_demux_reset_metadata (demux); if (demux->footer_partition_pack_offset != 0) { - offset = + demux->offset = demux->header_partition_pack_offset + demux->footer_partition_pack_offset; } else { MXFRandomIndexPackEntry *entry = &g_array_index (demux->partition_index, MXFRandomIndexPackEntry, demux->partition_index->len - 1); - offset = entry->offset; + demux->offset = entry->offset; } next_try: mxf_partition_pack_reset (&demux->partition); mxf_primer_pack_reset (&demux->primer); - ret = gst_mxf_demux_pull_klv_packet (demux, offset, &key, &buffer, &read); + ret = + gst_mxf_demux_pull_klv_packet (demux, demux->offset, &key, &buffer, + &read); if (G_UNLIKELY (ret != GST_FLOW_OK)) goto out; @@ -1541,7 +1551,7 @@ next_try: GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer))) goto out; - offset += read; + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; @@ -1550,44 +1560,46 @@ next_try: || demux->partition.this_partition == 0) goto out; - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; } while (TRUE) { - ret = gst_mxf_demux_pull_klv_packet (demux, offset, &key, &buffer, &read); + ret = + gst_mxf_demux_pull_klv_packet (demux, demux->offset, &key, &buffer, + &read); if (G_UNLIKELY (ret != GST_FLOW_OK)) { - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; } if (mxf_is_fill (&key)) { - offset += read; + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; } else if (mxf_is_primer_pack (&key)) { if (!mxf_primer_pack_parse (&key, &demux->primer, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer))) { - offset += read; + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; } - offset += read; + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; break; } else { gst_buffer_unref (buffer); buffer = NULL; - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; @@ -1596,9 +1608,11 @@ next_try: /* parse metadata */ while (TRUE) { - ret = gst_mxf_demux_pull_klv_packet (demux, offset, &key, &buffer, &read); + ret = + gst_mxf_demux_pull_klv_packet (demux, demux->offset, &key, &buffer, + &read); if (G_UNLIKELY (ret != GST_FLOW_OK)) { - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; @@ -1606,19 +1620,24 @@ next_try: if (mxf_is_metadata (&key)) { ret = gst_mxf_demux_handle_metadata (demux, &key, buffer); - offset += read; + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; if (G_UNLIKELY (ret != GST_FLOW_OK)) { gst_mxf_demux_reset_metadata (demux); - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; } - } else if (mxf_is_descriptive_metadata (&key) || mxf_is_fill (&key)) { - offset += read; + } else if (mxf_is_descriptive_metadata (&key)) { + ret = gst_mxf_demux_handle_descriptive_metadata (demux, &key, buffer); + demux->offset += read; + gst_buffer_unref (buffer); + buffer = NULL; + } else if (mxf_is_fill (&key)) { + demux->offset += read; gst_buffer_unref (buffer); buffer = NULL; } else { @@ -1632,7 +1651,7 @@ next_try: GST_FLOW_OK || gst_mxf_demux_handle_header_metadata_update_streams (demux) != GST_FLOW_OK) { - offset = + demux->offset = demux->header_partition_pack_offset + demux->partition.this_partition - demux->partition.prev_partition; goto next_try; diff --git a/gst/mxf/mxfdemux.h b/gst/mxf/mxfdemux.h index 847e93a1ac..4ba4221e84 100644 --- a/gst/mxf/mxfdemux.h +++ b/gst/mxf/mxfdemux.h @@ -81,7 +81,7 @@ struct _GstMXFDemux gboolean metadata_resolved; MXFMetadataPreface *preface; - GPtrArray *metadata; + GHashTable *metadata; MXFUMID current_package_uid; MXFMetadataGenericPackage *current_package; diff --git a/gst/mxf/mxfdms1.c b/gst/mxf/mxfdms1.c index 7880899100..e4105b8f58 100644 --- a/gst/mxf/mxfdms1.c +++ b/gst/mxf/mxfdms1.c @@ -272,68 +272,68 @@ mxf_dms1_framework_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_framework_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_framework_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Framework *self = MXF_DMS1_FRAMEWORK (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->titles_sets = g_new0 (MXFDMS1Titles *, self->n_titles_sets); - self->annotation_sets = g_new0 (MXFDMS1Annotation *, self->n_annotation_sets); - self->participant_sets = - g_new0 (MXFDMS1Participant *, self->n_participant_sets); - self->location_sets = g_new0 (MXFDMS1Location *, self->n_location_sets); - while (*p != NULL) { - current = *p; + if (self->titles_sets) + memset (self->titles_sets, 0, sizeof (gpointer) * self->n_titles_sets); + else + self->titles_sets = g_new0 (MXFDMS1Titles *, self->n_titles_sets); - if (MXF_IS_DMS1_TITLES (current)) { - for (i = 0; i < self->n_titles_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->titles_sets_uids[i])) { - self->titles_sets[i] = MXF_DMS1_TITLES (current); - break; - } - } + if (self->annotation_sets) + memset (self->annotation_sets, 0, + sizeof (gpointer) * self->n_annotation_sets); + else + self->annotation_sets = + g_new0 (MXFDMS1Annotation *, self->n_annotation_sets); + + if (self->participant_sets) + memset (self->participant_sets, 0, + sizeof (gpointer) * self->n_participant_sets); + else + self->participant_sets = + g_new0 (MXFDMS1Participant *, self->n_participant_sets); + + if (self->location_sets) + memset (self->location_sets, 0, sizeof (gpointer) * self->n_location_sets); + else + self->location_sets = g_new0 (MXFDMS1Location *, self->n_location_sets); + + for (i = 0; i < self->n_titles_sets; i++) { + current = g_hash_table_lookup (metadata, &self->titles_sets_uids[i]); + + if (current && MXF_IS_DMS1_TITLES (current)) { + self->titles_sets[i] = MXF_DMS1_TITLES (current); } + } - if (MXF_IS_DMS1_ANNOTATION (current)) { - for (i = 0; i < self->n_annotation_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->annotation_sets_uids[i])) { - self->annotation_sets[i] = MXF_DMS1_ANNOTATION (current); - break; - } - } + for (i = 0; i < self->n_annotation_sets; i++) { + current = g_hash_table_lookup (metadata, &self->annotation_sets_uids[i]); + if (current && MXF_IS_DMS1_ANNOTATION (current)) { + self->annotation_sets[i] = MXF_DMS1_ANNOTATION (current); } + } - if (MXF_IS_DMS1_PARTICIPANT (current)) { - for (i = 0; i < self->n_participant_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->participant_sets_uids[i])) { - self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); - break; - } - } + for (i = 0; i < self->n_participant_sets; i++) { + current = g_hash_table_lookup (metadata, &self->participant_sets_uids[i]); + if (current && MXF_IS_DMS1_PARTICIPANT (current)) { + self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); } + } - if (MXF_IS_DMS1_CONTACTS_LIST (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->contacts_list_set_uid)) { - self->contacts_list_set = MXF_DMS1_CONTACTS_LIST (current); - } + current = g_hash_table_lookup (metadata, &self->contacts_list_set_uid); + if (current && MXF_IS_DMS1_CONTACTS_LIST (current)) { + self->contacts_list_set = MXF_DMS1_CONTACTS_LIST (current); + } + + for (i = 0; i < self->n_location_sets; i++) { + current = g_hash_table_lookup (metadata, &self->location_sets_uids[i]); + if (current && MXF_IS_DMS1_LOCATION (current)) { + self->location_sets[i] = MXF_DMS1_LOCATION (current); } - - if (MXF_IS_DMS1_LOCATION (current)) { - for (i = 0; i < self->n_location_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->location_sets_uids[i])) { - self->location_sets[i] = MXF_DMS1_LOCATION (current); - break; - } - } - } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_framework_parent_class)->resolve (m, @@ -578,53 +578,51 @@ mxf_dms1_production_clip_framework_finalize (GstMiniObject * object) static gboolean mxf_dms1_production_clip_framework_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFDMS1ProductionClipFramework *self = MXF_DMS1_PRODUCTION_CLIP_FRAMEWORK (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->captions_description_sets = - g_new0 (MXFDMS1CaptionsDescription *, self->n_captions_description_sets); - self->contract_sets = g_new0 (MXFDMS1Contract *, self->n_contract_sets); - while (*p) { - current = *p; + if (self->captions_description_sets) + memset (self->captions_description_sets, 0, + sizeof (gpointer) * self->n_captions_description_sets); + else + self->captions_description_sets = + g_new0 (MXFDMS1CaptionsDescription *, + self->n_captions_description_sets); - if (MXF_IS_DMS1_PICTURE_FORMAT (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->picture_format_set_uid)) { - self->picture_format = MXF_DMS1_PICTURE_FORMAT (current); - } + if (self->contract_sets) + memset (self->contract_sets, 0, + sizeof (gpointer) * self->n_captions_description_sets); + else + self->contract_sets = g_new0 (MXFDMS1Contract *, self->n_contract_sets); + + current = g_hash_table_lookup (metadata, &self->picture_format_set_uid); + if (current && MXF_IS_DMS1_PICTURE_FORMAT (current)) { + self->picture_format = MXF_DMS1_PICTURE_FORMAT (current); + } + + for (i = 0; i < self->n_captions_description_sets; i++) { + current = + g_hash_table_lookup (metadata, + &self->captions_description_sets_uids[i]); + if (current && MXF_IS_DMS1_CAPTIONS_DESCRIPTION (current)) { + self->captions_description_sets[i] = + MXF_DMS1_CAPTIONS_DESCRIPTION (current); } + } - if (MXF_IS_DMS1_CAPTIONS_DESCRIPTION (current)) { - for (i = 0; i < self->n_captions_description_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->captions_description_sets_uids[i])) { - self->captions_description_sets[i] = - MXF_DMS1_CAPTIONS_DESCRIPTION (current); - break; - } - } + for (i = 0; i < self->n_contract_sets; i++) { + current = g_hash_table_lookup (metadata, &self->contract_sets_uids[i]); + if (current && MXF_IS_DMS1_CONTRACT (current)) { + self->contract_sets[i] = MXF_DMS1_CONTRACT (current); } + } - if (MXF_IS_DMS1_CONTRACT (current)) { - for (i = 0; i < self->n_contract_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->contract_sets_uids[i])) { - self->contract_sets[i] = MXF_DMS1_CONTRACT (current); - break; - } - } - } - - if (MXF_IS_DMS1_PROJECT (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->project_set_uid)) { - self->project_set = MXF_DMS1_PROJECT (current); - } - } - - p++; + current = g_hash_table_lookup (metadata, &self->project_set_uid); + if (current && MXF_IS_DMS1_PROJECT (current)) { + self->project_set = MXF_DMS1_PROJECT (current); } return @@ -799,78 +797,91 @@ mxf_dms1_production_framework_finalize (GstMiniObject * object) static gboolean mxf_dms1_production_framework_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFDMS1ProductionFramework *self = MXF_DMS1_PRODUCTION_FRAMEWORK (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->identification_sets = - g_new0 (MXFDMS1Identification *, self->n_identification_sets); - self->group_relationship_sets = - g_new0 (MXFDMS1GroupRelationship *, self->n_group_relationship_sets); - self->branding_sets = g_new0 (MXFDMS1Branding *, self->n_branding_sets); - self->event_sets = g_new0 (MXFDMS1Event *, self->n_event_sets); - self->award_sets = g_new0 (MXFDMS1Award *, self->n_award_sets); - self->setting_period_sets = - g_new0 (MXFDMS1SettingPeriod *, self->n_setting_period_sets); - while (*p) { - current = *p; + if (self->identification_sets) + memset (self->identification_sets, 0, + sizeof (gpointer) * self->n_identification_sets); + else + self->identification_sets = + g_new0 (MXFDMS1Identification *, self->n_identification_sets); - if (MXF_IS_DMS1_IDENTIFICATION (current)) { - for (i = 0; i < self->n_identification_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->identification_sets_uids[i])) { - self->identification_sets[i] = MXF_DMS1_IDENTIFICATION (current); - } - } + if (self->group_relationship_sets) + memset (self->group_relationship_sets, 0, + sizeof (gpointer) * self->n_group_relationship_sets); + else + self->group_relationship_sets = + g_new0 (MXFDMS1GroupRelationship *, self->n_group_relationship_sets); + + if (self->branding_sets) + memset (self->branding_sets, 0, sizeof (gpointer) * self->n_branding_sets); + else + self->branding_sets = g_new0 (MXFDMS1Branding *, self->n_branding_sets); + + if (self->event_sets) + memset (self->event_sets, 0, sizeof (gpointer) * self->n_event_sets); + else + self->event_sets = g_new0 (MXFDMS1Event *, self->n_event_sets); + + if (self->award_sets) + memset (self->award_sets, 0, sizeof (gpointer) * self->n_award_sets); + else + self->award_sets = g_new0 (MXFDMS1Award *, self->n_award_sets); + + if (self->setting_period_sets) + memset (self->setting_period_sets, 0, + sizeof (gpointer) * self->n_setting_period_sets); + else + self->setting_period_sets = + g_new0 (MXFDMS1SettingPeriod *, self->n_setting_period_sets); + + for (i = 0; i < self->n_identification_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->identification_sets_uids[i]); + if (current && MXF_IS_DMS1_IDENTIFICATION (current)) { + self->identification_sets[i] = MXF_DMS1_IDENTIFICATION (current); } + } - if (MXF_IS_DMS1_GROUP_RELATIONSHIP (current)) { - for (i = 0; i < self->n_group_relationship_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->group_relationship_sets_uids[i])) { - self->group_relationship_sets[i] = - MXF_DMS1_GROUP_RELATIONSHIP (current); - } - } + for (i = 0; i < self->n_group_relationship_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->group_relationship_sets_uids[i]); + if (current && MXF_IS_DMS1_GROUP_RELATIONSHIP (current)) { + self->group_relationship_sets[i] = MXF_DMS1_GROUP_RELATIONSHIP (current); } + } - if (MXF_IS_DMS1_BRANDING (current)) { - for (i = 0; i < self->n_branding_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->branding_sets_uids[i])) { - self->branding_sets[i] = MXF_DMS1_BRANDING (current); - } - } + for (i = 0; i < self->n_branding_sets; i++) { + current = g_hash_table_lookup (metadata, &self->branding_sets_uids[i]); + if (current && MXF_IS_DMS1_BRANDING (current)) { + self->branding_sets[i] = MXF_DMS1_BRANDING (current); } + } - if (MXF_IS_DMS1_EVENT (current)) { - for (i = 0; i < self->n_event_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->event_sets_uids[i])) { - self->event_sets[i] = MXF_DMS1_EVENT (current); - } - } + for (i = 0; i < self->n_event_sets; i++) { + current = g_hash_table_lookup (metadata, &self->event_sets_uids[i]); + if (current && MXF_IS_DMS1_EVENT (current)) { + self->event_sets[i] = MXF_DMS1_EVENT (current); } + } - if (MXF_IS_DMS1_AWARD (current)) { - for (i = 0; i < self->n_award_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->award_sets_uids[i])) { - self->award_sets[i] = MXF_DMS1_AWARD (current); - } - } + for (i = 0; i < self->n_award_sets; i++) { + current = g_hash_table_lookup (metadata, &self->award_sets_uids[i]); + if (current && MXF_IS_DMS1_AWARD (current)) { + self->award_sets[i] = MXF_DMS1_AWARD (current); } + } - if (MXF_IS_DMS1_SETTING_PERIOD (current)) { - for (i = 0; i < self->n_setting_period_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->setting_period_sets_uids[i])) { - self->setting_period_sets[i] = MXF_DMS1_SETTING_PERIOD (current); - } - } + for (i = 0; i < self->n_setting_period_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->setting_period_sets_uids[i]); + if (current && MXF_IS_DMS1_SETTING_PERIOD (current)) { + self->setting_period_sets[i] = MXF_DMS1_SETTING_PERIOD (current); } - - p++; } return @@ -1087,58 +1098,56 @@ mxf_dms1_clip_framework_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_clip_framework_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_dms1_clip_framework_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1ClipFramework *self = MXF_DMS1_CLIP_FRAMEWORK (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->scripting_sets = g_new0 (MXFDMS1Scripting *, self->n_scripting_sets); - self->shot_sets = g_new0 (MXFDMS1Shot *, self->n_shot_sets); - self->device_parameters_sets = - g_new0 (MXFDMS1DeviceParameters *, self->n_device_parameters_sets); + if (self->scripting_sets) + memset (self->scripting_sets, 0, + sizeof (gpointer) * self->n_scripting_sets); + else + self->scripting_sets = g_new0 (MXFDMS1Scripting *, self->n_scripting_sets); - while (*p) { - current = *p; + if (self->shot_sets) + memset (self->shot_sets, 0, sizeof (gpointer) * self->n_shot_sets); + else + self->shot_sets = g_new0 (MXFDMS1Shot *, self->n_shot_sets); - if (MXF_IS_DMS1_SCRIPTING (current)) { - for (i = 0; i < self->n_scripting_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->scripting_sets_uids[i])) { - self->scripting_sets[i] = MXF_DMS1_SCRIPTING (current); - break; - } - } + if (self->device_parameters_sets) + memset (self->device_parameters_sets, 0, + sizeof (gpointer) * self->n_device_parameters_sets); + else + self->device_parameters_sets = + g_new0 (MXFDMS1DeviceParameters *, self->n_device_parameters_sets); + + for (i = 0; i < self->n_scripting_sets; i++) { + current = g_hash_table_lookup (metadata, &self->scripting_sets_uids[i]); + + if (current && MXF_IS_DMS1_SCRIPTING (current)) { + self->scripting_sets[i] = MXF_DMS1_SCRIPTING (current); } + } - if (MXF_IS_DMS1_SHOT (current)) { - for (i = 0; i < self->n_shot_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->shot_sets_uids[i])) { - self->shot_sets[i] = MXF_DMS1_SHOT (current); - break; - } - } + for (i = 0; i < self->n_shot_sets; i++) { + current = g_hash_table_lookup (metadata, &self->shot_sets_uids[i]); + if (current && MXF_IS_DMS1_SHOT (current)) { + self->shot_sets[i] = MXF_DMS1_SHOT (current); } + } - if (MXF_IS_DMS1_DEVICE_PARAMETERS (current)) { - for (i = 0; i < self->n_device_parameters_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->device_parameters_sets_uids[i])) { - self->device_parameters_sets[i] = - MXF_DMS1_DEVICE_PARAMETERS (current); - break; - } - } + for (i = 0; i < self->n_device_parameters_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->device_parameters_sets_uids[i]); + if (current && MXF_IS_DMS1_DEVICE_PARAMETERS (current)) { + self->device_parameters_sets[i] = MXF_DMS1_DEVICE_PARAMETERS (current); } + } - if (MXF_IS_DMS1_PROCESSING (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->processing_set_uid)) { - self->processing_set = MXF_DMS1_PROCESSING (current); - } - } - - p++; + current = g_hash_table_lookup (metadata, &self->processing_set_uid); + if (current && MXF_IS_DMS1_PROCESSING (current)) { + self->processing_set = MXF_DMS1_PROCESSING (current); } return @@ -1354,41 +1363,38 @@ mxf_dms1_scene_framework_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_scene_framework_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_dms1_scene_framework_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1SceneFramework *self = MXF_DMS1_SCENE_FRAMEWORK (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->setting_period_sets = - g_new0 (MXFDMS1SettingPeriod *, self->n_setting_period_sets); - self->shot_scene_sets = g_new0 (MXFDMS1Shot *, self->n_shot_scene_sets); + if (self->setting_period_sets) + memset (self->setting_period_sets, 0, + sizeof (gpointer) * self->n_setting_period_sets); + else + self->setting_period_sets = + g_new0 (MXFDMS1SettingPeriod *, self->n_setting_period_sets); - while (*p) { - current = *p; + if (self->shot_scene_sets) + memset (self->shot_scene_sets, 0, + sizeof (gpointer) * self->n_shot_scene_sets); + else + self->shot_scene_sets = g_new0 (MXFDMS1Shot *, self->n_shot_scene_sets); - if (MXF_IS_DMS1_SETTING_PERIOD (current)) { - for (i = 0; i < self->n_setting_period_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->setting_period_sets_uids[i])) { - self->setting_period_sets[i] = MXF_DMS1_SETTING_PERIOD (current); - break; - } - } + for (i = 0; i < self->n_setting_period_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->setting_period_sets_uids[i]); + if (current && MXF_IS_DMS1_SETTING_PERIOD (current)) { + self->setting_period_sets[i] = MXF_DMS1_SETTING_PERIOD (current); } + } - if (MXF_IS_DMS1_SHOT (current)) { - for (i = 0; i < self->n_shot_scene_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->shot_scene_sets_uids[i])) { - self->shot_scene_sets[i] = MXF_DMS1_SHOT (current); - break; - } - } + for (i = 0; i < self->n_shot_scene_sets; i++) { + current = g_hash_table_lookup (metadata, &self->shot_scene_sets_uids[i]); + if (current && MXF_IS_DMS1_SHOT (current)) { + self->shot_scene_sets[i] = MXF_DMS1_SHOT (current); } - - p++; } return @@ -1924,40 +1930,38 @@ mxf_dms1_event_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_event_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_event_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Event *self = MXF_DMS1_EVENT (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->publication_sets = - g_new0 (MXFDMS1Publication *, self->n_publication_sets); - self->annotation_sets = g_new0 (MXFDMS1Annotation *, self->n_annotation_sets); + if (self->publication_sets) + memset (self->publication_sets, 0, + sizeof (gpointer) * self->n_publication_sets); + else + self->publication_sets = + g_new0 (MXFDMS1Publication *, self->n_publication_sets); - while (*p) { - current = *p; + if (self->annotation_sets) + memset (self->annotation_sets, 0, + sizeof (gpointer) * self->n_annotation_sets); + else + self->annotation_sets = + g_new0 (MXFDMS1Annotation *, self->n_annotation_sets); - if (MXF_IS_DMS1_PUBLICATION (current)) { - for (i = 0; i < self->n_publication_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->publication_sets_uids[i])) { - self->publication_sets[i] = MXF_DMS1_PUBLICATION (current); - break; - } - } + for (i = 0; i < self->n_publication_sets; i++) { + current = g_hash_table_lookup (metadata, &self->publication_sets_uids[i]); + if (current && MXF_IS_DMS1_PUBLICATION (current)) { + self->publication_sets[i] = MXF_DMS1_PUBLICATION (current); } + } - if (MXF_IS_DMS1_ANNOTATION (current)) { - for (i = 0; i < self->n_annotation_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->annotation_sets_uids[i])) { - self->annotation_sets[i] = MXF_DMS1_ANNOTATION (current); - break; - } - } + for (i = 0; i < self->n_annotation_sets; i++) { + current = g_hash_table_lookup (metadata, &self->annotation_sets_uids[i]); + if (current && MXF_IS_DMS1_ANNOTATION (current)) { + self->annotation_sets[i] = MXF_DMS1_ANNOTATION (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_event_parent_class)->resolve (m, @@ -2198,28 +2202,24 @@ mxf_dms1_award_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_award_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_award_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Award *self = MXF_DMS1_AWARD (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->participant_sets = - g_new0 (MXFDMS1Participant *, self->n_participant_sets); - while (*p) { - current = *p; + if (self->participant_sets) + memset (self->participant_sets, 0, + sizeof (gpointer) * self->n_participant_sets); + else + self->participant_sets = + g_new0 (MXFDMS1Participant *, self->n_participant_sets); - if (MXF_IS_DMS1_PARTICIPANT (current)) { - for (i = 0; i < self->n_participant_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->participant_sets_uids[i])) { - self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); - break; - } - } + for (i = 0; i < self->n_participant_sets; i++) { + current = g_hash_table_lookup (metadata, &self->participant_sets_uids[i]); + if (current && MXF_IS_DMS1_PARTICIPANT (current)) { + self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_award_parent_class)->resolve (m, @@ -2450,47 +2450,44 @@ mxf_dms1_annotation_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_annotation_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_annotation_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Annotation *self = MXF_DMS1_ANNOTATION (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->classification_sets = - g_new0 (MXFDMS1Classification *, self->n_classification_sets); - self->participant_sets = - g_new0 (MXFDMS1Participant *, self->n_participant_sets); + if (self->classification_sets) + memset (self->classification_sets, 0, + sizeof (gpointer) * self->n_classification_sets); + else + self->classification_sets = + g_new0 (MXFDMS1Classification *, self->n_classification_sets); - while (*p) { - current = *p; + if (self->participant_sets) + memset (self->participant_sets, 0, + sizeof (gpointer) * self->n_participant_sets); + else + self->participant_sets = + g_new0 (MXFDMS1Participant *, self->n_participant_sets); - if (MXF_IS_DMS1_CLASSIFICATION (current)) { - for (i = 0; i < self->n_classification_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->classification_sets_uids[i])) { - self->classification_sets[i] = MXF_DMS1_CLASSIFICATION (current); - break; - } - } + for (i = 0; i < self->n_classification_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->classification_sets_uids[i]); + if (current && MXF_IS_DMS1_CLASSIFICATION (current)) { + self->classification_sets[i] = MXF_DMS1_CLASSIFICATION (current); } + } - if (MXF_IS_DMS1_CUE_WORDS (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->cue_words_set_uid)) { - self->cue_words_set = MXF_DMS1_CUE_WORDS (current); - } + current = g_hash_table_lookup (metadata, &self->cue_words_set_uid); + if (current && MXF_IS_DMS1_CUE_WORDS (current)) { + self->cue_words_set = MXF_DMS1_CUE_WORDS (current); + } + + for (i = 0; i < self->n_participant_sets; i++) { + current = g_hash_table_lookup (metadata, &self->participant_sets_uids[i]); + if (current && MXF_IS_DMS1_PARTICIPANT (current)) { + self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); } - - if (MXF_IS_DMS1_PARTICIPANT (current)) { - for (i = 0; i < self->n_participant_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->participant_sets_uids[i])) { - self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); - break; - } - } - } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_annotation_parent_class)->resolve (m, @@ -2858,29 +2855,24 @@ mxf_dms1_classification_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_classification_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_dms1_classification_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Classification *self = MXF_DMS1_CLASSIFICATION (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->name_value_sets = g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); + if (self->name_value_sets) + memset (self->name_value_sets, 0, + sizeof (gpointer) * self->n_name_value_sets); + else + self->name_value_sets = + g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - while (*p) { - current = *p; - - if (MXF_IS_DMS1_NAME_VALUE (current)) { - for (i = 0; i < self->n_name_value_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->name_value_sets_uids[i])) { - self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); - break; - } - } + for (i = 0; i < self->n_name_value_sets; i++) { + current = g_hash_table_lookup (metadata, &self->name_value_sets_uids[i]); + if (current && MXF_IS_DMS1_NAME_VALUE (current)) { + self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); } - - p++; } return @@ -2995,34 +2987,28 @@ mxf_dms1_shot_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_shot_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_shot_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Shot *self = MXF_DMS1_SHOT (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->key_point_sets = g_new0 (MXFDMS1KeyPoint *, self->n_key_point_sets); + if (self->key_point_sets) + memset (self->key_point_sets, 0, + sizeof (gpointer) * self->n_key_point_sets); + else + self->key_point_sets = g_new0 (MXFDMS1KeyPoint *, self->n_key_point_sets); - while (*p) { - current = *p; + current = g_hash_table_lookup (metadata, &self->cue_words_set_uid); + if (current && MXF_IS_DMS1_CUE_WORDS (current)) { + self->cue_words_set = MXF_DMS1_CUE_WORDS (current); + } - if (MXF_IS_DMS1_CUE_WORDS (current)) { - if (mxf_ul_is_equal (¤t->instance_uid, &self->cue_words_set_uid)) { - self->cue_words_set = MXF_DMS1_CUE_WORDS (current); - } + for (i = 0; i < self->n_key_point_sets; i++) { + current = g_hash_table_lookup (metadata, &self->key_point_sets_uids[i]); + if (current && MXF_IS_DMS1_KEY_POINT (current)) { + self->key_point_sets[i] = MXF_DMS1_KEY_POINT (current); } - - if (MXF_IS_DMS1_KEY_POINT (current)) { - for (i = 0; i < self->n_key_point_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->key_point_sets_uids[i])) { - self->key_point_sets[i] = MXF_DMS1_KEY_POINT (current); - break; - } - } - } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_shot_parent_class)->resolve (m, @@ -3297,40 +3283,36 @@ mxf_dms1_participant_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_participant_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_participant_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Participant *self = MXF_DMS1_PARTICIPANT (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->person_sets = g_new0 (MXFDMS1Person *, self->n_person_sets); - self->organisation_sets = - g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); + if (self->person_sets) + memset (self->person_sets, 0, sizeof (gpointer) * self->n_person_sets); + else + self->person_sets = g_new0 (MXFDMS1Person *, self->n_person_sets); - while (*p) { - current = *p; + if (self->organisation_sets) + memset (self->organisation_sets, 0, + sizeof (gpointer) * self->n_organisation_sets); + else + self->organisation_sets = + g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); - if (MXF_IS_DMS1_PERSON (current)) { - for (i = 0; i < self->n_person_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->person_sets_uids[i])) { - self->person_sets[i] = MXF_DMS1_PERSON (current); - break; - } - } + for (i = 0; i < self->n_person_sets; i++) { + current = g_hash_table_lookup (metadata, &self->person_sets_uids[i]); + if (current && MXF_IS_DMS1_PERSON (current)) { + self->person_sets[i] = MXF_DMS1_PERSON (current); } + } - if (MXF_IS_DMS1_ORGANISATION (current)) { - for (i = 0; i < self->n_organisation_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->organisation_sets_uids[i])) { - self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); - break; - } - } + for (i = 0; i < self->n_organisation_sets; i++) { + current = g_hash_table_lookup (metadata, &self->organisation_sets_uids[i]); + if (current && MXF_IS_DMS1_ORGANISATION (current)) { + self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); } - - p++; } return @@ -3491,39 +3473,36 @@ mxf_dms1_contact_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_contact_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_contact_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Contact *self = MXF_DMS1_CONTACT (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->name_value_sets = g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - self->address_sets = g_new0 (MXFDMS1Address *, self->n_address_sets); + if (self->name_value_sets) + memset (self->name_value_sets, 0, + sizeof (gpointer) * self->n_name_value_sets); + else + self->name_value_sets = + g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - while (*p) { - current = *p; + if (self->address_sets) + memset (self->address_sets, 0, sizeof (gpointer) * self->n_address_sets); + else + self->address_sets = g_new0 (MXFDMS1Address *, self->n_address_sets); - if (MXF_IS_DMS1_NAME_VALUE (current)) { - for (i = 0; i < self->n_name_value_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->name_value_sets_uids[i])) { - self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); - break; - } - } + for (i = 0; i < self->n_name_value_sets; i++) { + current = g_hash_table_lookup (metadata, &self->name_value_sets_uids[i]); + if (current && MXF_IS_DMS1_NAME_VALUE (current)) { + self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); } + } - if (MXF_IS_DMS1_ADDRESS (current)) { - for (i = 0; i < self->n_address_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->address_sets_uids[i])) { - self->address_sets[i] = MXF_DMS1_ADDRESS (current); - break; - } - } + for (i = 0; i < self->n_address_sets; i++) { + current = g_hash_table_lookup (metadata, &self->address_sets_uids[i]); + if (current && MXF_IS_DMS1_ADDRESS (current)) { + self->address_sets[i] = MXF_DMS1_ADDRESS (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_contact_parent_class)->resolve (m, @@ -3677,29 +3656,24 @@ mxf_dms1_person_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_person_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_person_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Person *self = MXF_DMS1_PERSON (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->organisation_sets = - g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); + if (self->organisation_sets) + memset (self->organisation_sets, 0, + sizeof (gpointer) * self->n_organisation_sets); + else + self->organisation_sets = + g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); - while (*p) { - current = *p; - - if (MXF_IS_DMS1_ORGANISATION (current)) { - for (i = 0; i < self->n_organisation_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->organisation_sets_uids[i])) { - self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); - break; - } - } + for (i = 0; i < self->n_organisation_sets; i++) { + current = g_hash_table_lookup (metadata, &self->organisation_sets_uids[i]); + if (current && MXF_IS_DMS1_ORGANISATION (current)) { + self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_person_parent_class)->resolve (m, @@ -4078,39 +4052,39 @@ mxf_dms1_address_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_address_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_address_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Address *self = MXF_DMS1_ADDRESS (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->communications_sets = - g_new0 (MXFDMS1Communications *, self->n_communications_sets); - self->name_value_sets = g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - while (*p != NULL) { - current = *p; + if (self->communications_sets) + memset (self->communications_sets, 0, + sizeof (gpointer) * self->n_communications_sets); + else + self->communications_sets = + g_new0 (MXFDMS1Communications *, self->n_communications_sets); - if (MXF_IS_DMS1_COMMUNICATIONS (current)) { - for (i = 0; i < self->n_communications_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->communications_sets_uids[i])) { - self->communications_sets[i] = MXF_DMS1_COMMUNICATIONS (self); - break; - } - } + if (self->name_value_sets) + memset (self->name_value_sets, 0, + sizeof (gpointer) * self->n_name_value_sets); + else + self->name_value_sets = + g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); + + for (i = 0; i < self->n_communications_sets; i++) { + current = + g_hash_table_lookup (metadata, &self->communications_sets_uids[i]); + if (current && MXF_IS_DMS1_COMMUNICATIONS (current)) { + self->communications_sets[i] = MXF_DMS1_COMMUNICATIONS (current); } + } - if (MXF_IS_DMS1_NAME_VALUE (current)) { - for (i = 0; i < self->n_name_value_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->name_value_sets_uids[i])) { - self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (self); - break; - } - } + for (i = 0; i < self->n_name_value_sets; i++) { + current = g_hash_table_lookup (metadata, &self->name_value_sets_uids[i]); + if (current && MXF_IS_DMS1_NAME_VALUE (current)) { + self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_address_parent_class)->resolve (m, @@ -4440,39 +4414,36 @@ mxf_dms1_contract_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_contract_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_dms1_contract_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1Contract *self = MXF_DMS1_CONTRACT (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->rights_sets = g_new0 (MXFDMS1Rights *, self->n_rights_sets); - self->participant_sets = - g_new0 (MXFDMS1Participant *, self->n_participant_sets); - while (*p) { - current = *p; + if (self->rights_sets) + memset (self->rights_sets, 0, sizeof (gpointer) * self->n_rights_sets); + else + self->rights_sets = g_new0 (MXFDMS1Rights *, self->n_rights_sets); - if (MXF_IS_DMS1_RIGHTS (current)) { - for (i = 0; i < self->n_rights_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->rights_sets_uids[i])) { - self->rights_sets[i] = MXF_DMS1_RIGHTS (current); - break; - } - } + if (self->participant_sets) + memset (self->participant_sets, 0, + sizeof (gpointer) * self->n_participant_sets); + else + self->participant_sets = + g_new0 (MXFDMS1Participant *, self->n_participant_sets); + + for (i = 0; i < self->n_rights_sets; i++) { + current = g_hash_table_lookup (metadata, &self->rights_sets_uids[i]); + if (current && MXF_IS_DMS1_RIGHTS (current)) { + self->rights_sets[i] = MXF_DMS1_RIGHTS (current); } + } - if (MXF_IS_DMS1_PARTICIPANT (current)) { - for (i = 0; i < self->n_participant_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->participant_sets_uids[i])) { - self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); - break; - } - } + for (i = 0; i < self->n_participant_sets; i++) { + current = g_hash_table_lookup (metadata, &self->participant_sets_uids[i]); + if (current && MXF_IS_DMS1_PARTICIPANT (current)) { + self->participant_sets[i] = MXF_DMS1_PARTICIPANT (current); } - - p++; } return MXF_METADATA_BASE_CLASS (mxf_dms1_contract_parent_class)->resolve (m, @@ -4879,28 +4850,24 @@ mxf_dms1_device_parameters_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_device_parameters_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_dms1_device_parameters_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1DeviceParameters *self = MXF_DMS1_DEVICE_PARAMETERS (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->name_value_sets = g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - while (*p) { - current = *p; + if (self->name_value_sets) + memset (self->name_value_sets, 0, + sizeof (gpointer) * self->n_name_value_sets); + else + self->name_value_sets = + g_new0 (MXFDMS1NameValue *, self->n_name_value_sets); - if (MXF_IS_DMS1_NAME_VALUE (current)) { - for (i = 0; i < self->n_name_value_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->name_value_sets_uids[i])) { - self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); - break; - } - } + for (i = 0; i < self->n_name_value_sets; i++) { + current = g_hash_table_lookup (metadata, &self->name_value_sets_uids[i]); + if (current && MXF_IS_DMS1_NAME_VALUE (current)) { + self->name_value_sets[i] = MXF_DMS1_NAME_VALUE (current); } - - p++; } return @@ -5373,52 +5340,48 @@ mxf_dms1_contacts_list_finalize (GstMiniObject * object) } static gboolean -mxf_dms1_contacts_list_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_dms1_contacts_list_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFDMS1ContactsList *self = MXF_DMS1_CONTACTS_LIST (m); - MXFMetadataBase **p = metadata, *current = NULL; + MXFMetadataBase *current = NULL; guint i; - self->person_sets = g_new0 (MXFDMS1Person *, self->n_person_sets); - self->organisation_sets = - g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); - self->location_sets = g_new0 (MXFDMS1Location *, self->n_location_sets); + if (self->person_sets) + memset (self->person_sets, 0, sizeof (gpointer) * self->n_person_sets); + else + self->person_sets = g_new0 (MXFDMS1Person *, self->n_person_sets); - while (*p) { - current = *p; + if (self->organisation_sets) + memset (self->organisation_sets, 0, + sizeof (gpointer) * self->n_organisation_sets); + else + self->organisation_sets = + g_new0 (MXFDMS1Organisation *, self->n_organisation_sets); - if (MXF_IS_DMS1_PERSON (current)) { - for (i = 0; i < self->n_person_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->person_sets_uids[i])) { - self->person_sets[i] = MXF_DMS1_PERSON (current); - break; - } - } + if (self->location_sets) + memset (self->location_sets, 0, sizeof (gpointer) * self->n_location_sets); + else + self->location_sets = g_new0 (MXFDMS1Location *, self->n_location_sets); + + for (i = 0; i < self->n_person_sets; i++) { + current = g_hash_table_lookup (metadata, &self->person_sets_uids[i]); + if (current && MXF_IS_DMS1_PERSON (current)) { + self->person_sets[i] = MXF_DMS1_PERSON (current); } + } - if (MXF_IS_DMS1_ORGANISATION (current)) { - for (i = 0; i < self->n_organisation_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->organisation_sets_uids[i])) { - self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); - break; - } - } + for (i = 0; i < self->n_organisation_sets; i++) { + current = g_hash_table_lookup (metadata, &self->organisation_sets_uids[i]); + if (current && MXF_IS_DMS1_ORGANISATION (current)) { + self->organisation_sets[i] = MXF_DMS1_ORGANISATION (current); } + } - if (MXF_IS_DMS1_LOCATION (current)) { - for (i = 0; i < self->n_location_sets; i++) { - if (mxf_ul_is_equal (¤t->instance_uid, - &self->location_sets_uids[i])) { - self->location_sets[i] = MXF_DMS1_LOCATION (current); - break; - } - } + for (i = 0; i < self->n_location_sets; i++) { + current = g_hash_table_lookup (metadata, &self->location_sets_uids[i]); + if (current && MXF_IS_DMS1_LOCATION (current)) { + self->location_sets[i] = MXF_DMS1_LOCATION (current); } - - p++; } return diff --git a/gst/mxf/mxfmetadata.c b/gst/mxf/mxfmetadata.c index b2a70bbcf0..cda051bae9 100644 --- a/gst/mxf/mxfmetadata.c +++ b/gst/mxf/mxfmetadata.c @@ -56,7 +56,7 @@ mxf_metadata_base_handle_tag (MXFMetadataBase * self, MXFPrimerPack * primer, static gboolean mxf_metadata_base_resolve_default (MXFMetadataBase * self, - MXFMetadataBase ** metadata) + GHashTable * metadata) { return TRUE; } @@ -104,7 +104,7 @@ mxf_metadata_base_parse (MXFMetadataBase * self, MXFPrimerPack * primer, } gboolean -mxf_metadata_base_resolve (MXFMetadataBase * self, MXFMetadataBase ** metadata) +mxf_metadata_base_resolve (MXFMetadataBase * self, GHashTable * metadata) { MXFMetadataBaseClass *klass; gboolean ret = TRUE; @@ -262,8 +262,8 @@ mxf_metadata_register (guint16 type_id, GType type) } MXFMetadata * -mxf_metadata_new (guint16 type, MXFPrimerPack * primer, const guint8 * data, - guint size) +mxf_metadata_new (guint16 type, MXFPrimerPack * primer, guint64 offset, + const guint8 * data, guint size) { GSList *l; GType t = G_TYPE_INVALID; @@ -289,6 +289,10 @@ mxf_metadata_new (guint16 type, MXFPrimerPack * primer, const guint8 * data, t = MXF_TYPE_METADATA; } + + GST_DEBUG ("Metadata type 0x%06x is handled by type %s", type, + g_type_name (t)); + ret = (MXFMetadata *) g_type_create_instance (t); if (!mxf_metadata_base_parse (MXF_METADATA_BASE (ret), primer, data, size)) { GST_ERROR ("Parsing metadata failed"); @@ -297,6 +301,7 @@ mxf_metadata_new (guint16 type, MXFPrimerPack * primer, const guint8 * data, } ret->type = type; + ret->parent.offset = offset; return ret; } @@ -445,48 +450,49 @@ error: } static gboolean -mxf_metadata_preface_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_metadata_preface_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataPreface *self = MXF_METADATA_PREFACE (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; guint i; - while (*p && (self->primary_package == NULL || self->content_storage == NULL)) { - current = *p; - - if (MXF_IS_METADATA_GENERIC_PACKAGE (current) && - mxf_ul_is_equal (&self->primary_package_uid, ¤t->instance_uid)) { - if (mxf_metadata_base_resolve (current, metadata)) - self->primary_package = MXF_METADATA_GENERIC_PACKAGE (current); - } else if (MXF_IS_METADATA_CONTENT_STORAGE (current) && - mxf_ul_is_equal (&self->content_storage_uid, ¤t->instance_uid)) { - if (mxf_metadata_base_resolve (current, metadata)) - self->content_storage = MXF_METADATA_CONTENT_STORAGE (current); - } - p++; - } - - self->identifications = - g_new0 (MXFMetadataIdentification *, self->n_identifications); - for (i = 0; i < self->n_identifications; i++) { - p = metadata; - while (*p) { - current = *p; - - if (MXF_IS_METADATA_IDENTIFICATION (current) && - mxf_ul_is_equal (&self->identifications_uids[i], - ¤t->instance_uid)) { - if (mxf_metadata_base_resolve (current, metadata)) - self->identifications[i] = MXF_METADATA_IDENTIFICATION (current); - break; - } - p++; + current = g_hash_table_lookup (metadata, &self->primary_package_uid); + if (!current || !MXF_IS_METADATA_GENERIC_PACKAGE (current)) { + GST_ERROR ("Primary package not found"); + } else { + if (mxf_metadata_base_resolve (current, metadata)) { + self->primary_package = MXF_METADATA_GENERIC_PACKAGE (current); } } + current = NULL; - if (!self->content_storage) { - GST_ERROR ("Couldn't resolve content storage"); + current = g_hash_table_lookup (metadata, &self->content_storage_uid); + if (!current || !MXF_IS_METADATA_CONTENT_STORAGE (current)) { + GST_ERROR ("Content storage not found"); return FALSE; + } else { + if (mxf_metadata_base_resolve (current, metadata)) { + self->content_storage = MXF_METADATA_CONTENT_STORAGE (current); + } else { + GST_ERROR ("Couldn't resolve content storage"); + return FALSE; + } + } + current = NULL; + + if (self->identifications) + memset (self->identifications, 0, + sizeof (gpointer) * self->n_identifications); + else + self->identifications = + g_new0 (MXFMetadataIdentification *, self->n_identifications); + for (i = 0; i < self->n_identifications; i++) { + current = g_hash_table_lookup (metadata, &self->identifications_uids[i]); + if (current && MXF_IS_METADATA_IDENTIFICATION (current)) { + if (mxf_metadata_base_resolve (m, metadata)) + self->identifications[i] = MXF_METADATA_IDENTIFICATION (current); + } + current = NULL; } return @@ -727,49 +733,53 @@ error: static gboolean mxf_metadata_content_storage_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFMetadataContentStorage *self = MXF_METADATA_CONTENT_STORAGE (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; guint i; gboolean have_package = FALSE; gboolean have_ecd = FALSE; - self->packages = g_new0 (MXFMetadataGenericPackage *, self->n_packages); + if (self->packages) + memset (self->packages, 0, sizeof (gpointer) * self->n_packages); + else + self->packages = g_new0 (MXFMetadataGenericPackage *, self->n_packages); + for (i = 0; i < self->n_packages; i++) { - p = metadata; - while (*p) { - current = *p; - if (MXF_IS_METADATA_GENERIC_PACKAGE (current) && - mxf_ul_is_equal (¤t->instance_uid, &self->packages_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->packages[i] = MXF_METADATA_GENERIC_PACKAGE (current); - have_package = TRUE; - } - break; + current = g_hash_table_lookup (metadata, &self->packages_uids[i]); + if (current && MXF_IS_METADATA_GENERIC_PACKAGE (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->packages[i] = MXF_METADATA_GENERIC_PACKAGE (current); + have_package = TRUE; + } else { + GST_ERROR ("Couldn't resolve package"); } - p++; + } else { + GST_ERROR ("Package not found"); } } - self->essence_container_data = - g_new0 (MXFMetadataEssenceContainerData *, - self->n_essence_container_data); + if (self->essence_container_data) + memset (self->essence_container_data, 0, + sizeof (gpointer) * self->n_essence_container_data); + else + self->essence_container_data = + g_new0 (MXFMetadataEssenceContainerData *, + self->n_essence_container_data); for (i = 0; i < self->n_essence_container_data; i++) { - p = metadata; - while (*p) { - current = *p; - if (MXF_IS_METADATA_ESSENCE_CONTAINER_DATA (current) && - mxf_ul_is_equal (¤t->instance_uid, - &self->essence_container_data_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->essence_container_data[i] = - MXF_METADATA_ESSENCE_CONTAINER_DATA (current); - have_ecd = TRUE; - } - break; + current = + g_hash_table_lookup (metadata, &self->essence_container_data_uids[i]); + if (current && MXF_IS_METADATA_ESSENCE_CONTAINER_DATA (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->essence_container_data[i] = + MXF_METADATA_ESSENCE_CONTAINER_DATA (current); + have_ecd = TRUE; + } else { + GST_ERROR ("Couldn't resolve essence container data"); } - p++; + } else { + GST_ERROR ("Essence container data not found"); } } @@ -858,15 +868,16 @@ error: static gboolean mxf_metadata_essence_container_data_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFMetadataEssenceContainerData *self = MXF_METADATA_ESSENCE_CONTAINER_DATA (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; + GHashTableIter iter; - while (*p) { - current = *p; + g_hash_table_iter_init (&iter, metadata); + while (g_hash_table_iter_next (&iter, NULL, (gpointer) & current)) { if (MXF_IS_METADATA_SOURCE_PACKAGE (current)) { MXFMetadataSourcePackage *package = MXF_METADATA_SOURCE_PACKAGE (current); @@ -878,7 +889,6 @@ mxf_metadata_essence_container_data_resolve (MXFMetadataBase * m, break; } } - p++; } if (!self->linked_package) { @@ -1013,42 +1023,38 @@ error: static gboolean mxf_metadata_generic_package_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFMetadataGenericPackage *self = MXF_METADATA_GENERIC_PACKAGE (m); - MXFMetadataBase **p, *current; + MXFMetadataBase *current = NULL; guint i; gboolean have_track = FALSE; - self->tracks = g_new0 (MXFMetadataTrack *, self->n_tracks); + if (self->tracks) + memset (self->tracks, 0, sizeof (gpointer) * self->n_tracks); + else + self->tracks = g_new0 (MXFMetadataTrack *, self->n_tracks); for (i = 0; i < self->n_tracks; i++) { - p = metadata; - while (*p) { - current = *p; - - if (MXF_IS_METADATA_TRACK (current)) { + current = g_hash_table_lookup (metadata, &self->tracks_uids[i]); + if (current && MXF_IS_METADATA_TRACK (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { MXFMetadataTrack *track = MXF_METADATA_TRACK (current); - if (mxf_ul_is_equal (¤t->instance_uid, &self->tracks_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->tracks[i] = track; - have_track = TRUE; - - if ((track->type & 0xf0) == 0x10) - self->n_timecode_tracks++; - else if ((track->type & 0xf0) == 0x20) - self->n_metadata_tracks++; - else if ((track->type & 0xf0) == 0x30) - self->n_essence_tracks++; - else if ((track->type & 0xf0) == 0x40) - self->n_other_tracks++; - } - - break; - } + self->tracks[i] = track; + have_track = TRUE; + if ((track->type & 0xf0) == 0x10) + self->n_timecode_tracks++; + else if ((track->type & 0xf0) == 0x20) + self->n_metadata_tracks++; + else if ((track->type & 0xf0) == 0x30) + self->n_essence_tracks++; + else if ((track->type & 0xf0) == 0x40) + self->n_other_tracks++; + } else { + GST_ERROR ("Track couldn't be resolved"); } - - p++; + } else { + GST_ERROR ("Track not found"); } } @@ -1084,7 +1090,7 @@ G_DEFINE_TYPE (MXFMetadataMaterialPackage, mxf_metadata_material_package, static gboolean mxf_metadata_material_package_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { gboolean ret = MXF_METADATA_BASE_CLASS @@ -1194,12 +1200,11 @@ error: } static gboolean -mxf_metadata_source_package_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_metadata_source_package_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataSourcePackage *self = MXF_METADATA_SOURCE_PACKAGE (m); MXFMetadataGenericPackage *package = MXF_METADATA_GENERIC_PACKAGE (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; guint i, j; gboolean ret; MXFMetadataGenericDescriptor *d = NULL; @@ -1209,18 +1214,15 @@ mxf_metadata_source_package_resolve (MXFMetadataBase * m, MXF_METADATA_BASE_CLASS (mxf_metadata_source_package_parent_class)->resolve (m, metadata); - while (*p) { - current = *p; - - if (MXF_IS_METADATA_GENERIC_DESCRIPTOR (current) && - mxf_ul_is_equal (¤t->instance_uid, &self->descriptors_uid)) { - d = MXF_METADATA_GENERIC_DESCRIPTOR (current); - break; - } - p++; + current = g_hash_table_lookup (metadata, &self->descriptors_uid); + if (current && MXF_IS_METADATA_GENERIC_DESCRIPTOR (current)) { + d = MXF_METADATA_GENERIC_DESCRIPTOR (current); + } else { + GST_ERROR ("Descriptor not found"); + return FALSE; } - if (!d || !mxf_metadata_base_resolve (MXF_METADATA_BASE (d), metadata)) { + if (!mxf_metadata_base_resolve (MXF_METADATA_BASE (d), metadata)) { GST_ERROR ("Couldn't resolve descriptor"); return FALSE; } @@ -1230,6 +1232,8 @@ mxf_metadata_source_package_resolve (MXFMetadataBase * m, if (m->sub_descriptors) { self->n_descriptors = m->n_sub_descriptors + 1; + if (self->descriptors) + g_free (self->descriptors); self->descriptors = g_new0 (MXFMetadataGenericDescriptor *, self->n_descriptors); @@ -1241,6 +1245,8 @@ mxf_metadata_source_package_resolve (MXFMetadataBase * m, } } else { self->n_descriptors = 1; + if (self->descriptors) + g_free (self->descriptors); self->descriptors = g_new0 (MXFMetadataGenericDescriptor *, 1); self->descriptors[0] = d; } @@ -1264,6 +1270,8 @@ mxf_metadata_source_package_resolve (MXFMetadataBase * m, n_descriptor++; } + if (package->tracks[i]->descriptor) + g_free (package->tracks[i]->descriptor); package->tracks[i]->descriptor = g_new0 (MXFMetadataFileDescriptor *, n_descriptor); package->tracks[i]->n_descriptor = n_descriptor; @@ -1372,26 +1380,22 @@ error: } static gboolean -mxf_metadata_track_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_metadata_track_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataTrack *self = MXF_METADATA_TRACK (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; guint i; - while (*p) { - current = *p; - if (MXF_IS_METADATA_SEQUENCE (current) && - mxf_ul_is_equal (¤t->instance_uid, &self->sequence_uid)) { + current = g_hash_table_lookup (metadata, &self->sequence_uid); + if (current && MXF_IS_METADATA_SEQUENCE (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { self->sequence = MXF_METADATA_SEQUENCE (current); - break; + } else { + GST_ERROR ("Couldn't resolve sequence"); + return FALSE; } - p++; - } - - if (!self->sequence - || !mxf_metadata_base_resolve (MXF_METADATA_BASE (self->sequence), - metadata)) { - GST_ERROR ("Couldn't resolve sequence"); + } else { + GST_ERROR ("Couldn't find sequence"); return FALSE; } @@ -1674,40 +1678,36 @@ error: } static gboolean -mxf_metadata_sequence_resolve (MXFMetadataBase * m, MXFMetadataBase ** metadata) +mxf_metadata_sequence_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataSequence *self = MXF_METADATA_SEQUENCE (m); - MXFMetadataBase **p, *current; + MXFMetadataBase *current = NULL; guint i; - guint have_sc = 0; - self->structural_components = - g_new0 (MXFMetadataStructuralComponent *, self->n_structural_components); + if (self->structural_components) + memset (self->structural_components, 0, + sizeof (gpointer) * self->n_structural_components); + else + self->structural_components = + g_new0 (MXFMetadataStructuralComponent *, + self->n_structural_components); for (i = 0; i < self->n_structural_components; i++) { - p = metadata; - - while (*p) { - current = *p; - - if (MXF_IS_METADATA_STRUCTURAL_COMPONENT (current) - && mxf_ul_is_equal (¤t->instance_uid, - &self->structural_components_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->structural_components[i] = - MXF_METADATA_STRUCTURAL_COMPONENT (current); - have_sc++; - break; - } + current = + g_hash_table_lookup (metadata, &self->structural_components_uids[i]); + if (current && MXF_IS_METADATA_STRUCTURAL_COMPONENT (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->structural_components[i] = + MXF_METADATA_STRUCTURAL_COMPONENT (current); + } else { + GST_ERROR ("Couldn't resolve structural component"); + return FALSE; } - p++; + } else { + GST_ERROR ("Structural component not found"); + return FALSE; } } - if (have_sc != self->n_structural_components) { - GST_ERROR ("Couldn't resolve all structural components"); - return FALSE; - } - return MXF_METADATA_BASE_CLASS (mxf_metadata_sequence_parent_class)->resolve (m, metadata); @@ -1913,15 +1913,15 @@ error: } static gboolean -mxf_metadata_source_clip_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_metadata_source_clip_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataSourceClip *self = MXF_METADATA_SOURCE_CLIP (m); - MXFMetadataBase **p, *current; + MXFMetadataBase *current = NULL; + GHashTableIter iter; - p = metadata; - while (*p) { - current = *p; + g_hash_table_iter_init (&iter, metadata); + + while (g_hash_table_iter_next (&iter, NULL, (gpointer) & current)) { if (MXF_IS_METADATA_SOURCE_PACKAGE (current)) { MXFMetadataGenericPackage *p = MXF_METADATA_GENERIC_PACKAGE (current); @@ -1930,7 +1930,6 @@ mxf_metadata_source_clip_resolve (MXFMetadataBase * m, break; } } - p++; } return @@ -2143,31 +2142,25 @@ error: } static gboolean -mxf_metadata_dm_segment_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) +mxf_metadata_dm_segment_resolve (MXFMetadataBase * m, GHashTable * metadata) { MXFMetadataDMSegment *self = MXF_METADATA_DM_SEGMENT (m); - MXFMetadataBase **p = metadata, *current; + MXFMetadataBase *current = NULL; - while (*p) { - current = *p; - - if (MXF_IS_DESCRIPTIVE_METADATA_FRAMEWORK (current) - && mxf_ul_is_equal (¤t->instance_uid, &self->dm_framework_uid)) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->dm_framework = MXF_DESCRIPTIVE_METADATA_FRAMEWORK (current); - } - break; + current = g_hash_table_lookup (metadata, &self->dm_framework_uid); + if (current && MXF_IS_DESCRIPTIVE_METADATA_FRAMEWORK (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->dm_framework = MXF_DESCRIPTIVE_METADATA_FRAMEWORK (current); + } else { + GST_ERROR ("Couldn't resolve DM framework"); + return FALSE; } - - p++; - } - - if (!self->dm_framework) { - GST_ERROR ("Couldn't resolve DM framework"); + } else { + GST_ERROR ("Couldn't find DM framework"); return FALSE; } + return MXF_METADATA_BASE_CLASS (mxf_metadata_dm_segment_parent_class)->resolve (m, metadata); @@ -2257,28 +2250,28 @@ error: static gboolean mxf_metadata_generic_descriptor_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFMetadataGenericDescriptor *self = MXF_METADATA_GENERIC_DESCRIPTOR (m); - MXFMetadataBase **p, *current; + MXFMetadataBase *current = NULL; guint i; gboolean have_locator = FALSE; - self->locators = g_new0 (MXFMetadataLocator *, self->n_locators); + if (self->locators) + memset (self->locators, 0, sizeof (gpointer) * self->n_locators); + else + self->locators = g_new0 (MXFMetadataLocator *, self->n_locators); for (i = 0; i < self->n_locators; i++) { - p = metadata; - while (*p) { - current = *p; - - if (MXF_IS_METADATA_LOCATOR (current) && - mxf_ul_is_equal (¤t->instance_uid, &self->locators_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->locators[i] = MXF_METADATA_LOCATOR (current); - have_locator = TRUE; - } - break; + current = g_hash_table_lookup (metadata, &self->locators_uids[i]); + if (current && MXF_IS_METADATA_LOCATOR (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->locators[i] = MXF_METADATA_LOCATOR (current); + have_locator = TRUE; + } else { + GST_ERROR ("Couldn't resolve locator"); } - p++; + } else { + GST_ERROR ("Locator not found"); } } @@ -3149,36 +3142,34 @@ error: static gboolean mxf_metadata_multiple_descriptor_resolve (MXFMetadataBase * m, - MXFMetadataBase ** metadata) + GHashTable * metadata) { MXFMetadataMultipleDescriptor *self = MXF_METADATA_MULTIPLE_DESCRIPTOR (m); - MXFMetadataBase **p, *current; + MXFMetadataBase *current = NULL; guint i, have_subdescriptors = 0; - self->sub_descriptors = - g_new0 (MXFMetadataGenericDescriptor *, self->n_sub_descriptors); + if (self->sub_descriptors) + memset (self->sub_descriptors, 0, + sizeof (gpointer) * self->n_sub_descriptors); + else + self->sub_descriptors = + g_new0 (MXFMetadataGenericDescriptor *, self->n_sub_descriptors); for (i = 0; i < self->n_sub_descriptors; i++) { - p = metadata; - while (*p) { - current = *p; - if (MXF_IS_METADATA_GENERIC_DESCRIPTOR (current) && - mxf_ul_is_equal (¤t->instance_uid, - &self->sub_descriptors_uids[i])) { - if (mxf_metadata_base_resolve (current, metadata)) { - self->sub_descriptors[i] = MXF_METADATA_GENERIC_DESCRIPTOR (current); - have_subdescriptors++; - } - break; + current = g_hash_table_lookup (metadata, &self->sub_descriptors_uids[i]); + if (current && MXF_IS_METADATA_GENERIC_DESCRIPTOR (current)) { + if (mxf_metadata_base_resolve (current, metadata)) { + self->sub_descriptors[i] = MXF_METADATA_GENERIC_DESCRIPTOR (current); + have_subdescriptors++; + } else { + GST_ERROR ("Couldn't resolve descriptor"); + return FALSE; } - p++; + } else { + GST_ERROR ("Descriptor not found"); + return FALSE; } } - if (have_subdescriptors != self->n_sub_descriptors) { - GST_ERROR ("Couldn't resolve all subdescriptors"); - return FALSE; - } - return MXF_METADATA_BASE_CLASS (mxf_metadata_multiple_descriptor_parent_class)->resolve (m, metadata); @@ -3358,7 +3349,7 @@ mxf_descriptive_metadata_register (guint8 scheme, GSList * sets) MXFDescriptiveMetadata * mxf_descriptive_metadata_new (guint8 scheme, guint32 type, - MXFPrimerPack * primer, const guint8 * data, guint size) + MXFPrimerPack * primer, guint64 offset, const guint8 * data, guint size) { GSList *l; GType t = G_TYPE_INVALID; @@ -3400,6 +3391,9 @@ mxf_descriptive_metadata_new (guint8 scheme, guint32 type, return NULL; } + GST_DEBUG ("DM scheme 0x%02x type 0x%06x is handled by type %s", scheme, type, + g_type_name (t)); + ret = (MXFDescriptiveMetadata *) g_type_create_instance (t); if (!mxf_metadata_base_parse (MXF_METADATA_BASE (ret), primer, data, size)) { GST_ERROR ("Parsing metadata failed"); @@ -3408,6 +3402,7 @@ mxf_descriptive_metadata_new (guint8 scheme, guint32 type, } ret->type = type; + ret->parent.offset = offset; return ret; } @@ -3445,3 +3440,11 @@ mxf_descriptive_metadata_framework_get_type (void) return (GType) type; } + +GHashTable * +mxf_metadata_hash_table_new (void) +{ + return g_hash_table_new_full ((GHashFunc) mxf_ul_hash, + (GEqualFunc) mxf_ul_is_equal, (GDestroyNotify) NULL, + (GDestroyNotify) gst_mini_object_unref); +} diff --git a/gst/mxf/mxfmetadata.h b/gst/mxf/mxfmetadata.h index ac34a018e9..e162d9b924 100644 --- a/gst/mxf/mxfmetadata.h +++ b/gst/mxf/mxfmetadata.h @@ -373,6 +373,8 @@ struct _MXFMetadataBase { MXFUL instance_uid; MXFUL generation_uid; + guint64 offset; + MXFMetadataBaseResolveState resolved; GHashTable *other_tags; @@ -382,7 +384,7 @@ struct _MXFMetadataBaseClass { GstMiniObjectClass parent; gboolean (*handle_tag) (MXFMetadataBase *self, MXFPrimerPack *primer, guint16 tag, const guint8 *tag_data, guint tag_size); - gboolean (*resolve) (MXFMetadataBase *self, MXFMetadataBase **metadata); + gboolean (*resolve) (MXFMetadataBase *self, GHashTable *metadata); }; struct _MXFMetadata { @@ -745,9 +747,9 @@ struct _MXFDescriptiveMetadataFrameworkInterface { }; gboolean mxf_metadata_base_parse (MXFMetadataBase *self, MXFPrimerPack *primer, const guint8 *data, guint size); -gboolean mxf_metadata_base_resolve (MXFMetadataBase *self, MXFMetadataBase **metadata); +gboolean mxf_metadata_base_resolve (MXFMetadataBase *self, GHashTable *metadata); -MXFMetadata *mxf_metadata_new (guint16 type, MXFPrimerPack *primer, const guint8 *data, guint size); +MXFMetadata *mxf_metadata_new (guint16 type, MXFPrimerPack *primer, guint64 offset, const guint8 *data, guint size); void mxf_metadata_register (guint16 type_id, GType type); void mxf_metadata_init_types (void); @@ -757,6 +759,8 @@ void mxf_metadata_generic_picture_essence_descriptor_set_caps (MXFMetadataGeneri void mxf_metadata_generic_sound_essence_descriptor_set_caps (MXFMetadataGenericSoundEssenceDescriptor * self, GstCaps * caps); void mxf_descriptive_metadata_register (guint8 scheme, GSList *sets); -MXFDescriptiveMetadata * mxf_descriptive_metadata_new (guint8 scheme, guint32 type, MXFPrimerPack * primer, const guint8 * data, guint size); +MXFDescriptiveMetadata * mxf_descriptive_metadata_new (guint8 scheme, guint32 type, MXFPrimerPack * primer, guint64 offset, const guint8 * data, guint size); + +GHashTable *mxf_metadata_hash_table_new (void); #endif /* __MXF_METADATA_H__ */ diff --git a/gst/mxf/mxfparse.c b/gst/mxf/mxfparse.c index 0fe86162d7..6b8e95e443 100644 --- a/gst/mxf/mxfparse.c +++ b/gst/mxf/mxfparse.c @@ -215,6 +215,20 @@ 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]) { @@ -302,26 +316,6 @@ mxf_umid_from_string (const gchar * str, MXFUMID * umid) return umid; } -static guint -gst_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; -} - -static gboolean -gst_mxf_ul_equal (const MXFUL * a, const MXFUL * b) -{ - return (memcmp (a, b, 16) == 0); -} - gboolean mxf_timestamp_parse (MXFTimestamp * timestamp, const guint8 * data, guint size) { @@ -1015,7 +1009,7 @@ mxf_local_tag_parse (const guint8 * data, guint size, guint16 * tag, } void -gst_mxf_local_tag_free (MXFLocalTag * tag) +mxf_local_tag_free (MXFLocalTag * tag) { g_free (tag->data); g_slice_free (MXFLocalTag, tag); @@ -1036,9 +1030,9 @@ mxf_local_tag_add_to_hash_table (const MXFPrimerPack * primer, if (*hash_table == NULL) *hash_table = - g_hash_table_new_full ((GHashFunc) gst_mxf_ul_hash, - (GEqualFunc) gst_mxf_ul_equal, (GDestroyNotify) NULL, - (GDestroyNotify) gst_mxf_local_tag_free); + 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); diff --git a/gst/mxf/mxfparse.h b/gst/mxf/mxfparse.h index c0aafe00e1..3e6e91b200 100644 --- a/gst/mxf/mxfparse.h +++ b/gst/mxf/mxfparse.h @@ -37,6 +37,7 @@ typedef struct { 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);