comparison data/fileio/MP3FileReader.h @ 263:71dfc6ab3b54

* Threaded mp3/ogg file reading. Not activated yet, as it doesn't work in context (SV needs to know the duration of its main model at the outset)
author Chris Cannam
date Thu, 24 May 2007 16:20:22 +0000
parents c03ec31005e1
children e08f486e8d8c
comparison
equal deleted inserted replaced
262:524bcd89743b 263:71dfc6ab3b54
18 18
19 #ifdef HAVE_MAD 19 #ifdef HAVE_MAD
20 20
21 #include "CodedAudioFileReader.h" 21 #include "CodedAudioFileReader.h"
22 22
23 #include "base/Thread.h"
23 #include <mad.h> 24 #include <mad.h>
24 25
25 #include <set> 26 #include <set>
26 27
27 class QProgressDialog; 28 class QProgressDialog;
28 29
29 class MP3FileReader : public CodedAudioFileReader 30 class MP3FileReader : public CodedAudioFileReader
30 { 31 {
31 public: 32 public:
32 MP3FileReader(QString path, bool showProgress, CacheMode cacheMode); 33 enum DecodeMode {
34 DecodeAtOnce, // decode the file on construction, with progress dialog
35 DecodeThreaded // decode in a background thread after construction
36 };
37
38 MP3FileReader(QString path, DecodeMode decodeMode, CacheMode cacheMode);
33 virtual ~MP3FileReader(); 39 virtual ~MP3FileReader();
34 40
35 virtual QString getError() const { return m_error; } 41 virtual QString getError() const { return m_error; }
36 42
37 static void getSupportedExtensions(std::set<QString> &extensions); 43 static void getSupportedExtensions(std::set<QString> &extensions);
38 44
45 virtual bool isUpdating() const {
46 return m_decodeThread && m_decodeThread->isRunning();
47 }
48
39 protected: 49 protected:
40 QString m_path; 50 QString m_path;
41 QString m_error; 51 QString m_error;
42 size_t m_fileSize; 52 size_t m_fileSize;
43 double m_bitrateNum; 53 double m_bitrateNum;
44 size_t m_bitrateDenom; 54 size_t m_bitrateDenom;
55 bool m_done;
56
57 unsigned char *m_filebuffer;
45 58
46 QProgressDialog *m_progress; 59 QProgressDialog *m_progress;
47 bool m_cancelled; 60 bool m_cancelled;
48 61
49 struct DecoderData 62 struct DecoderData
57 enum mad_flow accept(struct mad_header const *, struct mad_pcm *); 70 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
58 71
59 static enum mad_flow input(void *, struct mad_stream *); 72 static enum mad_flow input(void *, struct mad_stream *);
60 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *); 73 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
61 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *); 74 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
75
76 class DecodeThread : public Thread
77 {
78 public:
79 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
80 virtual void run();
81
82 protected:
83 MP3FileReader *m_reader;
84 };
85
86 DecodeThread *m_decodeThread;
62 }; 87 };
63 88
64 #endif 89 #endif
65 90
66 #endif 91 #endif