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