diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-05-25 19:58:57 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-05-25 19:58:57 +0000 |
| commit | 5e8d2b5a9509adaae3e6a2ebc6145e45d69770db (patch) | |
| tree | 56a06449ebd92e628b0484882e483c4717f93f5f | |
| parent | df5422ee06ec484c25fcc35fb9d5cd0d19b1cf66 (diff) | |
| download | qmmp-5e8d2b5a9509adaae3e6a2ebc6145e45d69770db.tar.gz qmmp-5e8d2b5a9509adaae3e6a2ebc6145e45d69770db.tar.bz2 qmmp-5e8d2b5a9509adaae3e6a2ebc6145e45d69770db.zip | |
id3v2 support for streams
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@384 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/Input/mad/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/plugins/Input/mad/decoder_mad.cpp | 25 | ||||
| -rw-r--r-- | src/plugins/Input/mad/mad.pro | 12 | ||||
| -rw-r--r-- | src/plugins/Input/mad/tagextractor.cpp | 115 | ||||
| -rw-r--r-- | src/plugins/Input/mad/tagextractor.h | 67 |
5 files changed, 208 insertions, 13 deletions
diff --git a/src/plugins/Input/mad/CMakeLists.txt b/src/plugins/Input/mad/CMakeLists.txt index 690ec5629..eca08f578 100644 --- a/src/plugins/Input/mad/CMakeLists.txt +++ b/src/plugins/Input/mad/CMakeLists.txt @@ -37,6 +37,7 @@ SET(libmad_SRCS decodermadfactory.cpp detailsdialog.cpp settingsdialog.cpp + tagextractor.cpp ) SET(libmad_MOC_HDRS @@ -44,6 +45,7 @@ SET(libmad_MOC_HDRS decodermadfactory.h decoder_mad.h detailsdialog.h + tagextractor.h ) SET(libmad_RCCS translations/translations.qrc) diff --git a/src/plugins/Input/mad/decoder_mad.cpp b/src/plugins/Input/mad/decoder_mad.cpp index ef3b73b4e..1a58dc1c5 100644 --- a/src/plugins/Input/mad/decoder_mad.cpp +++ b/src/plugins/Input/mad/decoder_mad.cpp @@ -1,6 +1,7 @@ #include <QtGui> #include "decoder_mad.h" +#include "tagextractor.h" #include <qmmp/constants.h> #include <qmmp/buffer.h> #include <qmmp/output.h> @@ -8,7 +9,7 @@ #include <math.h> #include <stdio.h> -# define XING_MAGIC (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g') +# define XING_MAGIC (('X' << 24) | ('i' << 16) | ('n' << 8) | 'g') DecoderMAD::DecoderMAD(QObject *parent, DecoderFactory *d, QIODevice *i, Output *o) @@ -100,6 +101,14 @@ bool DecoderMAD::initialize() } } + if (input()->isSequential ()) //for streams only + { + TagExtractor extractor(input()); + FileTag tag = extractor.id3v2tag(); + if (!tag.isEmpty()) + dispatch(extractor.id3v2tag()); + } + mad_stream_init(&stream); mad_frame_init(&frame); mad_synth_init(&synth); @@ -118,7 +127,7 @@ bool DecoderMAD::initialize() void DecoderMAD::deinit() { - if(!inited) + if (!inited) return; mad_synth_finish(&synth); @@ -232,10 +241,10 @@ bool DecoderMAD::findHeader() if (mad_frame_decode(&frame, &stream) != -1) done = true; else if (!MAD_RECOVERABLE(stream.error)) - { - qWarning("DecoderMAD: Can't decode frame"); - break; - } + { + qWarning("DecoderMAD: Can't decode frame"); + break; + } count++; } @@ -344,7 +353,7 @@ void DecoderMAD::run() mutex()->unlock(); return; } - + DecoderState::Type stat = DecoderState::Decoding; @@ -433,7 +442,7 @@ void DecoderMAD::run() break; } - if(skip_frames) + if (skip_frames) { skip_frames-- ; mutex()->unlock(); diff --git a/src/plugins/Input/mad/mad.pro b/src/plugins/Input/mad/mad.pro index 5b2e2873b..dfafd0343 100644 --- a/src/plugins/Input/mad/mad.pro +++ b/src/plugins/Input/mad/mad.pro @@ -6,13 +6,15 @@ FORMS += detailsdialog.ui \ HEADERS += decodermadfactory.h \ decoder_mad.h \ detailsdialog.h \ - settingsdialog.h + settingsdialog.h \ + tagextractor.h SOURCES += decoder_mad.cpp \ decodermadfactory.cpp \ detailsdialog.cpp \ - settingsdialog.cpp + settingsdialog.cpp \ + tagextractor.cpp -TARGET=$$PLUGINS_PREFIX/Input/mad +TARGET =$$PLUGINS_PREFIX/Input/mad QMAKE_CLEAN =$$PLUGINS_PREFIX/Input/libmad.so INCLUDEPATH += ../../../ @@ -32,8 +34,8 @@ TRANSLATIONS = translations/mad_plugin_ru.ts \ translations/mad_plugin_de.ts RESOURCES = translations/translations.qrc -isEmpty (LIB_DIR){ -LIB_DIR = /lib +isEmpty(LIB_DIR){ + LIB_DIR = /lib } target.path = $$LIB_DIR/qmmp/Input INSTALLS += target diff --git a/src/plugins/Input/mad/tagextractor.cpp b/src/plugins/Input/mad/tagextractor.cpp new file mode 100644 index 000000000..dab104ab2 --- /dev/null +++ b/src/plugins/Input/mad/tagextractor.cpp @@ -0,0 +1,115 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QIODevice> +#include <QSettings> +#include <QByteArray> +#include <QBuffer> +#include <QTextCodec> +#include <QSettings> +#include <QDir> +#include <stdlib.h> + +#include "tagextractor.h" + +TagExtractor::TagExtractor(QIODevice *d) +{ + m_d = d; +} + + +TagExtractor::~TagExtractor() +{ +} + +const FileTag &TagExtractor::id3v2tag() +{ + QByteArray array = m_d->peek(2048); + int offset = array.indexOf("ID3"); + if (offset < 0) + return m_tag; + ID3v2Tag taglib_tag(&array, offset); + if (taglib_tag.isEmpty()) + return m_tag; + + TagLib::String album = taglib_tag.album(); + TagLib::String artist = taglib_tag.artist(); + TagLib::String comment = taglib_tag.comment(); + TagLib::String genre = taglib_tag.genre(); + TagLib::String title = taglib_tag.title(); + + QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat); + settings.beginGroup("MAD"); + QByteArray name = settings.value("ID3v2_encoding","UTF-8").toByteArray (); + bool utf = FALSE; + QTextCodec *codec = 0; + if (name.contains("UTF")) + { + codec = QTextCodec::codecForName ("UTF-8"); + utf = TRUE; + } + else + codec = QTextCodec::codecForName(name); + settings.endGroup(); + + if (!codec) + codec = QTextCodec::codecForName ("UTF-8"); + + m_tag.setValue(FileTag::ALBUM, + codec->toUnicode(album.toCString(utf)).trimmed()); + m_tag.setValue(FileTag::ARTIST, + codec->toUnicode(artist.toCString(utf)).trimmed()); + m_tag.setValue(FileTag::COMMENT, + codec->toUnicode(comment.toCString(utf)).trimmed()); + m_tag.setValue(FileTag::GENRE, + codec->toUnicode(genre.toCString(utf)).trimmed()); + m_tag.setValue(FileTag::TITLE, + codec->toUnicode(title.toCString(utf)).trimmed()); + m_tag.setValue(FileTag::YEAR, + taglib_tag.year()); + m_tag.setValue(FileTag::TRACK, + taglib_tag.track()); + + return m_tag; + +} + +ID3v2Tag::ID3v2Tag(QByteArray *array, long offset) : TagLib::ID3v2::Tag() +{ + m_buf = new QBuffer(array); + m_buf->open(QIODevice::ReadOnly); + m_offset = offset; + read(); +} + +void ID3v2Tag::read () +{ + m_buf->seek(m_offset); + uint to_read = TagLib::ID3v2::Header::size(); + if (to_read > 2048 - uint(m_offset)) + return; + header()->setData(TagLib::ByteVector(m_buf->read(to_read).data(), to_read)); + to_read = header()->tagSize(); + if (!to_read || 2048 < m_offset + TagLib::ID3v2::Header::size()) + return; + QByteArray array = m_buf->read(to_read); + TagLib::ByteVector v(array.data(), array.size()); + parse(v); +} diff --git a/src/plugins/Input/mad/tagextractor.h b/src/plugins/Input/mad/tagextractor.h new file mode 100644 index 000000000..c6fe70df3 --- /dev/null +++ b/src/plugins/Input/mad/tagextractor.h @@ -0,0 +1,67 @@ +/*************************************************************************** + * Copyright (C) 2008 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef TAGEXTRACTOR_H +#define TAGEXTRACTOR_H + + + +#include <taglib/tag.h> +#include <taglib/fileref.h> +#include <taglib/id3v1tag.h> +#include <taglib/id3v2tag.h> + +#include <qmmp/filetag.h> + +class QIODevice; +class QBuffer; +class QByteArray; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class TagExtractor +{ +public: + TagExtractor(QIODevice *d); + + ~TagExtractor(); + +const FileTag &id3v2tag(); + +private: + FileTag m_tag; + QIODevice *m_d; + +}; + +class ID3v2Tag : public TagLib::ID3v2::Tag +{ +public: + ID3v2Tag(QByteArray *array, long offset); + +protected: + void read (); + +private: + QBuffer *m_buf; + long m_offset; +}; + +#endif |
