comparison data/fileio/AudioFileReaderFactory.cpp @ 665:029dd9e5cc29 coreaudio_tests

tests for using coreaudio to read files in 64-bit mac osx
author luisf
date Thu, 18 Nov 2010 11:40:38 +0000
parents 5746c559af15
children c10cb8782576
comparison
equal deleted inserted replaced
623:f19437971e17 665:029dd9e5cc29
18 #include "WavFileReader.h" 18 #include "WavFileReader.h"
19 #include "ResamplingWavFileReader.h" 19 #include "ResamplingWavFileReader.h"
20 #include "OggVorbisFileReader.h" 20 #include "OggVorbisFileReader.h"
21 #include "MP3FileReader.h" 21 #include "MP3FileReader.h"
22 #include "QuickTimeFileReader.h" 22 #include "QuickTimeFileReader.h"
23 #include "CoreAudioFileReader.h"
23 24
24 #include <QString> 25 #include <QString>
25 #include <QFileInfo> 26 #include <QFileInfo>
26 #include <iostream> 27 #include <iostream>
27 28
39 OggVorbisFileReader::getSupportedExtensions(extensions); 40 OggVorbisFileReader::getSupportedExtensions(extensions);
40 #endif 41 #endif
41 #endif 42 #endif
42 #ifdef HAVE_QUICKTIME 43 #ifdef HAVE_QUICKTIME
43 QuickTimeFileReader::getSupportedExtensions(extensions); 44 QuickTimeFileReader::getSupportedExtensions(extensions);
45 #endif
46 #ifdef HAVE_COREAUDIO
47 CoreAudioFileReader::getSupportedExtensions(extensions);
44 #endif 48 #endif
45 49
46 QString rv; 50 QString rv;
47 for (std::set<QString>::const_iterator i = extensions.begin(); 51 for (std::set<QString>::const_iterator i = extensions.begin();
48 i != extensions.end(); ++i) { 52 i != extensions.end(); ++i) {
71 AudioFileReaderFactory::create(FileSource source, size_t targetRate, bool threading, 75 AudioFileReaderFactory::create(FileSource source, size_t targetRate, bool threading,
72 ProgressReporter *reporter) 76 ProgressReporter *reporter)
73 { 77 {
74 QString err; 78 QString err;
75 79
76 // std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\"): Requested rate: " << targetRate << std::endl; 80 std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\"): Requested rate: " << targetRate << std::endl;
77 81
78 if (!source.isOK() || !source.isAvailable()) { 82 if (!source.isOK() || !source.isAvailable()) {
79 std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\": Source unavailable" << std::endl; 83 std::cerr << "AudioFileReaderFactory::createReader(\"" << source.getLocation().toStdString() << "\": Source unavailable" << std::endl;
80 return 0; 84 return 0;
81 } 85 }
167 reader = 0; 171 reader = 0;
168 } 172 }
169 } 173 }
170 } 174 }
171 #endif 175 #endif
176
177 #ifdef HAVE_COREAUDIO
178 if (!reader) {
179 if (CoreAudioFileReader::supports(source)) {
180 reader = new CoreAudioFileReader
181 (source,
182 threading ?
183 CoreAudioFileReader::DecodeThreaded :
184 CoreAudioFileReader::DecodeAtOnce,
185 CoreAudioFileReader::CacheInTemporaryFile,
186 targetRate,
187 reporter);
188 if (!reader->isOK()) {
189 delete reader;
190 reader = 0;
191 }
192 }
193 }
194 #endif
195
172 196
173 // If none of the readers claimed to support this file extension, 197 // If none of the readers claimed to support this file extension,
174 // perhaps the extension is missing or misleading. Try again, 198 // perhaps the extension is missing or misleading. Try again,
175 // ignoring it. We have to be confident that the reader won't 199 // ignoring it. We have to be confident that the reader won't
176 // open just any old text file or whatever and pretend it's 200 // open just any old text file or whatever and pretend it's
257 reader = 0; 281 reader = 0;
258 } 282 }
259 } 283 }
260 #endif 284 #endif
261 285
286 #ifdef HAVE_COREAUDIO
287
288 std::cerr << "AudioFileReaderFactory: HAVE_COREAUDIO" << std::endl;
289
290 if (!reader) {
291 reader = new CoreAudioFileReader
292 (source,
293 threading ?
294 CoreAudioFileReader::DecodeThreaded :
295 CoreAudioFileReader::DecodeAtOnce,
296 CoreAudioFileReader::CacheInTemporaryFile,
297 targetRate,
298 reporter);
299
300 if (!reader->isOK()) {
301 delete reader;
302 reader = 0;
303 }
304 }
305 #endif
306
262 if (reader) { 307 if (reader) {
263 if (reader->isOK()) { 308 if (reader->isOK()) {
264 // std::cerr << "AudioFileReaderFactory: Reader is OK" << std::endl; 309 std::cerr << "AudioFileReaderFactory: Reader is OK" << std::endl;
265 return reader; 310 return reader;
266 } 311 }
267 std::cerr << "AudioFileReaderFactory: Preferred reader for " 312 std::cerr << "AudioFileReaderFactory: Preferred reader for "
268 << "url \"" << source.getLocation().toStdString() 313 << "url \"" << source.getLocation().toStdString()
269 << "\" (content type \"" 314 << "\" (content type \""