Mercurial > hg > svcore
comparison data/fileio/AudioFileReaderFactory.cpp @ 1527:710e6250a401 zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Mon, 17 Sep 2018 13:51:14 +0100 |
parents | 1c9bbbb6116a |
children | 70e172e6cc59 c8fad3c14a2b |
comparison
equal
deleted
inserted
replaced
1324:d4a28d1479a8 | 1527:710e6250a401 |
---|---|
17 | 17 |
18 #include "WavFileReader.h" | 18 #include "WavFileReader.h" |
19 #include "DecodingWavFileReader.h" | 19 #include "DecodingWavFileReader.h" |
20 #include "OggVorbisFileReader.h" | 20 #include "OggVorbisFileReader.h" |
21 #include "MP3FileReader.h" | 21 #include "MP3FileReader.h" |
22 #include "QuickTimeFileReader.h" | |
23 #include "CoreAudioFileReader.h" | 22 #include "CoreAudioFileReader.h" |
24 #include "AudioFileSizeEstimator.h" | 23 #include "AudioFileSizeEstimator.h" |
25 | 24 |
26 #include "base/StorageAdviser.h" | 25 #include "base/StorageAdviser.h" |
27 | 26 |
40 #endif | 39 #endif |
41 #ifdef HAVE_OGGZ | 40 #ifdef HAVE_OGGZ |
42 #ifdef HAVE_FISHSOUND | 41 #ifdef HAVE_FISHSOUND |
43 OggVorbisFileReader::getSupportedExtensions(extensions); | 42 OggVorbisFileReader::getSupportedExtensions(extensions); |
44 #endif | 43 #endif |
45 #endif | |
46 #ifdef HAVE_QUICKTIME | |
47 QuickTimeFileReader::getSupportedExtensions(extensions); | |
48 #endif | 44 #endif |
49 #ifdef HAVE_COREAUDIO | 45 #ifdef HAVE_COREAUDIO |
50 CoreAudioFileReader::getSupportedExtensions(extensions); | 46 CoreAudioFileReader::getSupportedExtensions(extensions); |
51 #endif | 47 #endif |
52 | 48 |
65 Parameters params, | 61 Parameters params, |
66 ProgressReporter *reporter) | 62 ProgressReporter *reporter) |
67 { | 63 { |
68 QString err; | 64 QString err; |
69 | 65 |
70 SVDEBUG << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\"): Requested rate: " << params.targetRate << (params.targetRate == 0 ? " (use source rate)" : "") << endl; | 66 SVDEBUG << "AudioFileReaderFactory: url \"" << source.getLocation() << "\": requested rate: " << params.targetRate << (params.targetRate == 0 ? " (use source rate)" : "") << endl; |
67 SVDEBUG << "AudioFileReaderFactory: local filename \"" << source.getLocalFilename() << "\", content type \"" << source.getContentType() << "\"" << endl; | |
71 | 68 |
72 if (!source.isOK()) { | 69 if (!source.isOK()) { |
73 SVDEBUG << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Failed to retrieve source (transmission error?): " << source.getErrorString() << endl; | 70 SVCERR << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Failed to retrieve source (transmission error?): " << source.getErrorString() << endl; |
74 return 0; | 71 return 0; |
75 } | 72 } |
76 | 73 |
77 if (!source.isAvailable()) { | 74 if (!source.isAvailable()) { |
78 SVDEBUG << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Source not found" << endl; | 75 SVCERR << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Source not found" << endl; |
79 return 0; | 76 return 0; |
80 } | 77 } |
81 | 78 |
82 AudioFileReader *reader = 0; | 79 AudioFileReader *reader = 0; |
83 | 80 |
90 CodedAudioFileReader::CacheMode cacheMode = | 87 CodedAudioFileReader::CacheMode cacheMode = |
91 CodedAudioFileReader::CacheInTemporaryFile; | 88 CodedAudioFileReader::CacheInTemporaryFile; |
92 | 89 |
93 if (estimatedSamples > 0) { | 90 if (estimatedSamples > 0) { |
94 size_t kb = (estimatedSamples * sizeof(float)) / 1024; | 91 size_t kb = (estimatedSamples * sizeof(float)) / 1024; |
92 SVDEBUG << "AudioFileReaderFactory: checking where to potentially cache " | |
93 << kb << "K of sample data" << endl; | |
95 StorageAdviser::Recommendation rec = | 94 StorageAdviser::Recommendation rec = |
96 StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb); | 95 StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb); |
97 if ((rec & StorageAdviser::UseMemory) || | 96 if ((rec & StorageAdviser::UseMemory) || |
98 (rec & StorageAdviser::PreferMemory)) { | 97 (rec & StorageAdviser::PreferMemory)) { |
98 SVDEBUG << "AudioFileReaderFactory: cacheing (if at all) in memory" << endl; | |
99 cacheMode = CodedAudioFileReader::CacheInMemory; | 99 cacheMode = CodedAudioFileReader::CacheInMemory; |
100 } else { | |
101 SVDEBUG << "AudioFileReaderFactory: cacheing (if at all) on disc" << endl; | |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 CodedAudioFileReader::DecodeMode decodeMode = | 105 CodedAudioFileReader::DecodeMode decodeMode = |
104 (params.threadingMode == ThreadingMode::Threaded ? | 106 (params.threadingMode == ThreadingMode::Threaded ? |
116 | 118 |
117 for (int any = 0; any <= 1; ++any) { | 119 for (int any = 0; any <= 1; ++any) { |
118 | 120 |
119 bool anyReader = (any > 0); | 121 bool anyReader = (any > 0); |
120 | 122 |
123 if (!anyReader) { | |
124 SVDEBUG << "AudioFileReaderFactory: Checking whether any reader officially handles this source" << endl; | |
125 } else { | |
126 SVDEBUG << "AudioFileReaderFactory: Source not officially handled by any reader, trying again with each reader in turn" | |
127 << endl; | |
128 } | |
129 | |
130 #ifdef HAVE_OGGZ | |
131 #ifdef HAVE_FISHSOUND | |
132 // If we have the "real" Ogg reader, use that first. Otherwise | |
133 // the WavFileReader will likely accept Ogg files (as | |
134 // libsndfile supports them) but it has no ability to return | |
135 // file metadata, so we get a slightly less useful result. | |
136 if (anyReader || OggVorbisFileReader::supports(source)) { | |
137 | |
138 reader = new OggVorbisFileReader | |
139 (source, decodeMode, cacheMode, targetRate, normalised, reporter); | |
140 | |
141 if (reader->isOK()) { | |
142 SVDEBUG << "AudioFileReaderFactory: Ogg file reader is OK, returning it" << endl; | |
143 return reader; | |
144 } else { | |
145 delete reader; | |
146 } | |
147 } | |
148 #endif | |
149 #endif | |
150 | |
121 if (anyReader || WavFileReader::supports(source)) { | 151 if (anyReader || WavFileReader::supports(source)) { |
122 | 152 |
123 reader = new WavFileReader(source); | 153 reader = new WavFileReader(source); |
124 | 154 |
125 sv_samplerate_t fileRate = reader->getSampleRate(); | 155 sv_samplerate_t fileRate = reader->getSampleRate(); |
128 (!reader->isQuicklySeekable() || | 158 (!reader->isQuicklySeekable() || |
129 normalised || | 159 normalised || |
130 (cacheMode == CodedAudioFileReader::CacheInMemory) || | 160 (cacheMode == CodedAudioFileReader::CacheInMemory) || |
131 (targetRate != 0 && fileRate != targetRate))) { | 161 (targetRate != 0 && fileRate != targetRate))) { |
132 | 162 |
133 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", in memory " << (cacheMode == CodedAudioFileReader::CacheInMemory) << ", creating decoding reader" << endl; | 163 SVDEBUG << "AudioFileReaderFactory: WAV file reader rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", in memory " << (cacheMode == CodedAudioFileReader::CacheInMemory) << ", creating decoding reader" << endl; |
134 | 164 |
135 delete reader; | 165 delete reader; |
136 reader = new DecodingWavFileReader | 166 reader = new DecodingWavFileReader |
137 (source, | 167 (source, |
138 decodeMode, cacheMode, | 168 decodeMode, cacheMode, |
140 normalised, | 170 normalised, |
141 reporter); | 171 reporter); |
142 } | 172 } |
143 | 173 |
144 if (reader->isOK()) { | 174 if (reader->isOK()) { |
145 return reader; | 175 SVDEBUG << "AudioFileReaderFactory: WAV file reader is OK, returning it" << endl; |
146 } else { | 176 return reader; |
147 delete reader; | 177 } else { |
148 } | 178 delete reader; |
149 } | 179 } |
150 | 180 } |
151 #ifdef HAVE_OGGZ | |
152 #ifdef HAVE_FISHSOUND | |
153 if (anyReader || OggVorbisFileReader::supports(source)) { | |
154 | |
155 reader = new OggVorbisFileReader | |
156 (source, decodeMode, cacheMode, targetRate, normalised, reporter); | |
157 | |
158 if (reader->isOK()) { | |
159 return reader; | |
160 } else { | |
161 delete reader; | |
162 } | |
163 } | |
164 #endif | |
165 #endif | |
166 | 181 |
167 #ifdef HAVE_MAD | 182 #ifdef HAVE_MAD |
168 if (anyReader || MP3FileReader::supports(source)) { | 183 if (anyReader || MP3FileReader::supports(source)) { |
169 | 184 |
170 MP3FileReader::GaplessMode gapless = | 185 MP3FileReader::GaplessMode gapless = |
175 reader = new MP3FileReader | 190 reader = new MP3FileReader |
176 (source, decodeMode, cacheMode, gapless, | 191 (source, decodeMode, cacheMode, gapless, |
177 targetRate, normalised, reporter); | 192 targetRate, normalised, reporter); |
178 | 193 |
179 if (reader->isOK()) { | 194 if (reader->isOK()) { |
180 return reader; | 195 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl; |
181 } else { | |
182 delete reader; | |
183 } | |
184 } | |
185 #endif | |
186 | |
187 #ifdef HAVE_QUICKTIME | |
188 if (anyReader || QuickTimeFileReader::supports(source)) { | |
189 | |
190 reader = new QuickTimeFileReader | |
191 (source, decodeMode, cacheMode, targetRate, normalised, reporter); | |
192 | |
193 if (reader->isOK()) { | |
194 return reader; | 196 return reader; |
195 } else { | 197 } else { |
196 delete reader; | 198 delete reader; |
197 } | 199 } |
198 } | 200 } |
203 | 205 |
204 reader = new CoreAudioFileReader | 206 reader = new CoreAudioFileReader |
205 (source, decodeMode, cacheMode, targetRate, normalised, reporter); | 207 (source, decodeMode, cacheMode, targetRate, normalised, reporter); |
206 | 208 |
207 if (reader->isOK()) { | 209 if (reader->isOK()) { |
208 return reader; | 210 SVDEBUG << "AudioFileReaderFactory: CoreAudio reader is OK, returning it" << endl; |
209 } else { | 211 return reader; |
210 delete reader; | 212 } else { |
211 } | 213 delete reader; |
212 } | 214 } |
213 #endif | 215 } |
214 | 216 #endif |
215 } | 217 |
216 | 218 } |
217 SVDEBUG << "AudioFileReaderFactory::Failed to create a reader for " | 219 |
218 << "url \"" << source.getLocation() | 220 SVCERR << "AudioFileReaderFactory::Failed to create a reader for " |
219 << "\" (content type \"" | 221 << "url \"" << source.getLocation() |
220 << source.getContentType() << "\")" << endl; | 222 << "\" (local filename \"" << source.getLocalFilename() |
223 << "\", content type \"" | |
224 << source.getContentType() << "\")" << endl; | |
221 return nullptr; | 225 return nullptr; |
222 } | 226 } |
223 | 227 |