aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2007-08-06 08:09:29 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2007-08-06 08:09:29 +0000
commita81ae71cb491c6e8d5a208a0b9b352fa11381a13 (patch)
treee5b764220888263314e90214510b1ae9ce2d926c /lib
parent7d75d2947cd4d1a9ff1da7e3b2d4bb2c7a0d9c69 (diff)
downloadqmmp-a81ae71cb491c6e8d5a208a0b9b352fa11381a13.tar.gz
qmmp-a81ae71cb491c6e8d5a208a0b9b352fa11381a13.tar.bz2
qmmp-a81ae71cb491c6e8d5a208a0b9b352fa11381a13.zip
added identification by content (ogg vorbis and mpeg)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@61 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'lib')
-rw-r--r--lib/decoder.cpp47
-rw-r--r--lib/decoder.h5
-rw-r--r--lib/qmmp/Input/mad/decodermadfactory.cpp22
-rw-r--r--lib/qmmp/Input/vorbis/decodervorbisfactory.cpp8
-rw-r--r--lib/soundcore.cpp2
-rw-r--r--lib/streamreader.cpp10
-rw-r--r--lib/streamreader.h2
7 files changed, 73 insertions, 23 deletions
diff --git a/lib/decoder.cpp b/lib/decoder.cpp
index 4e17c38a0..8b2fac51a 100644
--- a/lib/decoder.cpp
+++ b/lib/decoder.cpp
@@ -138,19 +138,32 @@ Decoder *Decoder::create(QObject *parent, const QString &source,
qDebug(qPrintable(source));
DecoderFactory *fact = 0;
- StreamReader* reader = qobject_cast<StreamReader *>(input);
- if(reader)
- fact = Decoder::findByContentType(reader->contentType());
+ if(!input->open(QIODevice::ReadOnly))
+ {
+ qDebug("Decoder: cannot open input");
+ return decoder;
+ }
+ StreamReader* sreader = qobject_cast<StreamReader *>(input);
+ if(sreader)
+ {
+ fact = Decoder::findByMime(sreader->contentType());
+ if(!fact)
+ fact = Decoder::findByContent(sreader);
+ }
else
- fact = Decoder::findFactory(source);
+ fact = Decoder::findByPath(source);
+
if (fact)
{
decoder = fact->create(parent, input, output);
}
+ if(!decoder)
+ input->close();
+
return decoder;
}
-DecoderFactory *Decoder::findFactory(const QString& source)
+DecoderFactory *Decoder::findByPath(const QString& source)
{
checkFactories();
@@ -162,11 +175,11 @@ DecoderFactory *Decoder::findFactory(const QString& source)
return factories->at(i);
}
}
- qDebug("Decoder: unable to find factory");
+ qDebug("Decoder: unable to find factory by path");
return 0;
}
-DecoderFactory *Decoder::findByContentType(const QString& type)
+DecoderFactory *Decoder::findByMime(const QString& type)
{
checkFactories();
for (int i=0; i<factories->size(); ++i)
@@ -181,13 +194,29 @@ DecoderFactory *Decoder::findByContentType(const QString& type)
}
}
}
- qDebug("Decoder: unable to find factory");
+ qDebug("Decoder: unable to find factory by mime");
+ return 0;
+}
+
+DecoderFactory *Decoder::findByContent(QIODevice *input)
+{
+ checkFactories();
+
+ for (int i=0; i<factories->size(); ++i)
+ {
+ if (factories->at(i)->canDecode(input) &&
+ !blacklist.contains(files.at(i).section('/',-1)))
+ {
+ return factories->at(i);
+ }
+ }
+ qDebug("Decoder: unable to find factory by content");
return 0;
}
FileTag *Decoder::createTag(const QString& source)
{
- DecoderFactory *fact = Decoder::findFactory(source);
+ DecoderFactory *fact = Decoder::findByPath(source);
if (fact)
{
return fact->createTag(source);
diff --git a/lib/decoder.h b/lib/decoder.h
index 8f2649366..d5d34cf4e 100644
--- a/lib/decoder.h
+++ b/lib/decoder.h
@@ -126,8 +126,9 @@ public:
static bool supports(const QString &);
//static void registerFactory(DecoderFactory *);
static Decoder *create(QObject *, const QString &, QIODevice *, Output *);
- static DecoderFactory *findFactory(const QString&);
- static DecoderFactory *findByContentType(const QString&);
+ static DecoderFactory *findByPath(const QString&);
+ static DecoderFactory *findByMime(const QString&);
+ static DecoderFactory *findByContent(QIODevice *);
static FileTag *createTag(const QString&);
static QString filter();
static QStringList nameFilters();
diff --git a/lib/qmmp/Input/mad/decodermadfactory.cpp b/lib/qmmp/Input/mad/decodermadfactory.cpp
index de23d1fb4..b253a60fa 100644
--- a/lib/qmmp/Input/mad/decodermadfactory.cpp
+++ b/lib/qmmp/Input/mad/decodermadfactory.cpp
@@ -1,6 +1,7 @@
#include <QtGui>
#include <QDialog>
#include <QMessageBox>
+#include <mad.h>
#include <taglib/tag.h>
#include <taglib/fileref.h>
#include <taglib/id3v1tag.h>
@@ -24,8 +25,25 @@ bool DecoderMADFactory::supports(const QString &source) const
bool DecoderMADFactory::canDecode(QIODevice *input) const
{
- static bool c = FALSE;
- return c;
+ char buf[16 * 512];
+
+ if (input->peek(buf,sizeof(buf)) == sizeof(buf))
+ {
+ 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));
+ stream.error = MAD_ERROR_NONE;
+
+ while((dec_res = mad_header_decode(&header, &stream)) == -1
+ && MAD_RECOVERABLE(stream.error))
+ ;
+ return dec_res != -1 ? TRUE: FALSE;
+ }
+ return FALSE;
}
const DecoderProperties &DecoderMADFactory::properties() const
diff --git a/lib/qmmp/Input/vorbis/decodervorbisfactory.cpp b/lib/qmmp/Input/vorbis/decodervorbisfactory.cpp
index 0e95ebc43..682e58229 100644
--- a/lib/qmmp/Input/vorbis/decodervorbisfactory.cpp
+++ b/lib/qmmp/Input/vorbis/decodervorbisfactory.cpp
@@ -42,8 +42,12 @@ const QString &DecoderVorbisFactory::contentType() const
bool DecoderVorbisFactory::canDecode(QIODevice *input) const
{
- static bool c = FALSE;
- return c;
+ char buf[36];
+ if (input->peek(buf, 36) == 36 && !memcmp(buf, "OggS", 4)
+ && !memcmp(buf + 29, "vorbis", 6))
+ return TRUE;
+
+ return FALSE;
}
const DecoderProperties &DecoderVorbisFactory::properties() const
diff --git a/lib/soundcore.cpp b/lib/soundcore.cpp
index e84d2925a..69424bb70 100644
--- a/lib/soundcore.cpp
+++ b/lib/soundcore.cpp
@@ -121,7 +121,7 @@ bool SoundCore::play(const QString &source)
setEQ(m_bands, m_preamp);
setEQEnabled(m_useEQ);
}
- qDebug("Decoder create OK");
+ qDebug("SoundCore: decoder was created successfully");
if (m_decoder->initialize())
{
diff --git a/lib/streamreader.cpp b/lib/streamreader.cpp
index a72d85363..e1af3201f 100644
--- a/lib/streamreader.cpp
+++ b/lib/streamreader.cpp
@@ -77,18 +77,20 @@ bool StreamReader::open ( OpenMode mode )
return TRUE;
}
-qint64 StreamReader::pos () const
+/*qint64 StreamReader::pos () const
{
return m_pos;
-}
+}*/
bool StreamReader::reset ()
{
+ QIODevice::reset();
return TRUE;
}
bool StreamReader::seek ( qint64 pos )
{
+ QIODevice::seek(pos);
return FALSE;
}
@@ -192,8 +194,6 @@ void StreamReader::fillBuffer()
const QString &StreamReader::contentType()
{
- //Downloader* dw = new Downloader(this, "http://127.0.0.1:8000/");
- m_downloader->start();
while (m_contentType.isEmpty() && m_downloader->isRunning())
{
m_downloader->mutex()->lock ();
@@ -201,8 +201,6 @@ const QString &StreamReader::contentType()
m_downloader->mutex()->unlock();
qApp->processEvents();
}
- //m_contentType = dw->contentType();
- m_downloader->abort();
qDebug("StreamReader: content type: %s", qPrintable(m_contentType));
return m_contentType;
}
diff --git a/lib/streamreader.h b/lib/streamreader.h
index 2489402ed..9b0af5df7 100644
--- a/lib/streamreader.h
+++ b/lib/streamreader.h
@@ -50,7 +50,7 @@ public:
void close ();
bool isSequential () const;
bool open ( OpenMode mode );
- qint64 pos () const;
+ //qint64 pos () const;
bool reset ();
bool seek ( qint64 pos );
qint64 size () const;