aboutsummaryrefslogtreecommitdiff
path: root/lib/decoder.cpp
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/decoder.cpp
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/decoder.cpp')
-rw-r--r--lib/decoder.cpp47
1 files changed, 38 insertions, 9 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);