diff options
author | Max Horn | 2004-06-28 22:35:22 +0000 |
---|---|---|
committer | Max Horn | 2004-06-28 22:35:22 +0000 |
commit | e0eab01e639acfa7eee9fcd755f6fceb88f38710 (patch) | |
tree | 049ebd5a41f6bdb1d73f2e8bb0049be8be93ee09 /sound | |
parent | a5df4fba77214a93442a0a9e9607cd0a523f24a8 (diff) | |
download | scummvm-rg350-e0eab01e639acfa7eee9fcd755f6fceb88f38710.tar.gz scummvm-rg350-e0eab01e639acfa7eee9fcd755f6fceb88f38710.tar.bz2 scummvm-rg350-e0eab01e639acfa7eee9fcd755f6fceb88f38710.zip |
Make use of new File refcount code; also fixed long standing bug in vorbis code (ov_clear was not being called, resulting in a file not being closed)
svn-id: r14107
Diffstat (limited to 'sound')
-rw-r--r-- | sound/audiostream.cpp | 8 | ||||
-rw-r--r-- | sound/audiostream.h | 2 | ||||
-rw-r--r-- | sound/flac.cpp | 12 | ||||
-rw-r--r-- | sound/mp3.cpp | 5 | ||||
-rw-r--r-- | sound/vorbis.cpp | 12 |
5 files changed, 30 insertions, 9 deletions
diff --git a/sound/audiostream.cpp b/sound/audiostream.cpp index 73ff1204cd..5d7a3ae4e1 100644 --- a/sound/audiostream.cpp +++ b/sound/audiostream.cpp @@ -67,7 +67,7 @@ static const StreamFileFormat STREAM_FILEFORMATS[] = { { NULL, NULL, NULL } // Terminator }; -AudioStream* AudioStream::openStreamFile(const char* filename, File *fileHandle) +AudioStream* AudioStream::openStreamFile(const char* filename) { char buffer[1024]; const uint len = strlen(filename); @@ -78,6 +78,7 @@ AudioStream* AudioStream::openStreamFile(const char* filename, File *fileHandle) char *ext = &buffer[len+1]; AudioStream* stream = NULL; + File *fileHandle = new File(); for (int i = 0; i < ARRAYSIZE(STREAM_FILEFORMATS)-1 && stream == NULL; ++i) { strcpy(ext, STREAM_FILEFORMATS[i].fileExtension); @@ -85,9 +86,12 @@ AudioStream* AudioStream::openStreamFile(const char* filename, File *fileHandle) if (fileHandle->isOpen()) stream = STREAM_FILEFORMATS[i].openStreamFile(fileHandle, fileHandle->size()); } + + // Do not reference the file anymore. If the stream didn't incRef the file, + // the object will be deleted (and the file be closed). + fileHandle->decRef(); if (stream == NULL) { - fileHandle->close(); debug(1, "AudioStream: Could not open compressed AudioFile %s", filename); } diff --git a/sound/audiostream.h b/sound/audiostream.h index 2dbc1ae81c..6cc719d457 100644 --- a/sound/audiostream.h +++ b/sound/audiostream.h @@ -86,7 +86,7 @@ public: * @return an Audiostream ready to use in case of success; * NULL in case of an error (e.g. invalid/nonexisting file) */ - static AudioStream* openStreamFile(const char* filename, File *fileHandle); + static AudioStream* openStreamFile(const char* filename); }; class AppendableAudioStream : public AudioStream { diff --git a/sound/flac.cpp b/sound/flac.cpp index 18e332ead9..15e04f34f6 100644 --- a/sound/flac.cpp +++ b/sound/flac.cpp @@ -166,6 +166,8 @@ FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart) _fileInfo.fileStartPos = fileStart; _fileInfo.filePos = fileStart; _fileInfo.fileEndPos = sourceFile->size(); + + _fileInfo.fileHandle->incRef(); } FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart, const uint32 fileStop) @@ -186,6 +188,8 @@ FlacInputStream::FlacInputStream(File *sourceFile, const uint32 fileStart, const _fileInfo.fileStartPos = fileStart; _fileInfo.filePos = fileStart; _fileInfo.fileEndPos = fileStop; + + _fileInfo.fileHandle->incRef(); } FlacInputStream::~FlacInputStream() { @@ -195,6 +199,8 @@ FlacInputStream::~FlacInputStream() { } if (_preBuffer.bufData != NULL) delete[] _preBuffer.bufData; + + _fileInfo.fileHandle->decRef(); } inline FLAC__SeekableStreamDecoderState FlacInputStream::getState() const { @@ -789,10 +795,8 @@ void FlacTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int star FlacTrackInfo::~FlacTrackInfo() { - if (_firstStream) - delete _firstStream; - if (_file) - delete _file; + delete _firstStream; + delete _file; } DigitalTrackInfo* getFlacTrack(int track) diff --git a/sound/mp3.cpp b/sound/mp3.cpp index 27938b7aa0..a71290952c 100644 --- a/sound/mp3.cpp +++ b/sound/mp3.cpp @@ -97,6 +97,8 @@ MP3InputStream::MP3InputStream(File *file, mad_timer_t duration, uint size) { // If a size is specified, we do not perform any further read operations if (size) { _file = 0; + } else { + _file->incRef(); } } @@ -106,6 +108,9 @@ MP3InputStream::~MP3InputStream() { mad_stream_finish(&_stream); free(_ptr); + + if (_file) + _file->decRef(); } bool MP3InputStream::init() { diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp index 4773823520..3d48d12b1b 100644 --- a/sound/vorbis.cpp +++ b/sound/vorbis.cpp @@ -102,7 +102,7 @@ static int seek_wrap(void *datasource, ogg_int64_t offset, int whence) { static int close_wrap(void *datasource) { file_info *f = (file_info *) datasource; - f->file->close(); + f->file->decRef(); delete f; return 0; } @@ -193,6 +193,8 @@ class VorbisInputStream : public AudioStream { inline bool eosIntern() const; public: VorbisInputStream(OggVorbis_File *file, int duration); + ~VorbisInputStream(); + int readBuffer(int16 *buffer, const int numSamples); int16 read(); @@ -225,6 +227,10 @@ VorbisInputStream::VorbisInputStream(OggVorbis_File *file, int duration) refill(); } +VorbisInputStream::~VorbisInputStream() { + ov_clear(_ov_file); +} + inline int16 VorbisInputStream::read() { assert(!eosIntern()); @@ -309,8 +315,10 @@ AudioStream *makeVorbisStream(File *file, uint32 size) { delete ov_file; delete f; return 0; - } else + } else { + file->incRef(); return new VorbisInputStream(ov_file, 0); + } } #endif |