comparison data/fileio/AudioFileReaderFactory.cpp @ 1342:c0fece5e7755 3.0-integration

Improved debug output for file open troubleshooting
author Chris Cannam
date Fri, 06 Jan 2017 09:43:40 +0000
parents 7d24f92158a7
children 1c9bbbb6116a
comparison
equal deleted inserted replaced
1341:513e4d67d8df 1342:c0fece5e7755
61 Parameters params, 61 Parameters params,
62 ProgressReporter *reporter) 62 ProgressReporter *reporter)
63 { 63 {
64 QString err; 64 QString err;
65 65
66 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;
67 68
68 if (!source.isOK()) { 69 if (!source.isOK()) {
69 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;
70 return 0; 71 return 0;
71 } 72 }
72 73
73 if (!source.isAvailable()) { 74 if (!source.isAvailable()) {
74 SVDEBUG << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Source not found" << endl; 75 SVCERR << "AudioFileReaderFactory::createReader(\"" << source.getLocation() << "\": Source not found" << endl;
75 return 0; 76 return 0;
76 } 77 }
77 78
78 AudioFileReader *reader = 0; 79 AudioFileReader *reader = 0;
79 80
86 CodedAudioFileReader::CacheMode cacheMode = 87 CodedAudioFileReader::CacheMode cacheMode =
87 CodedAudioFileReader::CacheInTemporaryFile; 88 CodedAudioFileReader::CacheInTemporaryFile;
88 89
89 if (estimatedSamples > 0) { 90 if (estimatedSamples > 0) {
90 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;
91 StorageAdviser::Recommendation rec = 94 StorageAdviser::Recommendation rec =
92 StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb); 95 StorageAdviser::recommend(StorageAdviser::SpeedCritical, kb, kb);
93 if ((rec & StorageAdviser::UseMemory) || 96 if ((rec & StorageAdviser::UseMemory) ||
94 (rec & StorageAdviser::PreferMemory)) { 97 (rec & StorageAdviser::PreferMemory)) {
98 SVDEBUG << "AudioFileReaderFactory: cacheing (if at all) in memory" << endl;
95 cacheMode = CodedAudioFileReader::CacheInMemory; 99 cacheMode = CodedAudioFileReader::CacheInMemory;
100 } else {
101 SVDEBUG << "AudioFileReaderFactory: cacheing (if at all) on disc" << endl;
96 } 102 }
97 } 103 }
98 104
99 CodedAudioFileReader::DecodeMode decodeMode = 105 CodedAudioFileReader::DecodeMode decodeMode =
100 (params.threadingMode == ThreadingMode::Threaded ? 106 (params.threadingMode == ThreadingMode::Threaded ?
112 118
113 for (int any = 0; any <= 1; ++any) { 119 for (int any = 0; any <= 1; ++any) {
114 120
115 bool anyReader = (any > 0); 121 bool anyReader = (any > 0);
116 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
117 if (anyReader || WavFileReader::supports(source)) { 130 if (anyReader || WavFileReader::supports(source)) {
118 131
119 reader = new WavFileReader(source); 132 reader = new WavFileReader(source);
120 133
121 sv_samplerate_t fileRate = reader->getSampleRate(); 134 sv_samplerate_t fileRate = reader->getSampleRate();
124 (!reader->isQuicklySeekable() || 137 (!reader->isQuicklySeekable() ||
125 normalised || 138 normalised ||
126 (cacheMode == CodedAudioFileReader::CacheInMemory) || 139 (cacheMode == CodedAudioFileReader::CacheInMemory) ||
127 (targetRate != 0 && fileRate != targetRate))) { 140 (targetRate != 0 && fileRate != targetRate))) {
128 141
129 SVDEBUG << "AudioFileReaderFactory::createReader: WAV file rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", in memory " << (cacheMode == CodedAudioFileReader::CacheInMemory) << ", creating decoding reader" << endl; 142 SVDEBUG << "AudioFileReaderFactory: WAV file reader rate: " << reader->getSampleRate() << ", normalised " << normalised << ", seekable " << reader->isQuicklySeekable() << ", in memory " << (cacheMode == CodedAudioFileReader::CacheInMemory) << ", creating decoding reader" << endl;
130 143
131 delete reader; 144 delete reader;
132 reader = new DecodingWavFileReader 145 reader = new DecodingWavFileReader
133 (source, 146 (source,
134 decodeMode, cacheMode, 147 decodeMode, cacheMode,
136 normalised, 149 normalised,
137 reporter); 150 reporter);
138 } 151 }
139 152
140 if (reader->isOK()) { 153 if (reader->isOK()) {
154 SVDEBUG << "AudioFileReaderFactory: WAV file reader is OK, returning it" << endl;
141 return reader; 155 return reader;
142 } else { 156 } else {
143 delete reader; 157 delete reader;
144 } 158 }
145 } 159 }
150 164
151 reader = new OggVorbisFileReader 165 reader = new OggVorbisFileReader
152 (source, decodeMode, cacheMode, targetRate, normalised, reporter); 166 (source, decodeMode, cacheMode, targetRate, normalised, reporter);
153 167
154 if (reader->isOK()) { 168 if (reader->isOK()) {
169 SVDEBUG << "AudioFileReaderFactory: Ogg file reader is OK, returning it" << endl;
155 return reader; 170 return reader;
156 } else { 171 } else {
157 delete reader; 172 delete reader;
158 } 173 }
159 } 174 }
171 reader = new MP3FileReader 186 reader = new MP3FileReader
172 (source, decodeMode, cacheMode, gapless, 187 (source, decodeMode, cacheMode, gapless,
173 targetRate, normalised, reporter); 188 targetRate, normalised, reporter);
174 189
175 if (reader->isOK()) { 190 if (reader->isOK()) {
191 SVDEBUG << "AudioFileReaderFactory: MP3 file reader is OK, returning it" << endl;
176 return reader; 192 return reader;
177 } else { 193 } else {
178 delete reader; 194 delete reader;
179 } 195 }
180 } 196 }
185 201
186 reader = new CoreAudioFileReader 202 reader = new CoreAudioFileReader
187 (source, decodeMode, cacheMode, targetRate, normalised, reporter); 203 (source, decodeMode, cacheMode, targetRate, normalised, reporter);
188 204
189 if (reader->isOK()) { 205 if (reader->isOK()) {
190 return reader; 206 SVDEBUG << "AudioFileReaderFactory: CoreAudio reader is OK, returning it" << endl;
191 } else { 207 return reader;
192 delete reader; 208 } else {
193 } 209 delete reader;
194 } 210 }
195 #endif 211 }
196 212 #endif
197 } 213
198 214 }
199 SVDEBUG << "AudioFileReaderFactory::Failed to create a reader for " 215
200 << "url \"" << source.getLocation() 216 SVCERR << "AudioFileReaderFactory::Failed to create a reader for "
201 << "\" (content type \"" 217 << "url \"" << source.getLocation()
202 << source.getContentType() << "\")" << endl; 218 << "\" (local filename \"" << source.getLocalFilename()
219 << "\", content type \""
220 << source.getContentType() << "\")" << endl;
203 return nullptr; 221 return nullptr;
204 } 222 }
205 223