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 <memory>
25 #include <cassert>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/scoped_ptr.hpp>
28 #include <boost/ptr_container/ptr_vector.hpp>
29 
30 #include "SoundInfo.h"
31 
32 // Forward declarations
33 namespace gnash {
34  class SimpleBuffer;
35  namespace sound {
36  class InputStream;
37  class StreamingSound;
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<InputStream*> Instances;
56 
58  //
61  StreamingSoundData(const media::SoundInfo& info, int nVolume);
62 
64 
66  //
71  size_t append(std::auto_ptr<SimpleBuffer> data, size_t sampleCount,
72  int seekSamples);
73 
75  bool empty() const {
76  return _buffers.empty();
77  }
78 
79  const SimpleBuffer& getBlock(size_t index) const {
80  return _buffers[index];
81  }
82 
83  size_t getSampleCount(size_t index) const {
84  return _blockData[index].sampleCount;
85  }
86 
87  size_t getSeekSamples(size_t index) const {
88  return _blockData[index].seekSamples;
89  }
90 
91  size_t blockCount() const {
92  return _buffers.size();
93  }
94 
95  size_t playingBlock() const;
96 
98  //
101  bool isPlaying() const;
102 
104  //
107  size_t numPlayingInstances() const;
108 
110  void getPlayingInstances(std::vector<InputStream*>& to) const;
111 
113  //
117 
119  //
128  std::auto_ptr<StreamingSound> createInstance(media::MediaHandler& mh,
129  unsigned long blockOffset);
130 
132  //
135  void clearInstances();
136 
138  //
143  Instances::iterator eraseActiveSound(Instances::iterator i);
144 
146  //
154  void eraseActiveSound(InputStream* inst);
155 
158 
161  int volume;
162 
163 private:
164 
165  struct BlockData
166  {
167  BlockData(size_t count, int seek)
168  :
169  sampleCount(count),
170  seekSamples(seek)
171  {}
172 
173  size_t sampleCount;
174  size_t seekSamples;
175  };
176 
178  //
181  Instances _soundInstances;
182 
184  mutable boost::mutex _soundInstancesMutex;
185 
186  boost::ptr_vector<SimpleBuffer> _buffers;
187 
188  std::vector<BlockData> _blockData;
189 };
190 
191 } // gnash.sound namespace
192 } // namespace gnash
193 
194 #endif // SOUND_EMBEDSOUND_H
A sound input stream.
Definition: InputStream.h:47
size_t numPlayingInstances() const
Return number of playing instances of this sound.
Definition: StreamingSoundData.cpp:122
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
~StreamingSoundData()
Definition: StreamingSoundData.cpp:90
Instances::iterator eraseActiveSound(Instances::iterator i)
Drop an active sound (by iterator)
Definition: StreamingSoundData.cpp:71
size_t playingBlock() const
Definition: StreamingSoundData.cpp:57
int volume
Definition: StreamingSoundData.h:161
bool empty() const
Do we have any data?
Definition: StreamingSoundData.h:75
void getPlayingInstances(std::vector< InputStream * > &to) const
Append to the given vector all playing instances of this sound def.
Definition: StreamingSoundData.cpp:136
SimpleBuffer data
Definition: LocalConnection_as.cpp:153
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::list< InputStream * > Instances
Container for the active instances of this sounds being played.
Definition: StreamingSoundData.h:55
Definition of an embedded sound.
Definition: StreamingSoundData.h:48
size_t blockCount() const
Definition: StreamingSoundData.h:91
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:68
void clearInstances()
Drop all active sounds.
Definition: StreamingSoundData.cpp:64
size_t getSampleCount(size_t index) const
Definition: StreamingSoundData.h:83
bool isPlaying() const
Are there known playing instances of this sound ?
Definition: StreamingSoundData.cpp:115
StreamingSoundData(const media::SoundInfo &info, int nVolume)
Construct a sound with given data, info and volume.
Definition: StreamingSoundData.cpp:48
media::SoundInfo soundinfo
Object holding information about the sound.
Definition: StreamingSoundData.h:157
size_t getSeekSamples(size_t index) const
Definition: StreamingSoundData.h:87
InputStream * firstPlayingInstance() const
Return the first created instance of this sound.
Definition: StreamingSoundData.cpp:129
Definition: GnashKey.h:155
std::auto_ptr< StreamingSound > createInstance(media::MediaHandler &mh, unsigned long blockOffset)
Create an instance of this sound.
Definition: StreamingSoundData.cpp:78
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
const SimpleBuffer & getBlock(size_t index) const
Definition: StreamingSoundData.h:79
size_t append(std::auto_ptr< SimpleBuffer > data, size_t sampleCount, int seekSamples)
Append a sound data block.
Definition: StreamingSoundData.cpp:38