port #121143 to HEAD (flac file detection)
authorJeremy Simon <jsimon13@yahoo.fr>
Sat, 20 Sep 2003 19:34:31 +0000 (19:34 +0000)
committerJeremy Simon <jsimon13@yahoo.fr>
Sat, 20 Sep 2003 19:34:31 +0000 (19:34 +0000)
Original commit message from CVS:
port #121143 to HEAD (flac file detection)

ext/flac/gstflac.c

index b8dd73e..2c30df3 100644 (file)
@@ -68,19 +68,39 @@ static GstTypeDefinition flacdefinition = {
   flac_type_find,
 };
 
+
 static GstCaps* 
 flac_type_find (GstBuffer *buf, gpointer private) 
 {
+  gint offset;
+  guint8 *data;
+  gint size;
   guint32 head;
   
   if (GST_BUFFER_SIZE (buf) < 4)
     return NULL;
 
+  data = GST_BUFFER_DATA (buf);
+  size = GST_BUFFER_SIZE (buf);
+  
   head = GUINT32_FROM_BE (*((guint32 *)GST_BUFFER_DATA (buf)));
-  if (head  != 0x664C6143)
-    return NULL;
 
-  return gst_caps_new ("flac_type_find", "audio/x-flac", NULL);
+  if (head  == 0x664C6143)
+    return gst_caps_new ("flac_type_find", "application/x-flac", NULL);
+  else {
+    /* checks for existance of flac identification header in case
+     * there's an ID3 tag */
+    for (offset = 0; offset < size-4; offset++) {
+      if (data[offset]   == 'f' && 
+          data[offset+1] == 'L' && 
+          data[offset+2] == 'a' &&
+          data[offset+3] == 'C' ) {
+        return gst_caps_new ("flac_type_find", "application/x-flac", NULL);
+      }
+    }
+  }
+
+  return NULL;
 }