Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SOUND_LIVESOUND_H
00021 #define SOUND_LIVESOUND_H
00022
00023 #include <boost/scoped_ptr.hpp>
00024 #include <cassert>
00025 #include <boost/cstdint.hpp>
00026
00027 #include "InputStream.h"
00028 #include "AudioDecoder.h"
00029 #include "SimpleBuffer.h"
00030 #include "SoundInfo.h"
00031
00032
00033 namespace gnash {
00034 namespace media {
00035 class MediaHandler;
00036 }
00037 }
00038
00039 namespace gnash {
00040 namespace sound {
00041
00043
00046 class LiveSound : public InputStream
00047 {
00048 protected:
00049
00051
00057 LiveSound(media::MediaHandler& mh, const media::SoundInfo& info,
00058 size_t inPoint);
00059
00060
00061 const boost::int16_t* getDecodedData(unsigned long int pos) const {
00062 assert(pos < _decodedData.size());
00063 return reinterpret_cast<const boost::int16_t*>(
00064 _decodedData.data() + pos);
00065 }
00066
00068
00071 virtual bool moreData() = 0;
00072
00074
00076 virtual bool eof() const = 0;
00077
00079 void restart() {
00080 _playbackPosition = _inPoint;
00081 _samplesFetched = 0;
00082 }
00083
00085
00087 unsigned int samplesFetched() const {
00088 return _samplesFetched;
00089 }
00090
00091 size_t playbackPosition() const {
00092 return _playbackPosition;
00093 }
00094
00095 media::AudioDecoder& decoder() const {
00096 return *_decoder;
00097 }
00098
00099 void appendDecodedData(boost::uint8_t* data, unsigned int size) {
00100 _decodedData.append(data, size);
00101 delete [] data;
00102 }
00103
00106 unsigned int decodedSamplesAhead() const {
00107
00108 const unsigned int dds = _decodedData.size();
00109 if (dds <= _playbackPosition) return 0;
00110
00111 size_t bytesAhead = dds - _playbackPosition;
00112 bytesAhead = checkEarlierEnd(bytesAhead, _playbackPosition);
00113
00114 assert(!(bytesAhead % 2));
00115
00116 const unsigned int samplesAhead = bytesAhead / 2;
00117 return samplesAhead;
00118 }
00119
00120 private:
00121
00123
00126 virtual size_t checkEarlierEnd(size_t left, size_t) const {
00127 return left;
00128 }
00129
00130
00131 unsigned int fetchSamples(boost::int16_t* to, unsigned int nSamples);
00132
00133 void createDecoder(media::MediaHandler& mediaHandler,
00134 const media::SoundInfo& info);
00135
00136 virtual bool decodingCompleted() const = 0;
00137
00138 const size_t _inPoint;
00139
00141 size_t _playbackPosition;
00142
00144 unsigned long _samplesFetched;
00145
00146 boost::scoped_ptr<media::AudioDecoder> _decoder;
00147
00149 SimpleBuffer _decodedData;
00150
00151 };
00152
00153
00154 }
00155 }
00156
00157 #endif // SOUND_EMBEDSOUNDINST_H