diff options
Diffstat (limited to 'audio/decoders')
-rw-r--r-- | audio/decoders/adpcm.cpp | 8 | ||||
-rw-r--r-- | audio/decoders/adpcm_intern.h | 5 | ||||
-rw-r--r-- | audio/decoders/mp3.cpp | 10 | ||||
-rw-r--r-- | audio/decoders/raw.cpp | 22 | ||||
-rw-r--r-- | audio/decoders/vorbis.cpp | 9 |
5 files changed, 18 insertions, 36 deletions
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp index 116f2f776a..535652a0b3 100644 --- a/audio/decoders/adpcm.cpp +++ b/audio/decoders/adpcm.cpp @@ -41,8 +41,7 @@ namespace Audio { // <http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM>. ADPCMStream::ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign) - : _stream(stream), - _disposeAfterUse(disposeAfterUse), + : _stream(stream, disposeAfterUse), _startpos(stream->pos()), _endpos(_startpos + size), _channels(channels), @@ -52,11 +51,6 @@ ADPCMStream::ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Fl reset(); } -ADPCMStream::~ADPCMStream() { - if (_disposeAfterUse == DisposeAfterUse::YES) - delete _stream; -} - void ADPCMStream::reset() { memset(&_status, 0, sizeof(_status)); _blockPos[0] = _blockPos[1] = _blockAlign; // To make sure first header is read diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h index c9f894fb84..38514d7fca 100644 --- a/audio/decoders/adpcm_intern.h +++ b/audio/decoders/adpcm_intern.h @@ -33,6 +33,7 @@ #include "audio/audiostream.h" #include "common/endian.h" +#include "common/ptr.h" #include "common/stream.h" #include "common/textconsole.h" @@ -41,8 +42,7 @@ namespace Audio { class ADPCMStream : public RewindableAudioStream { protected: - Common::SeekableReadStream *_stream; - const DisposeAfterUse::Flag _disposeAfterUse; + Common::DisposablePtr<Common::SeekableReadStream> _stream; const int32 _startpos; const int32 _endpos; const int _channels; @@ -62,7 +62,6 @@ protected: public: ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign); - ~ADPCMStream(); virtual bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos); } virtual bool isStereo() const { return _channels == 2; } diff --git a/audio/decoders/mp3.cpp b/audio/decoders/mp3.cpp index 8d7f006ec7..00669945c2 100644 --- a/audio/decoders/mp3.cpp +++ b/audio/decoders/mp3.cpp @@ -25,6 +25,7 @@ #ifdef USE_MAD #include "common/debug.h" +#include "common/ptr.h" #include "common/stream.h" #include "common/textconsole.h" #include "common/util.h" @@ -52,8 +53,7 @@ protected: MP3_STATE_EOS // end of data reached (may need to loop) }; - Common::SeekableReadStream *_inStream; - DisposeAfterUse::Flag _disposeAfterUse; + Common::DisposablePtr<Common::SeekableReadStream> _inStream; uint _posInFrame; State _state; @@ -95,8 +95,7 @@ protected: }; MP3Stream::MP3Stream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) : - _inStream(inStream), - _disposeAfterUse(dispose), + _inStream(inStream, dispose), _posInFrame(0), _state(MP3_STATE_INIT), _length(0, 1000), @@ -134,9 +133,6 @@ MP3Stream::MP3Stream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag MP3Stream::~MP3Stream() { deinitStream(); - - if (_disposeAfterUse == DisposeAfterUse::YES) - delete _inStream; } void MP3Stream::decodeMP3Data() { diff --git a/audio/decoders/raw.cpp b/audio/decoders/raw.cpp index 4789fd0f36..881b8c1d6a 100644 --- a/audio/decoders/raw.cpp +++ b/audio/decoders/raw.cpp @@ -51,7 +51,7 @@ template<bool is16Bit, bool isUnsigned, bool isLE> class RawStream : public SeekableAudioStream { public: RawStream(int rate, bool stereo, DisposeAfterUse::Flag disposeStream, Common::SeekableReadStream *stream, const RawStreamBlockList &blocks) - : _rate(rate), _isStereo(stereo), _playtime(0, rate), _stream(stream), _disposeAfterUse(disposeStream), _blocks(blocks), _curBlock(_blocks.begin()), _blockLeft(0), _buffer(0) { + : _rate(rate), _isStereo(stereo), _playtime(0, rate), _stream(stream, disposeStream), _blocks(blocks), _curBlock(_blocks.begin()), _blockLeft(0), _buffer(0) { assert(_blocks.size() > 0); @@ -82,9 +82,6 @@ public: } ~RawStream() { - if (_disposeAfterUse == DisposeAfterUse::YES) - delete _stream; - delete[] _buffer; } @@ -98,15 +95,14 @@ public: bool seek(const Timestamp &where); private: - const int _rate; ///< Sample rate of stream - const bool _isStereo; ///< Whether this is an stereo stream - Timestamp _playtime; ///< Calculated total play time - Common::SeekableReadStream *_stream; ///< Stream to read data from - const DisposeAfterUse::Flag _disposeAfterUse; ///< Indicates whether the stream object should be deleted when this RawStream is destructed - const RawStreamBlockList _blocks; ///< Audio block list - - RawStreamBlockList::const_iterator _curBlock; ///< Current audio block number - int32 _blockLeft; ///< How many bytes are still left in the current block + const int _rate; ///< Sample rate of stream + const bool _isStereo; ///< Whether this is an stereo stream + Timestamp _playtime; ///< Calculated total play time + Common::DisposablePtr<Common::SeekableReadStream> _stream; ///< Stream to read data from + const RawStreamBlockList _blocks; ///< Audio block list + + RawStreamBlockList::const_iterator _curBlock; ///< Current audio block number + int32 _blockLeft; ///< How many bytes are still left in the current block /** * Advance one block in the stream in case diff --git a/audio/decoders/vorbis.cpp b/audio/decoders/vorbis.cpp index e10ec11a50..455803dc05 100644 --- a/audio/decoders/vorbis.cpp +++ b/audio/decoders/vorbis.cpp @@ -29,6 +29,7 @@ #ifdef USE_VORBIS +#include "common/ptr.h" #include "common/stream.h" #include "common/textconsole.h" #include "common/util.h" @@ -89,8 +90,7 @@ static ov_callbacks g_stream_wrap = { class VorbisStream : public SeekableAudioStream { protected: - Common::SeekableReadStream *_inStream; - DisposeAfterUse::Flag _disposeAfterUse; + Common::DisposablePtr<Common::SeekableReadStream> _inStream; bool _isStereo; int _rate; @@ -121,8 +121,7 @@ protected: }; VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse::Flag dispose) : - _inStream(inStream), - _disposeAfterUse(dispose), + _inStream(inStream, dispose), _length(0, 1000), _bufferEnd(_buffer + ARRAYSIZE(_buffer)) { @@ -150,8 +149,6 @@ VorbisStream::VorbisStream(Common::SeekableReadStream *inStream, DisposeAfterUse VorbisStream::~VorbisStream() { ov_clear(&_ovFile); - if (_disposeAfterUse == DisposeAfterUse::YES) - delete _inStream; } int VorbisStream::readBuffer(int16 *buffer, const int numSamples) { |