Gnash 0.8.9

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,
00004 //   2011 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 "SimpleBuffer.h" // for composition
00024 #include "SoundInfo.h" // for composition
00025 #include "SoundEnvelope.h" // for SoundEnvelopes define
00026 
00027 #include <vector>
00028 #include <map> // for composition (m_frame_size)
00029 #include <memory> // for auto_ptr (composition)
00030 #include <set> // for composition (_soundInstances)
00031 #include <cassert>
00032 #include <boost/thread/mutex.hpp>
00033 
00034 
00035 // Forward declarations
00036 namespace gnash {
00037     namespace sound {
00038         class EmbedSoundInst;
00039         class InputStream;
00040     }
00041     namespace media {
00042         class MediaHandler;
00043     }
00044 }
00045 
00046 namespace gnash {
00047 namespace sound {
00048 
00050 class EmbedSound
00051 {
00053     std::auto_ptr<SimpleBuffer> _buf;
00054 
00055     void ensureBufferPadding();
00056 
00057 public:
00058 
00060     //
00069     EmbedSound(std::auto_ptr<SimpleBuffer> data,
00070             std::auto_ptr<media::SoundInfo> info, int nVolume,
00071             size_t paddingBytes);
00072 
00073     ~EmbedSound();
00074 
00076     std::auto_ptr<media::SoundInfo> soundinfo;
00077 
00078     typedef std::map<boost::uint32_t,boost::uint32_t> FrameSizeMap;
00079 
00081     FrameSizeMap m_frames_size;
00082 
00084     //
00091     void append(boost::uint8_t* data, unsigned int size);
00092 
00094     size_t size() const 
00095     {
00096         return _buf->size();
00097     }
00098 
00100     bool empty() const 
00101     {
00102         return _buf->empty();
00103     }
00104 
00106     const boost::uint8_t* data() const {
00107         return _buf->data();
00108     }
00109 
00111     boost::uint8_t* data() {
00112         return _buf->data();
00113     }
00114 
00116     //
00120     const boost::uint8_t* data(size_t pos) const {
00121         assert(pos < _buf->size());
00122         return _buf->data()+pos;
00123     }
00124 
00126     //
00130     boost::uint8_t* data(size_t pos) {
00131         assert(pos < _buf->size());
00132         return _buf->data()+pos;
00133     }
00134 
00136     //
00139     bool isPlaying() const;
00140 
00142     //
00145     size_t numPlayingInstances() const;
00146 
00148     void getPlayingInstances(std::vector<InputStream*>& to) const;
00149 
00151     //
00154     EmbedSoundInst* firstPlayingInstance() const;
00155 
00157     //
00194     std::auto_ptr<EmbedSoundInst> createInstance( media::MediaHandler& mh,
00195             unsigned long blockOffset,
00196             unsigned int inPoint, unsigned int outPoint,
00197             const SoundEnvelopes* envelopes, unsigned int loopCount);
00198 
00201     int volume;
00202 
00204     //
00207     typedef std::list<EmbedSoundInst*> Instances;
00208 
00210     //
00216     Instances _soundInstances;
00217 
00219     //
00222     mutable boost::mutex _soundInstancesMutex;
00223 
00225     //
00228     void clearInstances();
00229 
00231     //
00236     Instances::iterator eraseActiveSound(Instances::iterator i);
00237 
00239     //
00250     void eraseActiveSound(EmbedSoundInst* inst);
00251 
00252     const size_t _paddingBytes;
00253 };
00254 
00255 } // gnash.sound namespace 
00256 } // namespace gnash
00257 
00258 #endif // SOUND_EMBEDSOUND_H