[Scummvm-cvs-logs] SF.net SVN: scummvm: [23757] scummvm/trunk/graphics

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sat Aug 26 14:29:14 CEST 2006


Revision: 23757
Author:   eriktorbjorn
Date:     2006-08-26 05:29:00 -0700 (Sat, 26 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/scummvm/?rev=23757&view=rev

Log Message:
-----------
Now that the cutscene handling in both BS1 and BS2 has been extended to play
DXA movies (the MPEG movies still work, of course), there is no longer any need
for the MPEG decoder to handle sound and frame syncing. That is now the
responsibility of the player, not the decoder.

The obvious next step, then, would be to put that in a new player class, and
have both BS1 and BS2 use that. Maybe FF as well.

Modified Paths:
--------------
    scummvm/trunk/engines/sword1/animation.cpp
    scummvm/trunk/engines/sword1/animation.h
    scummvm/trunk/engines/sword2/animation.cpp
    scummvm/trunk/engines/sword2/animation.h
    scummvm/trunk/graphics/animation.cpp
    scummvm/trunk/graphics/animation.h
Modified: scummvm/trunk/engines/sword1/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword1/animation.cpp	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/engines/sword1/animation.cpp	2006-08-26 12:29:00 UTC (rev 23757)
@@ -186,6 +186,7 @@
 	_scr->clearScreen();
 	_framesSkipped = 0;
 	_ticks = _sys->getMillis();
+	_bgSoundStream = Audio::AudioStream::openStreamFile(sequenceList[_id]);
 	if (_bgSoundStream) {
 		_snd->playInputStream(Audio::Mixer::kSFXSoundType, &_bgSoundHandle, _bgSoundStream);
 	}
@@ -318,9 +319,6 @@
 		_frameHeight = getHeight();
 		_frameX = (640 - _frameWidth) / 2;
 		_frameY = (480 - _frameHeight) / 2;
-		if (!_bgSoundStream) {
-			_bgSoundStream = Audio::AudioStream::openStreamFile(sequenceList[id]);
-		}
 		return true;
 	}
 	return false;
@@ -395,8 +393,8 @@
 
 bool MoviePlayerMPEG::load(uint32 id) {
 	if (MoviePlayer::load(id)) {
-		_anim = new AnimationState(this, _scr, _snd, _sys);
-		return _anim->init(sequenceList[id], _bgSoundStream);
+		_anim = new AnimationState(this, _scr, _sys);
+		return _anim->init(sequenceList[id]);
 	}
 	return false;
 }
@@ -450,13 +448,10 @@
 #endif
 }
 
-void MoviePlayerMPEG::syncFrame(void) {
+AnimationState::AnimationState(MoviePlayer *player, Screen *scr, OSystem *sys)
+	: BaseAnimationState(sys, 640, 400), _player(player), _scr(scr) {
 }
 
-AnimationState::AnimationState(MoviePlayer *player, Screen *scr, Audio::Mixer *snd, OSystem *sys)
-	: BaseAnimationState(snd, sys, 640, 400), _player(player), _scr(scr) {
-}
-
 AnimationState::~AnimationState(void) {
 }
 

Modified: scummvm/trunk/engines/sword1/animation.h
===================================================================
--- scummvm/trunk/engines/sword1/animation.h	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/engines/sword1/animation.h	2006-08-26 12:29:00 UTC (rev 23757)
@@ -120,7 +120,7 @@
 	Screen *_scr;
 
 public:
-	AnimationState(MoviePlayer *player, Screen *scr, Audio::Mixer *snd, OSystem *sys);
+	AnimationState(MoviePlayer *player, Screen *scr, OSystem *sys);
 	~AnimationState(void);
 	OverlayColor *giveRgbBuffer(void);
 
@@ -149,7 +149,6 @@
 	bool initOverlays(uint32 id);
 	bool decodeFrame(void);
 	void processFrame(void);
-	void syncFrame(void);
 	void updateScreen(void);
 	void handleScreenChanged(void);
 };

Modified: scummvm/trunk/engines/sword2/animation.cpp
===================================================================
--- scummvm/trunk/engines/sword2/animation.cpp	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/engines/sword2/animation.cpp	2006-08-26 12:29:00 UTC (rev 23757)
@@ -75,6 +75,7 @@
 	_vm = vm;
 	_mixer = _vm->_mixer;
 	_system = _vm->_system;
+	_name = NULL;
 	_textSurface = NULL;
 	_bgSoundStream = NULL;
 	_ticks = 0;
@@ -96,6 +97,7 @@
 }
 
 MoviePlayer::~MoviePlayer() {
+	free(_name);
 }
 
 void MoviePlayer::updatePalette(byte *pal, bool packed) {
@@ -278,6 +280,8 @@
 	_currentText = 0;
 	_currentFrame = 0;
 
+	_name = strdup(name);
+
 	for (int i = 0; i < ARRAYSIZE(_movies); i++) {
 		if (scumm_stricmp(name, _movies[i].name) == 0) {
 			_seamless = _movies[i].seamless;
@@ -335,8 +339,8 @@
 #endif
 
 	_framesSkipped = 0;
-
 	_ticks = _system->getMillis();
+	_bgSoundStream = Audio::AudioStream::openStreamFile(_name);
 
 	if (_bgSoundStream) {
 		_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &_bgSoundHandle, _bgSoundStream);
@@ -504,8 +508,6 @@
 		_frameX = (_vm->_screen->getScreenWide() - _frameWidth) / 2;
 		_frameY = (_vm->_screen->getScreenDeep() - _frameHeight) / 2;
 
-		_bgSoundStream = Audio::AudioStream::openStreamFile(name);
-
 		return true;
 	}
 
@@ -566,11 +568,8 @@
 	return result;
 }
 
-void MoviePlayerMPEG::syncFrame() {
-}
-
 AnimationState::AnimationState(Sword2Engine *vm, MoviePlayer *player)
-	: BaseAnimationState(vm->_mixer, vm->_system, 640, 480) {
+	: BaseAnimationState(vm->_system, 640, 480) {
 	_vm = vm;
 	_player = player;
 }

Modified: scummvm/trunk/engines/sword2/animation.h
===================================================================
--- scummvm/trunk/engines/sword2/animation.h	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/engines/sword2/animation.h	2006-08-26 12:29:00 UTC (rev 23757)
@@ -57,6 +57,8 @@
 	Audio::Mixer *_mixer;
 	OSystem *_system;
 
+	char *_name;
+
 	byte _originalPalette[4 * 256];
 
 	byte *_textSurface;
@@ -156,7 +158,6 @@
 	AnimationState *_anim;
 
 	virtual bool decodeFrame();
-	virtual void syncFrame();
 
 #ifndef BACKEND_8BIT
 	void handleScreenChanged();

Modified: scummvm/trunk/graphics/animation.cpp
===================================================================
--- scummvm/trunk/graphics/animation.cpp	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/graphics/animation.cpp	2006-08-26 12:29:00 UTC (rev 23757)
@@ -22,7 +22,6 @@
 
 #include "common/stdafx.h"
 #include "graphics/animation.h"
-#include "sound/audiostream.h"
 #include "common/config-manager.h"
 #include "common/file.h"
 #include "common/system.h"
@@ -31,8 +30,8 @@
 
 namespace Graphics {
 
-BaseAnimationState::BaseAnimationState(Audio::Mixer *snd, OSystem *sys, int width, int height)
-	: _movieWidth(width), _movieHeight(height), _frameWidth(width), _frameHeight(height), _snd(snd), _sys(sys) {
+BaseAnimationState::BaseAnimationState(OSystem *sys, int width, int height)
+	: _movieWidth(width), _movieHeight(height), _frameWidth(width), _frameHeight(height), _sys(sys) {
 #ifndef BACKEND_8BIT
 	const int screenW = _sys->getOverlayWidth();
 	const int screenH = _sys->getOverlayHeight();
@@ -51,7 +50,6 @@
 
 BaseAnimationState::~BaseAnimationState() {
 #ifdef USE_MPEG2
-	_snd->stopHandle(_bgSound);
 	if (_mpegDecoder)
 		mpeg2_close(_mpegDecoder);
 	delete _mpegFile;
@@ -61,18 +59,16 @@
 	free(_colorTab);
 	free(_rgbToPix);
 #endif
-	delete _bgSoundStream;
 #endif
 }
 
 
-bool BaseAnimationState::init(const char *name, void *audioArg) {
+bool BaseAnimationState::init(const char *name) {
 #ifdef USE_MPEG2
 	char tempFile[512];
 
 	_mpegDecoder = NULL;
 	_mpegFile = NULL;
-	_bgSoundStream = NULL;
 
 #ifdef BACKEND_8BIT
 
@@ -146,28 +142,13 @@
 
 	_mpegInfo = mpeg2_info(_mpegDecoder);
 	_frameNum = 0;
-	_frameSkipped = 0;
-	_ticks = _sys->getMillis();
 
-	// Play audio
-	_bgSoundStream = createAudioStream(name, audioArg);
-
-	if (_bgSoundStream != NULL) {
-		_snd->playInputStream(Audio::Mixer::kSFXSoundType, &_bgSound, _bgSoundStream, -1, 255, 0, false);
-	} else {
-		warning("Cutscene: Could not open Audio Track for %s", name);
-	}
-
 	return true;
 #else /* USE_MPEG2 */
 	return false;
 #endif
 }
 
-Audio::AudioStream *BaseAnimationState::createAudioStream(const char *name, void *arg) {
-	return Audio::AudioStream::openStreamFile(name);
-}
-
 bool BaseAnimationState::decodeFrame() {
 #ifdef USE_MPEG2
 	mpeg2_state_t state;
@@ -188,39 +169,8 @@
 		case STATE_SLICE:
 		case STATE_END:
 			if (_mpegInfo->display_fbuf) {
-				/* simple audio video sync code:
-				 * we calculate the actual frame by taking the elapsed audio time and try
-				 * to stay inside +- 1 frame of this calculated frame number by dropping
-				 * frames if we run behind and delaying if we are too fast
-				 */
-
-				if (checkPaletteSwitch() || (_bgSoundStream == NULL) ||
-					((_snd->getSoundElapsedTime(_bgSound) * 12) / 1000 < _frameNum + 1) ||
-					_frameSkipped > 10) {
-					if (_frameSkipped > 10) {
-						warning("force frame %i redraw", _frameNum);
-						_frameSkipped = 0;
-					}
-					drawYUV(sequence_i->width, sequence_i->height, _mpegInfo->display_fbuf->buf);
-
-					if (_bgSoundStream && _snd->isSoundHandleActive(_bgSound)) {
-						while (_snd->isSoundHandleActive(_bgSound) && (_snd->getSoundElapsedTime(_bgSound) * 12) / 1000 < _frameNum) {
-							_sys->delayMillis(10);
-						}
-						// In case the background sound ends prematurely, update
-						// _ticks so that we can still fall back on the no-sound
-						// sync case for the subsequent frames.
-						_ticks = _sys->getMillis();
-					} else {
-						_ticks += 83;
-						while (_sys->getMillis() < _ticks)
-							_sys->delayMillis(10);
-					}
-				} else {
-					warning("dropped frame %i", _frameNum);
-					_frameSkipped++;
-				}
-
+				checkPaletteSwitch();
+				drawYUV(sequence_i->width, sequence_i->height, _mpegInfo->display_fbuf->buf);
 #ifdef BACKEND_8BIT
 				buildLookup(_palNum + 1, _lutCalcNum);
 #endif

Modified: scummvm/trunk/graphics/animation.h
===================================================================
--- scummvm/trunk/graphics/animation.h	2006-08-26 12:15:43 UTC (rev 23756)
+++ scummvm/trunk/graphics/animation.h	2006-08-26 12:29:00 UTC (rev 23757)
@@ -25,12 +25,6 @@
 
 #include "common/scummsys.h"
 
-#include "sound/mixer.h"
-
-namespace Audio {
-	class AudioStream;
-}
-
 // Uncomment this if you are using libmpeg2 0.3.1.
 // #define USE_MPEG2_0_3_1
 
@@ -72,6 +66,8 @@
 	class File;
 }
 
+class OSystem;
+
 namespace Graphics {
 
 class BaseAnimationState {
@@ -86,12 +82,9 @@
 	int _movieScale;
 #endif
 
-	Audio::Mixer *_snd;
 	OSystem *_sys;
 
 	uint _frameNum;
-	uint _frameSkipped;
-	uint32 _ticks;
 
 #ifdef USE_MPEG2
 	mpeg2dec_t *_mpegDecoder;
@@ -100,9 +93,6 @@
 
 	Common::File *_mpegFile;
 
-	Audio::SoundHandle _bgSound;
-	Audio::AudioStream *_bgSoundStream;
-
 #ifdef BACKEND_8BIT
 	int _palNum;
 	int _maxPalNum;
@@ -129,10 +119,10 @@
 #endif
 
 public:
-	BaseAnimationState(Audio::Mixer *snd, OSystem *sys, int width, int height);
+	BaseAnimationState(OSystem *sys, int width, int height);
 	virtual ~BaseAnimationState();
 
-	bool init(const char *name, void *audioArg = NULL);
+	bool init(const char *name);
 	bool decodeFrame();
 	void handleScreenChanged();
 	void updateScreen();
@@ -147,7 +137,6 @@
 protected:
 	bool checkPaletteSwitch();
 	virtual void drawYUV(int width, int height, byte *const *dat) = 0;
-	virtual Audio::AudioStream *createAudioStream(const char *name, void *arg);
 
 #ifdef BACKEND_8BIT
 	void buildLookup(int p, int lines);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Scummvm-git-logs mailing list