svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _OGG_VORBIS_FILE_READER_H_ 00017 #define _OGG_VORBIS_FILE_READER_H_ 00018 00019 #ifdef HAVE_OGGZ 00020 #ifdef HAVE_FISHSOUND 00021 00022 #include "CodedAudioFileReader.h" 00023 00024 #include "base/Thread.h" 00025 #include <oggz/oggz.h> 00026 #include <fishsound/fishsound.h> 00027 00028 #include <set> 00029 00030 class ProgressReporter; 00031 00032 class OggVorbisFileReader : public CodedAudioFileReader 00033 { 00034 Q_OBJECT 00035 00036 public: 00037 enum DecodeMode { 00038 DecodeAtOnce, // decode the file on construction, with progress 00039 DecodeThreaded // decode in a background thread after construction 00040 }; 00041 00042 OggVorbisFileReader(FileSource source, 00043 DecodeMode decodeMode, 00044 CacheMode cacheMode, 00045 int targetRate = 0, 00046 bool normalised = false, 00047 ProgressReporter *reporter = 0); 00048 virtual ~OggVorbisFileReader(); 00049 00050 virtual QString getError() const { return m_error; } 00051 00052 virtual QString getLocation() const { return m_source.getLocation(); } 00053 virtual QString getTitle() const { return m_title; } 00054 virtual QString getMaker() const { return m_maker; } 00055 virtual TagMap getTags() const { return m_tags; } 00056 00057 static void getSupportedExtensions(std::set<QString> &extensions); 00058 static bool supportsExtension(QString ext); 00059 static bool supportsContentType(QString type); 00060 static bool supports(FileSource &source); 00061 00062 virtual int getDecodeCompletion() const { return m_completion; } 00063 00064 virtual bool isUpdating() const { 00065 return m_decodeThread && m_decodeThread->isRunning(); 00066 } 00067 00068 public slots: 00069 void cancelled(); 00070 00071 protected: 00072 FileSource m_source; 00073 QString m_path; 00074 QString m_error; 00075 QString m_title; 00076 QString m_maker; 00077 TagMap m_tags; 00078 00079 OGGZ *m_oggz; 00080 FishSound *m_fishSound; 00081 ProgressReporter *m_reporter; 00082 int m_fileSize; 00083 int m_bytesRead; 00084 bool m_commentsRead; 00085 bool m_cancelled; 00086 int m_completion; 00087 00088 static int readPacket(OGGZ *, ogg_packet *, long, void *); 00089 static int acceptFrames(FishSound *, float **, long, void *); 00090 00091 class DecodeThread : public Thread 00092 { 00093 public: 00094 DecodeThread(OggVorbisFileReader *reader) : m_reader(reader) { } 00095 virtual void run(); 00096 00097 protected: 00098 OggVorbisFileReader *m_reader; 00099 }; 00100 00101 DecodeThread *m_decodeThread; 00102 }; 00103 00104 #endif 00105 #endif 00106 00107 #endif