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 <cassert>
25 #include <list>
26 #include <memory>
27 #include <mutex>
28 
29 #include "SoundInfo.h"
30 
31 // Forward declarations
32 namespace gnash {
33  class SimpleBuffer;
34  namespace sound {
35  class InputStream;
36  class StreamingSound;
37  }
38  namespace media {
39  class MediaHandler;
40  }
41 }
42 
43 namespace gnash {
44 namespace sound {
45 
48 {
49 public:
50 
52  //
54  typedef std::list<InputStream*> Instances;
55 
57  //
60  StreamingSoundData(media::SoundInfo info, int nVolume);
61 
63 
65  //
70  size_t append(SimpleBuffer data, size_t sampleCount,
71  int seekSamples);
72 
74  bool empty() const {
75  return _buffers.empty();
76  }
77 
78  const SimpleBuffer& getBlock(size_t index) const {
79  return _buffers[index];
80  }
81 
82  size_t getSampleCount(size_t index) const {
83  return _blockData[index].sampleCount;
84  }
85 
86  size_t getSeekSamples(size_t index) const {
87  return _blockData[index].seekSamples;
88  }
89 
90  size_t blockCount() const {
91  return _buffers.size();
92  }
93 
94  size_t playingBlock() const;
95 
97  //
100  bool isPlaying() const;
101 
103  //
106  size_t numPlayingInstances() const;
107 
109  void getPlayingInstances(std::vector<InputStream*>& to) const;
110 
112  //
115  InputStream* firstPlayingInstance() const;
116 
118  //
127  std::unique_ptr<StreamingSound> createInstance(media::MediaHandler& mh,
128  unsigned long blockOffset);
129 
131  //
134  void clearInstances();
135 
137  //
142  Instances::iterator eraseActiveSound(Instances::iterator i);
143 
145  //
153  void eraseActiveSound(InputStream* inst);
154 
157 
160  int volume;
161 
162 private:
163 
164  struct BlockData
165  {
166  BlockData(size_t count, int seek)
167  :
168  sampleCount(count),
169  seekSamples(seek)
170  {}
171 
172  size_t sampleCount;
173  size_t seekSamples;
174  };
175 
177  //
180  Instances _soundInstances;
181 
183  mutable std::mutex _soundInstancesMutex;
184 
185  std::vector<SimpleBuffer> _buffers;
186 
187  std::vector<BlockData> _blockData;
188 };
189 
190 } // gnash.sound namespace
191 } // namespace gnash
192 
193 #endif // SOUND_EMBEDSOUND_H
A sound input stream.
Definition: InputStream.h:47
Class containing information about an embedded sound definition.
Definition: SoundInfo.h:34
size_t blockCount() const
Definition: StreamingSoundData.h:90
bool empty() const
Do we have any data?
Definition: StreamingSoundData.h:74
int volume
Definition: StreamingSoundData.h:160
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
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:54
Definition of an embedded sound.
Definition: StreamingSoundData.h:47
The MediaHandler class acts as a factory to provide parser and decoders.
Definition: MediaHandler.h:69
size_t getSampleCount(size_t index) const
Definition: StreamingSoundData.h:82
size_t getSeekSamples(size_t index) const
Definition: StreamingSoundData.h:86
media::SoundInfo soundinfo
Object holding information about the sound.
Definition: StreamingSoundData.h:156
Definition: GnashKey.h:155
A simple buffer of bytes.
Definition: SimpleBuffer.h:38
const SimpleBuffer & getBlock(size_t index) const
Definition: StreamingSoundData.h:78