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 auto_ptr (composition)
25 #include <cassert>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/scoped_ptr.hpp>
28 
29 #include "SimpleBuffer.h" // for composition
30 #include "SoundInfo.h" // for composition
31 #include "SoundEnvelope.h" // for SoundEnvelopes define
32 
33 // Forward declarations
34 namespace gnash {
35  namespace sound {
36  class EmbedSoundInst;
37  class InputStream;
38  }
39  namespace media {
40  class MediaHandler;
41  }
42 }
43 
44 namespace gnash {
45 namespace sound {
46 
49 {
50 public:
51 
53  //
55  typedef std::list<EmbedSoundInst*> Instances;
56 
58  //
62  EmbedSound(std::auto_ptr<SimpleBuffer> data, const media::SoundInfo& info,
63  int volume);
64 
65  ~EmbedSound();
66 
68  size_t size() const {
69  return _buf->size();
70  }
71 
73  bool empty() const {
74  return _buf->empty();
75  }
76 
78  const boost::uint8_t* data() const {
79  return _buf->data();
80  }
81 
83  //
87  const boost::uint8_t* data(size_t pos) const {
88  assert(pos < _buf->size());
89  return _buf->data()+pos;
90  }
91 
93  //
96  bool isPlaying() const;
97 
99  //
102  size_t numPlayingInstances() const;
103 
105  void getPlayingInstances(std::vector<InputStream*>& to) const;
106 
108  //
112 
114  //
139  std::auto_ptr<EmbedSoundInst> createInstance(media::MediaHandler& mh,
140  unsigned int inPoint, unsigned int outPoint,
141  const SoundEnvelopes* envelopes, int loopCount);
142 
144  //
146  void clearInstances();
147 
149  //
153  Instances::iterator eraseActiveSound(Instances::iterator i);
154 
156  //
167  void eraseActiveSound(EmbedSoundInst* inst);
168 
171 
174  int volume;
175 
176 private:
177 
179  boost::scoped_ptr<SimpleBuffer> _buf;
180 
182  //
185  Instances _soundInstances;
186 
188  //
189  mutable boost::mutex _soundInstancesMutex;
190 };
191 
192 } // gnash.sound namespace
193 } // namespace gnash
194 
195 #endif // SOUND_EMBEDSOUND_H
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
Definition of an embedded sound.
Definition: EmbedSound.h:48
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:55
size_t numPlayingInstances() const
Return number of playing instances of this sound.
Definition: EmbedSound.cpp:104
EmbedSound(std::auto_ptr< SimpleBuffer > data, const media::SoundInfo &info, int volume)
Construct a sound with given data, info and volume.
Definition: EmbedSound.cpp:35
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:68
void getPlayingInstances(std::vector< InputStream * > &to) const
Append to the given vector all playing instances of this sound def.
Definition: EmbedSound.cpp:118
const boost::uint8_t * data(size_t pos) const
Return a pointer to an offset in the underlying buffer.
Definition: EmbedSound.h:87
void clearInstances()
Drop all active sounds.
Definition: EmbedSound.cpp:46
std::vector< SoundEnvelope > SoundEnvelopes
A vector of SoundEnvelope objects.
Definition: SoundEnvelope.h:60
const boost::uint8_t * data() const
Return a pointer to the underlying buffer.
Definition: EmbedSound.h:78
bool isPlaying() const
Are there known playing instances of this sound ?
Definition: EmbedSound.cpp:97
Instances::iterator eraseActiveSound(Instances::iterator i)
Drop an active sound (by iterator)
Definition: EmbedSound.cpp:53
bool empty() const
Is the data buffer empty ?
Definition: EmbedSound.h:73
Definition: GnashKey.h:155
std::auto_ptr< EmbedSoundInst > createInstance(media::MediaHandler &mh, unsigned int inPoint, unsigned int outPoint, const SoundEnvelopes *envelopes, int loopCount)
Create an instance of this sound.
Definition: EmbedSound.cpp:60
Instance of a defined sound (EmbedSound)
Definition: EmbedSoundInst.h:45
~EmbedSound()
Definition: EmbedSound.cpp:75
media::SoundInfo soundinfo
Object holding information about the sound.
Definition: EmbedSound.h:170
int volume
Definition: EmbedSound.h:174
size_t size() const
Return size of the data buffer.
Definition: EmbedSound.h:68
EmbedSoundInst * firstPlayingInstance() const
Return the first created instance of this sound.
Definition: EmbedSound.cpp:111