aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2004-06-29 23:27:18 +0000
committerMax Horn2004-06-29 23:27:18 +0000
commit4f80e2f36bcee0862f1360cae2b69ba7f0ad5732 (patch)
tree38e4e87c80db5e84f4f240ccf9c62384e0fd5e55 /sound
parentd40ea9f147eb0e73bdd571156a7207c2f0a557f8 (diff)
downloadscummvm-rg350-4f80e2f36bcee0862f1360cae2b69ba7f0ad5732.tar.gz
scummvm-rg350-4f80e2f36bcee0862f1360cae2b69ba7f0ad5732.tar.bz2
scummvm-rg350-4f80e2f36bcee0862f1360cae2b69ba7f0ad5732.zip
Fix for bug #981991 (VORBIS: Crash when using Ogg Vorbis CD tracks)
svn-id: r14128
Diffstat (limited to 'sound')
-rw-r--r--sound/vorbis.cpp57
1 files changed, 40 insertions, 17 deletions
diff --git a/sound/vorbis.cpp b/sound/vorbis.cpp
index 3d48d12b1b..26b04599ca 100644
--- a/sound/vorbis.cpp
+++ b/sound/vorbis.cpp
@@ -48,6 +48,7 @@ private:
public:
VorbisTrackInfo(File *file);
~VorbisTrackInfo();
+ bool openTrack();
bool error() { return _error_flag; }
void play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration);
};
@@ -119,21 +120,45 @@ static ov_callbacks g_File_wrap = {
VorbisTrackInfo::VorbisTrackInfo(File *file) {
+
+ _file = file;
+ if (openTrack()) {
+ warning("Invalid file format");
+ _error_flag = true;
+ _file = 0;
+ } else {
+ _error_flag = false;
+ _file->incRef();
+ ov_clear(&_ov_file);
+ }
+}
+
+bool VorbisTrackInfo::openTrack() {
+ assert(_file);
+
file_info *f = new file_info;
- f->file = file;
+ f->file = _file;
f->start = 0;
- f->len = file->size();
- f->curr_pos = file->pos();
-
- if (ov_open_callbacks((void *) f, &_ov_file, NULL, 0, g_File_wrap) < 0) {
- warning("Invalid file format");
- _error_flag = true;
+ f->len = _file->size();
+ f->curr_pos = 0;
+ _file->seek(0);
+
+ bool err = (ov_open_callbacks((void *) f, &_ov_file, NULL, 0, g_File_wrap) < 0);
+
+ if (err) {
delete f;
- delete file;
} else {
- _error_flag = false;
- _file = file;
+ _file->incRef();
+ }
+
+ return err;
+}
+
+VorbisTrackInfo::~VorbisTrackInfo() {
+ if (! _error_flag) {
+ ov_clear(&_ov_file);
+ _file->decRef();
}
}
@@ -142,6 +167,10 @@ VorbisTrackInfo::VorbisTrackInfo(File *file) {
#endif
void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int startFrame, int duration) {
+
+ bool err = openTrack();
+ assert(!err);
+
#ifdef VORBIS_TREMOR
ov_time_seek(&_ov_file, (ogg_int64_t)(startFrame / 75.0 * 1000));
#else
@@ -152,13 +181,6 @@ void VorbisTrackInfo::play(SoundMixer *mixer, PlayingSoundHandle *handle, int st
mixer->playInputStream(handle, input, true);
}
-VorbisTrackInfo::~VorbisTrackInfo() {
- if (! _error_flag) {
- ov_clear(&_ov_file);
- delete _file;
- }
-}
-
DigitalTrackInfo *getVorbisTrack(int track) {
char track_name[32];
File *file = new File();
@@ -168,6 +190,7 @@ DigitalTrackInfo *getVorbisTrack(int track) {
if (file->isOpen()) {
VorbisTrackInfo *trackInfo = new VorbisTrackInfo(file);
+ file->decRef();
if (!trackInfo->error())
return trackInfo;
delete trackInfo;