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

mthreepwood at users.sourceforge.net mthreepwood at users.sourceforge.net
Mon May 24 01:26:28 CEST 2010


Revision: 49172
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49172&view=rev
Author:   mthreepwood
Date:     2010-05-23 23:26:28 +0000 (Sun, 23 May 2010)

Log Message:
-----------
Add support for loading the QuickTime 'moov' atom from the file's resource fork, needed for SCI Mac.

Modified Paths:
--------------
    scummvm/trunk/graphics/video/qt_decoder.cpp
    scummvm/trunk/graphics/video/qt_decoder.h

Modified: scummvm/trunk/graphics/video/qt_decoder.cpp
===================================================================
--- scummvm/trunk/graphics/video/qt_decoder.cpp	2010-05-23 21:41:13 UTC (rev 49171)
+++ scummvm/trunk/graphics/video/qt_decoder.cpp	2010-05-23 23:26:28 UTC (rev 49172)
@@ -35,6 +35,7 @@
 
 #include "common/debug.h"
 #include "common/endian.h"
+#include "common/macresman.h"
 #include "common/util.h"
 #include "common/zlib.h"
 
@@ -67,10 +68,14 @@
 	_fd = 0;
 	_scaledSurface = 0;
 	_dirtyPalette = false;
+	_resFork = new Common::MacResManager();
+
+	initParseTable();
 }
 
 QuickTimeDecoder::~QuickTimeDecoder() {
 	close();
+	delete _resFork;
 }
 
 uint16 QuickTimeDecoder::getWidth() const {
@@ -256,7 +261,7 @@
 	if (endOfVideo() || _curFrame < 0)
 		return 0;
 
-	// Convert from the Sega FILM base to 1000
+	// Convert from the QuickTime rate base to 1000
 	uint32 nextFrameStartTime = _nextFrameStartTime * 1000 / _streams[_videoStreamIndex]->time_scale;
 	uint32 elapsedTime = getElapsedTime();
 
@@ -266,6 +271,41 @@
 	return nextFrameStartTime - elapsedTime;
 }
 
+bool QuickTimeDecoder::loadFile(const Common::String &filename) {
+	if (!_resFork->open(filename) || !_resFork->hasDataFork())
+		return false;
+
+	_foundMOOV = _foundMDAT = false;
+	_numStreams = 0;
+	_partial = 0;
+	_videoStreamIndex = _audioStreamIndex = -1;
+	_startTime = 0;
+
+	MOVatom atom = { 0, 0, 0xffffffff };
+
+	if (_resFork->hasResFork()) {
+		_fd = _resFork->getResource(MKID_BE('moov'), 0x80);
+		if (_fd) {
+			atom.size = _fd->size();
+			if (readDefault(atom) < 0 || !_foundMOOV)
+				return false;
+		}
+		delete _fd;
+
+		atom.type = 0;
+		atom.offset = 0;
+		atom.size = 0xffffffff;
+	}
+
+	_fd = _resFork->getDataFork();
+
+	if (readDefault(atom) < 0 || !_foundMOOV || !_foundMDAT)
+		return false;
+
+	init();
+	return true;
+}
+
 bool QuickTimeDecoder::load(Common::SeekableReadStream &stream) {
 	_fd = &stream;
 	_foundMOOV = _foundMDAT = false;
@@ -274,21 +314,22 @@
 	_videoStreamIndex = _audioStreamIndex = -1;
 	_startTime = 0;
 
-	initParseTable();
-
 	MOVatom atom = { 0, 0, 0xffffffff };
 
-	if (readDefault(atom) < 0 || (!_foundMOOV && !_foundMDAT))
+	if (readDefault(atom) < 0 || !_foundMOOV || !_foundMDAT) {
+		_fd = 0;
 		return false;
+	}
 
-	debug(0, "on_parse_exit_offset=%d", _fd->pos());
+	init();
+	return true;
+}
 
+void QuickTimeDecoder::init() {
 	// some cleanup : make sure we are on the mdat atom
 	if((uint32)_fd->pos() != _mdatOffset)
 		_fd->seek(_mdatOffset, SEEK_SET);
 
-	_next_chunk_offset = _mdatOffset; // initialise reading
-
 	for (uint32 i = 0; i < _numStreams;) {
 		if (_streams[i]->codec_type == CODEC_TYPE_MOV_OTHER) {// not audio, not video, delete
 			delete _streams[i];
@@ -302,14 +343,12 @@
 	for (uint32 i = 0; i < _numStreams; i++) {
 		MOVStreamContext *sc = _streams[i];
 
-		if(!sc->time_rate)
+		if (!sc->time_rate)
 			sc->time_rate = 1;
 
-		if(!sc->time_scale)
+		if (!sc->time_scale)
 			sc->time_scale = _timeScale;
 
-		//av_set_pts_info(s->streams[i], 64, sc->time_rate, sc->time_scale);
-
 		sc->duration /= sc->time_rate;
 
 		sc->ffindex = i;
@@ -341,8 +380,6 @@
 			_scaledSurface->create(getWidth(), getHeight(), getPixelFormat().bytesPerPixel);
 		}
 	}
-
-	return true;
 }
 
 void QuickTimeDecoder::initParseTable() {
@@ -392,6 +429,11 @@
 		if (atom.size >= 8) {
 			a.size = _fd->readUint32BE();
 			a.type = _fd->readUint32BE();
+
+			// Some QuickTime videos with resource forks have mdat chunks
+			// that are of size 0. Adjust it so it's the correct size.
+			if (a.size == 0)
+				a.size = _fd->size();
 		}
 
 		total_size += 8;

Modified: scummvm/trunk/graphics/video/qt_decoder.h
===================================================================
--- scummvm/trunk/graphics/video/qt_decoder.h	2010-05-23 21:41:13 UTC (rev 49171)
+++ scummvm/trunk/graphics/video/qt_decoder.h	2010-05-23 23:26:28 UTC (rev 49172)
@@ -45,6 +45,7 @@
 
 namespace Common {
 	class File;
+	class MacResManager;
 }
 
 namespace Graphics {
@@ -79,6 +80,12 @@
 	uint32 getFrameCount() const;
 
 	/**
+	 * Load a video file
+	 * @param filename	the filename to load
+	 */
+	bool loadFile(const Common::String &filename);
+
+	/**
 	 * Load a QuickTime video file from a SeekableReadStream
 	 * @param stream	the stream to load
 	 */
@@ -221,7 +228,6 @@
 	uint32 _duration;
 	uint32 _mdatOffset;
 	uint32 _mdatSize;
-	uint32 _next_chunk_offset;
 	MOVStreamContext *_partial;
 	uint32 _numStreams;
 	int _ni;
@@ -230,6 +236,7 @@
 	byte _palette[256 * 3];
 	bool _dirtyPalette;
 	uint32 _beginOffset;
+	Common::MacResManager *_resFork;
 
 	void initParseTable();
 	Audio::AudioStream *createAudioStream(Common::SeekableReadStream *stream);
@@ -238,6 +245,7 @@
 	uint32 getFrameDuration();
 	uint32 getCodecTag();
 	byte getBitsPerPixel();
+	void init();
 
 	Audio::QueuingAudioStream *_audStream;
 	void startAudio();


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