commit 475de6737d98be14dae1ceae64761a4882c686a3
Author: Felipe Contreras <felipe.contreras@nokia.com>
Date:   Thu Sep 13 13:48:41 2007 +0300

    Fix ISO/IEC 14496-12 typefinding.

diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c
index ce33979..57b5a18 100644
--- a/gst/typefind/gsttypefindfunctions.c
+++ b/gst/typefind/gsttypefindfunctions.c
@@ -1686,10 +1686,54 @@ m4a_type_find (GstTypeFind * tf, gpointer unused)
 {
   guint8 *data = gst_type_find_peek (tf, 4, 8);
 
-  if (data &&
-      (memcmp (data, "ftypM4A ", 8) == 0 ||
-          memcmp (data, "ftypmp42", 8) == 0)) {
-    gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
+  if (!data || (memcmp (data, "ftyp", 4) != 0)) {
+    return;
+  }
+
+  {
+    gchar *ftyp;
+    ftyp = g_ascii_strdown ((gchar *) data + 4, 4);
+
+    if ((strncmp (ftyp, "m4a ", 4) == 0) ||
+        (strncmp (ftyp, "m4b ", 4) == 0) ||
+        (strncmp (ftyp, "m4p ", 4) == 0) ||
+        (strncmp (ftyp, "msnv", 4) == 0) ||
+        (strncmp (ftyp, "ndas", 4) == 0)) {
+      gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4A_CAPS);
+    }
+
+    g_free (ftyp);
+  }
+}
+
+static GstStaticCaps m4v_caps = GST_STATIC_CAPS ("video/mp4");
+
+#define M4V_CAPS (gst_static_caps_get(&m4v_caps))
+static void
+m4v_type_find (GstTypeFind * tf, gpointer unused)
+{
+  guint8 *data = gst_type_find_peek (tf, 4, 8);
+
+  if (!data || (memcmp (data, "ftyp", 4) != 0)) {
+    return;
+  }
+
+  {
+    gchar *ftyp;
+    ftyp = g_ascii_strdown ((gchar *) data + 4, 4);
+
+    if ((strncmp (ftyp, "avc1", 4) == 0) ||
+        (strncmp (ftyp, "isom", 4) == 0) ||
+        (strncmp (ftyp, "m4v ", 4) == 0) ||
+        (strncmp (ftyp, "mmp4", 4) == 0) ||
+        (strncmp (ftyp, "mp41", 4) == 0) ||
+        (strncmp (ftyp, "mp42", 4) == 0) ||
+        (strncmp (ftyp, "nds", 3) == 0) ||
+        (strncmp (ftyp, "ndx", 3) == 0)) {
+      gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, M4V_CAPS);
+    }
+
+    g_free (ftyp);
   }
 }
 
@@ -1708,6 +1752,7 @@ q3gp_type_find (GstTypeFind * tf, gpointer unused)
   guint32 ftyp_size = 0;
   gint offset = 0;
   guint8 *data = NULL;
+  gboolean found = FALSE;
 
   if ((data = gst_type_find_peek (tf, 0, 12)) == NULL) {
     return;
@@ -1720,10 +1765,20 @@ q3gp_type_find (GstTypeFind * tf, gpointer unused)
 
   /* check major brand */
   data += 4;
-  if (memcmp (data, "3gp", 3) == 0 ||
-      memcmp (data, "3gr", 3) == 0 ||
-      memcmp (data, "3gs", 3) == 0 || memcmp (data, "3gg", 3) == 0) {
-    gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, Q3GP_CAPS);
+  {
+    gchar *ftyp;
+    ftyp = g_ascii_strdown ((gchar *) data, 4);
+
+    if (strncmp (ftyp, "3g", 2) == 0 ||
+        strncmp (ftyp, "kddi", 4) == 0) {
+      gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, Q3GP_CAPS);
+      found = TRUE;
+    }
+
+    g_free (ftyp);
+  }
+
+  if (found) {
     return;
   }
 
@@ -2817,7 +2872,7 @@ plugin_init (GstPlugin * plugin)
   static gchar *gz_exts[] = { "gz", NULL };
   static gchar *zip_exts[] = { "zip", NULL };
   static gchar *compress_exts[] = { "Z", NULL };
-  static gchar *m4a_exts[] = { "m4a", NULL };
+  static gchar *m4a_exts[] = { "m4a", "m4p", "m4b", NULL };
   static gchar *q3gp_exts[] = { "3gp", NULL };
   static gchar *aac_exts[] = { "aac", NULL };
   static gchar *spc_exts[] = { "spc", NULL };
@@ -2831,6 +2886,7 @@ plugin_init (GstPlugin * plugin)
   };
   static gchar *flv_exts[] = { "flv", NULL };
   static gchar *m4v_exts[] = { "m4v", NULL };
+  static gchar *mp4_exts[] = { "mp4", "m4v", "mp4v", NULL };
   static gchar *nuv_exts[] = { "nuv", NULL };
   static gchar *vivo_exts[] = { "viv", NULL };
 
@@ -2888,6 +2944,8 @@ plugin_init (GstPlugin * plugin)
   /* ISO formats */
   TYPE_FIND_REGISTER (plugin, "audio/x-m4a", GST_RANK_PRIMARY, m4a_type_find,
       m4a_exts, M4A_CAPS, NULL, NULL);
+  TYPE_FIND_REGISTER (plugin, "video/mp4", GST_RANK_PRIMARY, m4v_type_find,
+      mp4_exts, M4V_CAPS, NULL, NULL);
   TYPE_FIND_REGISTER (plugin, "application/x-3gp", GST_RANK_PRIMARY,
       q3gp_type_find, q3gp_exts, Q3GP_CAPS, NULL, NULL);
   TYPE_FIND_REGISTER (plugin, "video/quicktime", GST_RANK_SECONDARY,
