Gnash  0.8.10
EmbedSound.h
Go to the documentation of this file.
00001 // EmbedSound.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_EMBEDSOUND_H
00021 #define SOUND_EMBEDSOUND_H
00022 
00023 #include <vector>
00024 #include <memory> // for auto_ptr (composition)
00025 #include <set> // for composition (_soundInstances)
00026 #include <cassert>
00027 #include <boost/thread/mutex.hpp>
00028 #include <boost/scoped_ptr.hpp>
00029 
00030 #include "SimpleBuffer.h" // for composition
00031 #include "SoundInfo.h" // for composition
00032 #include "SoundEnvelope.h" // for SoundEnvelopes define
00033 
00034 // Forward declarations
00035 namespace gnash {
00036     namespace sound {
00037         class EmbedSoundInst;
00038         class InputStream;
00039     }
00040     namespace media {
00041         class MediaHandler;
00042     }
00043 }
00044 
00045 namespace gnash {
00046 namespace sound {
00047 
00049 class EmbedSound
00050 {
00051 public:
00052 
00054     //
00056     typedef std::list<EmbedSoundInst*> Instances;
00057 
00059     //
00063     EmbedSound(std::auto_ptr<SimpleBuffer> data, const media::SoundInfo& info,
00064             int volume);
00065 
00066     ~EmbedSound();
00067 
00069     size_t size() const {
00070         return _buf->size();
00071     }
00072 
00074     bool empty() const {
00075         return _buf->empty();
00076     }
00077 
00079     const boost::uint8_t* data() const {
00080         return _buf->data();
00081     }
00082 
00084     //
00088     const boost::uint8_t* data(size_t pos) const {
00089         assert(pos < _buf->size());
00090         return _buf->data()+pos;
00091     }
00092 
00094     //
00097     bool isPlaying() const;
00098 
00100     //
00103     size_t numPlayingInstances() const;
00104 
00106     void getPlayingInstances(std::vector<InputStream*>& to) const;
00107 
00109     //
00112     EmbedSoundInst* firstPlayingInstance() const;
00113 
00115     //
00140     std::auto_ptr<EmbedSoundInst> createInstance(media::MediaHandler& mh,
00141             unsigned int inPoint, unsigned int outPoint,
00142             const SoundEnvelopes* envelopes, unsigned int loopCount);
00143 
00145     //
00147     void clearInstances();
00148 
00150     //
00154     Instances::iterator eraseActiveSound(Instances::iterator i);
00155 
00157     //
00168     void eraseActiveSound(EmbedSoundInst* inst);
00169 
00171     media::SoundInfo soundinfo;
00172 
00175     int volume;
00176 
00177 private:
00178 
00180     boost::scoped_ptr<SimpleBuffer> _buf;
00181 
00183     //
00186     Instances _soundInstances;
00187 
00189     //
00190     mutable boost::mutex _soundInstancesMutex;
00191 };
00192 
00193 } // gnash.sound namespace 
00194 } // namespace gnash
00195 
00196 #endif // SOUND_EMBEDSOUND_H