OggVorbisFileReader.h

Go to the documentation of this file.
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 QProgressDialog;
00031 
00032 class OggVorbisFileReader : public CodedAudioFileReader
00033 {
00034 public:
00035     enum DecodeMode {
00036         DecodeAtOnce, // decode the file on construction, with progress dialog
00037         DecodeThreaded // decode in a background thread after construction
00038     };
00039 
00040     OggVorbisFileReader(FileSource source,
00041                         DecodeMode decodeMode,
00042                         CacheMode cacheMode,
00043                         size_t targetRate = 0);
00044     virtual ~OggVorbisFileReader();
00045 
00046     virtual QString getError() const { return m_error; }
00047 
00048     virtual QString getLocation() const { return m_source.getLocation(); }
00049     virtual QString getTitle() const { return m_title; }
00050     virtual QString getMaker() const { return m_maker; }
00051     
00052     static void getSupportedExtensions(std::set<QString> &extensions);
00053     static bool supportsExtension(QString ext);
00054     static bool supportsContentType(QString type);
00055     static bool supports(FileSource &source);
00056 
00057     virtual int getDecodeCompletion() const { return m_completion; }
00058 
00059     virtual bool isUpdating() const {
00060         return m_decodeThread && m_decodeThread->isRunning();
00061     }
00062 
00063 protected:
00064     FileSource m_source;
00065     QString m_path;
00066     QString m_error;
00067     QString m_title;
00068     QString m_maker;
00069 
00070     OGGZ *m_oggz;
00071     FishSound *m_fishSound;
00072     QProgressDialog *m_progress;
00073     size_t m_fileSize;
00074     size_t m_bytesRead;
00075     bool m_commentsRead;
00076     bool m_cancelled;
00077     int m_completion;
00078  
00079     static int readPacket(OGGZ *, ogg_packet *, long, void *);
00080     static int acceptFrames(FishSound *, float **, long, void *);
00081 
00082     class DecodeThread : public Thread
00083     {
00084     public:
00085         DecodeThread(OggVorbisFileReader *reader) : m_reader(reader) { }
00086         virtual void run();
00087 
00088     protected:
00089         OggVorbisFileReader *m_reader; 
00090     };
00091 
00092     DecodeThread *m_decodeThread;
00093 };
00094 
00095 #endif
00096 #endif
00097 
00098 #endif

Generated on Wed Feb 20 15:45:27 2008 for SonicVisualiser by  doxygen 1.5.1