Gnash  0.8.11dev
EmbedSoundInst.h
Go to the documentation of this file.
1 // EmbedSoundInst.h - instance of an embedded sound, 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_EMBEDSOUNDINST_H
21 #define SOUND_EMBEDSOUNDINST_H
22 
23 #include <memory>
24 #include <cassert>
25 #include <boost/cstdint.hpp> // For C99 int types
26 
27 #include "LiveSound.h"
28 #include "AudioDecoder.h"
29 #include "SoundEnvelope.h"
30 #include "EmbedSound.h"
31 #include "sound_handler.h"
32 
33 // Forward declarations
34 namespace gnash {
35  namespace sound {
36  class EmbedSound;
37  }
38  namespace media {
39  class MediaHandler;
40  }
41 }
42 
43 namespace gnash {
44 namespace sound {
45 
47 class EmbedSoundInst : public LiveSound
48 {
49 public:
50 
52  //
68  unsigned int inPoint, unsigned int outPoint,
69  const SoundEnvelopes* envelopes, int loopCount);
70 
71  // See dox in sound_handler.h (InputStream)
72  virtual bool eof() const;
73 
75  //
77  virtual ~EmbedSoundInst();
78 
79 private:
80 
81  virtual size_t checkEarlierEnd(size_t bytesAhead, size_t pos) const {
82  if (_outPoint < std::numeric_limits<unsigned long>::max()) {
83  const size_t toCustomEnd = _outPoint - pos;
84  return std::min(toCustomEnd, bytesAhead);
85  }
86  return bytesAhead;
87  }
88 
89  virtual bool moreData();
90 
92  //
109  void applyEnvelopes(boost::int16_t* samples, unsigned int nSamples,
110  unsigned int firstSampleNum, const SoundEnvelopes& env);
111 
112  bool reachedCustomEnd() const;
113 
115  virtual bool decodingCompleted() const {
116  return (decodingPosition >= _soundDef.size());
117  }
118 
120  //
122  virtual void decodeNextBlock();
123 
125  unsigned long decodingPosition;
126 
129  long loopCount;
130 
133  const unsigned long _outPoint;
134 
137  const SoundEnvelopes* envelopes;
138 
140  boost::uint32_t current_env;
141 
143  //
147  EmbedSound& _soundDef;
148 
149 };
150 
151 
152 } // gnash.sound namespace
153 } // namespace gnash
154 
155 #endif // SOUND_EMBEDSOUNDINST_H