aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input/mad
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2016-08-01 12:37:54 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2016-08-01 12:37:54 +0000
commit860a01511c7cd537382e77755d40d80a49190bbb (patch)
tree22e54b70de94c28ccb3059349c1de16d8bd5fb76 /src/plugins/Input/mad
parent18670c38c2ee9803687f031cec3e065379cf7d75 (diff)
downloadqmmp-860a01511c7cd537382e77755d40d80a49190bbb.tar.gz
qmmp-860a01511c7cd537382e77755d40d80a49190bbb.tar.bz2
qmmp-860a01511c7cd537382e77755d40d80a49190bbb.zip
mpeg decoder: improved file type detection
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@6628 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input/mad')
-rw-r--r--src/plugins/Input/mad/decodermadfactory.cpp38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/plugins/Input/mad/decodermadfactory.cpp b/src/plugins/Input/mad/decodermadfactory.cpp
index ec64c92ae..c3aebda8a 100644
--- a/src/plugins/Input/mad/decodermadfactory.cpp
+++ b/src/plugins/Input/mad/decodermadfactory.cpp
@@ -60,24 +60,50 @@ DecoderMADFactory::DecoderMADFactory()
bool DecoderMADFactory::canDecode(QIODevice *input) const
{
- char buf[16 * 512];
+ char buf[8192];
+ qint64 buf_at = sizeof(buf);
- if (input->peek(buf,sizeof(buf)) == sizeof(buf))
+ if(input->peek(buf, sizeof(buf)) != sizeof(buf))
+ return false;
+
+ if (!memcmp(buf + 8, "WAVE", 4) && !memcmp(buf + 20, "U" ,1))
+ return true;
+
+ if(!memcmp(buf, "ID3", 3))
{
- if (!memcmp(buf + 8, "WAVE", 4) && !memcmp(buf + 20, "U" ,1))
- return true;
+ TagLib::ByteVector byteVector(buf, sizeof(buf));
+ TagLib::ID3v2::Header header(byteVector);
+
+ //skip id3v2tag if possible
+ if(input->isSequential())
+ {
+ if(header.tagSize() >= sizeof(buf))
+ return false;
+
+ buf_at = sizeof(buf) - header.tagSize();
+ memmove(buf, buf + header.tagSize() + header.tagSize(), sizeof(buf) - header.tagSize());
+ }
+ else
+ {
+ input->seek(header.tagSize());
+ buf_at = input->read(buf, sizeof(buf));
+ input->seek(0);
+ }
+ }
+ if(buf_at > 0)
+ {
struct mad_stream stream;
struct mad_header header;
int dec_res;
mad_stream_init (&stream);
mad_header_init (&header);
- mad_stream_buffer (&stream, (unsigned char *) buf, sizeof(buf));
+ mad_stream_buffer (&stream, (unsigned char *) buf, buf_at);
stream.error = MAD_ERROR_NONE;
while ((dec_res = mad_header_decode(&header, &stream)) == -1
- && MAD_RECOVERABLE(stream.error))
+ && MAD_RECOVERABLE(stream.error))
;
return dec_res != -1 ? true: false;
}