[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.13,1.14 mixer.h,1.8,1.9
Lionel Ulmer
bbrox at users.sourceforge.net
Fri Apr 26 13:54:07 CEST 2002
- Previous message: [Scummvm-cvs-logs] CVS: scummvm resource.cpp,1.73,1.74 scumm.h,1.143,1.144
- Next message: [Scummvm-cvs-logs] CVS: web/images/save scummvm.xpm,NONE,1.1 scummvm_16.ico,NONE,1.1 scummvm_32.ico,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/scummvm/scummvm/sound
In directory usw-pr-cvs1:/tmp/cvs-serv13015/sound
Modified Files:
mixer.cpp mixer.h
Log Message:
Fixed race conditions in the sound code (where a sound could be
'freed' while it was mixed at the same time in the sound thread).
Now Monkey1 seems to play well with Valgrind without any memory
warning.
Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** mixer.cpp 26 Apr 2002 17:22:58 -0000 1.13
--- mixer.cpp 26 Apr 2002 20:53:48 -0000 1.14
***************
*** 51,55 ****
warning("SoundMixer::insert out of mixer slots");
! chan->destroy();
return -1;
--- 51,55 ----
warning("SoundMixer::insert out of mixer slots");
! chan->real_destroy();
return -1;
***************
*** 141,144 ****
--- 141,145 ----
_fp_pos = 0;
_fp_speed = (1 << 16) * rate / mixer->_output_rate;
+ _to_be_destroyed = false;
/* adjust the magnitute to prevent division error */
***************
*** 153,156 ****
--- 154,162 ----
uint32 fp_pos;
+ if (_to_be_destroyed) {
+ real_destroy();
+ return;
+ }
+
if (len > _size)
len = _size;
***************
*** 206,214 ****
if (_size < 1)
! destroy();
}
! void SoundMixer::Channel_RAW::destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
--- 212,220 ----
if (_size < 1)
! real_destroy();
}
! void SoundMixer::Channel_RAW::real_destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
***************
*** 227,230 ****
--- 233,237 ----
_size = size;
_ptr = sound;
+ _to_be_destroyed = false;
mad_stream_init(&_stream);
***************
*** 267,270 ****
--- 274,283 ----
void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
mad_fixed_t const *ch;
+
+ if (_to_be_destroyed) {
+ real_destroy();
+ return;
+ }
+
while (1) {
ch = _synth.pcm.samples[0] + _pos_in_frame;
***************
*** 282,286 ****
if (_position >= _size) {
! destroy();
return;
}
--- 295,299 ----
if (_position >= _size) {
! real_destroy();
return;
}
***************
*** 291,295 ****
/* End of audio... */
if (_stream.error == MAD_ERROR_BUFLEN) {
! destroy();
return;
} else if (!MAD_RECOVERABLE(_stream.error)) {
--- 304,308 ----
/* End of audio... */
if (_stream.error == MAD_ERROR_BUFLEN) {
! real_destroy();
return;
} else if (!MAD_RECOVERABLE(_stream.error)) {
***************
*** 303,307 ****
}
! void SoundMixer::Channel_MP3::destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
--- 316,320 ----
}
! void SoundMixer::Channel_MP3::real_destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
***************
*** 324,327 ****
--- 337,342 ----
_ptr = buffer;
_flags = 0;
+ _to_be_destroyed = false;
+
mad_stream_init(&_stream);
#ifdef _WIN32_WCE
***************
*** 331,334 ****
--- 346,351 ----
mad_frame_init(&_frame);
mad_synth_init(&_synth);
+
+ debug(1, "CRE %d", getpid());
}
***************
*** 337,340 ****
--- 354,364 ----
mad_timer_t frame_duration;
+ if (_to_be_destroyed) {
+ real_destroy();
+ return;
+ }
+
+ debug(1, "MIX %d", getpid());
+
if (!_initialized) {
int skip_loop;
***************
*** 343,347 ****
_size = fread(_ptr, 1, _buffer_size, _file);
if (!_size) {
! destroy();
return;
}
--- 367,371 ----
_size = fread(_ptr, 1, _buffer_size, _file);
if (!_size) {
! real_destroy();
return;
}
***************
*** 359,363 ****
if (!MAD_RECOVERABLE(_stream.error)) {
debug(1, "Unrecoverable error while skipping !");
! destroy();
return;
}
--- 383,387 ----
if (!MAD_RECOVERABLE(_stream.error)) {
debug(1, "Unrecoverable error while skipping !");
! real_destroy();
return;
}
***************
*** 371,378 ****
_pos_in_frame = 0;
_initialized = true;
! }
! else {
debug(1, "Cannot resume decoding");
! destroy();
return;
}
--- 395,401 ----
_pos_in_frame = 0;
_initialized = true;
! } else {
debug(1, "Cannot resume decoding");
! real_destroy();
return;
}
***************
*** 397,401 ****
mad_timer_add(&_duration, frame_duration);
if (mad_timer_compare(_duration, mad_timer_zero) < 0) {
! destroy();
return;
}
--- 420,424 ----
mad_timer_add(&_duration, frame_duration);
if (mad_timer_compare(_duration, mad_timer_zero) < 0) {
! real_destroy();
return;
}
***************
*** 428,432 ****
}
! void SoundMixer::Channel_MP3_CDMUSIC::destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
--- 451,455 ----
}
! void SoundMixer::Channel_MP3_CDMUSIC::real_destroy() {
if (_flags & FLAG_AUTOFREE)
free(_ptr);
***************
*** 435,438 ****
--- 458,463 ----
mad_frame_finish(&_frame);
mad_stream_finish(&_stream);
+
+ debug(1, "DES %d", getpid());
delete this;
Index: mixer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** mixer.h 22 Apr 2002 11:36:41 -0000 1.8
--- mixer.h 26 Apr 2002 20:53:48 -0000 1.9
***************
*** 33,38 ****
class Channel {
public:
virtual void mix(int16 *data, uint len) = 0;
! virtual void destroy() = 0;
};
--- 33,40 ----
class Channel {
public:
+ bool _to_be_destroyed;
virtual void mix(int16 *data, uint len) = 0;
! void destroy() { _to_be_destroyed = true; }
! virtual void real_destroy() = 0;
};
***************
*** 49,55 ****
public:
void mix(int16 *data, uint len);
- void destroy();
-
Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
};
--- 51,56 ----
public:
void mix(int16 *data, uint len);
Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
+ void real_destroy();
};
***************
*** 70,76 ****
public:
void mix(int16 *data, uint len);
- void destroy();
-
Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags);
};
--- 71,77 ----
public:
void mix(int16 *data, uint len);
Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags);
+ void real_destroy();
+
};
***************
*** 90,96 ****
public:
void mix(int16 *data, uint len);
- void destroy();
-
Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration);
};
--- 91,98 ----
public:
void mix(int16 *data, uint len);
Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, void *buffer, uint32 buffer_size, mad_timer_t duration);
+ void real_destroy();
+
+
};
- Previous message: [Scummvm-cvs-logs] CVS: scummvm resource.cpp,1.73,1.74 scumm.h,1.143,1.144
- Next message: [Scummvm-cvs-logs] CVS: web/images/save scummvm.xpm,NONE,1.1 scummvm_16.ico,NONE,1.1 scummvm_32.ico,NONE,1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Scummvm-git-logs
mailing list