diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-02-01 18:06:06 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-02-01 18:06:06 +0000 |
| commit | 23ca6b1444c69d5115d70d203db346204e6b44fc (patch) | |
| tree | f3ab33c0f6f64eb6c27ad484b2ef55ccd57a5f21 /src | |
| parent | 7e9e91c7a4ba8932db88d4c61f67491a4e2b0210 (diff) | |
| download | qmmp-23ca6b1444c69d5115d70d203db346204e6b44fc.tar.gz qmmp-23ca6b1444c69d5115d70d203db346204e6b44fc.tar.bz2 qmmp-23ca6b1444c69d5115d70d203db346204e6b44fc.zip | |
mad plugin: skip ID3v2 tag
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@771 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
| -rw-r--r-- | src/plugins/Input/mad/decoder_mad.cpp | 35 | ||||
| -rw-r--r-- | src/plugins/Input/mad/decoder_mad.h | 1 |
2 files changed, 33 insertions, 3 deletions
diff --git a/src/plugins/Input/mad/decoder_mad.cpp b/src/plugins/Input/mad/decoder_mad.cpp index 0eab8cfaa..daa1d8872 100644 --- a/src/plugins/Input/mad/decoder_mad.cpp +++ b/src/plugins/Input/mad/decoder_mad.cpp @@ -6,6 +6,8 @@ #include <QtGui> +#include <taglib/id3v2header.h> +#include <taglib/tbytevector.h> #include "decoder_mad.h" #include "tagextractor.h" @@ -393,7 +395,7 @@ void DecoderMAD::flush(bool final) void DecoderMAD::run() { - int skip_frames = 1; //skip first frame + int skip_frames = 0; //skip first frame mutex()->lock(); if (! inited) @@ -461,18 +463,28 @@ void DecoderMAD::run() mutex()->unlock(); // decode - while (! done && ! m_finish && ! derror) + while (!done && !m_finish && !derror) { if (mad_frame_decode(&frame, &stream) == -1) { if (stream.error == MAD_ERROR_LOSTSYNC) + { + //skip ID3v2 tag + uint tagSize = findID3v2((uchar *)stream.this_frame, + (uint) stream.bufend - (uint) stream.this_frame); + if (tagSize > 0) + { + mad_stream_skip(&stream, tagSize); + qDebug("DecoderMAD: %d bytes skipped", tagSize); + } continue; + } if (stream.error == MAD_ERROR_BUFLEN) break; // error in decoding - if (! MAD_RECOVERABLE(stream.error)) + if (!MAD_RECOVERABLE(stream.error)) { derror = true; break; @@ -536,6 +548,23 @@ void DecoderMAD::run() } +uint DecoderMAD::findID3v2(uchar *data, uint size) //retuns ID3v2 tag size +{ + if (size < 10) + return 0; + + if (((data[0] == 'I' && data[1] == 'D' && data[2] == '3') || //ID3v2 tag + (data[0] == '3' && data[1] == 'D' && data[2] == 'I')) && //ID3v2 footer + data[3] < 0xff && data[4] < 0xff && data[6] < 0x80 && + data[7] < 0x80 && data[8] < 0x80 && data[9] < 0x80) + { + TagLib::ByteVector byteVector((char *)data, size); + TagLib::ID3v2::Header header(byteVector); + return header.tagSize(); + } + return 0; +} + static inline signed int scale(mad_fixed_t sample) { /* round */ diff --git a/src/plugins/Input/mad/decoder_mad.h b/src/plugins/Input/mad/decoder_mad.h index 7de09b594..5caca7eba 100644 --- a/src/plugins/Input/mad/decoder_mad.h +++ b/src/plugins/Input/mad/decoder_mad.h @@ -43,6 +43,7 @@ private: void deinit(); bool findHeader(); bool findXingHeader(struct mad_bitptr, unsigned int); + uint findID3v2(uchar *data, uint size); bool inited, user_stop, done, m_finish, derror, eof, useeq; qint64 totalTime, seekTime; int channels; |
