Mercurial > hg > svcore
diff data/fileio/AudioFileReaderFactory.cpp @ 316:3a6725f285d6
* Make RemoteFile far more pervasive, and use it for local files as well
so that we can handle both transparently. Make it shallow copy with
reference counting, so it can be used by value without having to worry
about the cache file lifetime. Use RemoteFile for MainWindow file-open
functions, etc
author | Chris Cannam |
---|---|
date | Thu, 18 Oct 2007 15:31:20 +0000 |
parents | 14e0f60435b8 |
children | c324d410b096 |
line wrap: on
line diff
--- a/data/fileio/AudioFileReaderFactory.cpp Thu Oct 18 10:24:26 2007 +0000 +++ b/data/fileio/AudioFileReaderFactory.cpp Thu Oct 18 15:31:20 2007 +0000 @@ -54,24 +54,25 @@ } AudioFileReader * -AudioFileReaderFactory::createReader(QString path, size_t targetRate) +AudioFileReaderFactory::createReader(RemoteFile source, size_t targetRate) { QString err; - std::cerr << "AudioFileReaderFactory::createReader(\"" << path.toStdString() << "\"): Requested rate: " << targetRate << std::endl; + std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\"): Requested rate: " << targetRate << std::endl; + + if (!source.isOK() || !source.isAvailable()) { + std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\": Source unavailable" << std::endl; + return 0; + } AudioFileReader *reader = 0; - // First try to construct a preferred reader based on the - // extension. If we can't identify one or it fails to load the - // file, fall back to trying all readers in no particular order. + // Try to construct a preferred reader based on the extension or + // MIME type. - QString ext = QFileInfo(path).suffix().toLower(); - std::set<QString> extensions; + if (WavFileReader::supports(source)) { - WavFileReader::getSupportedExtensions(extensions); - if (extensions.find(ext) != extensions.end()) { - reader = new WavFileReader(path); + reader = new WavFileReader(source); if (targetRate != 0 && reader->isOK() && @@ -81,7 +82,7 @@ delete reader; reader = new ResamplingWavFileReader - (path, + (source, ResamplingWavFileReader::ResampleThreaded, ResamplingWavFileReader::CacheInTemporaryFile, targetRate); @@ -91,11 +92,9 @@ #ifdef HAVE_OGGZ #ifdef HAVE_FISHSOUND if (!reader) { - extensions.clear(); - OggVorbisFileReader::getSupportedExtensions(extensions); - if (extensions.find(ext) != extensions.end()) { + if (OggVorbisFileReader::supports(source)) { reader = new OggVorbisFileReader - (path, + (source, OggVorbisFileReader::DecodeThreaded, OggVorbisFileReader::CacheInTemporaryFile, targetRate); @@ -106,11 +105,9 @@ #ifdef HAVE_MAD if (!reader) { - extensions.clear(); - MP3FileReader::getSupportedExtensions(extensions); - if (extensions.find(ext) != extensions.end()) { + if (MP3FileReader::supports(source)) { reader = new MP3FileReader - (path, + (source, MP3FileReader::DecodeThreaded, MP3FileReader::CacheInTemporaryFile, targetRate); @@ -120,11 +117,9 @@ #ifdef HAVE_QUICKTIME if (!reader) { - extensions.clear(); - QuickTimeFileReader::getSupportedExtensions(extensions); - if (extensions.find(ext) != extensions.end()) { + if (QuickTimeFileReader::supports(source)) { reader = new QuickTimeFileReader - (path, + (source, QuickTimeFileReader::DecodeThreaded, QuickTimeFileReader::CacheInTemporaryFile, targetRate); @@ -133,20 +128,24 @@ #endif if (reader) { - if (reader->isOK()) return reader; + if (reader->isOK()) { + std::cerr << "AudioFileReaderFactory: Reader is OK" << std::endl; + return reader; + } + std::cerr << "AudioFileReaderFactory: Preferred reader for " + << "url \"" << source.getLocation().toStdString() + << "\" (content type \"" + << source.getContentType().toStdString() << "\") failed"; + if (reader->getError() != "") { - std::cerr << "AudioFileReaderFactory: Preferred reader for " - << "extension \"" << ext.toStdString() << "\" failed: \"" - << reader->getError().toStdString() << "\"" << std::endl; - } else { - std::cerr << "AudioFileReaderFactory: Preferred reader for " - << "extension \"" << ext.toStdString() << "\" failed" - << std::endl; - } + std::cerr << ": \"" << reader->getError().toStdString() << "\""; + } + std::cerr << std::endl; delete reader; reader = 0; } + std::cerr << "AudioFileReaderFactory: No reader" << std::endl; return reader; }