Build the random index pack while parsing

If the file contains no random index pack or just
an invalid one build the random index pack while
parsing.
This commit is contained in:
Sebastian Dröge 2009-01-22 11:44:46 +01:00
parent fc4be0acca
commit 52028f2e11
2 changed files with 40 additions and 10 deletions

View file

@ -293,6 +293,7 @@ gst_mxf_demux_reset (GstMXFDemux * demux)
g_array_free (demux->partition_index, TRUE); g_array_free (demux->partition_index, TRUE);
demux->partition_index = NULL; demux->partition_index = NULL;
} }
demux->parsed_random_index_pack = FALSE;
if (demux->index_table) { if (demux->index_table) {
guint i; guint i;
@ -416,6 +417,32 @@ gst_mxf_demux_handle_partition_pack (GstMXFDemux * demux, const MXFUL * key,
if (demux->partition.type == MXF_PARTITION_PACK_HEADER) if (demux->partition.type == MXF_PARTITION_PACK_HEADER)
demux->footer_partition_pack_offset = demux->partition.footer_partition; demux->footer_partition_pack_offset = demux->partition.footer_partition;
if (!demux->parsed_random_index_pack) {
MXFRandomIndexPackEntry entry, *last_entry = NULL;
GST_DEBUG_OBJECT (demux, "Adding partition pack to index");
if (demux->partition_index && demux->partition_index->len > 0) {
last_entry =
&g_array_index (demux->partition_index, MXFRandomIndexPackEntry,
demux->partition_index->len - 1);
} else if (!demux->partition_index) {
demux->partition_index =
g_array_new (FALSE, FALSE, sizeof (MXFRandomIndexPackEntry));
}
if (last_entry && last_entry->offset >= demux->offset) {
GST_DEBUG_OBJECT (demux,
"Not adding partition pack to index because it's before the last indexed one");
return GST_FLOW_OK;
}
entry.offset = demux->offset;
entry.body_sid = demux->partition.body_sid;
g_array_append_val (demux->partition_index, entry);
}
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -558,11 +585,11 @@ gst_mxf_demux_choose_package (GstMXFDemux * demux)
for (i = 0; i < demux->preface->content_storage->n_packages; i++) { for (i = 0; i < demux->preface->content_storage->n_packages; i++) {
if (demux->preface->content_storage->packages[i] && if (demux->preface->content_storage->packages[i] &&
MXF_IS_METADATA_MATERIAL_PACKAGE (demux->preface-> MXF_IS_METADATA_MATERIAL_PACKAGE (demux->preface->content_storage->
content_storage->packages[i])) { packages[i])) {
ret = ret =
MXF_METADATA_GENERIC_PACKAGE (demux->preface-> MXF_METADATA_GENERIC_PACKAGE (demux->preface->content_storage->
content_storage->packages[i]); packages[i]);
break; break;
} }
} }
@ -985,8 +1012,8 @@ gst_mxf_demux_pad_next_component (GstMXFDemux * demux, GstMXFDemuxPad * pad)
GST_DEBUG_OBJECT (demux, "Switching to component %u", pad->current_component); GST_DEBUG_OBJECT (demux, "Switching to component %u", pad->current_component);
pad->component = pad->component =
MXF_METADATA_SOURCE_CLIP (sequence-> MXF_METADATA_SOURCE_CLIP (sequence->structural_components[pad->
structural_components[pad->current_component]); current_component]);
if (pad->component == NULL) { if (pad->component == NULL) {
GST_ERROR_OBJECT (demux, "No such structural component"); GST_ERROR_OBJECT (demux, "No such structural component");
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
@ -994,8 +1021,8 @@ gst_mxf_demux_pad_next_component (GstMXFDemux * demux, GstMXFDemuxPad * pad)
if (!pad->component->source_package if (!pad->component->source_package
|| !pad->component->source_package->top_level || !pad->component->source_package->top_level
|| !MXF_METADATA_GENERIC_PACKAGE (pad->component->source_package)-> || !MXF_METADATA_GENERIC_PACKAGE (pad->component->
tracks) { source_package)->tracks) {
GST_ERROR_OBJECT (demux, "Invalid component"); GST_ERROR_OBJECT (demux, "Invalid component");
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -1272,7 +1299,7 @@ gst_mxf_demux_handle_random_index_pack (GstMXFDemux * demux, const MXFUL * key,
"Handling random index pack of size %u at offset %" "Handling random index pack of size %u at offset %"
G_GUINT64_FORMAT, GST_BUFFER_SIZE (buffer), demux->offset); G_GUINT64_FORMAT, GST_BUFFER_SIZE (buffer), demux->offset);
if (demux->partition_index) { if (demux->partition_index || demux->parsed_random_index_pack) {
GST_DEBUG_OBJECT (demux, "Already parsed random index pack"); GST_DEBUG_OBJECT (demux, "Already parsed random index pack");
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -1283,6 +1310,8 @@ gst_mxf_demux_handle_random_index_pack (GstMXFDemux * demux, const MXFUL * key,
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
demux->parsed_random_index_pack = TRUE;
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -1691,7 +1720,7 @@ gst_mxf_demux_handle_klv_packet (GstMXFDemux * demux, const MXFUL * key,
&& demux->partition.type == MXF_PARTITION_PACK_HEADER && demux->partition.type == MXF_PARTITION_PACK_HEADER
&& (!demux->partition.closed || !demux->partition.complete) && (!demux->partition.closed || !demux->partition.complete)
&& (demux->footer_partition_pack_offset != 0 || && (demux->footer_partition_pack_offset != 0 ||
demux->partition_index->len > 0)) { demux->parsed_random_index_pack)) {
GST_DEBUG_OBJECT (demux, GST_DEBUG_OBJECT (demux,
"Open or incomplete header partition, trying to get final metadata from the last partitions"); "Open or incomplete header partition, trying to get final metadata from the last partitions");
gst_mxf_demux_parse_footer_metadata (demux); gst_mxf_demux_parse_footer_metadata (demux);

View file

@ -71,6 +71,7 @@ struct _GstMXFDemux
MXFPartitionPack partition; MXFPartitionPack partition;
MXFPrimerPack primer; MXFPrimerPack primer;
gboolean parsed_random_index_pack;
GArray *partition_index; GArray *partition_index;
GArray *index_table; GArray *index_table;