1 // EmbedSound.cpp - embedded sound definition, for gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
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.
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"
24 #include <boost/cstdint.hpp>
26 #include "EmbedSoundInst.h"
27 #include "SoundInfo.h"
28 #include "MediaHandler.h"
30 #include "GnashException.h"
35 EmbedSound::EmbedSound(std::auto_ptr
<SimpleBuffer
> data
,
36 const media::SoundInfo
& info
, int nVolume
)
42 if (!_buf
.get()) _buf
.reset(new SimpleBuffer());
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());
75 EmbedSound::~EmbedSound()
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
);
97 EmbedSound::isPlaying() const
99 boost::mutex::scoped_lock
lock(_soundInstancesMutex
);
100 return !_soundInstances
.empty();
104 EmbedSound::numPlayingInstances() const
106 boost::mutex::scoped_lock
lock(_soundInstancesMutex
);
107 return _soundInstances
.size();
111 EmbedSound::firstPlayingInstance() const
113 boost::mutex::scoped_lock
lock(_soundInstancesMutex
);
114 return _soundInstances
.front();
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();
128 } // gnash.sound namespace