2007-07-30 15:53:38 +00:00
|
|
|
/* 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.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2007-07-30 15:53:38 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2007-07-30 15:53:38 +00:00
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:20 +00:00
|
|
|
*
|
2007-07-30 15:53:38 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-07-08 00:16:55 +00:00
|
|
|
|
2007-07-30 15:53:38 +00:00
|
|
|
#include "gob/videoplayer.h"
|
|
|
|
#include "gob/global.h"
|
|
|
|
#include "gob/dataio.h"
|
|
|
|
#include "gob/video.h"
|
|
|
|
#include "gob/game.h"
|
|
|
|
#include "gob/palanim.h"
|
|
|
|
#include "gob/inter.h"
|
2008-04-27 03:19:19 +00:00
|
|
|
#include "gob/map.h"
|
2008-05-08 15:51:02 +00:00
|
|
|
#include "gob/sound/sound.h"
|
2007-07-30 15:53:38 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2010-08-08 00:35:18 +00:00
|
|
|
VideoPlayer::Properties::Properties() : type(kVideoTypeTry), sprite(Draw::kFrontSurface),
|
2011-01-16 16:29:19 +00:00
|
|
|
x(-1), y(-1), width(-1), height(-1), flags(kFlagFrontSurface), switchColorMode(false),
|
2010-08-08 01:02:49 +00:00
|
|
|
startFrame(-1), lastFrame(-1), endFrame(-1), forceSeek(false),
|
|
|
|
breakKey(kShortKeyEscape), palCmd(8), palStart(0), palEnd(255), palFrame(-1),
|
2011-01-22 16:29:54 +00:00
|
|
|
noBlock(false), loop(false), fade(false), waitEndFrame(true),
|
|
|
|
hasSound(false), canceled(false) {
|
2010-08-08 00:34:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-19 18:57:43 +00:00
|
|
|
VideoPlayer::Video::Video() : decoder(0), live(false) {
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::Video::isEmpty() const {
|
|
|
|
return decoder == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::Video::close() {
|
|
|
|
delete decoder;
|
|
|
|
|
|
|
|
decoder = 0;
|
|
|
|
fileName.clear();
|
2010-08-08 00:35:50 +00:00
|
|
|
surface.reset();
|
2011-01-19 18:57:43 +00:00
|
|
|
|
|
|
|
live = false;
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-08 18:03:30 +00:00
|
|
|
const char *const VideoPlayer::_extensions[] = { "IMD", "IMD", "VMD", "RMD", "SMD" };
|
2007-07-30 15:53:38 +00:00
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
VideoPlayer::VideoPlayer(GobEngine *vm) : _vm(vm), _needBlit(false),
|
2010-08-08 00:33:59 +00:00
|
|
|
_noCursorSwitch(false), _woodruffCohCottWorkaround(false) {
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoPlayer::~VideoPlayer() {
|
2010-08-08 00:33:59 +00:00
|
|
|
for (int i = 0; i < kVideoSlotCount; i++)
|
2010-08-08 00:34:33 +00:00
|
|
|
_videoSlots[i].close();
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 11:39:03 +00:00
|
|
|
void VideoPlayer::evaluateFlags(Properties &properties) {
|
2010-08-08 00:41:22 +00:00
|
|
|
if (properties.flags & kFlagFrontSurface) {
|
|
|
|
properties.sprite = Draw::kFrontSurface;
|
|
|
|
} else if (properties.flags & kFlagOtherSurface) {
|
|
|
|
properties.sprite = properties.x;
|
|
|
|
properties.x = 0;
|
|
|
|
} else if (properties.flags & kFlagScreenSurface) {
|
|
|
|
properties.sprite = 0;
|
2010-08-08 00:52:01 +00:00
|
|
|
} else if (properties.flags & kFlagNoVideo) {
|
|
|
|
properties.sprite = 0;
|
2010-08-08 00:41:22 +00:00
|
|
|
} else {
|
|
|
|
properties.sprite = Draw::kBackSurface;
|
|
|
|
}
|
2011-01-22 15:06:12 +00:00
|
|
|
|
|
|
|
if (properties.noBlock && (properties.sprite == Draw::kFrontSurface))
|
|
|
|
properties.sprite = Draw::kBackSurface;
|
2010-08-08 00:41:22 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
int VideoPlayer::openVideo(bool primary, const Common::String &file, Properties &properties) {
|
|
|
|
int slot = 0;
|
|
|
|
|
|
|
|
Video *video = 0;
|
|
|
|
if (!primary) {
|
|
|
|
slot = getNextFreeSlot();
|
|
|
|
if (slot < 0) {
|
|
|
|
warning("VideoPlayer::openVideo(): Can't open video \"%s\": No free slot", file.c_str());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
video = &_videoSlots[slot];
|
|
|
|
} else
|
|
|
|
video = &_videoSlots[0];
|
|
|
|
|
|
|
|
// Different video already in the slot => close that video
|
|
|
|
if (!video->isEmpty() && (video->fileName.compareToIgnoreCase(file) != 0))
|
|
|
|
video->close();
|
|
|
|
|
|
|
|
// No video => load the requested file
|
|
|
|
if (video->isEmpty()) {
|
|
|
|
// Open the video
|
|
|
|
if (!(video->decoder = openVideo(file, properties)))
|
|
|
|
return -1;
|
|
|
|
|
2011-01-20 12:28:46 +00:00
|
|
|
if (video->decoder->hasVideo() && !(properties.flags & kFlagNoVideo) &&
|
|
|
|
(video->decoder->isPaletted() != !_vm->isTrueColor())) {
|
2011-01-16 16:29:19 +00:00
|
|
|
if (!properties.switchColorMode)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
_vm->setTrueColor(!video->decoder->isPaletted());
|
|
|
|
|
|
|
|
video->decoder->colorModeChanged();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
// Set the filename
|
|
|
|
video->fileName = file;
|
2010-08-08 00:35:50 +00:00
|
|
|
|
|
|
|
// WORKAROUND: In some rare cases, the cursor should still be
|
|
|
|
// displayed while a video is playing.
|
|
|
|
_noCursorSwitch = false;
|
|
|
|
if (primary && (_vm->getGameType() == kGameTypeLostInTime)) {
|
2010-08-08 00:44:56 +00:00
|
|
|
if (!file.compareToIgnoreCase("PORTA03") ||
|
|
|
|
!file.compareToIgnoreCase("PORTA03A") ||
|
|
|
|
!file.compareToIgnoreCase("CALE1") ||
|
|
|
|
!file.compareToIgnoreCase("AMIL2") ||
|
|
|
|
!file.compareToIgnoreCase("AMIL3B") ||
|
|
|
|
!file.compareToIgnoreCase("DELB"))
|
2010-08-08 00:35:50 +00:00
|
|
|
_noCursorSwitch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// WORKAROUND: In Woodruff, Coh Cott vanished in one video on her party.
|
|
|
|
// This is a bug in video, so we work around it.
|
|
|
|
_woodruffCohCottWorkaround = false;
|
|
|
|
if (primary && (_vm->getGameType() == kGameTypeWoodruff)) {
|
2010-08-08 00:44:56 +00:00
|
|
|
if (!file.compareToIgnoreCase("SQ32-03"))
|
2010-08-08 00:35:50 +00:00
|
|
|
_woodruffCohCottWorkaround = true;
|
|
|
|
}
|
2007-08-13 14:04:50 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
if (!(properties.flags & kFlagNoVideo) && (properties.sprite >= 0)) {
|
|
|
|
bool ownSurf = (properties.sprite != Draw::kFrontSurface) && (properties.sprite != Draw::kBackSurface);
|
|
|
|
bool screenSize = properties.flags & kFlagScreenSurface;
|
2010-08-08 00:35:50 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
if (ownSurf) {
|
|
|
|
_vm->_draw->_spritesArray[properties.sprite] =
|
2011-02-02 16:48:04 +00:00
|
|
|
_vm->_video->initSurfDesc(screenSize ? _vm->_width : video->decoder->getWidth(),
|
2010-08-08 00:42:59 +00:00
|
|
|
screenSize ? _vm->_height : video->decoder->getHeight(), 0);
|
|
|
|
}
|
|
|
|
|
2011-01-20 10:20:57 +00:00
|
|
|
if (!_vm->_draw->_spritesArray[properties.sprite] &&
|
|
|
|
(properties.sprite != Draw::kFrontSurface) &&
|
|
|
|
(properties.sprite != Draw::kBackSurface)) {
|
2010-08-08 00:42:59 +00:00
|
|
|
properties.sprite = -1;
|
|
|
|
video->surface.reset();
|
|
|
|
video->decoder->setSurfaceMemory();
|
2011-01-17 09:48:42 +00:00
|
|
|
properties.x = properties.y = 0;
|
2010-08-08 00:42:59 +00:00
|
|
|
} else {
|
|
|
|
video->surface = _vm->_draw->_spritesArray[properties.sprite];
|
2011-01-20 10:20:57 +00:00
|
|
|
if (properties.sprite == Draw::kFrontSurface)
|
|
|
|
video->surface = _vm->_draw->_frontSurface;
|
|
|
|
if (properties.sprite == Draw::kBackSurface)
|
|
|
|
video->surface = _vm->_draw->_backSurface;
|
|
|
|
|
2010-09-30 13:02:16 +00:00
|
|
|
video->decoder->setSurfaceMemory(video->surface->getData(),
|
|
|
|
video->surface->getWidth(), video->surface->getHeight(), video->surface->getBPP());
|
2010-08-08 00:42:59 +00:00
|
|
|
|
|
|
|
if (!ownSurf || (ownSurf && screenSize)) {
|
2011-01-17 09:48:42 +00:00
|
|
|
if ((properties.x >= 0) || (properties.y >= 0)) {
|
|
|
|
properties.x = (properties.x < 0) ? 0xFFFF : properties.x;
|
|
|
|
properties.y = (properties.y < 0) ? 0xFFFF : properties.y;
|
|
|
|
} else
|
|
|
|
properties.x = properties.y = -1;
|
2010-08-08 00:42:59 +00:00
|
|
|
} else
|
2011-01-17 09:48:42 +00:00
|
|
|
properties.x = properties.y = 0;
|
2010-08-08 00:42:59 +00:00
|
|
|
}
|
2010-08-08 00:35:50 +00:00
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
} else {
|
2010-08-08 00:37:19 +00:00
|
|
|
properties.sprite = -1;
|
2010-08-08 00:35:50 +00:00
|
|
|
video->surface.reset();
|
2010-08-08 00:37:52 +00:00
|
|
|
video->decoder->setSurfaceMemory();
|
2011-01-17 09:48:42 +00:00
|
|
|
properties.x = properties.y = 0;
|
2010-08-08 00:35:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-17 09:48:42 +00:00
|
|
|
video->decoder->setXY(properties.x, properties.y);
|
|
|
|
|
2010-08-08 00:35:50 +00:00
|
|
|
if (primary)
|
|
|
|
_needBlit = (properties.flags & kFlagUseBackSurfaceContent) && (properties.sprite == Draw::kFrontSurface);
|
|
|
|
|
2011-01-22 16:29:54 +00:00
|
|
|
properties.hasSound = video->decoder->hasSound();
|
|
|
|
|
2010-08-08 00:41:56 +00:00
|
|
|
if (!video->decoder->hasSound())
|
|
|
|
video->decoder->setFrameRate(_vm->_util->getFrameRate());
|
2010-08-08 00:34:33 +00:00
|
|
|
|
2010-08-08 00:35:50 +00:00
|
|
|
WRITE_VAR(7, video->decoder->getFrameCount());
|
|
|
|
|
|
|
|
return slot;
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::closeVideo(int slot) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
video->close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
void VideoPlayer::closeLiveSound() {
|
|
|
|
for (int i = 1; i < kVideoSlotCount; i++) {
|
|
|
|
Video *video = getVideoBySlot(i);
|
|
|
|
if (!video)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (video->live)
|
|
|
|
closeVideo(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::closeAll() {
|
|
|
|
for (int i = 0; i < kVideoSlotCount; i++)
|
|
|
|
closeVideo(i);
|
|
|
|
}
|
|
|
|
|
GOB: Add a way to reopen currently opened IMD/VMD videos
This is a workaround for how Lost in Time behaves in combination
with changes I made to the DataIO code for running Urban Runner
on low-memory devices.
Urban Runner's intro are far to big to have them copied into
memory for these devices, so I made the DataIO code return a
SafeSeekableSubReadStream into the opened archive stream instead.
Unfortunately, Lost in Time might not close a video file when it
closes the data file which it was originally in, especially when
loading a saved game. Since the video player needs to be able to
gaplessly continue a video and there does not, by itself, close
the video if not requested by the scripts, this leads to reading
out of an already closed stream in certain cases.
So, to worka round this issues, the video player tries to reopen
each currently opened video after a data archive was closed, to
make sure that that video is still available. If not, the video
is closed.
2012-06-06 22:21:54 +00:00
|
|
|
bool VideoPlayer::reopenVideo(int slot) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return reopenVideo(*video);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoPlayer::reopenAll() {
|
|
|
|
bool all = true;
|
|
|
|
for (int i = 0; i < kVideoSlotCount; i++)
|
|
|
|
if (!reopenVideo(i))
|
|
|
|
all = false;
|
|
|
|
|
|
|
|
return all;
|
|
|
|
}
|
|
|
|
|
2011-01-23 15:33:30 +00:00
|
|
|
void VideoPlayer::pauseVideo(int slot, bool pause) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video || !video->decoder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
video->decoder->pauseVideo(pause);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::pauseAll(bool pause) {
|
|
|
|
for (int i = 0; i < kVideoSlotCount; i++)
|
|
|
|
pauseVideo(i, pause);
|
|
|
|
}
|
|
|
|
|
2011-01-24 14:10:15 +00:00
|
|
|
void VideoPlayer::finishVideoSound(int slot) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video || !video->decoder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
video->decoder->finishSound();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::waitSoundEnd(int slot) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video || !video->decoder)
|
|
|
|
return;
|
|
|
|
|
|
|
|
video->decoder->finishSound();
|
|
|
|
|
2011-09-08 05:55:40 +00:00
|
|
|
while (video->decoder->isSoundPlaying())
|
2011-01-24 14:10:15 +00:00
|
|
|
_vm->_util->longDelay(1);
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
bool VideoPlayer::play(int slot, Properties &properties) {
|
2010-08-08 00:34:33 +00:00
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
bool primary = slot == 0;
|
2010-08-08 00:34:33 +00:00
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
if (properties.startFrame < 0)
|
|
|
|
properties.startFrame = video->decoder->getCurFrame() + 1;
|
|
|
|
if (properties.lastFrame < 0)
|
2010-08-08 00:42:59 +00:00
|
|
|
properties.lastFrame = video->decoder->getFrameCount() - 1;
|
2010-08-08 00:37:19 +00:00
|
|
|
if (properties.endFrame < 0)
|
|
|
|
properties.endFrame = properties.lastFrame;
|
|
|
|
if (properties.palFrame < 0)
|
|
|
|
properties.palFrame = properties.startFrame;
|
|
|
|
|
|
|
|
properties.startFrame--;
|
|
|
|
properties.endFrame--;
|
|
|
|
properties.palFrame--;
|
|
|
|
|
|
|
|
if (primary) {
|
|
|
|
_vm->_draw->_showCursor = _noCursorSwitch ? 3 : 0;
|
|
|
|
|
|
|
|
if (properties.fade)
|
|
|
|
_vm->_palAnim->fade(0, -2, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool backwards = properties.startFrame > properties.lastFrame;
|
|
|
|
|
|
|
|
properties.canceled = false;
|
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (properties.noBlock) {
|
2011-01-19 18:57:43 +00:00
|
|
|
properties.waitEndFrame = false;
|
2011-01-22 19:28:23 +00:00
|
|
|
|
|
|
|
video->live = true;
|
|
|
|
video->properties = properties;
|
|
|
|
|
|
|
|
updateLive(slot, true);
|
2011-01-19 18:57:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-22 11:39:03 +00:00
|
|
|
if ((_vm->getGameType() != kGameTypeUrban) && (_vm->getGameType() != kGameTypeBambou))
|
2011-01-22 04:39:39 +00:00
|
|
|
// NOTE: For testing (and comfort?) purposes, we enable aborting of all videos.
|
2011-01-22 11:39:03 +00:00
|
|
|
// Except for Urban Runner and Bambou, where it leads to glitches
|
2011-01-22 04:39:39 +00:00
|
|
|
properties.breakKey = kShortKeyEscape;
|
2011-01-20 17:06:50 +00:00
|
|
|
|
2010-08-08 01:03:21 +00:00
|
|
|
while ((properties.startFrame != properties.lastFrame) &&
|
|
|
|
(properties.startFrame < (int32)(video->decoder->getFrameCount() - 1))) {
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
playFrame(slot, properties);
|
|
|
|
if (properties.canceled)
|
|
|
|
break;
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
properties.startFrame += backwards ? -1 : 1;
|
|
|
|
|
|
|
|
evalBgShading(*video);
|
|
|
|
|
|
|
|
if (primary && properties.fade) {
|
|
|
|
_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
|
|
|
|
properties.fade = false;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:51:09 +00:00
|
|
|
if (!_noCursorSwitch && properties.waitEndFrame)
|
|
|
|
waitEndFrame(slot);
|
2010-08-08 00:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
evalBgShading(*video);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:55:27 +00:00
|
|
|
void VideoPlayer::waitEndFrame(int slot, bool onlySound) {
|
2010-08-08 00:51:09 +00:00
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return;
|
|
|
|
|
2011-01-20 03:22:43 +00:00
|
|
|
if (!onlySound || video->decoder->hasSound()) {
|
|
|
|
uint32 waitTime = video->decoder->getTimeToNextFrame();
|
|
|
|
if (!video->decoder->hasSound())
|
2011-01-29 09:56:23 +00:00
|
|
|
waitTime = video->decoder->getStaticTimeToNextFrame();
|
2011-01-20 03:22:43 +00:00
|
|
|
|
|
|
|
_vm->_util->delay(waitTime);
|
|
|
|
}
|
2010-08-08 00:51:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 12:26:31 +00:00
|
|
|
bool VideoPlayer::isPlayingLive() const {
|
|
|
|
const Video *video = getVideoBySlot(0);
|
|
|
|
return video && video->live;
|
|
|
|
}
|
|
|
|
|
2011-01-20 03:22:43 +00:00
|
|
|
void VideoPlayer::updateLive(bool force) {
|
2011-01-22 19:28:23 +00:00
|
|
|
for (int i = 0; i < kVideoSlotCount; i++)
|
|
|
|
updateLive(i, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::updateLive(int slot, bool force) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
2011-01-19 18:57:43 +00:00
|
|
|
if (!video || !video->live)
|
|
|
|
return;
|
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (video->properties.startFrame >= (int32)(video->decoder->getFrameCount() - 1)) {
|
2011-01-20 03:22:43 +00:00
|
|
|
// Video ended
|
2011-01-19 18:57:43 +00:00
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (!video->properties.loop) {
|
|
|
|
if (!(video->properties.flags & kFlagNoVideo))
|
|
|
|
WRITE_VAR_OFFSET(212, (uint32)-1);
|
2011-02-02 17:03:14 +00:00
|
|
|
_vm->_vidPlayer->closeVideo(slot);
|
2011-01-20 18:17:39 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
video->decoder->seek(0, SEEK_SET, true);
|
2011-01-22 19:28:23 +00:00
|
|
|
video->properties.startFrame = -1;
|
2011-01-20 18:17:39 +00:00
|
|
|
}
|
2011-01-19 18:57:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (video->properties.startFrame == video->properties.lastFrame)
|
2011-01-20 03:22:43 +00:00
|
|
|
// Current video sequence ended
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!force && (video->decoder->getTimeToNextFrame() > 0))
|
2011-01-19 18:57:43 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (!(video->properties.flags & kFlagNoVideo))
|
|
|
|
WRITE_VAR_OFFSET(212, video->properties.startFrame + 1);
|
2011-01-19 18:57:43 +00:00
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
bool backwards = video->properties.startFrame > video->properties.lastFrame;
|
|
|
|
playFrame(slot, video->properties);
|
2011-01-19 18:57:43 +00:00
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
video->properties.startFrame += backwards ? -1 : 1;
|
2011-01-19 18:57:43 +00:00
|
|
|
|
2011-01-22 19:28:23 +00:00
|
|
|
if (video->properties.fade) {
|
2011-01-19 18:57:43 +00:00
|
|
|
_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
|
2011-01-22 19:28:23 +00:00
|
|
|
video->properties.fade = false;
|
2011-01-19 18:57:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
bool VideoPlayer::playFrame(int slot, Properties &properties) {
|
|
|
|
Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool primary = slot == 0;
|
|
|
|
|
2010-08-08 00:47:54 +00:00
|
|
|
if (video->decoder->getCurFrame() != properties.startFrame) {
|
2010-08-08 01:02:49 +00:00
|
|
|
|
|
|
|
if (properties.startFrame != -1) {
|
|
|
|
// Seek into the middle of the video
|
|
|
|
|
|
|
|
if (video->decoder->hasSound()) {
|
|
|
|
// But there's sound
|
|
|
|
|
|
|
|
if (properties.forceSeek) {
|
|
|
|
// And we force seeking => Seek
|
|
|
|
|
|
|
|
video->decoder->disableSound();
|
|
|
|
video->decoder->seek(properties.startFrame + 1, SEEK_SET, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else
|
|
|
|
// No sound => We can safely seek
|
|
|
|
video->decoder->seek(properties.startFrame + 1, SEEK_SET, true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Seek to the start => We can safely seek
|
|
|
|
|
|
|
|
video->decoder->disableSound();
|
|
|
|
video->decoder->seek(0, SEEK_SET, true);
|
|
|
|
video->decoder->enableSound();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:47:54 +00:00
|
|
|
}
|
2010-08-08 00:37:19 +00:00
|
|
|
|
2010-08-08 01:02:49 +00:00
|
|
|
if (video->decoder->getCurFrame() > properties.startFrame)
|
|
|
|
// If the video is already beyond the wanted frame, skip
|
|
|
|
return true;
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
bool modifiedPal = false;
|
|
|
|
|
|
|
|
if (primary) {
|
|
|
|
// Pre-decoding palette and blitting, only for primary videos
|
|
|
|
|
|
|
|
if ((properties.startFrame == properties.palFrame) ||
|
|
|
|
((properties.startFrame == properties.endFrame) && (properties.palCmd == 8))) {
|
|
|
|
|
|
|
|
modifiedPal = true;
|
|
|
|
_vm->_draw->_applyPal = true;
|
|
|
|
|
|
|
|
if (properties.palCmd >= 4)
|
2010-08-08 00:42:59 +00:00
|
|
|
copyPalette(*video, properties.palStart, properties.palEnd);
|
2010-08-08 00:37:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:50:12 +00:00
|
|
|
if (modifiedPal && (properties.palCmd == 8) && (video->surface != _vm->_draw->_backSurface))
|
2010-08-08 00:37:19 +00:00
|
|
|
_vm->_video->setFullPalette(_vm->_global->_pPaletteDesc);
|
|
|
|
|
|
|
|
if (_needBlit)
|
|
|
|
_vm->_draw->forceBlit();
|
|
|
|
}
|
|
|
|
|
2010-12-16 01:35:13 +00:00
|
|
|
const Graphics::Surface *surface = video->decoder->decodeNextFrame();
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
WRITE_VAR(11, video->decoder->getCurFrame());
|
|
|
|
|
2010-08-08 01:06:44 +00:00
|
|
|
uint32 ignoreBorder = 0;
|
2010-08-08 00:37:19 +00:00
|
|
|
if (_woodruffCohCottWorkaround && (properties.startFrame == 31)) {
|
|
|
|
// WORKAROUND: This frame mistakenly masks Coh Cott, making her vanish
|
|
|
|
// To prevent that, we'll never draw that part
|
2010-08-08 01:06:44 +00:00
|
|
|
ignoreBorder = 50;
|
2010-08-08 00:37:19 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 01:02:49 +00:00
|
|
|
if (surface && primary) {
|
2010-08-08 00:37:19 +00:00
|
|
|
// Post-decoding palette and blitting, only for primary videos
|
|
|
|
|
|
|
|
if (_needBlit)
|
|
|
|
_vm->_draw->forceBlit(true);
|
|
|
|
|
|
|
|
if (modifiedPal && (properties.palCmd == 16)) {
|
2010-08-08 00:50:12 +00:00
|
|
|
if (video->surface == _vm->_draw->_backSurface)
|
2010-08-08 00:37:19 +00:00
|
|
|
_vm->_draw->forceBlit();
|
|
|
|
_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
|
|
|
|
_vm->_draw->_noInvalidated = true;
|
|
|
|
_vm->_video->dirtyRectsAll();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
if (video->decoder->hasPalette() && (properties.palCmd > 1)) {
|
|
|
|
copyPalette(*video, properties.palStart, properties.palEnd);
|
2010-08-08 00:37:19 +00:00
|
|
|
|
2010-08-08 00:50:12 +00:00
|
|
|
if (video->surface != _vm->_draw->_backSurface)
|
2010-08-08 00:37:19 +00:00
|
|
|
_vm->_video->setFullPalette(_vm->_global->_pPaletteDesc);
|
|
|
|
else
|
|
|
|
_vm->_draw->_applyPal = true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:39:03 +00:00
|
|
|
const Common::List<Common::Rect> &dirtyRects = video->decoder->getDirtyRects();
|
|
|
|
|
2010-08-08 00:50:12 +00:00
|
|
|
if (modifiedPal && (properties.palCmd == 8) && (video->surface == _vm->_draw->_backSurface))
|
2010-08-08 00:37:19 +00:00
|
|
|
_vm->_video->setFullPalette(_vm->_global->_pPaletteDesc);
|
|
|
|
|
2010-08-08 00:50:12 +00:00
|
|
|
if (video->surface == _vm->_draw->_backSurface) {
|
2010-08-08 00:37:19 +00:00
|
|
|
|
2010-08-08 00:39:03 +00:00
|
|
|
for (Common::List<Common::Rect>::const_iterator rect = dirtyRects.begin(); rect != dirtyRects.end(); ++rect)
|
2010-08-08 01:06:44 +00:00
|
|
|
_vm->_draw->invalidateRect(rect->left + ignoreBorder, rect->top, rect->right - 1, rect->bottom - 1);
|
2011-01-22 15:39:52 +00:00
|
|
|
if (!video->live)
|
|
|
|
_vm->_draw->blitInvalidated();
|
2010-08-08 00:37:19 +00:00
|
|
|
|
2010-08-08 00:50:12 +00:00
|
|
|
} else if (video->surface == _vm->_draw->_frontSurface) {
|
2010-08-08 00:39:03 +00:00
|
|
|
for (Common::List<Common::Rect>::const_iterator rect = dirtyRects.begin(); rect != dirtyRects.end(); ++rect)
|
2010-08-08 01:06:44 +00:00
|
|
|
_vm->_video->dirtyRectsAdd(rect->left + ignoreBorder, rect->top, rect->right - 1, rect->bottom - 1);
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-19 18:57:43 +00:00
|
|
|
if (!video->live && ((video->decoder->getCurFrame() - 1) == properties.startFrame))
|
2010-08-08 01:02:49 +00:00
|
|
|
// Only retrace if we're playing the frame we actually want to play
|
|
|
|
_vm->_video->retrace();
|
2010-08-08 00:52:01 +00:00
|
|
|
|
2010-08-08 01:05:46 +00:00
|
|
|
int32 subtitle = video->decoder->getSubtitleIndex();
|
|
|
|
if (subtitle != -1)
|
|
|
|
_vm->_draw->printTotText(subtitle);
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
if (modifiedPal && ((properties.palCmd == 2) || (properties.palCmd == 4)))
|
|
|
|
_vm->_palAnim->fade(_vm->_global->_pPaletteDesc, -2, 0);
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:51:09 +00:00
|
|
|
if (primary && properties.waitEndFrame)
|
2010-08-08 00:37:19 +00:00
|
|
|
checkAbort(*video, properties);
|
|
|
|
|
2010-08-08 01:02:49 +00:00
|
|
|
if ((video->decoder->getCurFrame() - 1) < properties.startFrame)
|
|
|
|
// The video played a frame we actually didn't want, so we have to adjust
|
|
|
|
properties.startFrame--;
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoPlayer::checkAbort(Video &video, Properties &properties) {
|
|
|
|
_vm->_util->processInput();
|
|
|
|
|
|
|
|
if (_vm->shouldQuit()) {
|
2010-08-08 00:42:30 +00:00
|
|
|
video.decoder->disableSound();
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
properties.canceled = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.breakKey != 0) {
|
|
|
|
_vm->_util->getMouseState(&_vm->_global->_inter_mouseX,
|
|
|
|
&_vm->_global->_inter_mouseY, &_vm->_game->_mouseButtons);
|
|
|
|
|
|
|
|
_vm->_inter->storeKey(_vm->_util->checkKey());
|
2011-01-22 04:39:39 +00:00
|
|
|
|
|
|
|
// Check for that specific key
|
|
|
|
bool pressedBreak = (VAR(0) == (unsigned)properties.breakKey);
|
|
|
|
|
|
|
|
// Mouse buttons
|
|
|
|
if (properties.breakKey < 4)
|
|
|
|
if (_vm->_game->_mouseButtons & properties.breakKey)
|
|
|
|
pressedBreak = true;
|
|
|
|
|
|
|
|
// Any key
|
|
|
|
if (properties.breakKey == 4)
|
|
|
|
if (VAR(0) != 0)
|
|
|
|
pressedBreak = true;
|
|
|
|
|
|
|
|
if (pressedBreak) {
|
2010-08-08 00:42:30 +00:00
|
|
|
video.decoder->disableSound();
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
// Seek to the last frame. Some scripts depend on that.
|
|
|
|
video.decoder->seek(properties.endFrame + 1, SEEK_SET, true);
|
|
|
|
|
|
|
|
properties.canceled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
bool VideoPlayer::slotIsOpen(int slot) const {
|
|
|
|
return getVideoBySlot(slot) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::String VideoPlayer::getFileName(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return video->fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 VideoPlayer::getFrameCount(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return video->decoder->getFrameCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 VideoPlayer::getCurrentFrame(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return video->decoder->getCurFrame();
|
|
|
|
}
|
2007-07-30 15:53:38 +00:00
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
uint16 VideoPlayer::getWidth(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return video->decoder->getWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 VideoPlayer::getHeight(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return video->decoder->getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16 VideoPlayer::getDefaultX(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
return video->decoder->getDefaultX();
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16 VideoPlayer::getDefaultY(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
return video->decoder->getDefaultY();
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:51:09 +00:00
|
|
|
const Common::List<Common::Rect> *VideoPlayer::getDirtyRects(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &video->decoder->getDirtyRects();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:46:34 +00:00
|
|
|
bool VideoPlayer::hasEmbeddedFile(const Common::String &fileName, int slot) const {
|
2010-08-08 00:34:33 +00:00
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
|
|
|
|
2010-08-08 00:46:34 +00:00
|
|
|
return video->decoder->hasEmbeddedFile(fileName);
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
2010-11-19 01:37:04 +00:00
|
|
|
Common::SeekableReadStream *VideoPlayer::getEmbeddedFile(const Common::String &fileName, int slot) {
|
2010-08-08 00:34:33 +00:00
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return 0;
|
|
|
|
|
2010-08-08 00:46:34 +00:00
|
|
|
return video->decoder->getEmbeddedFile(fileName);
|
2010-08-08 00:34:33 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 01:05:46 +00:00
|
|
|
int32 VideoPlayer::getSubtitleIndex(int slot) const {
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return video->decoder->getSubtitleIndex();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
void VideoPlayer::writeVideoInfo(const Common::String &file, int16 varX, int16 varY,
|
|
|
|
int16 varFrames, int16 varWidth, int16 varHeight) {
|
|
|
|
|
|
|
|
Properties properties;
|
|
|
|
|
|
|
|
int slot = openVideo(false, file, properties);
|
|
|
|
if (slot >= 0) {
|
|
|
|
Video &video = _videoSlots[slot];
|
|
|
|
|
|
|
|
int16 x = -1, y = -1, width = -1, height = -1;
|
|
|
|
|
2010-08-08 01:04:19 +00:00
|
|
|
x = video.decoder->getDefaultX();
|
|
|
|
y = video.decoder->getDefaultY();
|
|
|
|
width = video.decoder->getWidth();
|
|
|
|
height = video.decoder->getHeight();
|
2010-08-08 00:37:19 +00:00
|
|
|
|
|
|
|
if (VAR_OFFSET(varX) == 0xFFFFFFFF)
|
|
|
|
video.decoder->getFrameCoords(1, x, y, width, height);
|
|
|
|
|
|
|
|
WRITE_VAR_OFFSET(varX , x);
|
|
|
|
WRITE_VAR_OFFSET(varY , y);
|
|
|
|
WRITE_VAR_OFFSET(varFrames, video.decoder->getFrameCount());
|
|
|
|
WRITE_VAR_OFFSET(varWidth , width);
|
|
|
|
WRITE_VAR_OFFSET(varHeight, height);
|
|
|
|
|
2010-08-08 01:04:19 +00:00
|
|
|
closeVideo(slot);
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
} else {
|
|
|
|
WRITE_VAR_OFFSET(varX , (uint32) -1);
|
|
|
|
WRITE_VAR_OFFSET(varY , (uint32) -1);
|
|
|
|
WRITE_VAR_OFFSET(varFrames, (uint32) -1);
|
|
|
|
WRITE_VAR_OFFSET(varWidth , (uint32) -1);
|
|
|
|
WRITE_VAR_OFFSET(varHeight, (uint32) -1);
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 00:54:24 +00:00
|
|
|
|
2011-01-20 05:19:41 +00:00
|
|
|
bool VideoPlayer::copyFrame(int slot, Surface &dest,
|
|
|
|
uint16 left, uint16 top, uint16 width, uint16 height, uint16 x, uint16 y,
|
|
|
|
int32 transp) const {
|
2010-08-08 00:54:24 +00:00
|
|
|
|
|
|
|
const Video *video = getVideoBySlot(slot);
|
|
|
|
if (!video)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const Graphics::Surface *surface = video->decoder->getSurface();
|
|
|
|
if (!surface)
|
|
|
|
return false;
|
|
|
|
|
2013-08-02 21:32:31 +00:00
|
|
|
// FIXME? This currently casts away const from the pixel data. However, it
|
|
|
|
// is only used read-only in this case (as far as I can tell). Not casting
|
|
|
|
// the const qualifier away will lead to an additional allocation and copy
|
|
|
|
// of the frame data which is undesirable.
|
2013-08-03 00:39:04 +00:00
|
|
|
Surface src(surface->w, surface->h, surface->format.bytesPerPixel, (byte *)const_cast<void *>(surface->getPixels()));
|
2010-08-08 00:54:24 +00:00
|
|
|
|
2011-01-20 05:19:41 +00:00
|
|
|
dest.blit(src, left, top, left + width - 1, top + height - 1, x, y, transp);
|
2010-08-08 00:54:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-08-08 00:37:19 +00:00
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
const VideoPlayer::Video *VideoPlayer::getVideoBySlot(int slot) const {
|
|
|
|
if ((slot < 0) || (slot >= kVideoSlotCount))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (_videoSlots[slot].isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &_videoSlots[slot];
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoPlayer::Video *VideoPlayer::getVideoBySlot(int slot) {
|
|
|
|
if ((slot < 0) || (slot >= kVideoSlotCount))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (_videoSlots[slot].isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return &_videoSlots[slot];
|
|
|
|
}
|
|
|
|
|
|
|
|
int VideoPlayer::getNextFreeSlot() {
|
|
|
|
// Starting with 1, since 0 is reserved for the "primary" video
|
|
|
|
for (int i = 1; i < kVideoSlotCount; i++)
|
|
|
|
if (_videoSlots[i].isEmpty())
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:37:19 +00:00
|
|
|
void VideoPlayer::evalBgShading(Video &video) {
|
2010-08-08 00:42:30 +00:00
|
|
|
if (video.decoder->isSoundPlaying())
|
2010-08-08 00:37:19 +00:00
|
|
|
_vm->_sound->bgShade();
|
|
|
|
else
|
|
|
|
_vm->_sound->bgUnshade();
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
Common::String VideoPlayer::findFile(const Common::String &file, Properties &properties) {
|
|
|
|
|
|
|
|
bool hasExtension = false;
|
|
|
|
|
|
|
|
Common::String base = file;
|
|
|
|
Common::String fileName = file;
|
|
|
|
|
|
|
|
const char *posDot = strrchr(base.c_str(), '.');
|
|
|
|
if (posDot) {
|
|
|
|
hasExtension = true;
|
|
|
|
base = Common::String(base.c_str(), posDot);
|
|
|
|
posDot++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasExtension) {
|
2007-07-30 15:53:38 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAYSIZE(_extensions); i++) {
|
2010-08-08 00:34:33 +00:00
|
|
|
if (!scumm_stricmp(posDot, _extensions[i])) {
|
|
|
|
if ((properties.type != kVideoTypeTry) && (properties.type == ((Type) i))) {
|
|
|
|
warning("Attempted to open video \"%s\", but requested a different type", fileName.c_str());
|
|
|
|
return "";
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
2010-08-08 00:34:33 +00:00
|
|
|
properties.type = (Type) i;
|
2007-07-30 15:53:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= ARRAYSIZE(_extensions))
|
2010-08-08 00:34:33 +00:00
|
|
|
hasExtension = false;
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
if (!hasExtension) {
|
2007-07-30 15:53:38 +00:00
|
|
|
// No or unrecognized extension. Probing.
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAYSIZE(_extensions); i++) {
|
2010-08-08 00:34:33 +00:00
|
|
|
if ((properties.type == kVideoTypeTry) || (properties.type == ((Type) i))) {
|
|
|
|
fileName = base + "." + _extensions[i];
|
2007-07-30 15:53:38 +00:00
|
|
|
|
2010-10-31 20:07:14 +00:00
|
|
|
if (_vm->_dataIO->hasFile(fileName)) {
|
2010-08-08 00:34:33 +00:00
|
|
|
properties.type = (Type) i;
|
2007-07-30 15:53:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-08 00:34:33 +00:00
|
|
|
if ((i >= ARRAYSIZE(_extensions)) || (properties.type == kVideoTypeTry)) {
|
|
|
|
warning("Couldn't open video \"%s\"", file.c_str());
|
|
|
|
return "";
|
2007-07-30 15:53:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:34:33 +00:00
|
|
|
return fileName;
|
2008-04-27 03:19:19 +00:00
|
|
|
}
|
2007-07-30 15:53:38 +00:00
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
::Video::CoktelDecoder *VideoPlayer::openVideo(const Common::String &file, Properties &properties) {
|
2010-08-08 00:34:33 +00:00
|
|
|
Common::String fileName = findFile(file, properties);
|
|
|
|
if (fileName.empty())
|
|
|
|
return 0;
|
|
|
|
|
2010-10-31 20:07:14 +00:00
|
|
|
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
|
2010-08-08 00:33:59 +00:00
|
|
|
if (!stream)
|
|
|
|
return 0;
|
|
|
|
|
2011-01-23 19:08:09 +00:00
|
|
|
::Video::CoktelDecoder *video = 0;
|
2010-08-08 00:34:33 +00:00
|
|
|
if (properties.type == kVideoTypeIMD)
|
2011-01-23 19:08:09 +00:00
|
|
|
video = new ::Video::IMDDecoder(_vm->_mixer, Audio::Mixer::kSFXSoundType);
|
2010-08-08 00:40:52 +00:00
|
|
|
else if (properties.type == kVideoTypePreIMD)
|
2011-01-23 19:08:09 +00:00
|
|
|
video = new ::Video::PreIMDDecoder(properties.width, properties.height, _vm->_mixer, Audio::Mixer::kSFXSoundType);
|
2010-08-08 00:40:52 +00:00
|
|
|
else if (properties.type == kVideoTypeVMD)
|
2011-01-23 19:08:09 +00:00
|
|
|
video = new ::Video::VMDDecoder(_vm->_mixer, Audio::Mixer::kSFXSoundType);
|
2010-08-08 00:34:33 +00:00
|
|
|
else if (properties.type == kVideoTypeRMD)
|
2011-01-23 19:08:09 +00:00
|
|
|
video = new ::Video::VMDDecoder(_vm->_mixer, Audio::Mixer::kSFXSoundType);
|
2010-08-08 00:33:59 +00:00
|
|
|
else
|
2010-08-08 00:34:33 +00:00
|
|
|
warning("Couldn't open video \"%s\": Invalid video Type", fileName.c_str());
|
2010-08-08 00:33:59 +00:00
|
|
|
|
|
|
|
if (!video) {
|
|
|
|
delete stream;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-07 17:54:16 +00:00
|
|
|
if (!video->loadStream(stream)) {
|
2010-08-08 00:33:59 +00:00
|
|
|
delete video;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:40:52 +00:00
|
|
|
properties.width = video->getWidth();
|
|
|
|
properties.height = video->getHeight();
|
|
|
|
|
2010-08-08 00:33:59 +00:00
|
|
|
return video;
|
|
|
|
}
|
|
|
|
|
GOB: Add a way to reopen currently opened IMD/VMD videos
This is a workaround for how Lost in Time behaves in combination
with changes I made to the DataIO code for running Urban Runner
on low-memory devices.
Urban Runner's intro are far to big to have them copied into
memory for these devices, so I made the DataIO code return a
SafeSeekableSubReadStream into the opened archive stream instead.
Unfortunately, Lost in Time might not close a video file when it
closes the data file which it was originally in, especially when
loading a saved game. Since the video player needs to be able to
gaplessly continue a video and there does not, by itself, close
the video if not requested by the scripts, this leads to reading
out of an already closed stream in certain cases.
So, to worka round this issues, the video player tries to reopen
each currently opened video after a data archive was closed, to
make sure that that video is still available. If not, the video
is closed.
2012-06-06 22:21:54 +00:00
|
|
|
bool VideoPlayer::reopenVideo(Video &video) {
|
|
|
|
if (video.isEmpty())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (video.fileName.empty()) {
|
|
|
|
video.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Properties properties;
|
|
|
|
|
|
|
|
properties.type = video.properties.type;
|
|
|
|
|
|
|
|
Common::String fileName = findFile(video.fileName, properties);
|
|
|
|
if (fileName.empty()) {
|
|
|
|
video.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fileName);
|
|
|
|
if (!stream) {
|
|
|
|
video.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!video.decoder->reloadStream(stream)) {
|
|
|
|
delete stream;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-08 00:42:59 +00:00
|
|
|
void VideoPlayer::copyPalette(const Video &video, int16 palStart, int16 palEnd) {
|
2011-01-16 22:28:20 +00:00
|
|
|
if (!video.decoder->hasPalette() || !video.decoder->isPaletted())
|
2008-12-05 18:47:50 +00:00
|
|
|
return;
|
|
|
|
|
2008-06-19 22:54:17 +00:00
|
|
|
if (palStart < 0)
|
|
|
|
palStart = 0;
|
|
|
|
if (palEnd < 0)
|
|
|
|
palEnd = 255;
|
|
|
|
|
2010-08-08 01:08:17 +00:00
|
|
|
palStart = palStart * 3;
|
|
|
|
palEnd = (palEnd + 1) * 3;
|
|
|
|
|
|
|
|
for (int i = palStart; i <= palEnd; i++)
|
|
|
|
((char *)(_vm->_global->_pPaletteDesc->vgaPal))[i] = video.decoder->getPalette()[i] >> 2;
|
2008-05-08 15:51:02 +00:00
|
|
|
}
|
|
|
|
|
2007-07-30 15:53:38 +00:00
|
|
|
} // End of namespace Gob
|