00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _MP3_FILE_READER_H_
00017 #define _MP3_FILE_READER_H_
00018
00019 #ifdef HAVE_MAD
00020
00021 #include "CodedAudioFileReader.h"
00022
00023 #include "base/Thread.h"
00024 #include <mad.h>
00025
00026 #include <set>
00027
00028 class QProgressDialog;
00029
00030 class MP3FileReader : public CodedAudioFileReader
00031 {
00032 public:
00033 enum DecodeMode {
00034 DecodeAtOnce,
00035 DecodeThreaded
00036 };
00037
00038 MP3FileReader(FileSource source,
00039 DecodeMode decodeMode,
00040 CacheMode cacheMode,
00041 size_t targetRate = 0);
00042 virtual ~MP3FileReader();
00043
00044 virtual QString getError() const { return m_error; }
00045
00046 virtual QString getLocation() const { return m_source.getLocation(); }
00047 virtual QString getTitle() const { return m_title; }
00048 virtual QString getMaker() const { return m_maker; }
00049
00050 static void getSupportedExtensions(std::set<QString> &extensions);
00051 static bool supportsExtension(QString ext);
00052 static bool supportsContentType(QString type);
00053 static bool supports(FileSource &source);
00054
00055 virtual int getDecodeCompletion() const { return m_completion; }
00056
00057 virtual bool isUpdating() const {
00058 return m_decodeThread && m_decodeThread->isRunning();
00059 }
00060
00061 protected:
00062 FileSource m_source;
00063 QString m_path;
00064 QString m_error;
00065 QString m_title;
00066 QString m_maker;
00067 size_t m_fileSize;
00068 double m_bitrateNum;
00069 size_t m_bitrateDenom;
00070 int m_completion;
00071 bool m_done;
00072
00073 unsigned char *m_filebuffer;
00074 float **m_samplebuffer;
00075 size_t m_samplebuffersize;
00076
00077 QProgressDialog *m_progress;
00078 bool m_cancelled;
00079
00080 struct DecoderData
00081 {
00082 unsigned char const *start;
00083 unsigned long length;
00084 MP3FileReader *reader;
00085 };
00086
00087 bool decode(void *mm, size_t sz);
00088 enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
00089
00090 static enum mad_flow input(void *, struct mad_stream *);
00091 static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *);
00092 static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *);
00093
00094 class DecodeThread : public Thread
00095 {
00096 public:
00097 DecodeThread(MP3FileReader *reader) : m_reader(reader) { }
00098 virtual void run();
00099
00100 protected:
00101 MP3FileReader *m_reader;
00102 };
00103
00104 DecodeThread *m_decodeThread;
00105
00106 void loadTags();
00107 QString loadTag(void *vtag, const char *name);
00108 };
00109
00110 #endif
00111
00112 #endif