comparison data/fileio/MP3FileReader.cpp @ 742:c10cb8782576 coreaudio_tests

Merge from branch "default"
author Chris Cannam
date Sun, 01 Jul 2012 11:53:00 +0100
parents 1424aa29ae95
children e802e550a1f2
comparison
equal deleted inserted replaced
666:4efa7429cd85 742:c10cb8782576
94 delete[] m_filebuffer; 94 delete[] m_filebuffer;
95 ::close(fd); 95 ::close(fd);
96 return; 96 return;
97 } else if (sz == 0) { 97 } else if (sz == 0) {
98 std::cerr << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes") 98 std::cerr << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes")
99 .arg(offset).arg(m_fileSize).toStdString() << std::endl; 99 .arg(offset).arg(m_fileSize) << std::endl;
100 m_fileSize = offset; 100 m_fileSize = offset;
101 break; 101 break;
102 } 102 }
103 offset += sz; 103 offset += sz;
104 } 104 }
139 139
140 std::cerr << "MP3FileReader ctor: exiting with file rate = " << m_fileRate << std::endl; 140 std::cerr << "MP3FileReader ctor: exiting with file rate = " << m_fileRate << std::endl;
141 } 141 }
142 142
143 if (m_error != "") { 143 if (m_error != "") {
144 std::cerr << "MP3FileReader::MP3FileReader(\"" << m_path.toStdString() << "\"): ERROR: " << m_error.toStdString() << std::endl; 144 std::cerr << "MP3FileReader::MP3FileReader(\"" << m_path << "\"): ERROR: " << m_error << std::endl;
145 } 145 }
146 } 146 }
147 147
148 MP3FileReader::~MP3FileReader() 148 MP3FileReader::~MP3FileReader()
149 { 149 {
175 // when we implement support for more than just the one tag! 175 // when we implement support for more than just the one tag!
176 176
177 id3_tag *tag = id3_file_tag(file); 177 id3_tag *tag = id3_file_tag(file);
178 if (!tag) { 178 if (!tag) {
179 #ifdef DEBUG_ID3TAG 179 #ifdef DEBUG_ID3TAG
180 std::cerr << "MP3FileReader::loadTags: No ID3 tag found" << std::endl; 180 SVDEBUG << "MP3FileReader::loadTags: No ID3 tag found" << endl;
181 #endif 181 #endif
182 id3_file_close(file); 182 id3_file_close(file);
183 return; 183 return;
184 } 184 }
185 185
187 if (m_title == "") m_title = loadTag(tag, "TIT1"); 187 if (m_title == "") m_title = loadTag(tag, "TIT1");
188 188
189 m_maker = loadTag(tag, "TPE1"); // "lead artist" 189 m_maker = loadTag(tag, "TPE1"); // "lead artist"
190 if (m_maker == "") m_maker = loadTag(tag, "TPE2"); 190 if (m_maker == "") m_maker = loadTag(tag, "TPE2");
191 191
192 for (unsigned int i = 0; i < tag->nframes; ++i) {
193 if (tag->frames[i]) {
194 QString value = loadTag(tag, tag->frames[i]->id);
195 if (value != "") m_tags[tag->frames[i]->id] = value;
196 }
197 }
198
192 id3_file_close(file); 199 id3_file_close(file);
193 200
194 #else 201 #else
195 #ifdef DEBUG_ID3TAG 202 #ifdef DEBUG_ID3TAG
196 std::cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in" 203 SVDEBUG << "MP3FileReader::loadTags: ID3 tag support not compiled in"
197 << std::endl; 204 << endl;
198 #endif 205 #endif
199 #endif 206 #endif
200 } 207 }
201 208
202 QString 209 QString
206 id3_tag *tag = (id3_tag *)vtag; 213 id3_tag *tag = (id3_tag *)vtag;
207 214
208 id3_frame *frame = id3_tag_findframe(tag, name, 0); 215 id3_frame *frame = id3_tag_findframe(tag, name, 0);
209 if (!frame) { 216 if (!frame) {
210 #ifdef DEBUG_ID3TAG 217 #ifdef DEBUG_ID3TAG
211 std::cerr << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << std::endl; 218 SVDEBUG << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << endl;
212 #endif 219 #endif
213 return ""; 220 return "";
214 } 221 }
215 222
216 if (frame->nfields < 2) { 223 if (frame->nfields < 2) {
217 std::cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << std::endl; 224 SVDEBUG << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl;
218 return ""; 225 return "";
219 } 226 }
220 227
221 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]); 228 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]);
222 if (nstrings == 0) { 229 if (nstrings == 0) {
223 #ifdef DEBUG_ID3TAG 230 #ifdef DEBUG_ID3TAG
224 std::cerr << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << std::endl; 231 SVDEBUG << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << endl;
225 #endif 232 #endif
226 return ""; 233 return "";
227 } 234 }
228 235
229 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0); 236 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0);
230 if (!ustr) { 237 if (!ustr) {
231 #ifdef DEBUG_ID3TAG 238 #ifdef DEBUG_ID3TAG
232 std::cerr << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << std::endl; 239 SVDEBUG << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl;
233 #endif 240 #endif
234 return ""; 241 return "";
235 } 242 }
236 243
237 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr); 244 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr);
242 249
243 QString rv = QString::fromUtf8((const char *)u8str); 250 QString rv = QString::fromUtf8((const char *)u8str);
244 free(u8str); 251 free(u8str);
245 252
246 #ifdef DEBUG_ID3TAG 253 #ifdef DEBUG_ID3TAG
247 std::cerr << "MP3FileReader::loadTags: tag \"" << name << "\" -> \"" 254 SVDEBUG << "MP3FileReader::loadTags: tag \"" << name << "\" -> \""
248 << rv.toStdString() << "\"" << std::endl; 255 << rv << "\"" << endl;
249 #endif 256 #endif
250 257
251 258
252 return rv; 259 return rv;
253 260
356 m_channelCount = channels; 363 m_channelCount = channels;
357 364
358 initialiseDecodeCache(); 365 initialiseDecodeCache();
359 366
360 if (m_cacheMode == CacheInTemporaryFile) { 367 if (m_cacheMode == CacheInTemporaryFile) {
361 // std::cerr << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << std::endl; 368 // SVDEBUG << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << endl;
362 startSerialised("MP3FileReader::Decode"); 369 startSerialised("MP3FileReader::Decode");
363 } 370 }
364 } 371 }
365 372
366 if (m_bitrateDenom > 0) { 373 if (m_bitrateDenom > 0) {