Gnash  0.8.10
StreamingSoundData.h
Go to the documentation of this file.
00001 // StreamingSoundData.h - embedded sound definition, for gnash
00002 // 
00003 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00004 //   Free Software Foundation, Inc
00005 // 
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation; either version 3 of the License, or
00009 // (at your option) any later version.
00010 // 
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 // 
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program; if not, write to the Free Software
00018 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 #ifndef SOUND_STREAMING_SOUND_DATA_H
00021 #define SOUND_STREAMING_SOUND_DATA_H
00022 
00023 #include <vector>
00024 #include <map> 
00025 #include <memory> 
00026 #include <set> 
00027 #include <cassert>
00028 #include <boost/thread/mutex.hpp>
00029 #include <boost/scoped_ptr.hpp>
00030 #include <boost/ptr_container/ptr_vector.hpp>
00031 
00032 #include "SimpleBuffer.h" 
00033 #include "SoundInfo.h" 
00034 
00035 // Forward declarations
00036 namespace gnash {
00037     namespace sound {
00038         class InputStream;
00039         class StreamingSound;
00040     }
00041     namespace media {
00042         class MediaHandler;
00043     }
00044 }
00045 
00046 namespace gnash {
00047 namespace sound {
00048 
00050 class StreamingSoundData
00051 {
00052 public:
00053 
00055     //
00057     typedef std::list<InputStream*> Instances;
00058 
00060     //
00063     StreamingSoundData(const media::SoundInfo& info, int nVolume);
00064 
00065     ~StreamingSoundData();
00066 
00068     //
00073     size_t append(std::auto_ptr<SimpleBuffer> data, size_t sampleCount,
00074             int seekSamples);
00075 
00077     bool empty() const {
00078         return _buffers.empty();
00079     }
00080 
00081     const SimpleBuffer& getBlock(size_t index) const {
00082         return _buffers[index];
00083     }
00084 
00085     size_t getSampleCount(size_t index) const {
00086         return _blockData[index].sampleCount;
00087     }
00088 
00089     size_t getSeekSamples(size_t index) const {
00090         return _blockData[index].seekSamples;
00091     }
00092 
00093     size_t blockCount() const {
00094         return _buffers.size();
00095     }
00096 
00097     size_t playingBlock() const;
00098 
00100     //
00103     bool isPlaying() const;
00104 
00106     //
00109     size_t numPlayingInstances() const;
00110 
00112     void getPlayingInstances(std::vector<InputStream*>& to) const;
00113 
00115     //
00118     InputStream* firstPlayingInstance() const;
00119 
00121     //
00130     std::auto_ptr<StreamingSound> createInstance(media::MediaHandler& mh,
00131             unsigned long blockOffset);
00132 
00134     //
00137     void clearInstances();
00138 
00140     //
00145     Instances::iterator eraseActiveSound(Instances::iterator i);
00146 
00148     //
00156     void eraseActiveSound(InputStream* inst);
00157 
00159     media::SoundInfo soundinfo;
00160 
00163     int volume;
00164 
00165 private:
00166 
00167     struct BlockData
00168     {
00169         BlockData(size_t count, int seek)
00170             :
00171             sampleCount(count),
00172             seekSamples(seek)
00173         {}
00174 
00175         size_t sampleCount;
00176         size_t seekSamples;
00177     };
00178 
00180     //
00183     Instances _soundInstances;
00184 
00186     mutable boost::mutex _soundInstancesMutex;
00187 
00188     boost::ptr_vector<SimpleBuffer> _buffers;
00189 
00190     std::vector<BlockData> _blockData;
00191 };
00192 
00193 } // gnash.sound namespace 
00194 } // namespace gnash
00195 
00196 #endif // SOUND_EMBEDSOUND_H