mxfdemux: Handle files produced by legacy FFmpeg

Until March 2022, the FFmpeg MXF muxer would write the various index table
segments with the same instance ID, which should only be used if it is a
duplicate/repeated table.

In order to cope with those, we first compare the other index table segment
properties (body/index SID, start position) before comparing the instance
ID. This will ensure that we don't consider them as duplicate, but can still
detect "real" duplicates (which would have the same other properties).

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2407>
This commit is contained in:
Edward Hervey 2022-05-12 07:23:29 +02:00 committed by Edward Hervey
parent a1f30f5b9b
commit 7ac4dd3d9d

View file

@ -3320,16 +3320,22 @@ static gint
compare_index_table_segment (MXFIndexTableSegment * sa,
MXFIndexTableSegment * sb)
{
if (mxf_uuid_is_equal (&sa->instance_id, &sb->instance_id))
return 0;
if (sa->body_sid != sb->body_sid)
return (sa->body_sid < sb->body_sid) ? -1 : 1;
if (sa->index_sid != sb->index_sid)
return (sa->index_sid < sb->index_sid) ? -1 : 1;
/* Finally sort by index start position */
if (sa->index_start_position < sb->index_start_position)
return -1;
return (sa->index_start_position != sb->index_start_position);
if (sa->index_start_position != sb->index_start_position)
return (sa->index_start_position < sb->index_start_position) ? -1 : 1;
/* If all the above are equal ... the index table segments are only equal if
* their instance ID are equal. Until March 2022 the FFmpeg MXF muxer would
* write the same instance id for the various (different) index table
* segments, we therefore only check instance ID *after* all the above
* properties to make sure they are really different. */
if (mxf_uuid_is_equal (&sa->instance_id, &sb->instance_id))
return 0;
return 1;
}
#if !GLIB_CHECK_VERSION(2, 62, 0)
@ -3340,7 +3346,7 @@ has_table_segment (GArray * segments, MXFIndexTableSegment * target)
for (i = 0; i < segments->len; i++) {
MXFIndexTableSegment *cand =
&g_array_index (segments, MXFIndexTableSegment, i);
if (mxf_uuid_is_equal (&cand->instance_id, &target->instance_id))
if (compare_index_table_segment (cand, target) == 0)
return TRUE;
}
return FALSE;