Gnash  0.8.11dev
EmbedSound.h
Go to the documentation of this file.
1 // EmbedSound.h - 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.
10 //
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
19 
20 #ifndef SOUND_EMBEDSOUND_H
21 #define SOUND_EMBEDSOUND_H
22 
23 #include <vector>
24 #include <memory> // for unique_ptr (composition)
25 #include <cassert>
26 #include <memory>
27 #include <mutex>
28 #include <list>
29 
30 #include "SimpleBuffer.h" // for composition
31 #include "SoundInfo.h" // for composition
32 #include "SoundEnvelope.h" // for SoundEnvelopes define
33 
34 // Forward declarations
35 namespace gnash {
36  namespace sound {
37  class EmbedSoundInst;
38  class InputStream;
39  }
40  namespace media {
41  class MediaHandler;
42  }
43 }
44 
45 namespace gnash {
46 namespace sound {
47 
50 {
51 public:
52 
54  //
56  typedef std::list<EmbedSoundInst*> Instances;
57 
59  //
63  EmbedSound(std::unique_ptr<SimpleBuffer> data, media::SoundInfo info,
64  int volume);
65 
66  ~EmbedSound();
67 
69  size_t size() const {
70  return _buf->size();
71  }
72 
74  bool empty() const {
75  return _buf->empty();
76  }
77 
79  const std::uint8_t* data() const {
80  return _buf->data();
81  }
82 
84  //
88  const std::uint8_t* data(size_t pos) const {
89  assert(pos < _buf->size());
90  return _buf->data()+pos;
91  }
92 
94  //
97  bool isPlaying() const;
98 
100  //
103  size_t numPlayingInstances() const;
104 
106  void getPlayingInstances(std::vector<InputStream*>& to) const;
107 
109  //
112  EmbedSoundInst* firstPlayingInstance() const;
113 
115  //
140  std::unique_ptr<EmbedSoundInst> createInstance(media::MediaHandler& mh,
141  unsigned int inPoint, unsigned int outPoint,
142  const SoundEnvelopes* envelopes, int loopCount);
143 
145  //
147  void clearInstances();
148 
150  //
154  Instances::iterator eraseActiveSound(Instances::iterator i);
155 
157  //
168  void eraseActiveSound(EmbedSoundInst* inst);
169 
172 
175  int volume;
176 
177 private:
178 
180  std::unique_ptr<SimpleBuffer> _buf;
181 
183  //
186  Instances _soundInstances;
187 
189  //
190  mutable std::mutex _soundInstancesMutex;
191 };
192 
193 } // gnash.sound namespace
194 } // namespace gnash
195 
196 #endif // SOUND_EMBEDSOUND_H
Definition: klash_part.cpp:331
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
const std::uint8_t * data() const
Return a pointer to the underlying buffer.
Definition: EmbedSound.h:79
Definition of an embedded sound.
Definition: EmbedSound.h:49
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::list< EmbedSoundInst * > Instances
Vector containing the active instances of this sounds being played.
Definition: EmbedSound.h:56
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:69
bool empty() const
Is the data buffer empty ?
Definition: EmbedSound.h:74
std::vector< SoundEnvelope > SoundEnvelopes
A vector of SoundEnvelope objects.
Definition: SoundEnvelope.h:60
Definition: GnashKey.h:155
size_t size() const
Return size of the data buffer.
Definition: EmbedSound.h:69
Instance of a defined sound (EmbedSound)
Definition: EmbedSoundInst.h:45
media::SoundInfo soundinfo
Object holding information about the sound.
Definition: EmbedSound.h:171
int volume
Definition: EmbedSound.h:175
const std::uint8_t * data(size_t pos) const
Return a pointer to an offset in the underlying buffer.
Definition: EmbedSound.h:88