From 7ac4dd3d9d763a58bfff01bc771e1df9e466195f Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Thu, 12 May 2022 07:23:29 +0200 Subject: [PATCH] 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: --- subprojects/gst-plugins-bad/gst/mxf/mxfdemux.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/mxf/mxfdemux.c b/subprojects/gst-plugins-bad/gst/mxf/mxfdemux.c index 243f593..b0ccc17 100644 --- a/subprojects/gst-plugins-bad/gst/mxf/mxfdemux.c +++ b/subprojects/gst-plugins-bad/gst/mxf/mxfdemux.c @@ -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; -- 2.7.4