[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.11,1.12

Lionel Ulmer bbrox at users.sourceforge.net
Fri Apr 26 10:12:05 CEST 2002


Update of /cvsroot/scummvm/scummvm/sound
In directory usw-pr-cvs1:/tmp/cvs-serv13567/sound

Modified Files:
	mixer.cpp 
Log Message:
Fixed one memory overwrite problem in MP3-CD support. First pass at
some code clean-up. More ahead (once I understand better the code :-) ).



Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** mixer.cpp	22 Apr 2002 11:36:41 -0000	1.11
--- mixer.cpp	26 Apr 2002 17:11:05 -0000	1.12
***************
*** 311,314 ****
--- 311,316 ----
  	mad_stream_finish(&_stream);
  
+ 	debug(1, "Sound finished");
+ 
  	delete this;
  }
***************
*** 340,344 ****
  		int skip_loop;
  		// just skipped
! 		memset(_ptr, 0,_buffer_size + MAD_BUFFER_GUARD);
  		_size = fread(_ptr, 1, _buffer_size, _file);
  		if (!_size) {
--- 342,346 ----
  		int skip_loop;
  		// just skipped
! 		memset(_ptr, 0,_buffer_size);
  		_size = fread(_ptr, 1, _buffer_size, _file);
  		if (!_size) {
***************
*** 351,366 ****
  		while (skip_loop != 0) {
  			if (mad_frame_decode(&_frame,&_stream) == 0) {
! 					/* Do not decrease duration - see if it's a problem */
! 					skip_loop--;
! 					if (skip_loop == 0) {
! 						mad_synth_frame(&_synth, &_frame);
! 					}
  			} else {
! 						if (!MAD_RECOVERABLE(_stream.error)) {
! 								debug(1, "Unrecoverable error while skipping !");
! 								destroy();
! 								return;
! 						}
! 					}
  		}
  		// We are supposed to be in synch
--- 353,368 ----
  		while (skip_loop != 0) {
  			if (mad_frame_decode(&_frame,&_stream) == 0) {
! 				/* Do not decrease duration - see if it's a problem */
! 				skip_loop--;
! 				if (skip_loop == 0) {
! 					mad_synth_frame(&_synth, &_frame);
! 				}
  			} else {
! 				if (!MAD_RECOVERABLE(_stream.error)) {
! 					debug(1, "Unrecoverable error while skipping !");
! 					destroy();
! 					return;
! 				}
! 			}
  		}
  		// We are supposed to be in synch
***************
*** 373,379 ****
  		} 
  		else {
! 				debug(1, "Cannot resume decoding");
! 				destroy();
! 				return;
  		}
  	}
--- 375,381 ----
  		} 
  		else {
! 			debug(1, "Cannot resume decoding");
! 			destroy();
! 			return;
  		}
  	}
***************
*** 397,434 ****
  		mad_timer_add(&_duration, frame_duration);
  		if (mad_timer_compare(_duration, mad_timer_zero) < 0) {					
! 					destroy();
! 					return;
  		}		
  		if (mad_frame_decode(&_frame, &_stream) == -1) {
! 					if (_stream.error == MAD_ERROR_BUFLEN) {
! 						int not_decoded;
  
! 						if (!_stream.next_frame) {
! 							memset(_ptr, 0, _buffer_size + MAD_BUFFER_GUARD);
! 							_size =
! 								fread(_ptr, 1, _buffer_size, _file);
! 							not_decoded = 0;
! 						} 
! 						else {
! 							not_decoded = _stream.bufend - _stream.next_frame;
! 							memcpy(_ptr, _stream.next_frame, not_decoded);
! 							_size =
! 								fread((unsigned char *)_ptr + not_decoded, 1,
! 										_buffer_size - not_decoded, _file);
! 						}
! 						_stream.error = MAD_ERROR_NONE;
! 						// Restream
! 						mad_stream_buffer(&_stream, (unsigned char *)_ptr, _size + not_decoded);
! 						if (mad_frame_decode(&_frame, &_stream) == -1) {
! 							debug(1, "Error decoding after restream %d !",
! 										_stream.error);
! 						}
! 					} else if (!MAD_RECOVERABLE(_stream.error)) {
! 						error("MAD frame decode error in MP3 CDMUSIC !");
! 					}
  		}
  		mad_synth_frame(&_synth, &_frame);
  		_pos_in_frame = 0;
- 		
  	}
  }
--- 399,430 ----
  		mad_timer_add(&_duration, frame_duration);
  		if (mad_timer_compare(_duration, mad_timer_zero) < 0) {					
! 			destroy();
! 			return;
  		}		
  		if (mad_frame_decode(&_frame, &_stream) == -1) {
! 			if (_stream.error == MAD_ERROR_BUFLEN) {
! 				int not_decoded;
  
! 				if (!_stream.next_frame) {
! 					memset(_ptr, 0, _buffer_size + MAD_BUFFER_GUARD);
! 					_size =	fread(_ptr, 1, _buffer_size, _file);
! 					not_decoded = 0;
! 				} else {
! 					not_decoded = _stream.bufend - _stream.next_frame;
! 					memcpy(_ptr, _stream.next_frame, not_decoded);
! 					_size =	fread((unsigned char *)_ptr + not_decoded, 1, _buffer_size - not_decoded, _file);
! 				}
! 				_stream.error = MAD_ERROR_NONE;
! 				// Restream
! 				mad_stream_buffer(&_stream, (unsigned char *)_ptr, _size + not_decoded);
! 				if (mad_frame_decode(&_frame, &_stream) == -1) {
! 					debug(1, "Error decoding after restream %d !", _stream.error);
! 				}
! 			} else if (!MAD_RECOVERABLE(_stream.error)) {
! 				error("MAD frame decode error in MP3 CDMUSIC !");
! 			}
  		}
  		mad_synth_frame(&_synth, &_frame);
  		_pos_in_frame = 0;
  	}
  }





More information about the Scummvm-git-logs mailing list