From a81ae71cb491c6e8d5a208a0b9b352fa11381a13 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 6 Aug 2007 08:09:29 +0000 Subject: 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 --- lib/decoder.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) (limited to 'lib/decoder.cpp') 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(input); - if(reader) - fact = Decoder::findByContentType(reader->contentType()); + if(!input->open(QIODevice::ReadOnly)) + { + qDebug("Decoder: cannot open input"); + return decoder; + } + StreamReader* sreader = qobject_cast(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; isize(); ++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; isize(); ++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); -- cgit v1.2.3-13-gbd6f