Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@148: Chris@148: /* Chris@148: Sonic Visualiser Chris@148: An audio file viewer and annotation editor. Chris@148: Centre for Digital Music, Queen Mary, University of London. Chris@148: This file copyright 2006 Chris Cannam. Chris@148: Chris@148: This program is free software; you can redistribute it and/or Chris@148: modify it under the terms of the GNU General Public License as Chris@148: published by the Free Software Foundation; either version 2 of the Chris@148: License, or (at your option) any later version. See the file Chris@148: COPYING included with this distribution for more information. Chris@148: */ Chris@148: Chris@148: #ifndef _MP3_FILE_READER_H_ Chris@148: #define _MP3_FILE_READER_H_ Chris@148: Chris@148: #ifdef HAVE_MAD Chris@148: Chris@148: #include "CodedAudioFileReader.h" Chris@148: Chris@263: #include "base/Thread.h" Chris@148: #include Chris@148: Chris@157: #include Chris@157: Chris@392: class ProgressReporter; Chris@148: Chris@148: class MP3FileReader : public CodedAudioFileReader Chris@148: { Chris@392: Q_OBJECT Chris@392: Chris@148: public: Chris@263: enum DecodeMode { Chris@392: DecodeAtOnce, // decode the file on construction, with progress Chris@263: DecodeThreaded // decode in a background thread after construction Chris@263: }; Chris@263: Chris@317: MP3FileReader(FileSource source, Chris@297: DecodeMode decodeMode, Chris@297: CacheMode cacheMode, Chris@1040: sv_samplerate_t targetRate = 0, Chris@920: bool normalised = false, Chris@392: ProgressReporter *reporter = 0); Chris@148: virtual ~MP3FileReader(); Chris@148: Chris@290: virtual QString getError() const { return m_error; } Chris@290: Chris@345: virtual QString getLocation() const { return m_source.getLocation(); } Chris@290: virtual QString getTitle() const { return m_title; } Chris@334: virtual QString getMaker() const { return m_maker; } Chris@632: virtual TagMap getTags() const { return m_tags; } Chris@271: Chris@290: static void getSupportedExtensions(std::set &extensions); Chris@316: static bool supportsExtension(QString ext); Chris@316: static bool supportsContentType(QString type); Chris@317: static bool supports(FileSource &source); Chris@316: Chris@265: virtual int getDecodeCompletion() const { return m_completion; } Chris@265: Chris@263: virtual bool isUpdating() const { Chris@263: return m_decodeThread && m_decodeThread->isRunning(); Chris@263: } Chris@263: Chris@392: public slots: Chris@392: void cancelled(); Chris@392: Chris@148: protected: Chris@317: FileSource m_source; Chris@290: QString m_path; Chris@290: QString m_error; Chris@290: QString m_title; Chris@333: QString m_maker; Chris@632: TagMap m_tags; Chris@1038: sv_frame_t m_fileSize; Chris@148: double m_bitrateNum; Chris@929: int m_bitrateDenom; Chris@265: int m_completion; Chris@263: bool m_done; Chris@263: Chris@263: unsigned char *m_filebuffer; Chris@297: float **m_samplebuffer; Chris@929: int m_samplebuffersize; Chris@148: Chris@392: ProgressReporter *m_reporter; Chris@148: bool m_cancelled; Chris@148: Chris@148: struct DecoderData Chris@148: { Chris@148: unsigned char const *start; Chris@148: unsigned long length; Chris@148: MP3FileReader *reader; Chris@148: }; Chris@148: Chris@1038: bool decode(void *mm, sv_frame_t sz); Chris@148: enum mad_flow accept(struct mad_header const *, struct mad_pcm *); Chris@148: Chris@148: static enum mad_flow input(void *, struct mad_stream *); Chris@148: static enum mad_flow output(void *, struct mad_header const *, struct mad_pcm *); Chris@148: static enum mad_flow error(void *, struct mad_stream *, struct mad_frame *); Chris@263: Chris@263: class DecodeThread : public Thread Chris@263: { Chris@263: public: Chris@263: DecodeThread(MP3FileReader *reader) : m_reader(reader) { } Chris@263: virtual void run(); Chris@263: Chris@263: protected: Chris@263: MP3FileReader *m_reader; Chris@263: }; Chris@263: Chris@263: DecodeThread *m_decodeThread; Chris@271: Chris@271: void loadTags(); Chris@333: QString loadTag(void *vtag, const char *name); Chris@148: }; Chris@148: Chris@148: #endif Chris@148: Chris@148: #endif