diff options
author | Ronald S. Bultje <rbultje@ronald.bitfreak.net> | 2003-04-07 16:49:23 +0000 |
---|---|---|
committer | Ronald S. Bultje <rbultje@ronald.bitfreak.net> | 2003-04-07 16:49:23 +0000 |
commit | 3cec98c729b0d1f23e7c2a903ddb7d0b51a54946 (patch) | |
tree | bd6a6fd286e20c04e93625f18a725d971c18a739 | |
parent | e8f38e68ebcab33b10278c22f494a896735e279f (diff) | |
download | gst-plugins-bad-3cec98c729b0d1f23e7c2a903ddb7d0b51a54946.tar.gz gst-plugins-bad-3cec98c729b0d1f23e7c2a903ddb7d0b51a54946.tar.bz2 gst-plugins-bad-3cec98c729b0d1f23e7c2a903ddb7d0b51a54946.zip |
Fixes #104854
Original commit message from CVS:
Fixes #104854
-rw-r--r-- | gst/mpegaudioparse/gstmp3types.c | 56 |
1 files changed, 36 insertions, 20 deletions
diff --git a/gst/mpegaudioparse/gstmp3types.c b/gst/mpegaudioparse/gstmp3types.c index ef0e4c05..2e91397d 100644 --- a/gst/mpegaudioparse/gstmp3types.c +++ b/gst/mpegaudioparse/gstmp3types.c @@ -32,7 +32,7 @@ static GstCaps* mp3_type_find(GstBuffer *buf, gpointer private) { guint8 *data; - gint size; + gint size, offset; guint32 head; GstCaps *caps; @@ -48,13 +48,11 @@ mp3_type_find(GstBuffer *buf, gpointer private) data += 128; GST_DEBUG (0, "mp3typefind: detected ID3 Tag V1"); - } - else { + } else { if (size >= 10 && (data[0] == 'I' && data[1] == 'D' && data[2] == '3') && data[3] < 0xff && data[4] < 0xff && - data[6] < 0x80 && data[7] < 0x80 && data[8] < 0x80 && data[9] < 0x80) - { + data[6] < 0x80 && data[7] < 0x80 && data[8] < 0x80 && data[9] < 0x80) { guint32 skip = 0; skip = (skip << 7) | (data[6] & 0x7f); @@ -75,28 +73,46 @@ mp3_type_find(GstBuffer *buf, gpointer private) /* we currently accept a valid ID3 tag as an mp3 as some ID3 tags have invalid * offsets so the next check might fail */ - goto done; + goto success; } } - /* make sure there is enough of a buffer to check without running over */ + /* if we don't have enough bytes left to check for a header, die */ if (size < 4) return NULL; - /* now with the right postion, do typefinding */ - head = GUINT32_FROM_BE(*((gulong *)data)); - if ((head & 0xffe00000) != 0xffe00000) - return NULL; - if (!((head >> 17) & 3)) - return NULL; - if (((head >> 12) & 0xf) == 0xf) - return NULL; - if (!((head >> 12) & 0xf)) - return NULL; - if (((head >> 10) & 0x3) == 0x3) - return NULL; + /* Now search through the entire rest of the buffer for a valid header. + * This is a very rough initial cut, it should be checking the length of + * the frame and verifying that there is indeed a second frame. The mp3 + * header could very well be a false trigger otherwise. + */ + for (offset=0; offset < (size-4); offset++) { + head = GUINT32_FROM_BE(*((gulong *)data)); + +/* old negative checks + if ((head & 0xffe00000) != 0xffe00000) + return NULL; + if (!((head >> 17) & 3)) + return NULL; + if (((head >> 12) & 0xf) == 0xf) + return NULL; + if (!((head >> 12) & 0xf)) + return NULL; + if (((head >> 10) & 0x3) == 0x3) + return NULL; +*/ + + if ( ((head & 0xffe00000) == 0xffe00000) && + (((head >> 17) & 0x3) != 0x0) && + (((head >> 12) & 0xf) != 0xf) && + (((head >> 12) & 0xf) != 0x0) && + (((head >> 10) & 0x3) != 0x3) ) + goto success; + } + + return NULL; -done: +success: caps = gst_caps_new ("mp3_type_find", "audio/x-mp3", NULL); return caps; |