Gnash  0.8.11dev
StreamingSoundData.h
Go to the documentation of this file.
1 // StreamingSoundData.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_STREAMING_SOUND_DATA_H
21 #define SOUND_STREAMING_SOUND_DATA_H
22 
23 #include <vector>
24 #include <map>
25 #include <memory>
26 #include <set>
27 #include <cassert>
28 #include <boost/thread/mutex.hpp>
29 #include <boost/scoped_ptr.hpp>
30 #include <boost/ptr_container/ptr_vector.hpp>
31 
32 #include "SimpleBuffer.h"
33 #include "SoundInfo.h"
34 
35 // Forward declarations
36 namespace gnash {
37  namespace sound {
38  class InputStream;
39  class StreamingSound;
40  }
41  namespace media {
42  class MediaHandler;
43  }
44 }
45 
46 namespace gnash {
47 namespace sound {
48 
51 {
52 public:
53 
55  //
57  typedef std::list<InputStream*> Instances;
58 
60  //
63  StreamingSoundData(const media::SoundInfo& info, int nVolume);
64 
66 
68  //
73  size_t append(std::auto_ptr<SimpleBuffer> data, size_t sampleCount,
74  int seekSamples);
75 
77  bool empty() const {
78  return _buffers.empty();
79  }
80 
81  const SimpleBuffer& getBlock(size_t index) const {
82  return _buffers[index];
83  }
84 
85  size_t getSampleCount(size_t index) const {
86  return _blockData[index].sampleCount;
87  }
88 
89  size_t getSeekSamples(size_t index) const {
90  return _blockData[index].seekSamples;
91  }
92 
93  size_t blockCount() const {
94  return _buffers.size();
95  }
96 
97  size_t playingBlock() const;
98 
100  //
103  bool isPlaying() const;
104 
106  //
109  size_t numPlayingInstances() const;
110 
112  void getPlayingInstances(std::vector<InputStream*>& to) const;
113 
115  //
119 
121  //
130  std::auto_ptr<StreamingSound> createInstance(media::MediaHandler& mh,
131  unsigned long blockOffset);
132 
134  //
137  void clearInstances();
138 
140  //
145  Instances::iterator eraseActiveSound(Instances::iterator i);
146 
148  //
156  void eraseActiveSound(InputStream* inst);
157 
160 
163  int volume;
164 
165 private:
166 
167  struct BlockData
168  {
169  BlockData(size_t count, int seek)
170  :
171  sampleCount(count),
172  seekSamples(seek)
173  {}
174 
175  size_t sampleCount;
176  size_t seekSamples;
177  };
178 
180  //
183  Instances _soundInstances;
184 
186  mutable boost::mutex _soundInstancesMutex;
187 
188  boost::ptr_vector<SimpleBuffer> _buffers;
189 
190  std::vector<BlockData> _blockData;
191 };
192 
193 } // gnash.sound namespace
194 } // namespace gnash
195 
196 #endif // SOUND_EMBEDSOUND_H