1 // StreamingSound.h - instance of an embedded sound, for gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 // Free Software Foundation, Inc
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.
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.
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
20 #ifndef SOUND_STREAMINGSOUND_H
21 #define SOUND_STREAMINGSOUND_H
25 #include <cstdint> // For C99 int types
27 #include "LiveSound.h"
28 #include "StreamingSoundData.h"
29 #include "sound_handler.h"
31 // Forward declarations
34 class StreamingSoundData
;
44 /// Instance of a defined %sound (StreamingSoundData)
46 /// This class contains a pointer to the StreamingSoundData used for playing
47 /// and a SimpleBuffer to use when decoding is needed.
48 class StreamingSound
: public LiveSound
52 /// Create an embedded %sound instance
54 /// @param def The sound data for this sound
55 /// @param mh The MediaHandler to use for on-demand decoding
56 /// @param blockId Identifier of the encoded block to start decoding from.
57 /// @see gnash::swf::StreamSoundBlockTag
58 StreamingSound(StreamingSoundData
& def
, media::MediaHandler
& mh
,
59 sound_handler::StreamBlockId blockId
);
61 // See dox in sound_handler.h (InputStream)
62 virtual bool eof() const;
64 /// Unregister self from the associated StreamingSoundData
66 /// WARNING: must be thread-safe!
69 size_t currentBlock() const {
75 /// Called when more data is required.
77 /// StreamingSounds can temporarily run out of data if not enough
78 /// samples are present for a frame.
79 virtual bool moreData();
81 /// Return true if there's nothing more to decode
82 virtual bool decodingCompleted() const {
83 return _positionInBlock
== 0 &&
84 _currentBlock
>= _soundDef
.blockCount();
87 /// Decode next input block
89 /// It's assumed !decodingCompleted()
90 void decodeNextBlock();
92 // The current block of sound.
95 // The position within the current block.
96 size_t _positionInBlock
;
100 /// It is non-const because we deregister ourselves
101 /// from its container of playing instances on destruction
103 StreamingSoundData
& _soundDef
;
107 } // gnash.sound namespace