[Scummvm-cvs-logs] CVS: scummvm/sound audiostream.cpp,1.60,1.61 audiostream.h,1.34,1.35 flac.cpp,1.2,1.3 mp3.cpp,1.9,1.10 vorbis.cpp,1.14,1.15

Max Horn fingolfin at users.sourceforge.net
Mon Jun 28 15:36:03 CEST 2004


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25614/sound

Modified Files:
	audiostream.cpp audiostream.h flac.cpp mp3.cpp vorbis.cpp 
Log Message:
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)

Index: audiostream.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- audiostream.cpp	9 Jun 2004 06:30:49 -0000	1.60
+++ audiostream.cpp	28 Jun 2004 22:35:20 -0000	1.61
@@ -67,7 +67,7 @@
 	{ 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 @@
 	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 @@
 		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);
 	}
 

Index: audiostream.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/audiostream.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- audiostream.h	25 Apr 2004 18:43:46 -0000	1.34
+++ audiostream.h	28 Jun 2004 22:35:21 -0000	1.35
@@ -86,7 +86,7 @@
 	 * @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 {

Index: flac.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/flac.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- flac.cpp	9 Apr 2004 07:24:08 -0000	1.2
+++ flac.cpp	28 Jun 2004 22:35:21 -0000	1.3
@@ -166,6 +166,8 @@
 	_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 @@
 	_fileInfo.fileStartPos = fileStart;
 	_fileInfo.filePos = fileStart;
 	_fileInfo.fileEndPos = fileStop;
+	
+	_fileInfo.fileHandle->incRef();
 }
 
 FlacInputStream::~FlacInputStream() {
@@ -195,6 +199,8 @@
 	}
 	if (_preBuffer.bufData != NULL)
 		delete[] _preBuffer.bufData;
+	
+	_fileInfo.fileHandle->decRef();
 }
 
 inline FLAC__SeekableStreamDecoderState FlacInputStream::getState() const {
@@ -789,10 +795,8 @@
 
 FlacTrackInfo::~FlacTrackInfo()
 {
-	if (_firstStream)
-		delete _firstStream;
-	if (_file)
-		delete _file;
+	delete _firstStream;
+	delete _file;
 }
 
 DigitalTrackInfo* getFlacTrack(int track)

Index: mp3.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mp3.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mp3.cpp	22 Feb 2004 14:11:10 -0000	1.9
+++ mp3.cpp	28 Jun 2004 22:35:22 -0000	1.10
@@ -97,6 +97,8 @@
 	// If a size is specified, we do not perform any further read operations
 	if (size) {
 		_file = 0;
+	} else {
+		_file->incRef();
 	}
 }
 
@@ -106,6 +108,9 @@
 	mad_stream_finish(&_stream);
 
 	free(_ptr);
+
+	if (_file)
+		_file->decRef();
 }
 
 bool MP3InputStream::init() {

Index: vorbis.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/vorbis.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- vorbis.cpp	28 Mar 2004 15:00:58 -0000	1.14
+++ vorbis.cpp	28 Jun 2004 22:35:22 -0000	1.15
@@ -102,7 +102,7 @@
 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 @@
 	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 @@
 	refill();
 }
 
+VorbisInputStream::~VorbisInputStream() {
+	ov_clear(_ov_file);
+}
+
 inline int16 VorbisInputStream::read() {
 	assert(!eosIntern());
 
@@ -309,8 +315,10 @@
 		delete ov_file;
 		delete f;
 		return 0;
-	} else
+	} else {
+		file->incRef();
 		return new VorbisInputStream(ov_file, 0);
+	}
 }
 
 #endif





More information about the Scummvm-git-logs mailing list