comparison data/fileio/OggVorbisFileReader.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 c022976d18e8
children c324d410b096
comparison
equal deleted inserted replaced
315:96ef9746c560 316:3a6725f285d6
30 #include <QFileInfo> 30 #include <QFileInfo>
31 #include <QProgressDialog> 31 #include <QProgressDialog>
32 32
33 static int instances = 0; 33 static int instances = 0;
34 34
35 OggVorbisFileReader::OggVorbisFileReader(QString path, 35 OggVorbisFileReader::OggVorbisFileReader(RemoteFile source,
36 DecodeMode decodeMode, 36 DecodeMode decodeMode,
37 CacheMode mode, 37 CacheMode mode,
38 size_t targetRate) : 38 size_t targetRate) :
39 CodedAudioFileReader(mode, targetRate), 39 CodedAudioFileReader(mode, targetRate),
40 m_path(path), 40 m_source(source),
41 m_path(source.getLocalFilename()),
41 m_progress(0), 42 m_progress(0),
42 m_fileSize(0), 43 m_fileSize(0),
43 m_bytesRead(0), 44 m_bytesRead(0),
44 m_commentsRead(false), 45 m_commentsRead(false),
45 m_cancelled(false), 46 m_cancelled(false),
47 m_decodeThread(0) 48 m_decodeThread(0)
48 { 49 {
49 m_channelCount = 0; 50 m_channelCount = 0;
50 m_fileRate = 0; 51 m_fileRate = 0;
51 52
52 std::cerr << "OggVorbisFileReader::OggVorbisFileReader(" << path.toLocal8Bit().data() << "): now have " << (++instances) << " instances" << std::endl; 53 std::cerr << "OggVorbisFileReader::OggVorbisFileReader(" << m_path.toLocal8Bit().data() << "): now have " << (++instances) << " instances" << std::endl;
53 54
54 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader", true); 55 Profiler profiler("OggVorbisFileReader::OggVorbisFileReader", true);
55 56
56 QFileInfo info(path); 57 QFileInfo info(m_path);
57 m_fileSize = info.size(); 58 m_fileSize = info.size();
58 59
59 if (!(m_oggz = oggz_open(path.toLocal8Bit().data(), OGGZ_READ))) { 60 if (!(m_oggz = oggz_open(m_path.toLocal8Bit().data(), OGGZ_READ))) {
60 m_error = QString("File %1 is not an OGG file.").arg(path); 61 m_error = QString("File %1 is not an OGG file.").arg(m_path);
61 return; 62 return;
62 } 63 }
63 64
64 FishSoundInfo fsinfo; 65 FishSoundInfo fsinfo;
65 m_fishSound = fish_sound_new(FISH_SOUND_DECODE, &fsinfo); 66 m_fishSound = fish_sound_new(FISH_SOUND_DECODE, &fsinfo);
68 oggz_set_read_callback(m_oggz, -1, readPacket, this); 69 oggz_set_read_callback(m_oggz, -1, readPacket, this);
69 70
70 if (decodeMode == DecodeAtOnce) { 71 if (decodeMode == DecodeAtOnce) {
71 72
72 m_progress = new QProgressDialog 73 m_progress = new QProgressDialog
73 (QObject::tr("Decoding %1...").arg(QFileInfo(path).fileName()), 74 (QObject::tr("Decoding %1...").arg(QFileInfo(m_path).fileName()),
74 QObject::tr("Stop"), 0, 100); 75 QObject::tr("Stop"), 0, 100);
75 m_progress->hide(); 76 m_progress->hide();
76 77
77 while (oggz_read(m_oggz, 1024) > 0); 78 while (oggz_read(m_oggz, 1024) > 0);
78 79
199 OggVorbisFileReader::getSupportedExtensions(std::set<QString> &extensions) 200 OggVorbisFileReader::getSupportedExtensions(std::set<QString> &extensions)
200 { 201 {
201 extensions.insert("ogg"); 202 extensions.insert("ogg");
202 } 203 }
203 204
205 bool
206 OggVorbisFileReader::supportsExtension(QString extension)
207 {
208 std::set<QString> extensions;
209 getSupportedExtensions(extensions);
210 return (extensions.find(extension.toLower()) != extensions.end());
211 }
212
213 bool
214 OggVorbisFileReader::supportsContentType(QString type)
215 {
216 return (type == "application/ogg");
217 }
218
219 bool
220 OggVorbisFileReader::supports(RemoteFile &source)
221 {
222 return (supportsExtension(source.getExtension()) ||
223 supportsContentType(source.getContentType()));
224 }
225
204 #endif 226 #endif
205 #endif 227 #endif