aboutsummaryrefslogtreecommitdiff
path: root/graphics/video
diff options
context:
space:
mode:
authorMatthew Hoops2010-05-18 14:17:24 +0000
committerMatthew Hoops2010-05-18 14:17:24 +0000
commit11cbdd03180a655b2b23ee4a13f1a00a1d782b3c (patch)
tree5b0d84211308ea37a2fa2f7017d6f96314f3c6fb /graphics/video
parentf3892a506b2f935bae0be6319394c503c786d368 (diff)
downloadscummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.tar.gz
scummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.tar.bz2
scummvm-rg350-11cbdd03180a655b2b23ee4a13f1a00a1d782b3c.zip
Committing the rest of the VideoDecoder Rewrite from patch #2963496.
svn-id: r49079
Diffstat (limited to 'graphics/video')
-rw-r--r--graphics/video/avi_decoder.cpp110
-rw-r--r--graphics/video/avi_decoder.h33
-rw-r--r--graphics/video/codecs/codec.h3
-rw-r--r--graphics/video/codecs/msrle.h1
-rw-r--r--graphics/video/codecs/msvideo1.cpp2
-rw-r--r--graphics/video/codecs/msvideo1.h1
-rw-r--r--graphics/video/dxa_decoder.cpp182
-rw-r--r--graphics/video/dxa_decoder.h39
-rw-r--r--graphics/video/flic_decoder.cpp122
-rw-r--r--graphics/video/flic_decoder.h43
-rw-r--r--graphics/video/smk_decoder.cpp152
-rw-r--r--graphics/video/smk_decoder.h36
-rw-r--r--graphics/video/video_decoder.cpp101
-rw-r--r--graphics/video/video_decoder.h184
-rw-r--r--graphics/video/video_player.cpp245
-rw-r--r--graphics/video/video_player.h221
16 files changed, 630 insertions, 845 deletions
diff --git a/graphics/video/avi_decoder.cpp b/graphics/video/avi_decoder.cpp
index 1e0fb389b3..944c9700bd 100644
--- a/graphics/video/avi_decoder.cpp
+++ b/graphics/video/avi_decoder.cpp
@@ -23,7 +23,6 @@
*
*/
-#include "common/archive.h"
#include "common/endian.h"
#include "common/file.h"
#include "common/stream.h"
@@ -49,6 +48,7 @@ AviDecoder::AviDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) :
_audStream = NULL;
_fileStream = NULL;
_audHandle = new Audio::SoundHandle();
+ _dirtyPalette = false;
memset(_palette, 0, sizeof(_palette));
memset(&_wvInfo, 0, sizeof(PCMWAVEFORMAT));
memset(&_bmInfo, 0, sizeof(BITMAPINFOHEADER));
@@ -58,7 +58,7 @@ AviDecoder::AviDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) :
}
AviDecoder::~AviDecoder() {
- closeFile();
+ close();
delete _audHandle;
}
@@ -190,7 +190,7 @@ void AviDecoder::handleStreamHeader() {
/*_palette[i * 4 + 3] = */_fileStream->readByte();
}
- setPalette(_palette);
+ _dirtyPalette = true;
}
} else if (sHeader.streamType == ID_AUDS) {
_audsHeader = sHeader;
@@ -204,24 +204,16 @@ void AviDecoder::handleStreamHeader() {
}
}
-bool AviDecoder::loadFile(const char *fileName) {
- closeFile();
-
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
- return false;
+bool AviDecoder::load(Common::SeekableReadStream &stream) {
+ close();
+ _fileStream = &stream;
_decodedHeader = false;
- // Seek to the first frame
- _videoInfo.currentFrame = -1;
// Read chunks until we have decoded the header
while (!_decodedHeader)
runHandle(_fileStream->readUint32BE());
- _videoFrameBuffer = new byte[_header.width * _header.height];
- memset(_videoFrameBuffer, 0, _header.width * _header.height);
-
uint32 nextTag = _fileStream->readUint32BE();
// Throw out any JUNK section
@@ -247,34 +239,24 @@ bool AviDecoder::loadFile(const char *fileName) {
_mixer->playStream(_soundType, _audHandle, _audStream);
debug (0, "Frames = %d, Dimensions = %d x %d", _header.totalFrames, _header.width, _header.height);
- debug (0, "Frame Rate = %d", getFrameRate());
+ debug (0, "Frame Rate = %d", _vidsHeader.rate / _vidsHeader.scale);
if ((_audsHeader.scale != 0) && (_header.flags & AVIF_ISINTERLEAVED))
debug (0, "Sound Rate = %d", AUDIO_RATE);
debug (0, "Video Codec = \'%s\'", tag2str(_vidsHeader.streamHandler));
- _videoInfo.firstframeOffset = _fileStream->pos();
- _videoInfo.width = _header.width;
- _videoInfo.height = _header.height;
- _videoInfo.frameCount = _header.totalFrames;
- // Our frameDelay is calculated in 1/100 ms, so we convert it here
- _videoInfo.frameDelay = _header.microSecondsPerFrame / 10;
-
if (!_videoCodec)
return false;
return true;
}
-void AviDecoder::closeFile() {
+void AviDecoder::close() {
if (!_fileStream)
return;
delete _fileStream;
_fileStream = 0;
- delete[] _videoFrameBuffer;
- _videoFrameBuffer = 0;
-
// Deinitialize sound
_mixer->stopHandle(*_audHandle);
_audStream = 0;
@@ -293,14 +275,26 @@ void AviDecoder::closeFile() {
memset(&_vidsHeader, 0, sizeof(AVIStreamHeader));
memset(&_audsHeader, 0, sizeof(AVIStreamHeader));
memset(&_ixInfo, 0, sizeof(AVIOLDINDEX));
+
+ reset();
}
-Surface *AviDecoder::getNextFrame() {
+uint32 AviDecoder::getElapsedTime() const {
+ if (_audStream)
+ return _mixer->getSoundElapsedTime(*_audHandle);
+
+ return VideoDecoder::getElapsedTime();
+}
+
+Surface *AviDecoder::decodeNextFrame() {
uint32 nextTag = _fileStream->readUint32BE();
if (_fileStream->eos())
return NULL;
+ if (_curFrame == -1)
+ _startTime = g_system->getMillis();
+
if (nextTag == ID_LIST) {
// A list of audio/video chunks
uint32 listSize = _fileStream->readUint32LE() - 4;
@@ -312,7 +306,7 @@ Surface *AviDecoder::getNextFrame() {
// Decode chunks in the list and see if we get a frame
Surface *frame = NULL;
while (_fileStream->pos() < startPos + (int32)listSize) {
- Surface *temp = getNextFrame();
+ Surface *temp = decodeNextFrame();
if (temp)
frame = temp;
}
@@ -335,7 +329,7 @@ Surface *AviDecoder::getNextFrame() {
} else if (getStreamType(nextTag) == 'dc' || getStreamType(nextTag) == 'id' ||
getStreamType(nextTag) == 'AM' || getStreamType(nextTag) == '32') {
// Compressed Frame
- _videoInfo.currentFrame++;
+ _curFrame++;
uint32 chunkSize = _fileStream->readUint32LE();
if (chunkSize == 0) // Keep last frame on screen
@@ -364,7 +358,7 @@ Surface *AviDecoder::getNextFrame() {
_fileStream->readByte(); // Flags that don't serve us any purpose
}
- setPalette(_palette);
+ _dirtyPalette = true;
// No alignment necessary. It's always even.
} else if (nextTag == ID_JUNK) {
@@ -372,56 +366,11 @@ Surface *AviDecoder::getNextFrame() {
} else if (nextTag == ID_IDX1) {
runHandle(ID_IDX1);
} else
- error ("Tag = \'%s\', %d", tag2str(nextTag), _fileStream->pos());
+ error("Tag = \'%s\', %d", tag2str(nextTag), _fileStream->pos());
return NULL;
}
-bool AviDecoder::decodeNextFrame() {
- Surface *surface = NULL;
-
- int32 curFrame = _videoInfo.currentFrame;
-
- while (!surface && !endOfVideo() && !_fileStream->eos())
- surface = getNextFrame();
-
- if (curFrame == _videoInfo.currentFrame) {
- warning("No video frame found");
- _videoInfo.currentFrame++;
- }
-
- if (surface)
- memcpy(_videoFrameBuffer, surface->pixels, _header.width * _header.height);
-
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
-
- return !endOfVideo();
-}
-
-int32 AviDecoder::getAudioLag() {
- if (!_fileStream)
- return 0;
-
- int32 frameDelay = getFrameDelay();
- int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay;
- int32 audioTime;
-
- if (!_audStream) {
- /* No audio.
- Calculate the lag by how much time has gone by since the first frame
- and how much time *should* have passed.
- */
-
- audioTime = (g_system->getMillis() - _videoInfo.startTime) * 100;
- } else {
- const Audio::Timestamp ts = _mixer->getElapsedTime(*_audHandle);
- audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();
- }
-
- return videoTime - audioTime;
-}
-
Codec *AviDecoder::createCodec() {
switch (_vidsHeader.streamHandler) {
case ID_CRAM:
@@ -437,11 +386,14 @@ Codec *AviDecoder::createCodec() {
return NULL;
}
-Audio::QueuingAudioStream *AviDecoder::createAudioStream() {
+PixelFormat AviDecoder::getPixelFormat() const {
+ assert(_videoCodec);
+ return _videoCodec->getPixelFormat();
+}
- if (_wvInfo.tag == AVI_WAVE_FORMAT_PCM) {
+Audio::QueuingAudioStream *AviDecoder::createAudioStream() {
+ if (_wvInfo.tag == AVI_WAVE_FORMAT_PCM)
return Audio::makeQueuingAudioStream(AUDIO_RATE, false);
- }
if (_wvInfo.tag != 0) // No sound
warning ("Unsupported AVI audio format %d", _wvInfo.tag);
diff --git a/graphics/video/avi_decoder.h b/graphics/video/avi_decoder.h
index 0f0431c70b..5f09992647 100644
--- a/graphics/video/avi_decoder.h
+++ b/graphics/video/avi_decoder.h
@@ -26,7 +26,7 @@
#ifndef GRAPHICS_AVI_PLAYER_H
#define GRAPHICS_AVI_PLAYER_H
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "graphics/video/codecs/codec.h"
#include "sound/audiostream.h"
#include "sound/mixer.h"
@@ -172,26 +172,27 @@ struct AVIStreamHeader {
Common::Rect frame;
};
-class AviDecoder : public VideoDecoder {
+class AviDecoder : public FixedRateVideoDecoder {
public:
AviDecoder(Audio::Mixer *mixer,
Audio::Mixer::SoundType soundType = Audio::Mixer::kPlainSoundType);
virtual ~AviDecoder();
- /**
- * Load an AVI video file
- * @param filename the filename to load
- */
- bool loadFile(const char *fileName);
+ bool load(Common::SeekableReadStream &stream);
+ void close();
- /**
- * Close an AVI video file
- */
- void closeFile();
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _header.width; }
+ uint16 getHeight() const { return _header.height; }
+ uint32 getFrameCount() const { return _header.totalFrames; }
+ uint32 getElapsedTime() const;
+ Surface *decodeNextFrame();
+ PixelFormat getPixelFormat() const;
+ byte *getPalette() { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
- bool decodeNextFrame();
- int32 getAudioLag();
- int32 getFrameRate() { return _vidsHeader.rate / _vidsHeader.scale; }
+protected:
+ Common::Rational getFrameRate() const { return Common::Rational(_vidsHeader.rate, _vidsHeader.scale); }
private:
Audio::Mixer *_mixer;
@@ -202,7 +203,9 @@ private:
AVIStreamHeader _vidsHeader;
AVIStreamHeader _audsHeader;
byte _palette[3 * 256];
+ bool _dirtyPalette;
+ Common::SeekableReadStream *_fileStream;
bool _decodedHeader;
Codec *_videoCodec;
@@ -223,8 +226,6 @@ private:
static byte char2num(char c);
static byte getStreamNum(uint32 tag);
static uint16 getStreamType(uint32 tag);
-
- Surface *getNextFrame();
};
} // End of namespace Graphics
diff --git a/graphics/video/codecs/codec.h b/graphics/video/codecs/codec.h
index 124d1bc49d..4a280a81df 100644
--- a/graphics/video/codecs/codec.h
+++ b/graphics/video/codecs/codec.h
@@ -28,6 +28,7 @@
#include "common/stream.h"
#include "graphics/surface.h"
+#include "graphics/pixelformat.h"
namespace Graphics {
@@ -35,7 +36,9 @@ class Codec {
public:
Codec() {}
virtual ~Codec() {}
+
virtual Surface *decodeImage(Common::SeekableReadStream *stream) = 0;
+ virtual PixelFormat getPixelFormat() const = 0;
};
} // End of namespace Graphics
diff --git a/graphics/video/codecs/msrle.h b/graphics/video/codecs/msrle.h
index 634fe754ba..819e66a0bd 100644
--- a/graphics/video/codecs/msrle.h
+++ b/graphics/video/codecs/msrle.h
@@ -36,6 +36,7 @@ public:
~MSRLEDecoder();
Surface *decodeImage(Common::SeekableReadStream *stream);
+ PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); }
private:
byte _bitsPerPixel;
diff --git a/graphics/video/codecs/msvideo1.cpp b/graphics/video/codecs/msvideo1.cpp
index 16596926fd..f37bdbbf95 100644
--- a/graphics/video/codecs/msvideo1.cpp
+++ b/graphics/video/codecs/msvideo1.cpp
@@ -125,7 +125,7 @@ void MSVideo1Decoder::decode8(Common::SeekableReadStream *stream) {
}
}
-Graphics::Surface *MSVideo1Decoder::decodeImage(Common::SeekableReadStream *stream) {
+Surface *MSVideo1Decoder::decodeImage(Common::SeekableReadStream *stream) {
if (_bitsPerPixel == 8)
decode8(stream);
else {
diff --git a/graphics/video/codecs/msvideo1.h b/graphics/video/codecs/msvideo1.h
index ff6ffc6549..e07267476d 100644
--- a/graphics/video/codecs/msvideo1.h
+++ b/graphics/video/codecs/msvideo1.h
@@ -36,6 +36,7 @@ public:
~MSVideo1Decoder();
Surface *decodeImage(Common::SeekableReadStream *stream);
+ PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); }
private:
byte _bitsPerPixel;
diff --git a/graphics/video/dxa_decoder.cpp b/graphics/video/dxa_decoder.cpp
index 86f2415922..3f26012f5e 100644
--- a/graphics/video/dxa_decoder.cpp
+++ b/graphics/video/dxa_decoder.cpp
@@ -39,11 +39,12 @@ namespace Graphics {
DXADecoder::DXADecoder() {
_fileStream = 0;
+ _surface = 0;
+ _dirtyPalette = false;
_frameBuffer1 = 0;
_frameBuffer2 = 0;
_scaledBuffer = 0;
- _videoFrameBuffer = 0;
_inBuffer = 0;
_inBufferSize = 0;
@@ -51,67 +52,59 @@ DXADecoder::DXADecoder() {
_decompBuffer = 0;
_decompBufferSize = 0;
- _videoInfo.width = 0;
- _videoInfo.height = 0;
+ _width = 0;
+ _height = 0;
_frameSize = 0;
- _videoInfo.frameCount = 0;
- _videoInfo.currentFrame = -1;
- _videoInfo.frameRate = 0;
- _videoInfo.frameDelay = 0;
+ _frameCount = 0;
+ _frameRate = 0;
_scaleMode = S_NONE;
}
DXADecoder::~DXADecoder() {
- closeFile();
+ close();
}
-bool DXADecoder::loadFile(const char *fileName) {
- uint32 tag;
- int32 frameRate;
+bool DXADecoder::load(Common::SeekableReadStream &stream) {
+ close();
- closeFile();
+ _fileStream = &stream;
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
- return false;
-
- tag = _fileStream->readUint32BE();
+ uint32 tag = _fileStream->readUint32BE();
assert(tag == MKID_BE('DEXA'));
uint8 flags = _fileStream->readByte();
- _videoInfo.frameCount = _fileStream->readUint16BE();
- frameRate = _fileStream->readSint32BE();
-
- if (frameRate > 0) {
- _videoInfo.frameRate = 1000 / frameRate;
- _videoInfo.frameDelay = frameRate * 100;
- } else if (frameRate < 0) {
- _videoInfo.frameRate = 100000 / (-frameRate);
- _videoInfo.frameDelay = -frameRate;
- } else {
- _videoInfo.frameRate = 10;
- _videoInfo.frameDelay = 10000;
- }
+ _frameCount = _fileStream->readUint16BE();
+ int32 frameRate = _fileStream->readSint32BE();
+
+ if (frameRate > 0)
+ _frameRate = 1000 / frameRate;
+ else if (frameRate < 0)
+ _frameRate = 100000 / (-frameRate);
+ else
+ _frameRate = 10;
- _videoInfo.width = _fileStream->readUint16BE();
- _videoInfo.height = _fileStream->readUint16BE();
+ _width = _fileStream->readUint16BE();
+ _height = _fileStream->readUint16BE();
if (flags & 0x80) {
_scaleMode = S_INTERLACED;
- _curHeight = _videoInfo.height / 2;
+ _curHeight = _height / 2;
} else if (flags & 0x40) {
_scaleMode = S_DOUBLE;
- _curHeight = _videoInfo.height / 2;
+ _curHeight = _height / 2;
} else {
_scaleMode = S_NONE;
- _curHeight = _videoInfo.height;
+ _curHeight = _height;
}
- debug(2, "flags 0x0%x framesCount %d width %d height %d rate %d ticks %d", flags, getFrameCount(), getWidth(), getHeight(), getFrameRate(), getFrameDelay());
+ _surface = new Graphics::Surface();
+ _surface->bytesPerPixel = 1;
- _frameSize = _videoInfo.width * _videoInfo.height;
+ debug(2, "flags 0x0%x framesCount %d width %d height %d rate %d", flags, getFrameCount(), getWidth(), getHeight(), getFrameRate().toInt());
+
+ _frameSize = _width * _height;
_decompBufferSize = _frameSize;
_frameBuffer1 = (uint8 *)malloc(_frameSize);
memset(_frameBuffer1, 0, _frameSize);
@@ -135,9 +128,10 @@ bool DXADecoder::loadFile(const char *fileName) {
do {
tag = _fileStream->readUint32BE();
- if (tag != 0) {
+
+ if (tag != 0)
size = _fileStream->readUint32BE();
- }
+
switch (tag) {
case 0: // No more tags
break;
@@ -159,20 +153,19 @@ bool DXADecoder::loadFile(const char *fileName) {
// Read the sound header
_soundTag = _fileStream->readUint32BE();
- _videoInfo.currentFrame = -1;
-
- _videoInfo.firstframeOffset = _fileStream->pos();
-
return true;
}
-void DXADecoder::closeFile() {
+void DXADecoder::close() {
if (!_fileStream)
return;
delete _fileStream;
_fileStream = 0;
+ delete _surface;
+ _surface = 0;
+
free(_frameBuffer1);
free(_frameBuffer2);
free(_scaledBuffer);
@@ -181,6 +174,8 @@ void DXADecoder::closeFile() {
_inBuffer = 0;
_decompBuffer = 0;
+
+ reset();
}
void DXADecoder::decodeZlib(byte *data, int size, int totalSize) {
@@ -208,10 +203,10 @@ void DXADecoder::decode12(int size) {
memcpy(_frameBuffer2, _frameBuffer1, _frameSize);
- for (uint32 by = 0; by < _videoInfo.height; by += BLOCKH) {
- for (uint32 bx = 0; bx < _videoInfo.width; bx += BLOCKW) {
+ for (uint32 by = 0; by < _height; by += BLOCKH) {
+ for (uint32 bx = 0; bx < _width; bx += BLOCKW) {
byte type = *dat++;
- byte *b2 = _frameBuffer1 + bx + by * _videoInfo.width;
+ byte *b2 = _frameBuffer1 + bx + by * _width;
switch (type) {
case 0:
@@ -243,7 +238,7 @@ void DXADecoder::decode12(int size) {
}
diffMap <<= 1;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -254,7 +249,7 @@ void DXADecoder::decode12(int size) {
for (int xc = 0; xc < BLOCKW; xc++) {
b2[xc] = color;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -263,7 +258,7 @@ void DXADecoder::decode12(int size) {
for (int xc = 0; xc < BLOCKW; xc++) {
b2[xc] = *dat++;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -275,11 +270,11 @@ void DXADecoder::decode12(int size) {
int my = mbyte & 0x07;
if (mbyte & 0x08)
my = -my;
- byte *b1 = _frameBuffer2 + (bx+mx) + (by+my) * _videoInfo.width;
+ byte *b1 = _frameBuffer2 + (bx+mx) + (by+my) * _width;
for (int yc = 0; yc < BLOCKH; yc++) {
memcpy(b2, b1, BLOCKW);
- b1 += _videoInfo.width;
- b2 += _videoInfo.width;
+ b1 += _width;
+ b2 += _width;
}
break;
}
@@ -309,7 +304,7 @@ void DXADecoder::decode13(int size) {
memcpy(_frameBuffer2, _frameBuffer1, _frameSize);
- int codeSize = _videoInfo.width * _curHeight / 16;
+ int codeSize = _width * _curHeight / 16;
int dataSize, motSize, maskSize;
dataSize = READ_BE_UINT32(&_decompBuffer[0]);
@@ -322,9 +317,9 @@ void DXADecoder::decode13(int size) {
maskBuf = &motBuf[motSize];
for (uint32 by = 0; by < _curHeight; by += BLOCKH) {
- for (uint32 bx = 0; bx < _videoInfo.width; bx += BLOCKW) {
+ for (uint32 bx = 0; bx < _width; bx += BLOCKW) {
uint8 type = *codeBuf++;
- uint8 *b2 = (uint8*)_frameBuffer1 + bx + by * _videoInfo.width;
+ uint8 *b2 = (uint8*)_frameBuffer1 + bx + by * _width;
switch (type) {
case 0:
@@ -341,7 +336,7 @@ void DXADecoder::decode13(int size) {
}
diffMap <<= 1;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -352,7 +347,7 @@ void DXADecoder::decode13(int size) {
for (int xc = 0; xc < BLOCKW; xc++) {
b2[xc] = color;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -361,7 +356,7 @@ void DXADecoder::decode13(int size) {
for (int xc = 0; xc < BLOCKW; xc++) {
b2[xc] = *dataBuf++;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -375,11 +370,11 @@ void DXADecoder::decode13(int size) {
if (mbyte & 0x08)
my = -my;
- uint8 *b1 = (uint8*)_frameBuffer2 + (bx+mx) + (by+my) * _videoInfo.width;
+ uint8 *b1 = (uint8*)_frameBuffer2 + (bx+mx) + (by+my) * _width;
for (int yc = 0; yc < BLOCKH; yc++) {
memcpy(b2, b1, BLOCKW);
- b1 += _videoInfo.width;
- b2 += _videoInfo.width;
+ b1 += _width;
+ b2 += _width;
}
break;
}
@@ -391,7 +386,7 @@ void DXADecoder::decode13(int size) {
for (int subBlock = 0; subBlock < 4; subBlock++) {
int sx = bx + subX[subBlock], sy = by + subY[subBlock];
- b2 = (uint8*)_frameBuffer1 + sx + sy * _videoInfo.width;
+ b2 = (uint8*)_frameBuffer1 + sx + sy * _width;
switch (subMask & 0xC0) {
// 00: skip
case 0x00:
@@ -403,7 +398,7 @@ void DXADecoder::decode13(int size) {
for (int xc = 0; xc < BLOCKW / 2; xc++) {
b2[xc] = subColor;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -419,11 +414,11 @@ void DXADecoder::decode13(int size) {
if (mbyte & 0x08)
my = -my;
- uint8 *b1 = (uint8*)_frameBuffer2 + (sx+mx) + (sy+my) * _videoInfo.width;
+ uint8 *b1 = (uint8*)_frameBuffer2 + (sx+mx) + (sy+my) * _width;
for (int yc = 0; yc < BLOCKH / 2; yc++) {
memcpy(b2, b1, BLOCKW / 2);
- b1 += _videoInfo.width;
- b2 += _videoInfo.width;
+ b1 += _width;
+ b2 += _width;
}
break;
}
@@ -433,7 +428,7 @@ void DXADecoder::decode13(int size) {
for (int xc = 0; xc < BLOCKW / 2; xc++) {
b2[xc] = *dataBuf++;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
break;
}
@@ -458,7 +453,7 @@ void DXADecoder::decode13(int size) {
b2[xc] = pixels[code & 1];
code >>= 1;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
} else {
uint32 code = READ_BE_UINT32(maskBuf);
@@ -468,7 +463,7 @@ void DXADecoder::decode13(int size) {
b2[xc] = pixels[code & 3];
code >>= 2;
}
- b2 += _videoInfo.width;
+ b2 += _width;
}
}
break;
@@ -481,20 +476,11 @@ void DXADecoder::decode13(int size) {
#endif
}
-bool DXADecoder::decodeNextFrame() {
- uint32 tag;
-
- _videoInfo.currentFrame++;
-
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
-
- tag = _fileStream->readUint32BE();
+Surface *DXADecoder::decodeNextFrame() {
+ uint32 tag = _fileStream->readUint32BE();
if (tag == MKID_BE('CMAP')) {
- byte rgb[768];
-
- _fileStream->read(rgb, ARRAYSIZE(rgb));
- setPalette(rgb);
+ _fileStream->read(_palette, 256 * 3);
+ _dirtyPalette = true;
}
tag = _fileStream->readUint32BE();
@@ -531,8 +517,8 @@ bool DXADecoder::decodeNextFrame() {
if (type == 3) {
for (uint32 j = 0; j < _curHeight; ++j) {
- for (uint32 i = 0; i < _videoInfo.width; ++i) {
- const int offs = j * _videoInfo.width + i;
+ for (uint32 i = 0; i < _width; ++i) {
+ const int offs = j * _width + i;
_frameBuffer1[offs] ^= _frameBuffer2[offs];
}
}
@@ -542,24 +528,34 @@ bool DXADecoder::decodeNextFrame() {
switch (_scaleMode) {
case S_INTERLACED:
for (int cy = 0; cy < _curHeight; cy++) {
- memcpy(&_scaledBuffer[2 * cy * _videoInfo.width], &_frameBuffer1[cy * _videoInfo.width], _videoInfo.width);
- memset(&_scaledBuffer[((2 * cy) + 1) * _videoInfo.width], 0, _videoInfo.width);
+ memcpy(&_scaledBuffer[2 * cy * _width], &_frameBuffer1[cy * _width], _width);
+ memset(&_scaledBuffer[((2 * cy) + 1) * _width], 0, _width);
}
- _videoFrameBuffer = _scaledBuffer;
+ _surface->pixels = _scaledBuffer;
break;
case S_DOUBLE:
for (int cy = 0; cy < _curHeight; cy++) {
- memcpy(&_scaledBuffer[2 * cy * _videoInfo.width], &_frameBuffer1[cy * _videoInfo.width], _videoInfo.width);
- memcpy(&_scaledBuffer[((2 * cy) + 1) * _videoInfo.width], &_frameBuffer1[cy * _videoInfo.width], _videoInfo.width);
+ memcpy(&_scaledBuffer[2 * cy * _width], &_frameBuffer1[cy * _width], _width);
+ memcpy(&_scaledBuffer[((2 * cy) + 1) * _width], &_frameBuffer1[cy * _width], _width);
}
- _videoFrameBuffer = _scaledBuffer;
+ _surface->pixels = _scaledBuffer;
break;
case S_NONE:
- _videoFrameBuffer = _frameBuffer1;
+ _surface->pixels = _frameBuffer1;
break;
}
- return !endOfVideo();
+ // Copy in the relevant info to the Surface
+ _surface->w = getWidth();
+ _surface->h = getHeight();
+ _surface->pitch = getWidth();
+
+ _curFrame++;
+
+ if (_curFrame == 0)
+ _startTime = g_system->getMillis();
+
+ return _surface;
}
} // End of namespace Graphics
diff --git a/graphics/video/dxa_decoder.h b/graphics/video/dxa_decoder.h
index 3edcc75ca9..0312828195 100644
--- a/graphics/video/dxa_decoder.h
+++ b/graphics/video/dxa_decoder.h
@@ -26,7 +26,7 @@
#ifndef GRAPHICS_VIDEO_DXA_PLAYER_H
#define GRAPHICS_VIDEO_DXA_PLAYER_H
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
namespace Graphics {
@@ -38,29 +38,33 @@ namespace Graphics {
* - sword1
* - sword2
*/
-class DXADecoder : public VideoDecoder {
+class DXADecoder : public FixedRateVideoDecoder {
public:
DXADecoder();
virtual ~DXADecoder();
- /**
- * Load a DXA encoded video file
- * @param filename the filename to load
- */
- bool loadFile(const char *fileName);
-
- /**
- * Close a DXA encoded video file
- */
- void closeFile();
-
- bool decodeNextFrame();
+ bool load(Common::SeekableReadStream &stream);
+ void close();
+
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _width; }
+ uint16 getHeight() const { return _height; }
+ uint32 getFrameCount() const { return _frameCount; }
+ Surface *decodeNextFrame();
+ PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); }
+ byte *getPalette() { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
/**
* Get the sound chunk tag of the loaded DXA file
*/
uint32 getSoundTag() { return _soundTag; }
+protected:
+ Common::Rational getFrameRate() const { return _frameRate; }
+
+ Common::SeekableReadStream *_fileStream;
+
private:
void decodeZlib(byte *data, int size, int totalSize);
void decode12(int size);
@@ -72,6 +76,10 @@ private:
S_DOUBLE
};
+ Graphics::Surface *_surface;
+ byte _palette[256 * 3];
+ bool _dirtyPalette;
+
byte *_frameBuffer1;
byte *_frameBuffer2;
byte *_scaledBuffer;
@@ -83,6 +91,9 @@ private:
uint32 _frameSize;
ScaleMode _scaleMode;
uint32 _soundTag;
+ uint16 _width, _height;
+ uint32 _frameRate;
+ uint32 _frameCount;
};
} // End of namespace Graphics
diff --git a/graphics/video/flic_decoder.cpp b/graphics/video/flic_decoder.cpp
index 14d062562f..bb5b4f219b 100644
--- a/graphics/video/flic_decoder.cpp
+++ b/graphics/video/flic_decoder.cpp
@@ -34,20 +34,17 @@ namespace Graphics {
FlicDecoder::FlicDecoder() {
_paletteChanged = false;
_fileStream = 0;
- _videoFrameBuffer = 0;
- memset(&_videoInfo, 0, sizeof(_videoInfo));
+ _surface = 0;
}
FlicDecoder::~FlicDecoder() {
- closeFile();
+ close();
}
-bool FlicDecoder::loadFile(const char *fileName) {
- closeFile();
+bool FlicDecoder::load(Common::SeekableReadStream &stream) {
+ close();
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
- return false;
+ _fileStream = &stream;
/* uint32 frameSize = */ _fileStream->readUint32LE();
uint16 frameType = _fileStream->readUint16LE();
@@ -60,9 +57,10 @@ bool FlicDecoder::loadFile(const char *fileName) {
return false;
}
- _videoInfo.frameCount = _fileStream->readUint16LE();
- _videoInfo.width = _fileStream->readUint16LE();
- _videoInfo.height = _fileStream->readUint16LE();
+
+ _frameCount = _fileStream->readUint16LE();
+ uint16 width = _fileStream->readUint16LE();
+ uint16 height = _fileStream->readUint16LE();
uint16 colorDepth = _fileStream->readUint16LE();
if (colorDepth != 8) {
warning("FlicDecoder::FlicDecoder(): attempted to load an FLC with a palette of color depth %d. Only 8-bit color palettes are supported", frameType);
@@ -70,45 +68,48 @@ bool FlicDecoder::loadFile(const char *fileName) {
_fileStream = 0;
return false;
}
+
_fileStream->readUint16LE(); // flags
// Note: The normal delay is a 32-bit integer (dword), whereas the overriden delay is a 16-bit integer (word)
// frameDelay is the FLIC "speed", in milliseconds. Our frameDelay is calculated in 1/100 ms, so we convert it here
- _videoInfo.frameDelay = 100 * _fileStream->readUint32LE();
- _videoInfo.frameRate = 100 * 1000 / _videoInfo.frameDelay;
+ uint32 frameDelay = 100 * _fileStream->readUint32LE();
+ _frameRate = 100 * 1000 / frameDelay;
_fileStream->seek(80);
_offsetFrame1 = _fileStream->readUint32LE();
_offsetFrame2 = _fileStream->readUint32LE();
- _videoFrameBuffer = new byte[_videoInfo.width * _videoInfo.height];
+ _surface = new Graphics::Surface();
+ _surface->create(width, height, 1);
_palette = (byte *)malloc(3 * 256);
memset(_palette, 0, 3 * 256);
_paletteChanged = false;
// Seek to the first frame
- _videoInfo.currentFrame = -1;
_fileStream->seek(_offsetFrame1);
return true;
}
-void FlicDecoder::closeFile() {
+void FlicDecoder::close() {
if (!_fileStream)
return;
delete _fileStream;
_fileStream = 0;
- delete[] _videoFrameBuffer;
- _videoFrameBuffer = 0;
+ _surface->free();
+ delete _surface;
+ _surface = 0;
free(_palette);
-
_dirtyRects.clear();
+
+ reset();
}
void FlicDecoder::decodeByteRun(uint8 *data) {
- byte *ptr = (uint8 *)_videoFrameBuffer;
- while ((uint32)(ptr - _videoFrameBuffer) < (_videoInfo.width * _videoInfo.height)) {
+ byte *ptr = (byte *)_surface->pixels;
+ while ((int32)(ptr - (byte *)_surface->pixels) < (getWidth() * getHeight())) {
int chunks = *data++;
while (chunks--) {
int count = (int8)*data++;
@@ -125,7 +126,7 @@ void FlicDecoder::decodeByteRun(uint8 *data) {
// Redraw
_dirtyRects.clear();
- _dirtyRects.push_back(Common::Rect(0, 0, _videoInfo.width, _videoInfo.height));
+ _dirtyRects.push_back(Common::Rect(0, 0, getWidth(), getHeight()));
}
#define OP_PACKETCOUNT 0
@@ -152,8 +153,8 @@ void FlicDecoder::decodeDeltaFLC(uint8 *data) {
case OP_UNDEFINED:
break;
case OP_LASTPIXEL:
- _videoFrameBuffer[currentLine * _videoInfo.width + _videoInfo.width - 1] = (opcode & 0xFF);
- _dirtyRects.push_back(Common::Rect(_videoInfo.width - 1, currentLine, _videoInfo.width, currentLine + 1));
+ *((byte *)_surface->pixels + currentLine * getWidth() + getWidth() - 1) = (opcode & 0xFF);
+ _dirtyRects.push_back(Common::Rect(getWidth() - 1, currentLine, getWidth(), currentLine + 1));
break;
case OP_LINESKIPCOUNT:
currentLine += -(int16)opcode;
@@ -168,14 +169,14 @@ void FlicDecoder::decodeDeltaFLC(uint8 *data) {
column += *data++;
int rleCount = (int8)*data++;
if (rleCount > 0) {
- memcpy(_videoFrameBuffer + (currentLine * _videoInfo.width) + column, data, rleCount * 2);
+ memcpy((byte *)_surface->pixels + (currentLine * getWidth()) + column, data, rleCount * 2);
data += rleCount * 2;
_dirtyRects.push_back(Common::Rect(column, currentLine, column + rleCount * 2, currentLine + 1));
} else if (rleCount < 0) {
rleCount = -rleCount;
uint16 dataWord = READ_UINT16(data); data += 2;
for (int i = 0; i < rleCount; ++i) {
- WRITE_UINT16(_videoFrameBuffer + currentLine * _videoInfo.width + column + i * 2, dataWord);
+ WRITE_UINT16((byte *)_surface->pixels + currentLine * getWidth() + column + i * 2, dataWord);
}
_dirtyRects.push_back(Common::Rect(column, currentLine, column + rleCount * 2, currentLine + 1));
} else { // End of cutscene ?
@@ -194,34 +195,40 @@ void FlicDecoder::decodeDeltaFLC(uint8 *data) {
#define PSTAMP 18
#define FRAME_TYPE 0xF1FA
-bool FlicDecoder::decodeNextFrame() {
+Surface *FlicDecoder::decodeNextFrame() {
// Read chunk
uint32 frameSize = _fileStream->readUint32LE();
uint16 frameType = _fileStream->readUint16LE();
uint16 chunkCount = 0;
switch (frameType) {
- case FRAME_TYPE: {
- chunkCount = _fileStream->readUint16LE();
- // Note: The overriden delay is a 16-bit integer (word), whereas the normal delay is a 32-bit integer (dword)
- // frameDelay is the FLIC "speed", in milliseconds. Our frameDelay is calculated in 1/100 ms, so we convert it here
- uint16 newFrameDelay = _fileStream->readUint16LE(); // "speed", in milliseconds
- if (newFrameDelay > 0) {
- _videoInfo.frameDelay = 100 * newFrameDelay;
- _videoInfo.frameRate = 100 * 1000 / _videoInfo.frameDelay;
- }
- _fileStream->readUint16LE(); // reserved, always 0
- uint16 newWidth = _fileStream->readUint16LE();
- uint16 newHeight = _fileStream->readUint16LE();
- if (newWidth > 0)
- _videoInfo.width = newWidth;
- if (newHeight > 0)
- _videoInfo.height = newHeight;
-
- _videoInfo.currentFrame++;
-
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
+ case FRAME_TYPE:
+ {
+ // FIXME: FLIC should be switched over to a variable frame rate VideoDecoder to handle
+ // this properly.
+
+ chunkCount = _fileStream->readUint16LE();
+ // Note: The overriden delay is a 16-bit integer (word), whereas the normal delay is a 32-bit integer (dword)
+ // frameDelay is the FLIC "speed", in milliseconds. Our frameDelay is calculated in 1/100 ms, so we convert it here
+ uint16 newFrameDelay = _fileStream->readUint16LE(); // "speed", in milliseconds
+ if (newFrameDelay > 0)
+ _frameRate = 1000 / newFrameDelay;
+
+ _fileStream->readUint16LE(); // reserved, always 0
+ uint16 newWidth = _fileStream->readUint16LE();
+ uint16 newHeight = _fileStream->readUint16LE();
+
+ if ((newWidth != 0) && (newHeight != 0)) {
+ if (newWidth == 0)
+ newWidth = _surface->w;
+ if (newHeight == 0)
+ newHeight = _surface->h;
+
+ _surface->free();
+ delete _surface;
+ _surface = new Graphics::Surface();
+ _surface->create(newWidth, newHeight, 1);
+ }
}
break;
default:
@@ -239,7 +246,6 @@ bool FlicDecoder::decodeNextFrame() {
switch (frameType) {
case FLI_SETPAL:
unpackPalette(data);
- setPalette(_palette);
_paletteChanged = true;
break;
case FLI_SS2:
@@ -259,19 +265,25 @@ bool FlicDecoder::decodeNextFrame() {
delete[] data;
}
}
+
+ _curFrame++;
+
+ if (_curFrame == 0)
+ _startTime = g_system->getMillis();
// If we just processed the ring frame, set the next frame
- if (_videoInfo.currentFrame == (int32)_videoInfo.frameCount) {
- _videoInfo.currentFrame = 0;
+ if (_curFrame == (int32)_frameCount) {
+ _curFrame = 0;
_fileStream->seek(_offsetFrame2);
}
- return !endOfVideo();
+ return _surface;
}
void FlicDecoder::reset() {
- _videoInfo.currentFrame = -1;
- _fileStream->seek(_offsetFrame1);
+ VideoDecoder::reset();
+ if (_fileStream)
+ _fileStream->seek(_offsetFrame1);
}
void FlicDecoder::unpackPalette(uint8 *data) {
@@ -303,7 +315,7 @@ void FlicDecoder::copyDirtyRectsToBuffer(uint8 *dst, uint pitch) {
for (Common::List<Common::Rect>::const_iterator it = _dirtyRects.begin(); it != _dirtyRects.end(); ++it) {
for (int y = (*it).top; y < (*it).bottom; ++y) {
const int x = (*it).left;
- memcpy(dst + y * pitch + x, _videoFrameBuffer + y * _videoInfo.width + x, (*it).right - x);
+ memcpy(dst + y * pitch + x, (byte *)_surface->pixels + y * getWidth() + x, (*it).right - x);
}
}
_dirtyRects.clear();
diff --git a/graphics/video/flic_decoder.h b/graphics/video/flic_decoder.h
index b0a2b771b1..60d68889a2 100644
--- a/graphics/video/flic_decoder.h
+++ b/graphics/video/flic_decoder.h
@@ -23,10 +23,10 @@
*
*/
-#ifndef GRAPHICS_VIDEO_FlicDecoder_H
-#define GRAPHICS_VIDEO_FlicDecoder_H
+#ifndef GRAPHICS_VIDEO_FLICDECODER_H
+#define GRAPHICS_VIDEO_FLICDECODER_H
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "common/list.h"
#include "common/rect.h"
@@ -42,35 +42,42 @@ namespace Graphics {
* Video decoder used in engines:
* - tucker
*/
-class FlicDecoder : public VideoDecoder {
+class FlicDecoder : public FixedRateVideoDecoder {
public:
FlicDecoder();
virtual ~FlicDecoder();
/**
- * Load a FLIC encoded video file
- * @param filename the filename to load
+ * Load a video file
+ * @param stream the stream to load
*/
- bool loadFile(const char *fileName);
+ bool load(Common::SeekableReadStream &stream);
+ void close();
/**
- * Close a FLIC encoded video file
+ * Decode the next frame and return the frame's surface
+ * @note the return surface should *not* be freed
+ * @note this may return 0, in which case the last frame should be kept on screen
*/
- void closeFile();
+ Surface *decodeNextFrame();
- /**
- * Decode the next frame
- */
- bool decodeNextFrame();
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _surface->w; }
+ uint16 getHeight() const { return _surface->h; }
+ uint32 getFrameCount() const { return _frameCount; }
+ PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); }
const Common::List<Common::Rect> *getDirtyRects() const { return &_dirtyRects; }
void clearDirtyRects() { _dirtyRects.clear(); }
void copyDirtyRectsToBuffer(uint8 *dst, uint pitch);
- const byte *getPalette() { _paletteChanged = false; return _palette; }
- bool paletteChanged() { return _paletteChanged; }
+ byte *getPalette() { _paletteChanged = false; return _palette; }
+ bool hasDirtyPalette() { return _paletteChanged; }
void reset();
+protected:
+ Common::Rational getFrameRate() const { return _frameRate; }
+
private:
uint16 _offsetFrame1;
uint16 _offsetFrame2;
@@ -81,8 +88,12 @@ private:
void decodeDeltaFLC(uint8 *data);
void unpackPalette(uint8 *mem);
- Common::List<Common::Rect> _dirtyRects;
+ Common::SeekableReadStream *_fileStream;
+ Surface *_surface;
+ uint32 _frameCount;
+ uint32 _frameRate;
+ Common::List<Common::Rect> _dirtyRects;
};
} // End of namespace Graphics
diff --git a/graphics/video/smk_decoder.cpp b/graphics/video/smk_decoder.cpp
index 2f796c4a65..68fac32aae 100644
--- a/graphics/video/smk_decoder.cpp
+++ b/graphics/video/smk_decoder.cpp
@@ -351,52 +351,28 @@ uint32 BigHuffmanTree::getCode(BitStream &bs) {
SmackerDecoder::SmackerDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType)
: _audioStarted(false), _audioStream(0), _mixer(mixer), _soundType(soundType) {
+ _surface = 0;
+ _fileStream = 0;
+ _dirtyPalette = false;
}
SmackerDecoder::~SmackerDecoder() {
- closeFile();
+ close();
}
-int SmackerDecoder::getHeight() {
- if (!_fileStream)
- return 0;
- return (_header.flags ? 2 : 1) * _videoInfo.height;
-}
-
-int32 SmackerDecoder::getAudioLag() {
- if (!_fileStream)
- return 0;
+uint32 SmackerDecoder::getElapsedTime() const {
+ if (_audioStream)
+ return _mixer->getSoundElapsedTime(_audioHandle);
- int32 frameDelay = getFrameDelay();
- int32 videoTime = (_videoInfo.currentFrame + 1) * frameDelay;
- int32 audioTime;
-
- if (!_audioStream) {
- /* No audio.
- Calculate the lag by how much time has gone by since the first frame
- and how much time *should* have passed.
- */
-
- audioTime = (g_system->getMillis() - _videoInfo.startTime) * 100;
- } else {
- const Audio::Timestamp ts = _mixer->getElapsedTime(_audioHandle);
- audioTime = ts.convertToFramerate(100000).totalNumberOfFrames();
- }
-
- return videoTime - audioTime;
+ return VideoDecoder::getElapsedTime();
}
-bool SmackerDecoder::loadFile(const char *fileName) {
- int32 frameRate;
-
- closeFile();
+bool SmackerDecoder::load(Common::SeekableReadStream &stream) {
+ close();
- _fileStream = SearchMan.createReadStreamForMember(fileName);
- if (!_fileStream)
- return false;
+ _fileStream = &stream;
// Seek to the first frame
- _videoInfo.currentFrame = -1;
_header.signature = _fileStream->readUint32BE();
// No BINK support available
@@ -408,21 +384,17 @@ bool SmackerDecoder::loadFile(const char *fileName) {
assert(_header.signature == MKID_BE('SMK2') || _header.signature == MKID_BE('SMK4'));
- _videoInfo.width = _fileStream->readUint32LE();
- _videoInfo.height = _fileStream->readUint32LE();
- _videoInfo.frameCount = _fileStream->readUint32LE();
- frameRate = _fileStream->readSint32LE();
-
- if (frameRate > 0) {
- _videoInfo.frameRate = 1000 / frameRate;
- _videoInfo.frameDelay = frameRate * 100;
- } else if (frameRate < 0) {
- _videoInfo.frameRate = 100000 / (-frameRate);
- _videoInfo.frameDelay = -frameRate;
- } else {
- _videoInfo.frameRate = 10;
- _videoInfo.frameDelay = 10000;
- }
+ uint32 width = _fileStream->readUint32LE();
+ uint32 height = _fileStream->readUint32LE();
+ _frameCount = _fileStream->readUint32LE();
+ int32 frameRate = _fileStream->readSint32LE();
+
+ if (frameRate > 0)
+ _frameRate = 1000 / frameRate;
+ else if (frameRate < 0)
+ _frameRate = 100000 / (-frameRate);
+ else
+ _frameRate = 10;
// Flags are determined by which bit is set, which can be one of the following:
// 0 - set to 1 if file contains a ring frame.
@@ -447,7 +419,6 @@ bool SmackerDecoder::loadFile(const char *fileName) {
_header.fullSize = _fileStream->readUint32LE();
_header.typeSize = _fileStream->readUint32LE();
- uint32 audioInfo;
for (i = 0; i < 7; ++i) {
// AudioRate - Frequency and format information for each sound track, up to 7 audio tracks.
// The 32 constituent bits have the following meaning:
@@ -458,7 +429,7 @@ bool SmackerDecoder::loadFile(const char *fileName) {
// * bits 27-26 - if both set to zero - use v2 sound decompression
// * bits 25-24 - unused
// * bits 23-0 - audio sample rate
- audioInfo = _fileStream->readUint32LE();
+ uint32 audioInfo = _fileStream->readUint32LE();
_header.audioInfo[i].isCompressed = audioInfo & 0x80000000;
_header.audioInfo[i].hasAudio = audioInfo & 0x40000000;
_header.audioInfo[i].is16Bits = audioInfo & 0x20000000;
@@ -467,19 +438,18 @@ bool SmackerDecoder::loadFile(const char *fileName) {
!(audioInfo & 0x4000000);
_header.audioInfo[i].sampleRate = audioInfo & 0xFFFFFF;
- if (_header.audioInfo[i].hasAudio && i == 0) {
+ if (_header.audioInfo[i].hasAudio && i == 0)
_audioStream = Audio::makeQueuingAudioStream(_header.audioInfo[0].sampleRate, _header.audioInfo[0].isStereo);
- }
}
_header.dummy = _fileStream->readUint32LE();
- _frameSizes = (uint32 *)malloc(_videoInfo.frameCount * sizeof(uint32));
- for (i = 0; i < _videoInfo.frameCount; ++i)
+ _frameSizes = new uint32[_frameCount];
+ for (i = 0; i < _frameCount; ++i)
_frameSizes[i] = _fileStream->readUint32LE();
- _frameTypes = (byte *)malloc(_videoInfo.frameCount);
- for (i = 0; i < _videoInfo.frameCount; ++i)
+ _frameTypes = new byte[_frameCount];
+ for (i = 0; i < _frameCount; ++i)
_frameTypes[i] = _fileStream->readByte();
byte *huffmanTrees = new byte[_header.treesSize];
@@ -494,17 +464,17 @@ bool SmackerDecoder::loadFile(const char *fileName) {
delete[] huffmanTrees;
- _videoFrameBuffer = (byte *)malloc(2 * _videoInfo.width * _videoInfo.height);
- memset(_videoFrameBuffer, 0, 2 * _videoInfo.width * _videoInfo.height);
- _palette = (byte *)malloc(3 * 256);
- memset(_palette, 0, 3 * 256);
+ _surface = new Graphics::Surface();
- _videoInfo.firstframeOffset = _fileStream->pos();
+ // Height needs to be doubled if we have flags (Y-interlaced or Y-doubled)
+ _surface->create(width, height * (_header.flags ? 2 : 1), 1);
+ _palette = (byte *)malloc(3 * 256);
+ memset(_palette, 0, 3 * 256);
return true;
}
-void SmackerDecoder::closeFile() {
+void SmackerDecoder::close() {
if (!_fileStream)
return;
@@ -517,40 +487,42 @@ void SmackerDecoder::closeFile() {
delete _fileStream;
_fileStream = 0;
+ _surface->free();
+ delete _surface;
+ _surface = 0;
+
delete _MMapTree;
delete _MClrTree;
delete _FullTree;
delete _TypeTree;
- free(_frameSizes);
- free(_frameTypes);
- free(_videoFrameBuffer);
+ delete[] _frameSizes;
+ delete[] _frameTypes;
free(_palette);
+
+ reset();
}
-bool SmackerDecoder::decodeNextFrame() {
+Surface *SmackerDecoder::decodeNextFrame() {
uint i;
uint32 chunkSize = 0;
uint32 dataSizeUnpacked = 0;
uint32 startPos = _fileStream->pos();
- _videoInfo.currentFrame++;
-
- if (_videoInfo.currentFrame == 0)
- _videoInfo.startTime = g_system->getMillis();
+ _curFrame++;
// Check if we got a frame with palette data, and
// call back the virtual setPalette function to set
// the current palette
- if (_frameTypes[_videoInfo.currentFrame] & 1) {
+ if (_frameTypes[_curFrame] & 1) {
unpackPalette();
- setPalette(_palette);
+ _dirtyPalette = true;
}
// Load audio tracks
for (i = 0; i < 7; ++i) {
- if (!(_frameTypes[_videoInfo.currentFrame] & (2 << i)))
+ if (!(_frameTypes[_curFrame] & (2 << i)))
continue;
chunkSize = _fileStream->readUint32LE();
@@ -598,10 +570,10 @@ bool SmackerDecoder::decodeNextFrame() {
}
}
- uint32 frameSize = _frameSizes[_videoInfo.currentFrame] & ~3;
+ uint32 frameSize = _frameSizes[_curFrame] & ~3;
if (_fileStream->pos() - startPos > frameSize)
- exit(1);
+ error("Smacker actual frame size exceeds recorded frame size");
uint32 frameDataSize = frameSize - (_fileStream->pos() - startPos);
@@ -615,13 +587,14 @@ bool SmackerDecoder::decodeNextFrame() {
_FullTree->reset();
_TypeTree->reset();
- uint bw = _videoInfo.width / 4;
- uint bh = _videoInfo.height / 4;
- uint stride = _videoInfo.width;
- uint block = 0, blocks = bw*bh;
-
+ // Height needs to be doubled if we have flags (Y-interlaced or Y-doubled)
uint doubleY = _header.flags ? 2 : 1;
+ uint bw = getWidth() / 4;
+ uint bh = getHeight() / doubleY / 4;
+ uint stride = getWidth();
+ uint block = 0, blocks = bw*bh;
+
byte *out;
uint type, run, j, mode;
uint32 p1, p2, clr, map;
@@ -636,7 +609,7 @@ bool SmackerDecoder::decodeNextFrame() {
while (run-- && block < blocks) {
clr = _MClrTree->getCode(bs);
map = _MMapTree->getCode(bs);
- out = _videoFrameBuffer + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
+ out = (byte *)_surface->pixels + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
hi = clr >> 8;
lo = clr & 0xff;
for (i = 0; i < 4; i++) {
@@ -669,7 +642,7 @@ bool SmackerDecoder::decodeNextFrame() {
}
while (run-- && block < blocks) {
- out = _videoFrameBuffer + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
+ out = (byte *)_surface->pixels + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
switch (mode) {
case 0:
for (i = 0; i < 4; ++i) {
@@ -735,7 +708,7 @@ bool SmackerDecoder::decodeNextFrame() {
uint32 col;
mode = type >> 8;
while (run-- && block < blocks) {
- out = _videoFrameBuffer + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
+ out = (byte *)_surface->pixels + (block / bw) * (stride * 4 * doubleY) + (block % bw) * 4;
col = mode * 0x01010101;
for (i = 0; i < 4 * doubleY; ++i) {
out[0] = out[1] = out[2] = out[3] = col;
@@ -751,7 +724,10 @@ bool SmackerDecoder::decodeNextFrame() {
free(_frameData);
- return !endOfVideo();
+ if (_curFrame == 0)
+ _startTime = g_system->getMillis();
+
+ return _surface;
}
void SmackerDecoder::queueCompressedBuffer(byte *buffer, uint32 bufferSize,
@@ -806,15 +782,12 @@ void SmackerDecoder::queueCompressedBuffer(byte *buffer, uint32 bufferSize,
// If the sample is stereo, the data is stored for the left and right channel, respectively
// (the exact opposite to the base values)
if (!is16Bits) {
-
for (int k = 0; k < (isStereo ? 2 : 1); k++) {
bases[k] += (int8) ((int16) audioTrees[k]->getCode(audioBS));
*curPointer++ = CLIP<int>(bases[k], 0, 255) ^ 0x80;
curPos++;
}
-
} else {
-
for (int k = 0; k < (isStereo ? 2 : 1); k++) {
bases[k] += (int16) (audioTrees[k * 2]->getCode(audioBS) |
(audioTrees[k * 2 + 1]->getCode(audioBS) << 8));
@@ -887,7 +860,6 @@ void SmackerDecoder::unpackPalette() {
}
_fileStream->seek(startPos + len);
-
free(chunk);
}
diff --git a/graphics/video/smk_decoder.h b/graphics/video/smk_decoder.h
index 443d063138..437f47f2d6 100644
--- a/graphics/video/smk_decoder.h
+++ b/graphics/video/smk_decoder.h
@@ -26,7 +26,7 @@
#ifndef GRAPHICS_VIDEO_SMK_PLAYER_H
#define GRAPHICS_VIDEO_SMK_PLAYER_H
-#include "graphics/video/video_player.h"
+#include "graphics/video/video_decoder.h"
#include "sound/mixer.h"
namespace Audio {
@@ -51,27 +51,28 @@ class BigHuffmanTree;
* - sword1
* - sword2
*/
-class SmackerDecoder : public VideoDecoder {
+class SmackerDecoder : public FixedRateVideoDecoder {
public:
SmackerDecoder(Audio::Mixer *mixer,
Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType);
virtual ~SmackerDecoder();
- int getHeight();
- int32 getAudioLag();
+ bool load(Common::SeekableReadStream &stream);
+ void close();
- /**
- * Load an SMK encoded video file
- * @param filename the filename to load
- */
- bool loadFile(const char *filename);
+ bool isVideoLoaded() const { return _fileStream != 0; }
+ uint16 getWidth() const { return _surface->w; }
+ uint16 getHeight() const { return _surface->h; }
+ uint32 getFrameCount() const { return _frameCount; }
+ uint32 getElapsedTime() const;
+ Surface *decodeNextFrame();
+ PixelFormat getPixelFormat() const { return PixelFormat::createFormatCLUT8(); }
+ byte *getPalette() { _dirtyPalette = false; return _palette; }
+ bool hasDirtyPalette() const { return _dirtyPalette; }
- /**
- * Close an SMK encoded video file
- */
- void closeFile();
-
- bool decodeNextFrame();
+protected:
+ Common::Rational getFrameRate() const { return _frameRate; }
+ Common::SeekableReadStream *_fileStream;
private:
void unpackPalette();
@@ -111,6 +112,11 @@ private:
byte *_frameData;
// The RGB palette
byte *_palette;
+ bool _dirtyPalette;
+
+ uint32 _frameRate;
+ uint32 _frameCount;
+ Surface *_surface;
Audio::Mixer::SoundType _soundType;
Audio::Mixer *_mixer;
diff --git a/graphics/video/video_decoder.cpp b/graphics/video/video_decoder.cpp
new file mode 100644
index 0000000000..a3f63921a8
--- /dev/null
+++ b/graphics/video/video_decoder.cpp
@@ -0,0 +1,101 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#include "graphics/video/video_decoder.h"
+
+#include "common/file.h"
+#include "common/system.h"
+
+namespace Graphics {
+
+VideoDecoder::VideoDecoder() {
+ reset();
+}
+
+bool VideoDecoder::loadFile(const Common::String &filename) {
+ Common::File *file = new Common::File();
+
+ if (!file->open(filename)) {
+ delete file;
+ return false;
+ }
+
+ return load(*file);
+}
+
+uint32 VideoDecoder::getElapsedTime() const {
+ return g_system->getMillis() - _startTime;
+}
+
+void VideoDecoder::setSystemPalette() {
+ byte *vidPalette = getPalette();
+ byte *sysPalette = new byte[256 * 4];
+
+ for (uint16 i = 0; i < 256; i++) {
+ sysPalette[i * 4] = vidPalette[i * 3];
+ sysPalette[i * 4 + 1] = vidPalette[i * 3 + 1];
+ sysPalette[i * 4 + 2] = vidPalette[i * 3 + 2];
+ sysPalette[i * 4 + 3] = 0;
+ }
+
+ g_system->setPalette(sysPalette, 0, 256);
+ delete[] sysPalette;
+}
+
+bool VideoDecoder::needsUpdate() const {
+ return !endOfVideo() && getTimeToNextFrame() == 0;
+}
+
+void VideoDecoder::reset() {
+ _curFrame = -1;
+ _startTime = 0;
+}
+
+bool VideoDecoder::endOfVideo() const {
+ return !isVideoLoaded() || (getCurFrame() >= (int32)getFrameCount() - 1);
+}
+
+uint32 FixedRateVideoDecoder::getTimeToNextFrame() const {
+ if (endOfVideo() || _curFrame < 0)
+ return 0;
+
+ uint32 elapsedTime = getElapsedTime();
+ uint32 nextFrameStartTime = getFrameBeginTime(_curFrame + 1);
+
+ // If the time that the next frame should be shown has past
+ // the frame should be shown ASAP.
+ if (nextFrameStartTime <= elapsedTime)
+ return 0;
+
+ return nextFrameStartTime - elapsedTime;
+}
+
+uint32 FixedRateVideoDecoder::getFrameBeginTime(uint32 frame) const {
+ Common::Rational beginTime = frame * 1000;
+ beginTime /= getFrameRate();
+ return beginTime.toInt();
+}
+
+} // End of namespace Graphics
diff --git a/graphics/video/video_decoder.h b/graphics/video/video_decoder.h
new file mode 100644
index 0000000000..62aa496148
--- /dev/null
+++ b/graphics/video/video_decoder.h
@@ -0,0 +1,184 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * $URL$
+ * $Id$
+ *
+ */
+
+#ifndef GRAPHICS_VIDEO_PLAYER_H
+#define GRAPHICS_VIDEO_PLAYER_H
+
+#include "common/events.h"
+#include "common/list.h"
+#include "common/rational.h"
+#include "common/stream.h"
+
+#include "graphics/surface.h"
+#include "graphics/pixelformat.h"
+
+namespace Common {
+ class SeekableReadStream;
+}
+
+namespace Graphics {
+
+/**
+ * Implementation of a generic video decoder
+ */
+class VideoDecoder {
+public:
+ VideoDecoder();
+ virtual ~VideoDecoder() {}
+
+ /**
+ * Returns the width of the video
+ * @return the width of the video
+ */
+ virtual uint16 getWidth() const = 0;
+
+ /**
+ * Returns the height of the video
+ * @return the height of the video
+ */
+ virtual uint16 getHeight() const = 0;
+
+ /**
+ * Returns the current frame number of the video
+ * @return the last frame decoded by the video
+ */
+ virtual int32 getCurFrame() const { return _curFrame; }
+
+ /**
+ * Returns the amount of frames in the video
+ * @return the amount of frames in the video
+ */
+ virtual uint32 getFrameCount() const = 0;
+
+ /**
+ * Returns the time (in ms) that the video has been running
+ */
+ virtual uint32 getElapsedTime() const;
+
+ /**
+ * Returns whether a frame should be decoded or not
+ * @return whether a frame should be decoded or not
+ */
+ virtual bool needsUpdate() const;
+
+ /**
+ * Load a video file
+ * @param filename the filename to load
+ */
+ virtual bool loadFile(const Common::String &filename);
+
+ /**
+ * Load a video file
+ * @param stream the stream to load
+ */
+ virtual bool load(Common::SeekableReadStream &stream) = 0;
+
+ /**
+ * Close a video file
+ */
+ virtual void close() = 0;
+
+ /**
+ * Returns if a video file is loaded or not
+ */
+ virtual bool isVideoLoaded() const = 0;
+
+ /**
+ * Decode the next frame and return the frame's surface
+ * @note the return surface should *not* be freed
+ * @note this may return 0, in which case the last frame should be kept on screen
+ */
+ virtual Surface *decodeNextFrame() = 0;
+
+ /**
+ * Get the pixel format of the video
+ */
+ virtual PixelFormat getPixelFormat() const = 0;
+
+ /**
+ * Get the palette for the video in RGB format (if 8bpp or less)
+ */
+ virtual byte *getPalette() { return 0; }
+
+ /**
+ * Returns if the palette is dirty or not
+ */
+ 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;
+
+ /**
+ * Set the current palette to the system palette
+ */
+ void setSystemPalette();
+
+ /**
+ * Return the time until the next frame (in ms)
+ */
+ virtual uint32 getTimeToNextFrame() const = 0;
+
+protected:
+ /**
+ * Resets _curFrame and _startTime. Should be called from every close() function.
+ */
+ void reset();
+
+ int32 _curFrame;
+ uint32 _startTime;
+};
+
+/**
+ * A VideoDecoder wrapper that implements getTimeToNextFrame() based on getFrameRate().
+ */
+class FixedRateVideoDecoder : public VideoDecoder {
+public:
+ FixedRateVideoDecoder() {}
+ virtual ~FixedRateVideoDecoder() {}
+
+ uint32 getTimeToNextFrame() const;
+
+protected:
+ /**
+ * Return the frame rate in frames per second
+ * This returns a Rational because videos can have rates that are not integers and
+ * there are some videos with frame rates < 1.
+ */
+ virtual Common::Rational getFrameRate() const = 0;
+
+private:
+ uint32 getFrameBeginTime(uint32 frame) const;
+};
+
+} // End of namespace Graphics
+
+#endif
diff --git a/graphics/video/video_player.cpp b/graphics/video/video_player.cpp
deleted file mode 100644
index a8676ed594..0000000000
--- a/graphics/video/video_player.cpp
+++ /dev/null
@@ -1,245 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#include "common/archive.h"
-#include "common/debug.h"
-#include "common/events.h"
-#include "common/system.h"
-#include "common/util.h"
-#include "common/array.h"
-#include "common/endian.h"
-
-#include "graphics/video/video_player.h"
-#include "graphics/surface.h"
-
-namespace Graphics {
-
-VideoDecoder::VideoDecoder() : _fileStream(0) {
- _curFrameBlack = 0;
- _curFrameWhite = 255;
- _videoInfo.currentFrame = -1;
-}
-
-VideoDecoder::~VideoDecoder() {
-}
-
-int VideoDecoder::getWidth() {
- if (!_fileStream)
- return 0;
- return _videoInfo.width;
-}
-
-int VideoDecoder::getHeight() {
- if (!_fileStream)
- return 0;
- return _videoInfo.height;
-}
-
-int32 VideoDecoder::getCurFrame() const {
- return _videoInfo.currentFrame;
-}
-
-int32 VideoDecoder::getFrameCount() const {
- if (!_fileStream)
- return 0;
- return _videoInfo.frameCount;
-}
-
-int32 VideoDecoder::getFrameRate() {
- if (!_fileStream)
- return 0;
- return _videoInfo.frameRate;
-}
-
-int32 VideoDecoder::getFrameDelay() {
- if (!_fileStream)
- return 0;
- return _videoInfo.frameDelay;
-}
-
-int32 VideoDecoder::getAudioLag() {
- if (!_fileStream)
- return 0;
-
- /* No audio.
- Calculate the lag by how much time has gone by since the first frame
- and how much time *should* have passed.
- */
- int32 audioTime = (g_system->getMillis() - _videoInfo.startTime) * 100;
- int32 videoTime = _videoInfo.currentFrame * getFrameDelay();
-
- return videoTime - audioTime;
-}
-
-uint32 VideoDecoder::getFrameWaitTime() {
- int32 waitTime = (getFrameDelay() + getAudioLag()) / 100;
-
- if (waitTime < 0)
- return 0;
-
- return waitTime;
-}
-
-void VideoDecoder::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
- uint h = getHeight();
- uint w = getWidth();
-
- byte *src = _videoFrameBuffer;
- dst += y * pitch + x;
-
- do {
- memcpy(dst, src, w);
- dst += pitch;
- src += w;
- } while (--h);
-}
-
-void VideoDecoder::setPalette(byte *pal) {
- byte videoPalette[256 * 4];
-
- uint32 maxWeight = 0;
- uint32 minWeight = 0xFFFFFFFF;
- uint32 weight = 0;
- byte r, g, b;
-
- for (int i = 0; i < 256; i++) {
- videoPalette[i * 4 + 0] = *pal++;
- videoPalette[i * 4 + 1] = *pal++;
- videoPalette[i * 4 + 2] = *pal++;
- videoPalette[i * 4 + 3] = 0;
-
- // Try and find the white and black colors for the current palette
- r = videoPalette[i * 4 + 0];
- g = videoPalette[i * 4 + 1];
- b = videoPalette[i * 4 + 2];
-
- weight = 3 * r * r + 6 * g * g + 2 * b * b;
-
- if (weight >= maxWeight) {
- _curFrameWhite = i;
- maxWeight = weight;
- }
-
- if (weight <= minWeight) {
- _curFrameBlack = i;
- minWeight = i;
- }
- }
-
- g_system->setPalette(videoPalette, 0, 256);
-}
-
-bool VideoDecoder::endOfVideo() const {
- return !isVideoLoaded() || getCurFrame() >= (int32)getFrameCount() - 1;
-}
-
-
-/*
- * VideoPlayer
- */
-
-void VideoPlayer::processVideoEvents(Common::List<Common::Event> &stopEvents) {
- Common::Event curEvent;
- Common::EventManager *eventMan = g_system->getEventManager();
-
- // Process events, and skip video if esc is pressed
- while (eventMan->pollEvent(curEvent)) {
- if (curEvent.type == Common::EVENT_RTL || curEvent.type == Common::EVENT_QUIT) {
- _skipVideo = true;
- }
-
- for (Common::List<Common::Event>::const_iterator iter = stopEvents.begin(); iter != stopEvents.end(); ++iter) {
- if (curEvent.type == iter->type) {
- if (iter->type == Common::EVENT_KEYDOWN || iter->type == Common::EVENT_KEYUP) {
- if (curEvent.kbd.keycode == iter->kbd.keycode) {
- _skipVideo = true;
- break;
- }
- } else {
- _skipVideo = true;
- break;
- }
- }
- }
- }
-}
-
-bool VideoPlayer::playVideo(Common::List<Common::Event> &stopEvents) {
- _skipVideo = false;
- debug(0, "Playing video");
-
- g_system->fillScreen(0);
-
- int frameX = (g_system->getWidth() - _decoder->getWidth()) / 2;
- int frameY = (g_system->getHeight() - _decoder->getHeight()) / 2;
-
- while (!_decoder->endOfVideo() && !_skipVideo) {
- processVideoEvents(stopEvents);
-
- uint32 startTime = 0;
- _decoder->decodeNextFrame();
-
- Graphics::Surface *screen = g_system->lockScreen();
- _decoder->copyFrameToBuffer((byte *)screen->pixels, frameX, frameY, g_system->getWidth());
- performPostProcessing((byte *)screen->pixels);
- g_system->unlockScreen();
-
- uint32 waitTime = _decoder->getFrameWaitTime();
-
- if (!waitTime) {
- warning("dropped frame %i", _decoder->getCurFrame());
- continue;
- }
-
- // Update the screen
- g_system->updateScreen();
-
- startTime = g_system->getMillis();
-
- // Wait before showing the next frame
- while (g_system->getMillis() < startTime + waitTime && !_skipVideo) {
- processVideoEvents(stopEvents);
- g_system->delayMillis(10);
- }
- }
-
- return !_skipVideo;
-}
-
-bool VideoPlayer::playVideo() {
- Common::Event stopEvent;
- Common::List<Common::Event> stopEvents;
- stopEvents.clear();
- stopEvent.type = Common::EVENT_KEYDOWN;
- stopEvent.kbd = Common::KEYCODE_ESCAPE;
- stopEvents.push_back(stopEvent);
-
- return playVideo(stopEvents);
-}
-
-void VideoPlayer::performPostProcessing(byte *screen) {
-}
-
-} // End of namespace Graphics
diff --git a/graphics/video/video_player.h b/graphics/video/video_player.h
deleted file mode 100644
index 4f38bd9740..0000000000
--- a/graphics/video/video_player.h
+++ /dev/null
@@ -1,221 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#ifndef GRAPHICS_VIDEO_PLAYER_H
-#define GRAPHICS_VIDEO_PLAYER_H
-
-#include "common/events.h"
-#include "common/list.h"
-#include "common/stream.h"
-
-namespace Common {
- class SeekableReadStream;
-}
-
-namespace Graphics {
-
-/**
- * Implementation of a generic video decoder
- */
-class VideoDecoder {
-public:
- VideoDecoder();
- virtual ~VideoDecoder();
-
- /**
- * Returns the width of the video
- * @return the width of the video
- */
- virtual int getWidth();
-
- /**
- * Returns the height of the video
- * @return the height of the video
- */
- virtual int getHeight();
-
- /**
- * Returns the current frame number of the video
- * @return the current frame number of the video
- */
- virtual int32 getCurFrame() const;
-
- /**
- * Returns the amount of frames in the video
- * @return the amount of frames in the video
- */
- virtual int32 getFrameCount() const;
-
- /**
- * Returns the frame rate of the video
- * @return the frame rate of the video
- */
- virtual int32 getFrameRate();
-
- /**
- * Returns the time to wait for each frame in 1/100 ms (to avoid rounding errors)
- * @return the time to wait for each frame in 1/100 ms (to avoid rounding errors)
- */
- virtual int32 getFrameDelay();
-
- /**
- * Returns the current A/V lag in 1/100 ms (to avoid rounding errors)
- * If > 0, audio lags behind
- * If < 0, video lags behind
- * @return the current A/V lag in 1/100 ms (to avoid rounding errors)
- */
- virtual int32 getAudioLag();
-
- /**
- * Returns the time to wait until the next frame in ms, minding any lag
- * @return the time to wait until the next frame in ms
- */
- virtual uint32 getFrameWaitTime();
-
- /**
- * Load a video file
- * @param filename the filename to load
- */
- virtual bool loadFile(const char *filename) = 0;
-
- /**
- * Close a video file
- */
- virtual void closeFile() = 0;
-
- /**
- * Returns if a video file is loaded or not
- */
- bool isVideoLoaded() const { return (_fileStream != NULL); }
-
- /**
- * Set RGB palette, based on current frame
- * @param pal the RGB palette data
- */
- virtual void setPalette(byte *pal);
-
- /**
- * Gets the value of the pixel at the specified x and y coordinates
- * Note: This method assumes that the video's pitch equals its width, and that
- * the video has an 8bpp palette
- * @param x the x coordinate of the pixel
- * @param y the y coordinate of the pixel
- */
- byte getPixel(int x, int y) {
- return *(_videoFrameBuffer + y * _videoInfo.width + x * 1);
- }
-
- /**
- * Gets the value of the pixel at the specified offset
- * @param offset the offset of the pixel in the video buffer
- */
- byte getPixel(int offset) { return getPixel(offset, 0); }
-
- /**
- * Return the black palette color for the current frame
- */
- byte getBlack() { return _curFrameBlack; }
-
- /**
- * Return the white palette color for the current frame
- */
- byte getWhite() { return _curFrameWhite; }
-
- /**
- * Copy current frame into the specified position of the destination
- * buffer.
- * @param dst the buffer
- * @param x the x position of the buffer
- * @param y the y position of the buffer
- * @param pitch the pitch of buffer
- */
- void copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch);
-
- /**
- * Decode the next frame to _videoFrameBuffer
- */
- virtual bool decodeNextFrame() = 0;
-
- /**
- * Returns if the video is finished or not
- */
- virtual bool endOfVideo() const;
-
-protected:
- struct {
- uint32 width;
- uint32 height;
- uint32 frameCount;
- int32 frameRate;
- int32 frameDelay; // 1/100 ms (to avoid rounding errors)
- uint32 firstframeOffset;
- int32 currentFrame;
- uint32 startTime;
- } _videoInfo;
-
- byte _curFrameBlack, _curFrameWhite;
-
- Common::SeekableReadStream *_fileStream;
- byte *_videoFrameBuffer;
-};
-
-class VideoPlayer {
-public:
- VideoPlayer(VideoDecoder* decoder) : _skipVideo(false), _decoder(decoder)
- { }
- virtual ~VideoPlayer() { }
- /**
- * A default implementation of a video player
- * Plays a non-interactive full screen video till it's stopped by a
- * specific event
- * @param filename the name of the file to play
- * @param stopEvents a list of events that can stop the video
- *
- * Returns true if the video was played to the end, false if skipped
- */
- bool playVideo(Common::List<Common::Event> &stopEvents);
-
- /**
- * Provides the same functionality as the video player, and it adds the
- * event of skipping the video with the escape key by default
- */
- bool playVideo();
-
-protected:
- /**
- * Perform postprocessing once the frame data is copied to the screen,
- * right before the frame is drawn. Called by playVideo()
- */
- virtual void performPostProcessing(byte *screen);
-
- bool _skipVideo;
- VideoDecoder* _decoder;
-
- void processVideoEvents(Common::List<Common::Event> &stopEvents);
-};
-
-} // End of namespace Graphics
-
-#endif