gst/typefind/gsttypefindfunctions.c: Improve MXF typefinding a bit by searching for...
authorSebastian Dröge <slomo@circular-chaos.org>
Mon, 20 Oct 2008 14:08:52 +0000 (14:08 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 20 Oct 2008 14:08:52 +0000 (14:08 +0000)
Original commit message from CVS:
* gst/typefind/gsttypefindfunctions.c: (mxf_type_find):
Improve MXF typefinding a bit by searching for a header partition
pack instead of just a general partition pack and checking more
bytes for valid values.

ChangeLog
gst/typefind/gsttypefindfunctions.c

index bf6a08b..f2f4f2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-10-20  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
+       * gst/typefind/gsttypefindfunctions.c: (mxf_type_find):
+       Improve MXF typefinding a bit by searching for a header partition
+       pack instead of just a general partition pack and checking more
+       bytes for valid values.
+
 2008-10-20  Wim Taymans  <wim.taymans@collabora.co.uk>
 
        * tests/icles/.cvsignore:
index a36e32a..ea33632 100644 (file)
@@ -2375,28 +2375,41 @@ static GstStaticCaps mxf_caps = GST_STATIC_CAPS ("application/mxf");
 #define MXF_CAPS (gst_static_caps_get(&mxf_caps))
 
 /*
- * Quoting http://www.digitalpreservation.gov/formats/fdd/fdd000013.shtml:
- * "MXF files start with an optional run-in followed by the SMPTE header partition pack key.
- *  The run-in is less than 64k bytes and the condition for finding the start of the file is
- *  to identify the first 11 bytes of the partition pack key . . . scan the initial 64 k bytes
- *  for these 11 bytes" to identify an MXF file. (From SMPTE EG 41, p. 45) The 11 bytes listed
- *  are from SMPTE 377M, p.20.
+ * MXF files start with a header partition pack key of 16 bytes which is defined
+ * at SMPTE-377M 6.1. Before this there can be up to 64K of run-in which _must_
+ * not contain the partition pack key.
  */
 static void
 mxf_type_find (GstTypeFind * tf, gpointer ununsed)
 {
-  static const guint8 header_partition_pack_key[] =
-      { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02 };
+  static const guint8 partition_pack_key[] =
+      { 0x06, 0x0e, 0x2b, 0x34, 0x02, 0x05, 0x01, 0x01, 0x0d, 0x01, 0x02, 0x01,
+    0x01
+  };
   DataScanCtx c = { 0, NULL, 0 };
 
   while (c.offset <= MXF_MAX_PROBE_LENGTH) {
-    if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 11)))
+    if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 16)))
       break;
 
-    if (memcmp (c.data, header_partition_pack_key, 11) == 0) {
+    if (memcmp (c.data, partition_pack_key, 13) == 0) {
+      /* Header partition pack? */
+      if (c.data[13] != 0x02)
+        goto advance;
+
+      /* Partition status */
+      if (c.data[14] >= 0x05)
+        goto advance;
+
+      /* Reserved, must be 0x00 */
+      if (c.data[15] != 0x00)
+        goto advance;
+
       gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, MXF_CAPS);
       return;
     }
+
+  advance:
     data_scan_ctx_advance (tf, &c, 1);
   }
 }