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 <set> // for composition (_soundInstances)
26 #include <cassert>
27 #include <boost/thread/mutex.hpp>
28 #include <boost/scoped_ptr.hpp>
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::auto_ptr<SimpleBuffer> data, const 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 boost::uint8_t* data() const {
80  return _buf->data();
81  }
82 
84  //
88  const boost::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  //
113 
115  //
140  std::auto_ptr<EmbedSoundInst> createInstance(media::MediaHandler& mh,
141  unsigned int inPoint, unsigned int outPoint,
142  const SoundEnvelopes* envelopes, unsigned 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  boost::scoped_ptr<SimpleBuffer> _buf;
181 
183  //
186  Instances _soundInstances;
187 
189  //
190  mutable boost::mutex _soundInstancesMutex;
191 };
192 
193 } // gnash.sound namespace
194 } // namespace gnash
195 
196 #endif // SOUND_EMBEDSOUND_H