enable docbook, install info pages
[gnash.git] / libsound / EmbedSound.cpp
blobe115ce1c2ad3dc0b9c561f920928cc66826437ce
1 // EmbedSound.cpp - embedded sound definition, for gnash
2 //
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "EmbedSound.h"
23 #include <vector>
24 #include <boost/cstdint.hpp>
26 #include "EmbedSoundInst.h"
27 #include "SoundInfo.h"
28 #include "MediaHandler.h"
29 #include "log.h"
30 #include "GnashException.h"
32 namespace gnash {
33 namespace sound {
35 EmbedSound::EmbedSound(std::auto_ptr<SimpleBuffer> data,
36 const media::SoundInfo& info, int nVolume)
38 soundinfo(info),
39 volume(nVolume),
40 _buf(data.release())
42 if (!_buf.get()) _buf.reset(new SimpleBuffer());
45 void
46 EmbedSound::clearInstances()
48 boost::mutex::scoped_lock lock(_soundInstancesMutex);
49 _soundInstances.clear();
52 EmbedSound::Instances::iterator
53 EmbedSound::eraseActiveSound(Instances::iterator i)
55 // Mutex intentionally NOT locked...
56 return _soundInstances.erase(i);
59 std::auto_ptr<EmbedSoundInst>
60 EmbedSound::createInstance(media::MediaHandler& mh, unsigned int inPoint,
61 unsigned int outPoint, const SoundEnvelopes* envelopes,
62 unsigned int loopCount)
64 std::auto_ptr<EmbedSoundInst> ret(
65 new EmbedSoundInst(*this, mh, inPoint, outPoint, envelopes, loopCount));
67 boost::mutex::scoped_lock lock(_soundInstancesMutex);
69 // Push the sound onto the playing sounds container.
70 _soundInstances.push_back(ret.get());
72 return ret;
75 EmbedSound::~EmbedSound()
77 clearInstances();
80 void
81 EmbedSound::eraseActiveSound(EmbedSoundInst* inst)
83 boost::mutex::scoped_lock lock(_soundInstancesMutex);
85 Instances::iterator it = std::find( _soundInstances.begin(),
86 _soundInstances.end(), inst);
88 if (it == _soundInstances.end()) {
89 log_error("EmbedSound::eraseActiveSound: instance %p not found!", inst);
90 return;
93 eraseActiveSound(it);
96 bool
97 EmbedSound::isPlaying() const
99 boost::mutex::scoped_lock lock(_soundInstancesMutex);
100 return !_soundInstances.empty();
103 size_t
104 EmbedSound::numPlayingInstances() const
106 boost::mutex::scoped_lock lock(_soundInstancesMutex);
107 return _soundInstances.size();
110 EmbedSoundInst*
111 EmbedSound::firstPlayingInstance() const
113 boost::mutex::scoped_lock lock(_soundInstancesMutex);
114 return _soundInstances.front();
117 void
118 EmbedSound::getPlayingInstances(std::vector<InputStream*>& to) const
120 boost::mutex::scoped_lock lock(_soundInstancesMutex);
121 for (Instances::const_iterator i=_soundInstances.begin(), e=_soundInstances.end();
122 i!=e; ++i)
124 to.push_back(*i);
128 } // gnash.sound namespace
129 } // namespace gnash