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 #ifndef _MP3_FILE_READER_H_
|
Chris@148
|
17 #define _MP3_FILE_READER_H_
|
Chris@148
|
18
|
Chris@148
|
19 #ifdef HAVE_MAD
|
Chris@148
|
20
|
Chris@148
|
21 #include "CodedAudioFileReader.h"
|
Chris@148
|
22
|
Chris@263
|
23 #include "base/Thread.h"
|
Chris@148
|
24 #include <mad.h>
|
Chris@148
|
25
|
Chris@157
|
26 #include <set>
|
Chris@157
|
27
|
Chris@148
|
28 class QProgressDialog;
|
Chris@148
|
29
|
Chris@148
|
30 class MP3FileReader : public CodedAudioFileReader
|
Chris@148
|
31 {
|
Chris@148
|
32 public:
|
Chris@263
|
33 enum DecodeMode {
|
Chris@263
|
34 DecodeAtOnce, // decode the file on construction, with progress dialog
|
Chris@263
|
35 DecodeThreaded // decode in a background thread after construction
|
Chris@263
|
36 };
|
Chris@263
|
37
|
Chris@263
|
38 MP3FileReader(QString path, DecodeMode decodeMode, CacheMode cacheMode);
|
Chris@148
|
39 virtual ~MP3FileReader();
|
Chris@148
|
40
|
Chris@148
|
41 virtual QString getError() const { return m_error; }
|
Chris@157
|
42
|
Chris@157
|
43 static void getSupportedExtensions(std::set<QString> &extensions);
|
Chris@148
|
44
|
Chris@265
|
45 virtual int getDecodeCompletion() const { return m_completion; }
|
Chris@265
|
46
|
Chris@263
|
47 virtual bool isUpdating() const {
|
Chris@263
|
48 return m_decodeThread && m_decodeThread->isRunning();
|
Chris@263
|
49 }
|
Chris@263
|
50
|
Chris@148
|
51 protected:
|
Chris@148
|
52 QString m_path;
|
Chris@148
|
53 QString m_error;
|
Chris@148
|
54 size_t m_fileSize;
|
Chris@148
|
55 double m_bitrateNum;
|
Chris@148
|
56 size_t m_bitrateDenom;
|
Chris@265
|
57 int m_completion;
|
Chris@263
|
58 bool m_done;
|
Chris@263
|
59
|
Chris@263
|
60 unsigned char *m_filebuffer;
|
Chris@148
|
61
|
Chris@148
|
62 QProgressDialog *m_progress;
|
Chris@148
|
63 bool m_cancelled;
|
Chris@148
|
64
|
Chris@148
|
65 struct DecoderData
|
Chris@148
|
66 {
|
Chris@148
|
67 unsigned char const *start;
|
Chris@148
|
68 unsigned long length;
|
Chris@148
|
69 MP3FileReader *reader;
|
Chris@148
|
70 };
|
Chris@148
|
71
|
Chris@148
|
72 bool decode(void *mm, size_t sz);
|
Chris@148
|
73 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
|
Chris@148
|
74
|
Chris@148
|
75 static enum mad_flow input(void *, struct mad_stream *);
|
Chris@148
|
76 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
|
Chris@148
|
77 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
|
Chris@263
|
78
|
Chris@263
|
79 class DecodeThread : public Thread
|
Chris@263
|
80 {
|
Chris@263
|
81 public:
|
Chris@263
|
82 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
|
Chris@263
|
83 virtual void run();
|
Chris@263
|
84
|
Chris@263
|
85 protected:
|
Chris@263
|
86 MP3FileReader *m_reader;
|
Chris@263
|
87 };
|
Chris@263
|
88
|
Chris@263
|
89 DecodeThread *m_decodeThread;
|
Chris@148
|
90 };
|
Chris@148
|
91
|
Chris@148
|
92 #endif
|
Chris@148
|
93
|
Chris@148
|
94 #endif
|