Chris@148
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@148
|
2
|
Chris@148
|
3 /*
|
Chris@148
|
4 Sonic Visualiser
|
Chris@148
|
5 An audio file viewer and annotation editor.
|
Chris@148
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@148
|
7 This file copyright 2006 Chris Cannam.
|
Chris@148
|
8
|
Chris@148
|
9 This program is free software; you can redistribute it and/or
|
Chris@148
|
10 modify it under the terms of the GNU General Public License as
|
Chris@148
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@148
|
12 License, or (at your option) any later version. See the file
|
Chris@148
|
13 COPYING included with this distribution for more information.
|
Chris@148
|
14 */
|
Chris@148
|
15
|
Chris@148
|
16 #ifdef HAVE_MAD
|
Chris@148
|
17
|
Chris@148
|
18 #include "MP3FileReader.h"
|
Chris@392
|
19 #include "base/ProgressReporter.h"
|
Chris@357
|
20
|
Chris@150
|
21 #include "system/System.h"
|
Chris@148
|
22
|
Chris@148
|
23 #include <sys/types.h>
|
Chris@148
|
24 #include <sys/stat.h>
|
Chris@148
|
25 #include <fcntl.h>
|
Chris@148
|
26
|
Chris@148
|
27 #include <iostream>
|
Chris@148
|
28
|
Chris@405
|
29 #include <cstdlib>
|
Chris@1218
|
30 //#include <unistd.h>
|
Chris@405
|
31
|
Chris@271
|
32 #ifdef HAVE_ID3TAG
|
Chris@271
|
33 #include <id3tag.h>
|
Chris@271
|
34 #endif
|
Chris@1168
|
35
|
Chris@1169
|
36 //#define DEBUG_ID3TAG 1
|
Chris@271
|
37
|
Chris@186
|
38 #include <QFileInfo>
|
Chris@148
|
39
|
Chris@1218
|
40 #ifdef _MSC_VER
|
Chris@1218
|
41 #include <io.h>
|
Chris@1218
|
42 #define open _open
|
Chris@1218
|
43 #endif
|
Chris@1218
|
44
|
Chris@317
|
45 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode,
|
Chris@1040
|
46 CacheMode mode, sv_samplerate_t targetRate,
|
Chris@920
|
47 bool normalised,
|
Chris@392
|
48 ProgressReporter *reporter) :
|
Chris@920
|
49 CodedAudioFileReader(mode, targetRate, normalised),
|
Chris@316
|
50 m_source(source),
|
Chris@316
|
51 m_path(source.getLocalFilename()),
|
Chris@264
|
52 m_decodeThread(0)
|
Chris@148
|
53 {
|
Chris@148
|
54 m_channelCount = 0;
|
Chris@297
|
55 m_fileRate = 0;
|
Chris@148
|
56 m_fileSize = 0;
|
Chris@148
|
57 m_bitrateNum = 0;
|
Chris@148
|
58 m_bitrateDenom = 0;
|
Chris@148
|
59 m_cancelled = false;
|
Chris@265
|
60 m_completion = 0;
|
Chris@263
|
61 m_done = false;
|
Chris@392
|
62 m_reporter = reporter;
|
Chris@148
|
63
|
Chris@148
|
64 struct stat stat;
|
Chris@316
|
65 if (::stat(m_path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) {
|
Chris@316
|
66 m_error = QString("File %1 does not exist.").arg(m_path);
|
Chris@148
|
67 return;
|
Chris@148
|
68 }
|
Chris@148
|
69
|
Chris@148
|
70 m_fileSize = stat.st_size;
|
Chris@148
|
71
|
Chris@977
|
72 m_filebuffer = 0;
|
Chris@977
|
73 m_samplebuffer = 0;
|
Chris@977
|
74 m_samplebuffersize = 0;
|
Chris@977
|
75
|
Chris@229
|
76 int fd = -1;
|
Chris@316
|
77 if ((fd = ::open(m_path.toLocal8Bit().data(), O_RDONLY
|
Chris@231
|
78 #ifdef _WIN32
|
Chris@231
|
79 | O_BINARY
|
Chris@231
|
80 #endif
|
Chris@231
|
81 , 0)) < 0) {
|
Chris@316
|
82 m_error = QString("Failed to open file %1 for reading.").arg(m_path);
|
Chris@148
|
83 return;
|
Chris@148
|
84 }
|
Chris@148
|
85
|
Chris@148
|
86 try {
|
Chris@263
|
87 m_filebuffer = new unsigned char[m_fileSize];
|
Chris@148
|
88 } catch (...) {
|
Chris@290
|
89 m_error = QString("Out of memory");
|
Chris@148
|
90 ::close(fd);
|
Chris@148
|
91 return;
|
Chris@148
|
92 }
|
Chris@148
|
93
|
Chris@229
|
94 ssize_t sz = 0;
|
Chris@1038
|
95 ssize_t offset = 0;
|
Chris@229
|
96 while (offset < m_fileSize) {
|
Chris@263
|
97 sz = ::read(fd, m_filebuffer + offset, m_fileSize - offset);
|
Chris@229
|
98 if (sz < 0) {
|
Chris@290
|
99 m_error = QString("Read error for file %1 (after %2 bytes)")
|
Chris@316
|
100 .arg(m_path).arg(offset);
|
Chris@263
|
101 delete[] m_filebuffer;
|
Chris@229
|
102 ::close(fd);
|
Chris@229
|
103 return;
|
Chris@230
|
104 } else if (sz == 0) {
|
Chris@843
|
105 cerr << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes")
|
Chris@843
|
106 .arg(offset).arg(m_fileSize) << endl;
|
Chris@231
|
107 m_fileSize = offset;
|
Chris@230
|
108 break;
|
Chris@229
|
109 }
|
Chris@229
|
110 offset += sz;
|
Chris@148
|
111 }
|
Chris@148
|
112
|
Chris@148
|
113 ::close(fd);
|
Chris@148
|
114
|
Chris@271
|
115 loadTags();
|
Chris@271
|
116
|
Chris@263
|
117 if (decodeMode == DecodeAtOnce) {
|
Chris@263
|
118
|
Chris@392
|
119 if (m_reporter) {
|
Chris@392
|
120 connect(m_reporter, SIGNAL(cancelled()), this, SLOT(cancelled()));
|
Chris@392
|
121 m_reporter->setMessage
|
Chris@392
|
122 (tr("Decoding %1...").arg(QFileInfo(m_path).fileName()));
|
Chris@327
|
123 }
|
Chris@148
|
124
|
Chris@263
|
125 if (!decode(m_filebuffer, m_fileSize)) {
|
Chris@316
|
126 m_error = QString("Failed to decode file %1.").arg(m_path);
|
Chris@263
|
127 }
|
Chris@263
|
128
|
Chris@263
|
129 delete[] m_filebuffer;
|
Chris@263
|
130 m_filebuffer = 0;
|
Chris@148
|
131
|
Chris@263
|
132 if (isDecodeCacheInitialised()) finishDecodeCache();
|
Chris@398
|
133 endSerialised();
|
Chris@263
|
134
|
Chris@392
|
135 } else {
|
Chris@263
|
136
|
Chris@392
|
137 if (m_reporter) m_reporter->setProgress(100);
|
Chris@263
|
138
|
Chris@263
|
139 m_decodeThread = new DecodeThread(this);
|
Chris@263
|
140 m_decodeThread->start();
|
Chris@263
|
141
|
Chris@386
|
142 while ((m_channelCount == 0 || m_fileRate == 0 || m_sampleRate == 0)
|
Chris@386
|
143 && !m_done) {
|
Chris@263
|
144 usleep(10);
|
Chris@263
|
145 }
|
Chris@386
|
146
|
Chris@843
|
147 cerr << "MP3FileReader ctor: exiting with file rate = " << m_fileRate << endl;
|
Chris@148
|
148 }
|
Chris@499
|
149
|
Chris@499
|
150 if (m_error != "") {
|
Chris@843
|
151 cerr << "MP3FileReader::MP3FileReader(\"" << m_path << "\"): ERROR: " << m_error << endl;
|
Chris@499
|
152 }
|
Chris@148
|
153 }
|
Chris@148
|
154
|
Chris@148
|
155 MP3FileReader::~MP3FileReader()
|
Chris@148
|
156 {
|
Chris@263
|
157 if (m_decodeThread) {
|
Chris@265
|
158 m_cancelled = true;
|
Chris@263
|
159 m_decodeThread->wait();
|
Chris@263
|
160 delete m_decodeThread;
|
Chris@263
|
161 }
|
Chris@148
|
162 }
|
Chris@148
|
163
|
Chris@263
|
164 void
|
Chris@392
|
165 MP3FileReader::cancelled()
|
Chris@392
|
166 {
|
Chris@392
|
167 m_cancelled = true;
|
Chris@392
|
168 }
|
Chris@392
|
169
|
Chris@392
|
170 void
|
Chris@271
|
171 MP3FileReader::loadTags()
|
Chris@271
|
172 {
|
Chris@271
|
173 m_title = "";
|
Chris@271
|
174
|
Chris@271
|
175 #ifdef HAVE_ID3TAG
|
Chris@271
|
176
|
Chris@290
|
177 id3_file *file = id3_file_open(m_path.toLocal8Bit().data(),
|
Chris@271
|
178 ID3_FILE_MODE_READONLY);
|
Chris@271
|
179 if (!file) return;
|
Chris@271
|
180
|
Chris@273
|
181 // We can do this a lot more elegantly, but we'll leave that for
|
Chris@273
|
182 // when we implement support for more than just the one tag!
|
Chris@273
|
183
|
Chris@271
|
184 id3_tag *tag = id3_file_tag(file);
|
Chris@273
|
185 if (!tag) {
|
Chris@273
|
186 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
187 cerr << "MP3FileReader::loadTags: No ID3 tag found" << endl;
|
Chris@273
|
188 #endif
|
Chris@273
|
189 id3_file_close(file);
|
Chris@273
|
190 return;
|
Chris@271
|
191 }
|
Chris@271
|
192
|
Chris@333
|
193 m_title = loadTag(tag, "TIT2"); // work title
|
Chris@333
|
194 if (m_title == "") m_title = loadTag(tag, "TIT1");
|
Chris@273
|
195
|
Chris@333
|
196 m_maker = loadTag(tag, "TPE1"); // "lead artist"
|
Chris@333
|
197 if (m_maker == "") m_maker = loadTag(tag, "TPE2");
|
Chris@273
|
198
|
Chris@632
|
199 for (unsigned int i = 0; i < tag->nframes; ++i) {
|
Chris@632
|
200 if (tag->frames[i]) {
|
Chris@632
|
201 QString value = loadTag(tag, tag->frames[i]->id);
|
Chris@632
|
202 if (value != "") m_tags[tag->frames[i]->id] = value;
|
Chris@632
|
203 }
|
Chris@632
|
204 }
|
Chris@632
|
205
|
Chris@271
|
206 id3_file_close(file);
|
Chris@273
|
207
|
Chris@273
|
208 #else
|
Chris@273
|
209 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
210 cerr << "MP3FileReader::loadTags: ID3 tag support not compiled in"
|
Chris@687
|
211 << endl;
|
Chris@271
|
212 #endif
|
Chris@273
|
213 #endif
|
Chris@333
|
214 }
|
Chris@273
|
215
|
Chris@333
|
216 QString
|
Chris@333
|
217 MP3FileReader::loadTag(void *vtag, const char *name)
|
Chris@333
|
218 {
|
Chris@333
|
219 #ifdef HAVE_ID3TAG
|
Chris@333
|
220 id3_tag *tag = (id3_tag *)vtag;
|
Chris@333
|
221
|
Chris@333
|
222 id3_frame *frame = id3_tag_findframe(tag, name, 0);
|
Chris@333
|
223 if (!frame) {
|
Chris@333
|
224 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
225 cerr << "MP3FileReader::loadTags: No \"" << name << "\" in ID3 tag" << endl;
|
Chris@333
|
226 #endif
|
Chris@333
|
227 return "";
|
Chris@333
|
228 }
|
Chris@333
|
229
|
Chris@333
|
230 if (frame->nfields < 2) {
|
Chris@1168
|
231 cerr << "MP3FileReader::loadTags: WARNING: Not enough fields (" << frame->nfields << ") for \"" << name << "\" in ID3 tag" << endl;
|
Chris@333
|
232 return "";
|
Chris@333
|
233 }
|
Chris@333
|
234
|
Chris@333
|
235 unsigned int nstrings = id3_field_getnstrings(&frame->fields[1]);
|
Chris@333
|
236 if (nstrings == 0) {
|
Chris@333
|
237 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
238 cerr << "MP3FileReader::loadTags: No strings for \"" << name << "\" in ID3 tag" << endl;
|
Chris@333
|
239 #endif
|
Chris@333
|
240 return "";
|
Chris@333
|
241 }
|
Chris@333
|
242
|
Chris@333
|
243 id3_ucs4_t const *ustr = id3_field_getstrings(&frame->fields[1], 0);
|
Chris@333
|
244 if (!ustr) {
|
Chris@333
|
245 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
246 cerr << "MP3FileReader::loadTags: Invalid or absent data for \"" << name << "\" in ID3 tag" << endl;
|
Chris@333
|
247 #endif
|
Chris@333
|
248 return "";
|
Chris@333
|
249 }
|
Chris@333
|
250
|
Chris@333
|
251 id3_utf8_t *u8str = id3_ucs4_utf8duplicate(ustr);
|
Chris@333
|
252 if (!u8str) {
|
Chris@843
|
253 cerr << "MP3FileReader::loadTags: ERROR: Internal error: Failed to convert UCS4 to UTF8 in ID3 title" << endl;
|
Chris@333
|
254 return "";
|
Chris@333
|
255 }
|
Chris@333
|
256
|
Chris@333
|
257 QString rv = QString::fromUtf8((const char *)u8str);
|
Chris@333
|
258 free(u8str);
|
Chris@334
|
259
|
Chris@334
|
260 #ifdef DEBUG_ID3TAG
|
Chris@1168
|
261 cerr << "MP3FileReader::loadTags: tag \"" << name << "\" -> \""
|
Chris@687
|
262 << rv << "\"" << endl;
|
Chris@334
|
263 #endif
|
Chris@334
|
264
|
Chris@334
|
265
|
Chris@333
|
266 return rv;
|
Chris@333
|
267
|
Chris@333
|
268 #else
|
Chris@333
|
269 return "";
|
Chris@333
|
270 #endif
|
Chris@271
|
271 }
|
Chris@271
|
272
|
Chris@271
|
273 void
|
Chris@263
|
274 MP3FileReader::DecodeThread::run()
|
Chris@263
|
275 {
|
Chris@263
|
276 if (!m_reader->decode(m_reader->m_filebuffer, m_reader->m_fileSize)) {
|
Chris@290
|
277 m_reader->m_error = QString("Failed to decode file %1.").arg(m_reader->m_path);
|
Chris@263
|
278 }
|
Chris@263
|
279
|
Chris@263
|
280 delete[] m_reader->m_filebuffer;
|
Chris@263
|
281 m_reader->m_filebuffer = 0;
|
Chris@297
|
282
|
Chris@297
|
283 if (m_reader->m_samplebuffer) {
|
Chris@929
|
284 for (int c = 0; c < m_reader->m_channelCount; ++c) {
|
Chris@297
|
285 delete[] m_reader->m_samplebuffer[c];
|
Chris@297
|
286 }
|
Chris@297
|
287 delete[] m_reader->m_samplebuffer;
|
Chris@297
|
288 m_reader->m_samplebuffer = 0;
|
Chris@297
|
289 }
|
Chris@297
|
290
|
Chris@263
|
291 if (m_reader->isDecodeCacheInitialised()) m_reader->finishDecodeCache();
|
Chris@263
|
292
|
Chris@263
|
293 m_reader->m_done = true;
|
Chris@265
|
294 m_reader->m_completion = 100;
|
Chris@297
|
295
|
Chris@297
|
296 m_reader->endSerialised();
|
Chris@263
|
297 }
|
Chris@263
|
298
|
Chris@148
|
299 bool
|
Chris@1038
|
300 MP3FileReader::decode(void *mm, sv_frame_t sz)
|
Chris@148
|
301 {
|
Chris@148
|
302 DecoderData data;
|
Chris@148
|
303 struct mad_decoder decoder;
|
Chris@148
|
304
|
Chris@148
|
305 data.start = (unsigned char const *)mm;
|
Chris@148
|
306 data.length = (unsigned long)sz;
|
Chris@148
|
307 data.reader = this;
|
Chris@148
|
308
|
Chris@148
|
309 mad_decoder_init(&decoder, &data, input, 0, 0, output, error, 0);
|
Chris@148
|
310 mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
|
Chris@148
|
311 mad_decoder_finish(&decoder);
|
Chris@148
|
312
|
Chris@263
|
313 m_done = true;
|
Chris@148
|
314 return true;
|
Chris@148
|
315 }
|
Chris@148
|
316
|
Chris@148
|
317 enum mad_flow
|
Chris@148
|
318 MP3FileReader::input(void *dp, struct mad_stream *stream)
|
Chris@148
|
319 {
|
Chris@148
|
320 DecoderData *data = (DecoderData *)dp;
|
Chris@148
|
321
|
Chris@148
|
322 if (!data->length) return MAD_FLOW_STOP;
|
Chris@348
|
323
|
Chris@348
|
324 unsigned char const *start = data->start;
|
Chris@348
|
325 unsigned long length = data->length;
|
Chris@348
|
326
|
Chris@348
|
327 #ifdef HAVE_ID3TAG
|
Chris@348
|
328 if (length > ID3_TAG_QUERYSIZE) {
|
Chris@1038
|
329 ssize_t taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE);
|
Chris@348
|
330 if (taglen > 0) {
|
Chris@843
|
331 // cerr << "ID3 tag length to skip: " << taglen << endl;
|
Chris@348
|
332 start += taglen;
|
Chris@348
|
333 length -= taglen;
|
Chris@348
|
334 }
|
Chris@348
|
335 }
|
Chris@348
|
336 #endif
|
Chris@348
|
337
|
Chris@348
|
338 mad_stream_buffer(stream, start, length);
|
Chris@148
|
339 data->length = 0;
|
Chris@148
|
340
|
Chris@148
|
341 return MAD_FLOW_CONTINUE;
|
Chris@148
|
342 }
|
Chris@148
|
343
|
Chris@148
|
344 enum mad_flow
|
Chris@148
|
345 MP3FileReader::output(void *dp,
|
Chris@148
|
346 struct mad_header const *header,
|
Chris@148
|
347 struct mad_pcm *pcm)
|
Chris@148
|
348 {
|
Chris@148
|
349 DecoderData *data = (DecoderData *)dp;
|
Chris@148
|
350 return data->reader->accept(header, pcm);
|
Chris@148
|
351 }
|
Chris@148
|
352
|
Chris@148
|
353 enum mad_flow
|
Chris@148
|
354 MP3FileReader::accept(struct mad_header const *header,
|
Chris@148
|
355 struct mad_pcm *pcm)
|
Chris@148
|
356 {
|
Chris@148
|
357 int channels = pcm->channels;
|
Chris@148
|
358 int frames = pcm->length;
|
Chris@148
|
359
|
Chris@148
|
360 if (header) {
|
Chris@1038
|
361 m_bitrateNum = m_bitrateNum + double(header->bitrate);
|
Chris@148
|
362 m_bitrateDenom ++;
|
Chris@148
|
363 }
|
Chris@148
|
364
|
Chris@148
|
365 if (frames < 1) return MAD_FLOW_CONTINUE;
|
Chris@148
|
366
|
Chris@148
|
367 if (m_channelCount == 0) {
|
Chris@297
|
368
|
Chris@297
|
369 m_fileRate = pcm->samplerate;
|
Chris@148
|
370 m_channelCount = channels;
|
Chris@297
|
371
|
Chris@297
|
372 initialiseDecodeCache();
|
Chris@297
|
373
|
Chris@297
|
374 if (m_cacheMode == CacheInTemporaryFile) {
|
Chris@690
|
375 // SVDEBUG << "MP3FileReader::accept: channel count " << m_channelCount << ", file rate " << m_fileRate << ", about to start serialised section" << endl;
|
Chris@297
|
376 startSerialised("MP3FileReader::Decode");
|
Chris@297
|
377 }
|
Chris@148
|
378 }
|
Chris@148
|
379
|
Chris@148
|
380 if (m_bitrateDenom > 0) {
|
Chris@148
|
381 double bitrate = m_bitrateNum / m_bitrateDenom;
|
Chris@148
|
382 double duration = double(m_fileSize * 8) / bitrate;
|
Chris@148
|
383 double elapsed = double(m_frameCount) / m_sampleRate;
|
Chris@375
|
384 double percent = 100;
|
Chris@375
|
385 if (duration > 0.0) percent = ((elapsed * 100.0) / duration);
|
Chris@357
|
386 int p = int(percent);
|
Chris@357
|
387 if (p < 1) p = 1;
|
Chris@357
|
388 if (p > 99) p = 99;
|
Chris@392
|
389 if (m_completion != p && m_reporter) {
|
Chris@357
|
390 m_completion = p;
|
Chris@392
|
391 m_reporter->setProgress(m_completion);
|
Chris@148
|
392 }
|
Chris@148
|
393 }
|
Chris@148
|
394
|
Chris@148
|
395 if (m_cancelled) return MAD_FLOW_STOP;
|
Chris@148
|
396
|
Chris@148
|
397 if (!isDecodeCacheInitialised()) {
|
Chris@148
|
398 initialiseDecodeCache();
|
Chris@148
|
399 }
|
Chris@148
|
400
|
Chris@929
|
401 if (int(m_samplebuffersize) < frames) {
|
Chris@297
|
402 if (!m_samplebuffer) {
|
Chris@297
|
403 m_samplebuffer = new float *[channels];
|
Chris@297
|
404 for (int c = 0; c < channels; ++c) {
|
Chris@297
|
405 m_samplebuffer[c] = 0;
|
Chris@297
|
406 }
|
Chris@297
|
407 }
|
Chris@297
|
408 for (int c = 0; c < channels; ++c) {
|
Chris@297
|
409 delete[] m_samplebuffer[c];
|
Chris@297
|
410 m_samplebuffer[c] = new float[frames];
|
Chris@297
|
411 }
|
Chris@297
|
412 m_samplebuffersize = frames;
|
Chris@297
|
413 }
|
Chris@148
|
414
|
Chris@297
|
415 int activeChannels = int(sizeof(pcm->samples) / sizeof(pcm->samples[0]));
|
Chris@297
|
416
|
Chris@297
|
417 for (int ch = 0; ch < channels; ++ch) {
|
Chris@297
|
418
|
Chris@297
|
419 for (int i = 0; i < frames; ++i) {
|
Chris@297
|
420
|
Chris@148
|
421 mad_fixed_t sample = 0;
|
Chris@297
|
422 if (ch < activeChannels) {
|
Chris@148
|
423 sample = pcm->samples[ch][i];
|
Chris@148
|
424 }
|
Chris@148
|
425 float fsample = float(sample) / float(MAD_F_ONE);
|
Chris@297
|
426
|
Chris@297
|
427 m_samplebuffer[ch][i] = fsample;
|
Chris@148
|
428 }
|
Chris@148
|
429 }
|
Chris@148
|
430
|
Chris@297
|
431 addSamplesToDecodeCache(m_samplebuffer, frames);
|
Chris@148
|
432
|
Chris@148
|
433 return MAD_FLOW_CONTINUE;
|
Chris@148
|
434 }
|
Chris@148
|
435
|
Chris@148
|
436 enum mad_flow
|
Chris@929
|
437 MP3FileReader::error(void * /* dp */,
|
Chris@929
|
438 struct mad_stream * /* stream */,
|
Chris@148
|
439 struct mad_frame *)
|
Chris@148
|
440 {
|
Chris@929
|
441 // DecoderData *data = (DecoderData *)dp;
|
Chris@148
|
442
|
Chris@523
|
443 // fprintf(stderr, "decoding error 0x%04x (%s) at byte offset %lu\n",
|
Chris@523
|
444 // stream->error, mad_stream_errorstr(stream),
|
Chris@523
|
445 // (unsigned long)(stream->this_frame - data->start));
|
Chris@148
|
446
|
Chris@148
|
447 return MAD_FLOW_CONTINUE;
|
Chris@148
|
448 }
|
Chris@148
|
449
|
Chris@157
|
450 void
|
Chris@290
|
451 MP3FileReader::getSupportedExtensions(std::set<QString> &extensions)
|
Chris@157
|
452 {
|
Chris@157
|
453 extensions.insert("mp3");
|
Chris@157
|
454 }
|
Chris@157
|
455
|
Chris@316
|
456 bool
|
Chris@316
|
457 MP3FileReader::supportsExtension(QString extension)
|
Chris@316
|
458 {
|
Chris@316
|
459 std::set<QString> extensions;
|
Chris@316
|
460 getSupportedExtensions(extensions);
|
Chris@316
|
461 return (extensions.find(extension.toLower()) != extensions.end());
|
Chris@316
|
462 }
|
Chris@316
|
463
|
Chris@316
|
464 bool
|
Chris@316
|
465 MP3FileReader::supportsContentType(QString type)
|
Chris@316
|
466 {
|
Chris@316
|
467 return (type == "audio/mpeg");
|
Chris@316
|
468 }
|
Chris@316
|
469
|
Chris@316
|
470 bool
|
Chris@317
|
471 MP3FileReader::supports(FileSource &source)
|
Chris@316
|
472 {
|
Chris@316
|
473 return (supportsExtension(source.getExtension()) ||
|
Chris@316
|
474 supportsContentType(source.getContentType()));
|
Chris@316
|
475 }
|
Chris@316
|
476
|
Chris@316
|
477
|
Chris@148
|
478 #endif
|