Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libsound / EmbedSound.cpp
bloba4853d8d634f7054f04564d90f4328e3c59e7453
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 <cstdint>
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::unique_ptr<SimpleBuffer> data,
36 media::SoundInfo info, int nVolume)
38 soundinfo(std::move(info)),
39 volume(nVolume),
40 _buf(data.release())
42 if (!_buf.get()) _buf.reset(new SimpleBuffer());
45 void
46 EmbedSound::clearInstances()
48 std::lock_guard<std::mutex> 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::unique_ptr<EmbedSoundInst>
60 EmbedSound::createInstance(media::MediaHandler& mh, unsigned int inPoint,
61 unsigned int outPoint, const SoundEnvelopes* envelopes,
62 int loopCount)
64 std::unique_ptr<EmbedSoundInst> ret(
65 new EmbedSoundInst(*this, mh, inPoint, outPoint, envelopes, loopCount));
67 std::lock_guard<std::mutex> 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 std::lock_guard<std::mutex> 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 std::lock_guard<std::mutex> lock(_soundInstancesMutex);
100 return !_soundInstances.empty();
103 size_t
104 EmbedSound::numPlayingInstances() const
106 std::lock_guard<std::mutex> lock(_soundInstancesMutex);
107 return _soundInstances.size();
110 EmbedSoundInst*
111 EmbedSound::firstPlayingInstance() const
113 std::lock_guard<std::mutex> lock(_soundInstancesMutex);
114 return _soundInstances.front();
117 void
118 EmbedSound::getPlayingInstances(std::vector<InputStream*>& to) const
120 std::lock_guard<std::mutex> lock(_soundInstancesMutex);
121 for (InputStream* stream : _soundInstances)
123 to.push_back(stream);
127 } // gnash.sound namespace
128 } // namespace gnash