diff --git a/ext/flac/gstflac.c b/ext/flac/gstflac.c index b8dd73e814..2c30df32d5 100644 --- a/ext/flac/gstflac.c +++ b/ext/flac/gstflac.c @@ -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; }