1 // StreamingSoundData.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 "StreamingSoundData.h"
26 #include "SoundInfo.h"
27 #include "MediaHandler.h"
29 #include "GnashException.h"
30 #include "StreamingSound.h"
38 StreamingSoundData::append(SimpleBuffer data
,
39 size_t sampleCount
, int seekSamples
)
41 _buffers
.push_back(std::move(data
));
42 _blockData
.emplace_back(sampleCount
, seekSamples
);
43 assert(_blockData
.size() == _buffers
.size());
44 return _buffers
.size() - 1;
47 StreamingSoundData::StreamingSoundData(media::SoundInfo info
,
50 soundinfo(std::move(info
)),
56 StreamingSoundData::playingBlock() const
58 if (_soundInstances
.empty()) return 0;
59 return static_cast<StreamingSound
*>(_soundInstances
.front())->currentBlock();
63 StreamingSoundData::clearInstances()
65 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
66 _soundInstances
.clear();
69 StreamingSoundData::Instances::iterator
70 StreamingSoundData::eraseActiveSound(Instances::iterator i
)
72 // Mutex intentionally NOT locked...
73 return _soundInstances
.erase(i
);
76 std::unique_ptr
<StreamingSound
>
77 StreamingSoundData::createInstance(media::MediaHandler
& mh
, unsigned long block
)
79 std::unique_ptr
<StreamingSound
> ret(new StreamingSound(*this, mh
, block
));
81 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
83 // Push the sound onto the playing sounds container.
84 _soundInstances
.push_back(ret
.get());
89 StreamingSoundData::~StreamingSoundData()
95 StreamingSoundData::eraseActiveSound(InputStream
* inst
)
97 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
99 Instances::iterator it
= std::find(
100 _soundInstances
.begin(),
101 _soundInstances
.end(),
104 if (it
== _soundInstances
.end()) {
105 log_error("StreamingSoundData::eraseActiveSound: instance %p "
110 eraseActiveSound(it
);
114 StreamingSoundData::isPlaying() const
116 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
117 return !_soundInstances
.empty();
121 StreamingSoundData::numPlayingInstances() const
123 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
124 return _soundInstances
.size();
128 StreamingSoundData::firstPlayingInstance() const
130 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
131 return _soundInstances
.front();
135 StreamingSoundData::getPlayingInstances(std::vector
<InputStream
*>& to
) const
137 std::lock_guard
<std::mutex
> lock(_soundInstancesMutex
);
138 for (InputStream
* stream
: _soundInstances
)
140 to
.push_back(stream
);
144 } // gnash.sound namespace