Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Video Player - Proof of Concept #3143

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
#endif

namespace {
#ifdef SUPPORT_MOVIES
auto MOVIE_TYPES = { ".avi", ".mpg" };
#endif
//#ifdef SUPPORT_MOVIES
constexpr const auto MOVIE_TYPES = Utils::MakeSvArray( ".mov", ".mp4", ".webm", ".ogv", ".avi", ".mpg");
//#endif

std::string fonts_path;
std::shared_ptr<Filesystem> root_fs;
Expand Down Expand Up @@ -358,6 +358,12 @@ std::string FileFinder::FindMusic(StringView name) {

}

std::string FileFinder::FindMovie(StringView name) {
DirectoryTree::Args args = { MakePath("Movie", name), MOVIE_TYPES, 1, true };
return find_generic(args);

}

std::string FileFinder::FindSound(StringView name) {
DirectoryTree::Args args = { MakePath("Sound", name), SOUND_TYPES, 1, false };
return find_generic(args);
Expand Down
2 changes: 2 additions & 0 deletions src/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ namespace FileFinder {
*/
std::string FindMusic(StringView name);

std::string FindMovie(StringView name);

/**
* Finds a sound file in the current RPG Maker game.
*
Expand Down
4 changes: 2 additions & 2 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,10 @@ bool Game_Interpreter_Map::CommandPlayMovie(lcf::rpg::EventCommand const& com) {
int res_x = com.parameters[3];
int res_y = com.parameters[4];

Output::Warning("Couldn't play movie: {}. Movie playback is not implemented (yet).", filename);
//Output::Warning("Couldn't play movie: {}. Movie playback is not implemented (yet).", filename);

Main_Data::game_screen->PlayMovie(filename, pos_x, pos_y, res_x, res_y);

_state.wait_time = 5;
return true;
}

Expand Down
73 changes: 71 additions & 2 deletions src/game_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include "flash.h"
#include "shake.h"
#include "rand.h"
#include <Windows.h> //#include <cstdlib> // For system function
#include <iostream>
#include "baseui.h"

Game_Screen::Game_Screen()
{
Expand Down Expand Up @@ -170,12 +173,78 @@ void Game_Screen::SetWeatherEffect(int type, int strength) {
}

void Game_Screen::PlayMovie(std::string filename,
int pos_x, int pos_y, int res_x, int res_y) {
movie_filename = std::move(filename);
int pos_x, int pos_y, int res_x, int res_y) {

movie_pos_x = pos_x;
movie_pos_y = pos_y;
movie_res_x = res_x;
movie_res_y = res_y;
movie_filename = filename;

Rect metrics = DisplayUi->GetWindowMetrics();
int w = metrics.width;
int h = metrics.height;
int x = metrics.x;
int y = metrics.y;

const auto& config = DisplayUi->GetConfig();
std::string fs = int(DisplayUi->IsFullscreen()) ? "-fs" : "";
std::string stretch = int(config.stretch.Get()) ? "-vf \"setdar = 16 / 9\"" : "";
int zoom = config.window_zoom.Get();

std::string path = FileFinder::GetFullFilesystemPath(FileFinder::Game());
if (path.empty()) path = "%cd%";

std::string movie_src = path + "/" + FileFinder::FindMovie(movie_filename);

std::string pluginPath = path + "/Plugin/ffplay.exe";

std::string xtraParams = "-noborder -autoexit -fast -nostats -alwaysontop -exitonmousedown -exitonkeydown";

std::string command = fmt::format(
"{} -i \"{}\" -left {} -top {} -x {} -y {} {} {} {}" ,
pluginPath, movie_src, x, y, w, h, fs, stretch, xtraParams);

Output::Debug("\n\ncmd: {}\n\n", command);

// Define a structure to set up the startup information
STARTUPINFO startupInfo;
PROCESS_INFORMATION processInfo;

HWND oldWindow = GetForegroundWindow();

ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.dwFlags = STARTF_USESHOWWINDOW;
startupInfo.wShowWindow = SW_SHOWNORMAL; // Show the window normally
ZeroMemory(&processInfo, sizeof(processInfo));

std::wstring wideCommand = std::wstring(command.begin(), command.end());
if (CreateProcess(nullptr,
const_cast<LPWSTR>(wideCommand.c_str()), // Command to execute
nullptr, // Process handle not inheritable
nullptr, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
nullptr, // Use parent's environment block
nullptr, // Use parent's starting directory
&startupInfo, // Pointer to STARTUPINFO structure
&processInfo) // Pointer to PROCESS_INFORMATION structure)
) {
WaitForSingleObject(processInfo.hProcess, INFINITE);

// Close handles
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);

// Bring focus back to the old window
SetForegroundWindow(oldWindow);
}
else {
Output::Warning("CreateProcess failed, Error Code: {}", GetLastError());
}

Player::Resume();
}

static double interpolate(double d, double x0, double x1)
Expand Down
Loading