[Scummvm-cvs-logs] SF.net SVN: scummvm:[55204] scummvm/trunk/engines/mohawk

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Tue Jan 11 18:27:43 CET 2011


Revision: 55204
          http://scummvm.svn.sourceforge.net/scummvm/?rev=55204&view=rev
Author:   mthreepwood
Date:     2011-01-11 17:27:43 +0000 (Tue, 11 Jan 2011)

Log Message:
-----------
MOHAWK: Adapt the VideoManager to allow for seeking; cleanup

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

Modified: scummvm/trunk/engines/mohawk/video.cpp
===================================================================
--- scummvm/trunk/engines/mohawk/video.cpp	2011-01-11 17:27:37 UTC (rev 55203)
+++ scummvm/trunk/engines/mohawk/video.cpp	2011-01-11 17:27:43 UTC (rev 55204)
@@ -32,6 +32,22 @@
 
 namespace Mohawk {
 
+void VideoEntry::clear() {
+	video = 0;
+	x = 0;
+	y = 0;
+	loop = false;
+	enabled = false;
+	start = Graphics::VideoTimestamp(0);
+	end = Graphics::VideoTimestamp(0xFFFFFFFF); // Largest possible, there is an endOfVideo() check anyway
+	filename.clear();
+	id = 0;
+}
+
+bool VideoEntry::endOfVideo() {
+	return !video || video->endOfVideo() || video->getElapsedTime() >= end.getUnitsInScale(1000);
+}
+
 VideoManager::VideoManager(MohawkEngine* vm) : _vm(vm) {
 }
 
@@ -54,6 +70,7 @@
 void VideoManager::stopVideos() {
 	for (uint16 i = 0; i < _videoStreams.size(); i++)
 		delete _videoStreams[i].video;
+
 	_videoStreams.clear();
 }
 
@@ -91,7 +108,7 @@
 void VideoManager::waitUntilMovieEnds(VideoHandle videoHandle) {
 	bool continuePlaying = true;
 
-	while (_videoStreams[videoHandle].video && !_videoStreams[videoHandle]->endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
+	while (!_videoStreams[videoHandle].endOfVideo() && !_vm->shouldQuit() && continuePlaying) {
 		if (updateBackgroundMovies())
 			_vm->_system->updateScreen();
 
@@ -123,9 +140,7 @@
 	}
 
 	delete _videoStreams[videoHandle].video;
-	_videoStreams[videoHandle].video = 0;
-	_videoStreams[videoHandle].id = 0;
-	_videoStreams[videoHandle].filename.clear();
+	_videoStreams[videoHandle].clear();
 }
 
 VideoHandle VideoManager::playBackgroundMovie(const Common::String &filename, int16 x, int16 y, bool loop) {
@@ -169,14 +184,12 @@
 			continue;
 
 		// Remove any videos that are over
-		if (_videoStreams[i]->endOfVideo()) {
+		if (_videoStreams[i].endOfVideo()) {
 			if (_videoStreams[i].loop) {
-				_videoStreams[i]->rewind();
+				_videoStreams[i]->seekToTime(_videoStreams[i].start);
 			} else {
 				delete _videoStreams[i].video;
-				_videoStreams[i].video = 0;
-				_videoStreams[i].id = 0;
-				_videoStreams[i].filename.clear();
+				_videoStreams[i].clear();
 				continue;
 			}
 		}
@@ -281,13 +294,14 @@
 	_mlstRecords.clear();
 }
 
-void VideoManager::playMovie(uint16 id) {
+VideoHandle VideoManager::playMovie(uint16 id) {
 	for (uint16 i = 0; i < _mlstRecords.size(); i++)
 		if (_mlstRecords[i].code == id) {
 			debug(1, "Play tMOV %d (non-blocking) at (%d, %d) %s", _mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0 ? "looping" : "non-looping");
-			createVideoHandle(_mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0);
-			return;
+			return createVideoHandle(_mlstRecords[i].movieID, _mlstRecords[i].left, _mlstRecords[i].top, _mlstRecords[i].loop != 0);
 		}
+
+	return NULL_VID_HANDLE;
 }
 
 void VideoManager::playMovieBlocking(uint16 id) {
@@ -306,10 +320,8 @@
 		if (_mlstRecords[i].code == id)
 			for (uint16 j = 0; j < _videoStreams.size(); j++)
 				if (_mlstRecords[i].movieID == _videoStreams[j].id) {
-					delete _videoStreams[j].video;
-					_videoStreams[j].video = 0;
-					_videoStreams[j].id = 0;
-					_videoStreams[j].filename.clear();
+					delete _videoStreams[i].video;
+					_videoStreams[j].clear();
 					return;
 				}
 }
@@ -349,16 +361,18 @@
 			return i;
 
 	// Otherwise, create a new entry
+	Graphics::QuickTimeDecoder *decoder = new Graphics::QuickTimeDecoder();
+	decoder->setChunkBeginOffset(_vm->getResourceOffset(ID_TMOV, id));
+	decoder->load(_vm->getResource(ID_TMOV, id));
+
 	VideoEntry entry;
-	entry.video = new Graphics::QuickTimeDecoder();
+	entry.clear();
+	entry.video = decoder;
 	entry.x = x;
 	entry.y = y;
-	entry.filename = "";
 	entry.id = id;
 	entry.loop = loop;
 	entry.enabled = true;
-	entry->setChunkBeginOffset(_vm->getResourceOffset(ID_TMOV, id));
-	entry->load(_vm->getResource(ID_TMOV, id));
 
 	// Search for any deleted videos so we can take a formerly used slot
 	for (uint32 i = 0; i < _videoStreams.size(); i++)
@@ -380,11 +394,11 @@
 
 	// Otherwise, create a new entry
 	VideoEntry entry;
+	entry.clear();
 	entry.video = new Graphics::QuickTimeDecoder();
 	entry.x = x;
 	entry.y = y;
 	entry.filename = filename;
-	entry.id = 0;
 	entry.loop = loop;
 	entry.enabled = true;
 	
@@ -440,32 +454,54 @@
 	return NULL_VID_HANDLE;
 }
 
-int32 VideoManager::getCurFrame(const VideoHandle &handle) {
+int32 VideoManager::getCurFrame(VideoHandle handle) {
 	assert(handle != NULL_VID_HANDLE);
 	return _videoStreams[handle]->getCurFrame();
 }
 
-uint32 VideoManager::getFrameCount(const VideoHandle &handle) {
+uint32 VideoManager::getFrameCount(VideoHandle handle) {
 	assert(handle != NULL_VID_HANDLE);
 	return _videoStreams[handle]->getFrameCount();
 }
 
-uint32 VideoManager::getElapsedTime(const VideoHandle &handle) {
+uint32 VideoManager::getElapsedTime(VideoHandle handle) {
 	assert(handle != NULL_VID_HANDLE);
 	return _videoStreams[handle]->getElapsedTime();
 }
 
-bool VideoManager::endOfVideo(const VideoHandle &handle) {
+bool VideoManager::endOfVideo(VideoHandle handle) {
 	assert(handle != NULL_VID_HANDLE);
-	return _videoStreams[handle]->endOfVideo();
+	return _videoStreams[handle].endOfVideo();
 }
 
 bool VideoManager::isVideoPlaying() {
 	for (uint32 i = 0; i < _videoStreams.size(); i++)
-		if (_videoStreams[i].video && !_videoStreams[i]->endOfVideo())
+		if (!_videoStreams[i].endOfVideo())
 			return true;
 
 	return false;
 }
 
+void VideoManager::setVideoBounds(VideoHandle handle, Graphics::VideoTimestamp start, Graphics::VideoTimestamp end) {
+	assert(handle != NULL_VID_HANDLE);
+	_videoStreams[handle].start = start;
+	_videoStreams[handle].end = end;
+	_videoStreams[handle]->seekToTime(start);
+}
+
+void VideoManager::seekToTime(VideoHandle handle, Graphics::VideoTimestamp time) {
+	assert(handle != NULL_VID_HANDLE);
+	_videoStreams[handle]->seekToTime(time);
+}
+
+void VideoManager::seekToFrame(VideoHandle handle, uint32 frame) {
+	assert(handle != NULL_VID_HANDLE);
+	_videoStreams[handle]->seekToFrame(frame);
+}
+
+void VideoManager::setVideoLooping(VideoHandle handle, bool loop) {
+	assert(handle != NULL_VID_HANDLE);
+	_videoStreams[handle].loop = loop;
+}
+
 } // End of namespace Mohawk

Modified: scummvm/trunk/engines/mohawk/video.h
===================================================================
--- scummvm/trunk/engines/mohawk/video.h	2011-01-11 17:27:37 UTC (rev 55203)
+++ scummvm/trunk/engines/mohawk/video.h	2011-01-11 17:27:43 UTC (rev 55204)
@@ -28,11 +28,8 @@
 
 #include "common/array.h"
 #include "graphics/pixelformat.h"
+#include "graphics/video/video_decoder.h"
 
-namespace Graphics {
-	class QuickTimeDecoder;
-}
-
 namespace Mohawk {
 
 class MohawkEngine;
@@ -50,15 +47,22 @@
 };
 
 struct VideoEntry {
-	Graphics::QuickTimeDecoder *video;
+	// Playback variables
+	Graphics::SeekableVideoDecoder *video;
 	uint16 x;
 	uint16 y;
 	bool loop;
-	Common::String filename;
-	uint16 id; // Riven only
 	bool enabled;
+	Graphics::VideoTimestamp start, end;
 
-	Graphics::QuickTimeDecoder *operator->() const { assert(video); return video; }
+	// Identification
+	Common::String filename; // External video files
+	uint16 id;               // Internal Mohawk files
+
+	// Helper functions
+	Graphics::SeekableVideoDecoder *operator->() const { assert(video); return video; } // TODO: Remove this eventually
+	void clear();
+	bool endOfVideo();
 };
 
 typedef int32 VideoHandle;
@@ -89,7 +93,7 @@
 	void enableMovie(uint16 id);
 	void disableMovie(uint16 id);
 	void disableAllMovies();
-	void playMovie(uint16 id);
+	VideoHandle playMovie(uint16 id);
 	void stopMovie(uint16 id);
 	void playMovieBlocking(uint16 id);
 	VideoHandle findVideoHandleRiven(uint16 id);
@@ -97,10 +101,15 @@
 	// Handle functions
 	VideoHandle findVideoHandle(uint16 id);
 	VideoHandle findVideoHandle(const Common::String &filename);
-	int32 getCurFrame(const VideoHandle &handle);
-	uint32 getFrameCount(const VideoHandle &handle);
-	uint32 getElapsedTime(const VideoHandle &handle);
-	bool endOfVideo(const VideoHandle &handle);
+	int32 getCurFrame(VideoHandle handle);
+	uint32 getFrameCount(VideoHandle handle);
+	uint32 getElapsedTime(VideoHandle handle);
+	bool endOfVideo(VideoHandle handle);
+	void setVideoBounds(VideoHandle handle, Graphics::VideoTimestamp start, Graphics::VideoTimestamp end);
+	void seekToTime(VideoHandle handle, Graphics::VideoTimestamp time);
+	void seekToFrame(VideoHandle handle, uint32 frame);
+	void setVideoLooping(VideoHandle handle, bool loop);
+	void waitUntilMovieEnds(VideoHandle videoHandle);
 
 private:
 	MohawkEngine *_vm;
@@ -113,7 +122,6 @@
 
 	VideoHandle createVideoHandle(uint16 id, uint16 x, uint16 y, bool loop);
 	VideoHandle createVideoHandle(const Common::String &filename, uint16 x, uint16 y, bool loop);
-	void waitUntilMovieEnds(VideoHandle videoHandle);
 };
 
 } // End of namespace Mohawk


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