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

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Thu May 20 20:38:06 CEST 2010


Revision: 49120
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49120&view=rev
Author:   mthreepwood
Date:     2010-05-20 18:38:06 +0000 (Thu, 20 May 2010)

Log Message:
-----------
Add a pause level system to VideoDecoder (blatantly ripped off from Engine) and adapt Mohawk to it.

Modified Paths:
--------------
    scummvm/trunk/engines/mohawk/video/qt_player.cpp
    scummvm/trunk/engines/mohawk/video/qt_player.h
    scummvm/trunk/engines/mohawk/video/video.cpp
    scummvm/trunk/engines/mohawk/video/video.h
    scummvm/trunk/graphics/video/video_decoder.cpp
    scummvm/trunk/graphics/video/video_decoder.h

Modified: scummvm/trunk/engines/mohawk/video/qt_player.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video/qt_player.cpp	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/engines/mohawk/video/qt_player.cpp	2010-05-20 18:38:06 UTC (rev 49120)
@@ -187,25 +187,22 @@
 }
 
 void QTPlayer::startAudio() {
-	if (!_audStream) // No audio/audio not supported
-		return;
-
-	g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream);
+	if (_audStream) // No audio/audio not supported
+		g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audHandle, _audStream);
 }
 
-void QTPlayer::pauseAudio() {
-	g_system->getMixer()->pauseHandle(_audHandle, true);
+void QTPlayer::stopAudio() {
+	if (_audStream) {
+		g_system->getMixer()->stopHandle(_audHandle);
+		_audStream = NULL; // the mixer automatically frees the stream
+	}
 }
 
-void QTPlayer::resumeAudio() {
-	g_system->getMixer()->pauseHandle(_audHandle, false);
+void QTPlayer::pauseVideoIntern(bool pause) {
+	if (_audStream)
+		g_system->getMixer()->pauseHandle(_audHandle, pause);		
 }
 
-void QTPlayer::stopAudio() {
-	g_system->getMixer()->stopHandle(_audHandle);
-	_audStream = NULL; // the mixer automatically frees the stream
-}
-
 Graphics::Surface *QTPlayer::decodeNextFrame() {
 	if (!_videoCodec || _curFrame >= (int32)getFrameCount() - 1)
 		return NULL;
@@ -244,12 +241,6 @@
 	return (!_audStream || _audStream->endOfData()) && (!_videoCodec || _curFrame >= (int32)getFrameCount() - 1);
 }
 
-void QTPlayer::addPauseTime(uint32 p) {
-	Graphics::VideoDecoder::addPauseTime(p);
-	if (_videoStreamIndex >= 0)
-		_nextFrameStartTime += p * _streams[_videoStreamIndex]->time_scale / 1000;
-}
-
 bool QTPlayer::needsUpdate() const {
 	return !endOfVideo() && getTimeToNextFrame() == 0;
 }

Modified: scummvm/trunk/engines/mohawk/video/qt_player.h
===================================================================
--- scummvm/trunk/engines/mohawk/video/qt_player.h	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/engines/mohawk/video/qt_player.h	2010-05-20 18:38:06 UTC (rev 49120)
@@ -104,7 +104,6 @@
 	void setChunkBeginOffset(uint32 offset) { _beginOffset = offset; }
 
 	bool isVideoLoaded() const { return _fd != 0; }
-	void addPauseTime(uint32 p);
 	Graphics::Surface *decodeNextFrame();
 	bool needsUpdate() const;
 	bool endOfVideo() const;
@@ -112,14 +111,15 @@
 	uint32 getTimeToNextFrame() const;
 	Graphics::PixelFormat getPixelFormat() const;
 
+	// RewindableVideoDecoder API
 	void rewind();
 
 	// TODO: These audio functions need to be removed from the public and/or added to
 	// the VideoDecoder API directly.
 	void updateAudioBuffer(); // This is going to be problematic.
-	void pauseAudio();
-	void resumeAudio();
 
+
+
 protected:
 	// This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream.
 	Common::SeekableReadStream *_fd;
@@ -255,6 +255,8 @@
 	Graphics::Surface *scaleSurface(Graphics::Surface *frame);
 	ScaleMode getScaleMode() const;
 
+	void pauseVideoIntern(bool pause);
+
 	int readDefault(MOVatom atom);
 	int readLeaf(MOVatom atom);
 	int readELST(MOVatom atom);

Modified: scummvm/trunk/engines/mohawk/video/video.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video/video.cpp	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/engines/mohawk/video/video.cpp	2010-05-20 18:38:06 UTC (rev 49120)
@@ -32,7 +32,6 @@
 namespace Mohawk {
 
 VideoManager::VideoManager(MohawkEngine* vm) : _vm(vm) {
-	_pauseStart = 0;
 }
 
 VideoManager::~VideoManager() {
@@ -42,17 +41,12 @@
 
 void VideoManager::pauseVideos() {
 	for (uint16 i = 0; i < _videoStreams.size(); i++)
-		_videoStreams[i]->pauseAudio();
-	_pauseStart = _vm->_system->getMillis() * 100;
+		_videoStreams[i]->pauseVideo(true);
 }
 
 void VideoManager::resumeVideos() {
-	for (uint16 i = 0; i < _videoStreams.size(); i++) {
-		_videoStreams[i]->addPauseTime(_vm->_system->getMillis() * 100 - _pauseStart);
-		_videoStreams[i]->resumeAudio();
-	}
-
-	_pauseStart = 0;
+	for (uint16 i = 0; i < _videoStreams.size(); i++)
+		_videoStreams[i]->pauseVideo(false);
 }
 
 void VideoManager::stopVideos() {

Modified: scummvm/trunk/engines/mohawk/video/video.h
===================================================================
--- scummvm/trunk/engines/mohawk/video/video.h	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/engines/mohawk/video/video.h	2010-05-20 18:38:06 UTC (rev 49120)
@@ -97,7 +97,6 @@
 
 	// Keep tabs on any videos playing
 	Common::Array<VideoEntry> _videoStreams;
-	uint32 _pauseStart;
 
 	VideoHandle createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop);
 	VideoHandle createVideoHandle(Common::String filename, uint16 x, uint16 y, bool loop);

Modified: scummvm/trunk/graphics/video/video_decoder.cpp
===================================================================
--- scummvm/trunk/graphics/video/video_decoder.cpp	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/graphics/video/video_decoder.cpp	2010-05-20 18:38:06 UTC (rev 49120)
@@ -71,12 +71,30 @@
 void VideoDecoder::reset() {
 	_curFrame = -1;
 	_startTime = 0;
+	_pauseLevel = 0;
 }
 
 bool VideoDecoder::endOfVideo() const {
 	return !isVideoLoaded() || (getCurFrame() >= (int32)getFrameCount() - 1);
 }
 
+void VideoDecoder::pauseVideo(bool pause) {
+	if (pause) {
+		_pauseLevel++;
+	} else {
+		assert(_pauseLevel); // We can't go negative
+		_pauseLevel--;
+	}
+
+	if (_pauseLevel == 1 && pause) {
+		_pauseStartTime = g_system->getMillis(); // Store the starting time from pausing to keep it for later
+		pauseVideoIntern(true);
+	} else if (_pauseLevel == 0) {
+		pauseVideoIntern(false);
+		addPauseTime(g_system->getMillis() - _pauseStartTime);
+	}
+}
+
 uint32 FixedRateVideoDecoder::getTimeToNextFrame() const {
 	if (endOfVideo() || _curFrame < 0)
 		return 0;

Modified: scummvm/trunk/graphics/video/video_decoder.h
===================================================================
--- scummvm/trunk/graphics/video/video_decoder.h	2010-05-20 17:22:45 UTC (rev 49119)
+++ scummvm/trunk/graphics/video/video_decoder.h	2010-05-20 18:38:06 UTC (rev 49120)
@@ -128,11 +128,6 @@
 	virtual bool hasDirtyPalette() const { return false; }
 
 	/**
-	 * Add the time the video has been paused to maintain sync
-	 */
-	virtual void addPauseTime(uint32 ms) { _startTime += ms; }
-
-	/**
 	 * Returns if the video is finished or not
 	 */
 	virtual bool endOfVideo() const;
@@ -147,14 +142,47 @@
 	 */
 	virtual uint32 getTimeToNextFrame() const = 0;
 
+	/**
+	 * Pause or resume the video. This should stop/resume any audio playback
+	 * and other stuff. The initial pause time is kept so that any timing
+	 * variables can be updated appropriately.
+	 *
+	 * This is a convenience tracker which automatically keeps track on how
+	 * often the video has been paused, ensuring that after pausing an video
+	 * e.g. twice, it has to be unpaused twice before actuallying resuming.
+	 *
+	 * @param pause		true to pause the video, false to resume it
+	 */
+	void pauseVideo(bool pause);
+
+	/**
+	 * Return whether the video is currently paused or not.
+	 */
+	bool isPaused() const { return _pauseLevel != 0; }
+
 protected:
 	/**
 	 * Resets _curFrame and _startTime. Should be called from every close() function.
 	 */
 	void reset();
 
+	/**
+	 * Actual implementation of pause by subclasses. See pause()
+	 * for details.
+	 */
+	virtual void pauseVideoIntern(bool pause) {}
+
+	/**
+	 * Add the time the video has been paused to maintain sync
+	 */
+	virtual void addPauseTime(uint32 ms) { _startTime += ms; }
+
 	int32 _curFrame;
 	uint32 _startTime;
+
+private:
+	uint32 _pauseLevel;
+	uint32 _pauseStartTime;
 };
 
 /**


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