Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on Wintermute Engine
* http://dead-code.org/redir.php?target=wme
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/video/subtitle_card.h"
#include "engines/wintermute/base/base_game.h"
namespace Wintermute {
SubtitleCard::SubtitleCard(BaseGame *inGame,
const Common::String &text,
const uint &startFrame,
const uint &endFrame) :
_game(inGame),
_startFrame(startFrame),
_endFrame(endFrame) {
_text = text;
_game->_stringTable->expand(_text);
}
uint32 SubtitleCard::getStartFrame() const {
return _startFrame;
}
uint32 SubtitleCard::getEndFrame() const {
return _endFrame;
}
Common::String SubtitleCard::getText() const {
return _text;
}
} // End of namespace Wintermute

View File

@@ -0,0 +1,52 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on Wintermute Engine
* http://dead-code.org/redir.php?target=wme
* Copyright (c) 2011 Jan Nedoma
*/
#ifndef WINTERMUTE_SUBTITLECARD_H
#define WINTERMUTE_SUBTITLECARD_H
#include "common/str.h"
namespace Wintermute {
class BaseGame;
class SubtitleCard {
public:
SubtitleCard(BaseGame *inGame, const Common::String &text, const uint &startFrame, const uint &endFrame);
uint32 getEndFrame() const;
uint32 getStartFrame() const;
Common::String getText() const;
private:
BaseGame *_game;
uint32 _endFrame;
uint32 _startFrame;
Common::String _text;
};
} // End of namespace Wintermute
#endif

View File

@@ -0,0 +1,264 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/video/video_player.h"
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/base_engine.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/base/gfx/base_surface.h"
#include "engines/wintermute/platform_osystem.h"
#include "engines/wintermute/dcgf.h"
namespace Wintermute {
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
VideoPlayer::VideoPlayer(BaseGame *inGame) : BaseClass(inGame) {
setDefaults();
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::setDefaults() {
_playing = false;
_aviDecoder = nullptr;
_playPosX = _playPosY = 0;
_playZoom = 0.0f;
_texture = nullptr;
_videoFrameReady = false;
_playbackStarted = false;
_freezeGame = false;
_filename.clear();
_subtitler = nullptr;
_foundSubtitles = false;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
VideoPlayer::~VideoPlayer() {
cleanup();
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::cleanup() {
_playing = false;
SAFE_DELETE(_subtitler);
if (_aviDecoder) {
_aviDecoder->close();
}
SAFE_DELETE(_aviDecoder);
SAFE_DELETE(_texture);
return setDefaults();
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::initialize(const Common::String &filename, const Common::String &subtitleFile) {
cleanup();
if (BaseEngine::instance().getGameId() == "sof1" ||
BaseEngine::instance().getGameId() == "sof2") {
warning("PlayVideo: %s - Xvid support not implemented yet", filename.c_str());
return STATUS_FAILED;
}
_filename = filename;
// Load a file, but avoid having the File-manager handle the disposal of it.
Common::SeekableReadStream *file = BaseFileManager::getEngineInstance()->openFile(filename, true, false);
if (!file) {
return STATUS_FAILED;
}
_aviDecoder = new Video::AVIDecoder();
_aviDecoder->loadStream(file);
_subtitler = new VideoSubtitler(_game);
_foundSubtitles = _subtitler->loadSubtitles(_filename, subtitleFile);
if (!_aviDecoder->isVideoLoaded()) {
// W/A: Missing DX50 decoder support for 'Looky' game.
if (BaseEngine::instance().getGameId() == "looky")
return STATUS_OK;
return STATUS_FAILED;
}
// Additional setup.
_texture = _game->_renderer->createSurface();
_texture->create(_aviDecoder->getWidth(), _aviDecoder->getHeight());
_playZoom = 100;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::update() {
if (!isPlaying()) {
return STATUS_OK;
}
if (_playbackStarted) {
return STATUS_OK;
}
if (_playbackStarted && !_freezeGame && _game->_state == GAME_FROZEN) {
return STATUS_OK;
}
if (_subtitler && _foundSubtitles && _game->_subtitles) {
_subtitler->update(_aviDecoder->getCurFrame());
}
if (_aviDecoder->endOfVideo()) {
_playbackStarted = false;
if (_freezeGame) {
_game->unfreeze();
}
}
if (!_aviDecoder->endOfVideo() && _aviDecoder->getTimeToNextFrame() == 0) {
const Graphics::Surface *decodedFrame = _aviDecoder->decodeNextFrame();
if (decodedFrame && _texture) {
_texture->putSurface(*decodedFrame, false);
_videoFrameReady = true;
}
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::display() {
Common::Rect32 rc;
bool res;
if (_texture && _videoFrameReady) {
BasePlatform::setRect(&rc, 0, 0, _texture->getWidth(), _texture->getHeight());
if (_playZoom == 100.0f) {
res = _texture->display(_playPosX, _playPosY, rc);
} else {
res = _texture->displayTransZoom(_playPosX, _playPosY, rc, _playZoom, _playZoom);
}
} else {
res = STATUS_FAILED;
}
if (_subtitler && _foundSubtitles && _game->_subtitles) {
_subtitler->display();
}
return res;
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::play(TVideoPlayback type, int x, int y, bool freezeMusic) {
if (!_aviDecoder)
return STATUS_FAILED;
if (!_playbackStarted && freezeMusic) {
_game->freeze(freezeMusic);
_freezeGame = freezeMusic;
}
_playbackStarted = false;
float width, height;
if (_aviDecoder) {
if (_subtitler && _foundSubtitles && _game->_subtitles) {
_subtitler->update(_aviDecoder->getFrameCount());
_subtitler->display();
}
_playPosX = x;
_playPosY = y;
width = (float)_aviDecoder->getWidth();
height = (float)_aviDecoder->getHeight();
} else {
width = (float)_game->_renderer->getWidth();
height = (float)_game->_renderer->getHeight();
}
switch (type) {
case VID_PLAY_POS:
_playZoom = 100.0f;
_playPosX = x;
_playPosY = y;
break;
case VID_PLAY_STRETCH: {
float zoomX = (float)((float)_game->_renderer->getWidth() / width * 100);
float zoomY = (float)((float)_game->_renderer->getHeight() / height * 100);
_playZoom = MIN(zoomX, zoomY);
_playPosX = (int)((_game->_renderer->getWidth() - width * (_playZoom / 100)) / 2);
_playPosX = (int)((_game->_renderer->getHeight() - height * (_playZoom / 100)) / 2);
}
break;
case VID_PLAY_CENTER:
_playZoom = 100.0f;
_playPosX = (int)((_game->_renderer->getWidth() - width) / 2);
_playPosY = (int)((_game->_renderer->getHeight() - height) / 2);
break;
default:
break;
}
if (_aviDecoder)
_aviDecoder->start();
_playing = true;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::stop() {
_aviDecoder->close();
cleanup();
if (_freezeGame)
_game->unfreeze();
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoPlayer::isPlaying() {
return _playing;
}
} // End of namespace Wintermute

View File

@@ -0,0 +1,78 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#ifndef WINTERMUTE_VIDPLAYER_H
#define WINTERMUTE_VIDPLAYER_H
#include "video/avi_decoder.h"
#include "engines/wintermute/dctypes.h" // Added by ClassView
#include "engines/wintermute/base/base.h"
#include "engines/wintermute/video/video_subtitler.h"
#include "graphics/surface.h"
#define MAX_AUDIO_STREAMS 5
#define MAX_VIDEO_STREAMS 5
namespace Wintermute {
class BaseSurface;
// AVI-Video-player
class VideoPlayer : public BaseClass {
public:
bool isPlaying();
// external object
Common::String _filename;
bool stop();
bool play(TVideoPlayback Type = VID_PLAY_CENTER, int x = 0, int y = 0, bool freezeMusic = true);
Video::AVIDecoder *_aviDecoder;
bool setDefaults();
bool _playing;
bool display();
bool update();
bool initialize(const Common::String &filename, const Common::String &subtitleFile = Common::String());
bool cleanup();
VideoPlayer(BaseGame *inGame);
~VideoPlayer() override;
BaseSurface *_texture;
VideoSubtitler *_subtitler;
int32 _playPosX;
int32 _playPosY;
float _playZoom;
private:
bool _foundSubtitles;
bool _videoFrameReady;
bool _playbackStarted;
bool _freezeGame;
};
} // End of namespace Wintermute
#endif

View File

@@ -0,0 +1,261 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on Wintermute Engine
* http://dead-code.org/redir.php?target=wme
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/video/video_subtitler.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/utils/path_util.h"
#include "engines/wintermute/base/font/base_font.h"
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
namespace Wintermute {
VideoSubtitler::VideoSubtitler(BaseGame *inGame): BaseClass(inGame) {
_lastSample = -1;
_currentSubtitle = 0;
_showSubtitle = false;
}
VideoSubtitler::~VideoSubtitler() {
_subtitles.clear();
}
bool VideoSubtitler::loadSubtitles(const Common::String &filename, const Common::String &subtitleFile) {
if (filename.size() == 0) {
return false;
}
_subtitles.clear();
_lastSample = -1;
_currentSubtitle = 0;
_showSubtitle = false;
Common::String newFile;
/*
* Okay, the expected behaviour is this: either we are
* provided with a subtitle file to use by the script when
* calling PlayTheora(), or we try to autodetect a suitable
* one which, for /some/path/movie/ogg is to be called
* /some/path/movie.sub
*/
if (subtitleFile.size() != 0) {
newFile = subtitleFile;
} else {
Common::String path = PathUtil::getDirectoryName(filename);
Common::String name = PathUtil::getFileNameWithoutExtension(filename);
Common::String ext = ".SUB";
newFile = PathUtil::combine(path, name + ext);
}
uint32 fileSize;
char *buffer = (char *)BaseFileManager::getEngineInstance()->readWholeFile(newFile, &fileSize);
if (buffer == nullptr) {
return false; // no subtitles
}
/* This is where we parse .sub files.
* Subtitles cards are in the form
* {StartFrame}{EndFrame} FirstLine | SecondLine \n
*/
uint32 pos = 0;
while (pos < fileSize) {
char *tokenStart = 0;
int tokenLength = 0;
int tokenPos = -1;
int lineLength = 0;
int start = -1;
int end = -1;
bool inToken = false;
while (pos + lineLength < fileSize &&
buffer[pos + lineLength] != '\n' &&
buffer[pos + lineLength] != '\0') {
// Measure the line until we hit EOL, EOS or just hit the boundary
lineLength++;
}
int realLength;
if (pos + lineLength >= fileSize) {
realLength = lineLength - 0;
} else {
// If we got here the above loop exited after hitting "\0" "\n"
realLength = lineLength - 1;
}
Common::String cardText;
char *fileLine = &buffer[pos];
for (int i = 0; i < realLength; i++) {
if (fileLine[i] == '{') {
if (!inToken) {
// We've hit the start of a Start/EndFrame token
inToken = true;
tokenStart = fileLine + i + 1;
tokenLength = 0;
tokenPos++;
} else {
// Actually, we were already inside an (invalid) one.
tokenLength++;
}
} else if (fileLine[i] == '}') {
if (inToken) {
// we were /inside/ a {.*} token, so this is the end of the block
inToken = false;
char *token = new char[tokenLength + 1];
strncpy(token, tokenStart, tokenLength);
token[tokenLength] = '\0';
if (tokenPos == 0) {
// Was this StartFrame...
start = atoi(token);
} else if (tokenPos == 1) {
// Or the EndFrame?
end = atoi(token);
}
delete[] token;
} else {
// This char is part of the plain text, just append it
cardText += fileLine[i];
}
} else {
if (inToken) {
tokenLength++;
} else {
if (fileLine[i] == '|') {
// The pipe character signals a linebreak in the text
cardText += '\n';
} else {
// This char is part of the plain text, just append it
cardText += fileLine[i];
}
}
}
}
if (start != -1 && cardText.size() > 0 && (start != 1 || end != 1)){
// Add a subtitlecard based on the line we have just parsed
_subtitles.push_back(SubtitleCard(_game, cardText, start, end));
}
pos += lineLength + 1;
}
delete[] buffer;
// Succeeded loading subtitles!
return true;
}
void VideoSubtitler::display() {
if (_showSubtitle) {
BaseFont *font;
if (_game->_videoFont == nullptr) {
font = _game->_systemFont;
} else {
font = _game->_videoFont;
}
int textHeight = font->getTextHeight(
(const byte *)_subtitles[_currentSubtitle].getText().c_str(),
_game->_renderer->getWidth());
font->drawText(
(const byte *)_subtitles[_currentSubtitle].getText().c_str(),
0,
(_game->_renderer->getHeight() - textHeight - 5),
(_game->_renderer->getWidth()),
TAL_CENTER);
}
}
void VideoSubtitler::update(uint32 frame) {
if (_subtitles.size() == 0) {
// Edge case: we have loaded subtitles early on... from a blank file.
return;
}
if ((int32)frame != _lastSample) {
/*
* If the frame count hasn't advanced the previous state still matches
* the current frame (obviously).
*/
_lastSample = frame;
// Otherwise, we update _lastSample; see above.
_showSubtitle = false;
bool overdue = (frame > _subtitles[_currentSubtitle].getEndFrame());
bool hasNext = (_currentSubtitle + 1 < _subtitles.size());
bool nextStarted = false;
if (hasNext) {
nextStarted = (_subtitles[_currentSubtitle + 1].getStartFrame() <= frame);
}
while (_currentSubtitle < _subtitles.size() &&
overdue && hasNext && nextStarted) {
/*
* We advance until we get past all overdue subtitles.
* We should exit the cycle when we either reach the first
* subtitle which is not overdue whose subsequent subtitle
* has not started yet (aka the one we must display now or
* the one which WILL be displayed when its time comes)
* and / or when we reach the last one.
*/
_currentSubtitle++;
overdue = (frame > _subtitles[_currentSubtitle].getEndFrame());
hasNext = (_currentSubtitle + 1 < _subtitles.size());
if (hasNext) {
nextStarted = (_subtitles[_currentSubtitle + 1].getStartFrame() <= frame);
} else {
nextStarted = false;
}
}
bool currentValid = (_subtitles[_currentSubtitle].getEndFrame() != 0);
/*
* No idea why we do this check, carried over from Mnemonic's code.
* Possibly a workaround for buggy subtitles or some kind of sentinel? :-\
*/
bool currentStarted = frame >= _subtitles[_currentSubtitle].getStartFrame();
if (currentStarted && !overdue && currentValid) {
_showSubtitle = true;
}
}
}
} // End of namespace Wintermute

View File

@@ -0,0 +1,52 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on Wintermute Engine
* http://dead-code.org/redir.php?target=wme
* Copyright (c) 2011 Jan Nedoma
*/
#ifndef WINTERMUTE_VIDSUBTITLER_H
#define WINTERMUTE_VIDSUBTITLER_H
#include "engines/wintermute/base/base.h"
#include "engines/wintermute/video/subtitle_card.h"
namespace Wintermute {
class VideoSubtitler : public BaseClass {
public:
VideoSubtitler(BaseGame *inGame);
~VideoSubtitler() override;
bool _showSubtitle;
uint32 _currentSubtitle;
bool loadSubtitles(const Common::String &filename, const Common::String &subtitleFile);
void display();
void update(uint32 frame);
int32 _lastSample;
Common::Array<SubtitleCard> _subtitles;
};
} // End of namespace Wintermute
#endif

View File

@@ -0,0 +1,484 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#include "engines/wintermute/video/video_theora_player.h"
#include "engines/wintermute/base/base_game.h"
#include "engines/wintermute/base/base_file_manager.h"
#include "engines/wintermute/base/gfx/base_surface.h"
#include "engines/wintermute/base/gfx/base_image.h"
#include "engines/wintermute/base/gfx/base_renderer.h"
#include "engines/wintermute/base/sound/base_sound_manager.h"
#include "engines/wintermute/platform_osystem.h"
#include "engines/wintermute/wintermute.h"
#include "engines/wintermute/utils/utils.h"
#include "engines/wintermute/dcgf.h"
#include "video/theora_decoder.h"
#include "common/system.h"
namespace Wintermute {
IMPLEMENT_PERSISTENT(VideoTheoraPlayer, false)
//////////////////////////////////////////////////////////////////////////
VideoTheoraPlayer::VideoTheoraPlayer(BaseGame *inGame) : BaseClass(inGame) {
setDefaults();
}
//////////////////////////////////////////////////////////////////////////
void VideoTheoraPlayer::setDefaults() {
_filename = "";
_startTime = 0;
_looping = false;
_freezeGame = false;
_currentTime = 0;
_state = THEORA_STATE_NONE;
_videoFrameReady = false;
_audioFrameReady = false;
_videobufTime = 0;
_playbackStarted = false;
_dontDropFrames = false;
_texture = nullptr;
_alphaFilename = nullptr;
_frameRendered = false;
_seekingKeyframe = false;
_timeOffset = 0.0f;
_posX = _posY = 0;
_playbackType = VID_PLAY_CENTER;
_playZoom = 0.0f;
_savedState = THEORA_STATE_NONE;
_savedPos = 0;
_volume = 100;
_theoraDecoder = nullptr;
_subtitler = nullptr;
_foundSubtitles = false;
}
//////////////////////////////////////////////////////////////////////////
VideoTheoraPlayer::~VideoTheoraPlayer() {
cleanup();
}
//////////////////////////////////////////////////////////////////////////
void VideoTheoraPlayer::cleanup() {
if (_theoraDecoder) {
_theoraDecoder->close();
}
SAFE_DELETE(_subtitler);
SAFE_DELETE(_theoraDecoder);
SAFE_DELETE(_texture);
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::initialize(const Common::String &filename, const Common::String &subtitleFile) {
cleanup();
_filename = filename;
#if defined (USE_THEORADEC)
// Load a file, but avoid having the File-manager handle the disposal of it.
Common::SeekableReadStream *file = BaseFileManager::getEngineInstance()->openFile(filename, true, false);
if (!file) {
return STATUS_FAILED;
}
_theoraDecoder = new Video::TheoraDecoder();
_theoraDecoder->loadStream(file);
#else
warning("VideoTheoraPlayer::initialize - Theora support not compiled in, video will be skipped: %s", filename.c_str());
return STATUS_FAILED;
#endif
_subtitler = new VideoSubtitler(_game);
_foundSubtitles = _subtitler->loadSubtitles(_filename, subtitleFile);
if (!_theoraDecoder->isVideoLoaded()) {
return STATUS_FAILED;
}
_state = THEORA_STATE_PAUSED;
// Additional setup.
_texture = _game->_renderer->createSurface();
_texture->create(_theoraDecoder->getWidth(), _theoraDecoder->getHeight());
_state = THEORA_STATE_PLAYING;
_playZoom = 100;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::resetStream() {
// HACK: Just reopen the same file again.
if (_theoraDecoder) {
_theoraDecoder->close();
}
SAFE_DELETE(_theoraDecoder);
#if defined (USE_THEORADEC)
// Load a file, but avoid having the File-manager handle the disposal of it.
Common::SeekableReadStream *file = BaseFileManager::getEngineInstance()->openFile(_filename, true, false);
if (!file) {
return STATUS_FAILED;
}
_theoraDecoder = new Video::TheoraDecoder();
_theoraDecoder->loadStream(file);
#else
return STATUS_FAILED;
#endif
if (!_theoraDecoder->isVideoLoaded()) {
return STATUS_FAILED;
}
return play(_playbackType, _posX, _posY, false, false, _looping, 0, _playZoom);
// End of hack.
#if 0 // Stubbed for now, as theora isn't seekable
if (_sound) {
_sound->Stop();
}
m_TimeOffset = 0.0f;
Initialize(m_Filename);
Play(m_PlaybackType, m_PosX, m_PosY, false, false, m_Looping, 0, m_PlayZoom);
#endif
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::play(TVideoPlayback type, int x, int y, bool freezeGame, bool freezeMusic, bool looping, uint32 startTime, float forceZoom, int volume) {
if (forceZoom < 0.0f) {
forceZoom = 100.0f;
}
if (volume < 0) {
_volume = _game->_soundMgr->getVolumePercent(TSoundType::SOUND_SFX);
} else {
_volume = volume;
}
_freezeGame = freezeGame;
if (!_playbackStarted && _freezeGame) {
_game->freeze(freezeMusic);
}
_playbackStarted = false;
float width, height;
if (_theoraDecoder) {
_state = THEORA_STATE_PLAYING;
_looping = looping;
_playbackType = type;
if (_subtitler && _foundSubtitles && _game->_subtitles) {
_subtitler->update(_theoraDecoder->getFrameCount());
_subtitler->display();
}
_startTime = startTime;
_volume = volume;
_posX = x;
_posY = y;
_playZoom = forceZoom;
width = (float)_theoraDecoder->getWidth();
height = (float)_theoraDecoder->getHeight();
} else {
width = (float)_game->_renderer->getWidth();
height = (float)_game->_renderer->getHeight();
}
switch (type) {
case VID_PLAY_POS:
_playZoom = forceZoom;
_posX = x;
_posY = y;
break;
case VID_PLAY_STRETCH: {
float zoomX = (float)((float)_game->_renderer->getWidth() / width * 100);
float zoomY = (float)((float)_game->_renderer->getHeight() / height * 100);
_playZoom = MIN(zoomX, zoomY);
_posX = (int)((_game->_renderer->getWidth() - width * (_playZoom / 100)) / 2);
_posY = (int)((_game->_renderer->getHeight() - height * (_playZoom / 100)) / 2);
}
break;
case VID_PLAY_CENTER:
_playZoom = 100.0f;
_posX = (int)((_game->_renderer->getWidth() - width) / 2);
_posY = (int)((_game->_renderer->getHeight() - height) / 2);
break;
default:
break;
}
if (_theoraDecoder)
_theoraDecoder->start();
return STATUS_OK;
#if 0 // Stubbed for now as theora isn't seekable
if (StartTime) SeekToTime(StartTime);
update();
#endif
return STATUS_FAILED;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::stop() {
_theoraDecoder->close();
_state = THEORA_STATE_FINISHED;
if (_freezeGame) {
_game->unfreeze();
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::update() {
_currentTime = _freezeGame ? _game->_liveTimer : _game->_timer;
if (!isPlaying()) {
return STATUS_OK;
}
if (_playbackStarted /*&& m_Sound && !m_Sound->IsPlaying()*/) {
return STATUS_OK;
}
if (_playbackStarted && !_freezeGame && _game->_state == GAME_FROZEN) {
return STATUS_OK;
}
if (_theoraDecoder) {
if (_subtitler && _foundSubtitles && _game->_subtitles) {
int curFrame = _theoraDecoder->getCurFrame();
if (curFrame != -1) { // passing UINT32_MAX would skip all subtitles!
_subtitler->update(curFrame);
}
}
if (_theoraDecoder->endOfVideo() && _looping) {
_theoraDecoder->rewind();
// HACK: Just reinitialize the same video again
return resetStream();
} else if (_theoraDecoder->endOfVideo() && !_looping) {
debugC(kWintermuteDebugLog, "Finished movie %s", _filename.c_str());
_state = THEORA_STATE_FINISHED;
_playbackStarted = false;
if (_freezeGame) {
_game->unfreeze();
}
}
if (_state == THEORA_STATE_PLAYING) {
if (!_theoraDecoder->endOfVideo() && _theoraDecoder->getTimeToNextFrame() == 0) {
const Graphics::Surface *decodedFrame = _theoraDecoder->decodeNextFrame();
if (decodedFrame && _texture) {
writeVideo(decodedFrame);
}
}
return STATUS_OK;
}
}
// Skip the busy-loop?
if ((!_texture || !_videoFrameReady) && _theoraDecoder && !_theoraDecoder->endOfVideo()) {
// end playback
if (!_looping) {
_state = THEORA_STATE_FINISHED;
if (_freezeGame) {
_game->unfreeze();
}
return STATUS_OK;
} else {
resetStream();
return STATUS_OK;
}
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
uint32 VideoTheoraPlayer::getMovieTime() const {
if (!_playbackStarted) {
return 0;
} else {
return _theoraDecoder->getTime();
}
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::writeVideo(const Graphics::Surface *decodedFrame) {
if (!_texture) {
return STATUS_FAILED;
}
_texture->putSurface(*decodedFrame, false);
//RenderFrame(_texture, &yuv);
_videoFrameReady = true;
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::display(uint32 alpha) {
Common::Rect32 rc;
bool res;
if (_texture && _videoFrameReady) {
BasePlatform::setRect(&rc, 0, 0, _texture->getWidth(), _texture->getHeight());
if (_playZoom == 100.0f) {
res = _texture->displayTrans(_posX, _posY, rc, alpha);
} else {
res = _texture->displayTransZoom(_posX, _posY, rc, _playZoom, _playZoom, alpha);
}
} else {
res = STATUS_FAILED;
}
if (_subtitler && _foundSubtitles && _game->_subtitles) {
_subtitler->display();
}
return res;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::setAlphaImage(const char *filename) {
assert(_texture);
if (!filename || !_texture || DID_FAIL(_texture->setAlphaImage(filename))) {
SAFE_DELETE_ARRAY(_alphaFilename);
return STATUS_FAILED;
}
if (_alphaFilename != filename) {
BaseUtils::setString(&_alphaFilename, filename);
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
inline int intlog(int num) {
int r = 0;
while (num > 0) {
num = num / 2;
r = r + 1;
}
return r;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::seekToTime(uint32 time) {
error("VideoTheoraPlayer::SeekToTime(%d) - not supported", time);
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::pause() {
if (_state == THEORA_STATE_PLAYING) {
_state = THEORA_STATE_PAUSED;
_theoraDecoder->pauseVideo(true);
return STATUS_OK;
} else {
return STATUS_FAILED;
}
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::resume() {
if (_state == THEORA_STATE_PAUSED) {
_state = THEORA_STATE_PLAYING;
_theoraDecoder->pauseVideo(false);
return STATUS_OK;
} else {
return STATUS_FAILED;
}
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::persist(BasePersistenceManager *persistMgr) {
//BaseClass::persist(persistMgr);
if (persistMgr->getIsSaving()) {
_savedPos = getMovieTime() * 1000;
_savedState = _state;
} else {
setDefaults();
}
persistMgr->transferPtr(TMEMBER_PTR(_game));
persistMgr->transferUint32(TMEMBER(_savedPos));
persistMgr->transferSint32(TMEMBER(_savedState));
persistMgr->transferString(TMEMBER(_filename));
persistMgr->transferCharPtr(TMEMBER(_alphaFilename));
persistMgr->transferSint32(TMEMBER(_posX));
persistMgr->transferSint32(TMEMBER(_posY));
persistMgr->transferFloat(TMEMBER(_playZoom));
persistMgr->transferSint32(TMEMBER_INT(_playbackType));
persistMgr->transferBool(TMEMBER(_looping));
persistMgr->transferSint32(TMEMBER(_volume));
if (!persistMgr->getIsSaving() && (_savedState != THEORA_STATE_NONE)) {
initializeSimple();
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
bool VideoTheoraPlayer::initializeSimple() {
if (DID_SUCCEED(initialize(_filename))) {
if (_alphaFilename && _alphaFilename[0]) {
setAlphaImage(_alphaFilename);
}
play(_playbackType, _posX, _posY, false, false, _looping, _savedPos, _playZoom);
} else {
_state = THEORA_STATE_FINISHED;
}
return STATUS_OK;
}
//////////////////////////////////////////////////////////////////////////
BaseSurface *VideoTheoraPlayer::getTexture() const {
return _texture;
}
} // End of namespace Wintermute

View File

@@ -0,0 +1,143 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
/*
* This file is based on WME Lite.
* http://dead-code.org/redir.php?target=wmelite
* Copyright (c) 2011 Jan Nedoma
*/
#ifndef WINTERMUTE_VIDTHEORAPLAYER_H
#define WINTERMUTE_VIDTHEORAPLAYER_H
#include "engines/wintermute/base/base.h"
#include "engines/wintermute/persistent.h"
#include "engines/wintermute/video/video_subtitler.h"
#include "video/video_decoder.h"
#include "common/stream.h"
#include "graphics/surface.h"
namespace Wintermute {
class BaseSurface;
class BaseImage;
class VideoTheoraPlayer : public BaseClass {
private:
enum {
THEORA_STATE_NONE = 0,
THEORA_STATE_PLAYING = 1,
THEORA_STATE_PAUSED = 2,
THEORA_STATE_FINISHED = 3
};
Video::VideoDecoder *_theoraDecoder;
public:
DECLARE_PERSISTENT(VideoTheoraPlayer, BaseClass)
VideoTheoraPlayer(BaseGame *inGame);
~VideoTheoraPlayer() override;
// external objects
Common::String _filename;
BaseSurface *_texture;
VideoSubtitler *_subtitler;
// control methods
bool initialize(const Common::String &filename, const Common::String &subtitleFile = Common::String());
bool initializeSimple();
bool update();
bool play(TVideoPlayback type = VID_PLAY_CENTER, int x = 0, int y = 0, bool freezeGame = false, bool freezeMusic = true, bool looping = false, uint32 startTime = 0, float forceZoom = -1.0f, int volume = -1);
bool stop();
bool display(uint32 alpha = 0xFFFFFFFF);
bool pause();
bool resume();
bool isPlaying() const {
return _state == THEORA_STATE_PLAYING;
};
bool isFinished() const {
return _state == THEORA_STATE_FINISHED;
};
bool isPaused() const {
return _state == THEORA_STATE_PAUSED;
};
uint32 getMovieTime() const;
BaseSurface *getTexture() const;
// alpha related
char *_alphaFilename;
bool setAlphaImage(const char *filename);
bool seekToTime(uint32 Time);
void cleanup();
bool resetStream();
// video properties
int32 _posX;
int32 _posY;
bool _dontDropFrames;
private:
int32 _state;
uint32 _startTime;
int32 _savedState;
uint32 _savedPos;
// video properties
TVideoPlayback _playbackType;
bool _looping;
float _playZoom;
int32 _volume;
bool _freezeGame;
uint32 _currentTime;
// seeking support
bool _seekingKeyframe;
float _timeOffset;
bool _frameRendered;
bool getIsFrameReady() const {
return _videoFrameReady;
}
bool _audioFrameReady;
bool _videoFrameReady;
float _videobufTime;
bool writeVideo(const Graphics::Surface *decodedFrame);
bool _playbackStarted;
bool _foundSubtitles;
// helpers
void setDefaults();
};
} // End of namespace Wintermute
#endif