1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
/* 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/>.
*
*/
#include "common/config-manager.h"
#include "common/file.h"
#include "graphics/managed_surface.h"
#include "video/mpegps_decoder.h"
#include "qdengine/qdengine.h"
#include "qdengine/qdcore/util/WinVideo.h"
#include "qdengine/system/graphics/gr_dispatcher.h"
namespace QDEngine {
bool winVideo::_is_initialized = false;
winVideo::winVideo() {
_decoder = new Video::MPEGPSDecoder();
_x = _y = 0;
_vidWidth = _vidHeight = 0;
_videostream = nullptr;
}
winVideo::~winVideo() {
close_file();
delete _decoder;
}
bool winVideo::init() {
return true;
}
bool winVideo::done() {
if (!_is_initialized)
return false;
_is_initialized = false;
return true;
}
void winVideo::set_window(int x, int y, int xsize, int ysize) {
_x = x;
_y = y;
_vidWidth = xsize;
_vidHeight = ysize;
delete _tempSurf;
_tempSurf = nullptr;
if (_vidWidth != _decoder->getWidth() || _vidHeight != _decoder->getHeight())
_tempSurf = new Graphics::ManagedSurface(xsize, ysize, g_engine->_pixelformat);
}
bool winVideo::open_file(const Common::Path fname) {
Common::String filename = (char *)transCyrillic(fname.toString());
debugC(3, kDebugLoad, "winVideo::open_file(%s)", filename.c_str());
_videostream = new Common::File();
if (!_videostream->open(filename.c_str())) {
warning("WinVideo::open: Failed to open file %s", filename.c_str());
delete _videostream;
_videostream = nullptr;
return false;
}
if (!_decoder->loadStream(_videostream)) {
warning("WinVideo::open: Failed to Load Stream for file '%s'", filename.c_str());
_videostream = nullptr;
return false;
}
return true;
}
bool winVideo::play() {
if (!_videostream) {
warning("WinVideo::play: No video stream loaded");
return false;
}
_decoder->setVolume(ConfMan.getInt("music_volume"));
_decoder->start();
return true;
}
bool winVideo::quant() {
debugC(9, kDebugGraphics, "WinVideo::play: Video Playback loop");
// Video Playback loop
if (_decoder->needsUpdate()) {
const Graphics::Surface *frame = _decoder->decodeNextFrame();
int frameWidth = _decoder->getWidth();
int frameHeight = _decoder->getHeight();
const Graphics::Surface *surf = frame;
if (frame) {
if (_tempSurf) {
const Common::Rect srcRect(0, 0, frameWidth, frameHeight);
const Common::Rect destRect(0, 0, _vidWidth, _vidHeight);
_tempSurf->blitFrom(*frame, srcRect, destRect);
surf = _tempSurf->surfacePtr();
}
g_system->copyRectToScreen(surf->getPixels(), surf->pitch, _x, _y, _vidWidth, _vidHeight);
}
g_system->delayMillis(10);
g_system->updateScreen();
}
return true;
}
bool winVideo::stop() {
delete _tempSurf;
_tempSurf = NULL;
return true;
}
bool winVideo::is_playback_finished() {
return _decoder->endOfVideo();
}
bool winVideo::get_movie_size(int &sx, int &sy) {
if (!_decoder)
return false;
sx = _decoder->getWidth();
sy = _decoder->getHeight();
return true;
}
void winVideo::close_file() {
if (_videostream)
_videostream->close();
}
} // namespace QDEngine
|