From 4428ddaa6dabaa3daf5659bf3dda80325f56a091 Mon Sep 17 00:00:00 2001 From: Tomas Jakobsson Date: Fri, 19 Jan 2018 02:09:49 +0100 Subject: [PATCH] Fix omxplayer when using --screensize, --screenoffset and --screenrotate --- .../src/components/VideoPlayerComponent.cpp | 71 ++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) diff --git a/es-core/src/components/VideoPlayerComponent.cpp b/es-core/src/components/VideoPlayerComponent.cpp index 64a67793f..8f0ef8df2 100644 --- a/es-core/src/components/VideoPlayerComponent.cpp +++ b/es-core/src/components/VideoPlayerComponent.cpp @@ -3,6 +3,7 @@ #include "utils/StringUtil.h" #include "AudioManager.h" +#include "Renderer.h" #include "Settings.h" #include #include @@ -93,14 +94,68 @@ void VideoPlayerComponent::startVideo() // Find out the pixel position of the video view and build a command line for // omxplayer to position it in the right place - char buf[32]; + char buf1[32]; + char buf2[32]; float x = mPosition.x() - (mOrigin.x() * mSize.x()); float y = mPosition.y() - (mOrigin.y() * mSize.y()); - sprintf(buf, "%d,%d,%d,%d", (int)x, (int)y, (int)(x + mSize.x()), (int)(y + mSize.y())); + + // fix x and y + switch(Renderer::getScreenRotate()) + { + case 0: + { + const int x1 = (int)(Renderer::getScreenOffsetX() + x); + const int y1 = (int)(Renderer::getScreenOffsetY() + y); + const int x2 = (int)(x1 + mSize.x()); + const int y2 = (int)(y1 + mSize.y()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 1: + { + const int x1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y()); + const int y1 = (int)(Renderer::getScreenOffsetX() + x); + const int x2 = (int)(x1 + mSize.y()); + const int y2 = (int)(y1 + mSize.x()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 2: + { + const int x1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x()); + const int y1 = (int)(Renderer::getScreenOffsetY() + Renderer::getScreenHeight() - y - mSize.y()); + const int x2 = (int)(x1 + mSize.x()); + const int y2 = (int)(y1 + mSize.y()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + + case 3: + { + const int x1 = (int)(Renderer::getScreenOffsetY() + y); + const int y1 = (int)(Renderer::getScreenOffsetX() + Renderer::getScreenWidth() - x - mSize.x()); + const int x2 = (int)(x1 + mSize.y()); + const int y2 = (int)(y1 + mSize.x()); + sprintf(buf1, "%d,%d,%d,%d", x1, y1, x2, y2); + } + break; + } + + // rotate the video + switch(Renderer::getScreenRotate()) + { + case 0: { sprintf(buf2, "%d", (int) 0); } break; + case 1: { sprintf(buf2, "%d", (int) 90); } break; + case 2: { sprintf(buf2, "%d", (int)180); } break; + case 3: { sprintf(buf2, "%d", (int)270); } break; + } + // We need to specify the layer of 10000 or above to ensure the video is displayed on top // of our SDL display - const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf, "--no-ghost-box", "", "", "", "", NULL }; + const char* argv[] = { "", "--layer", "10010", "--loop", "--no-osd", "--aspect-mode", "letterbox", "--vol", "0", "-o", "both","--win", buf1, "--orientation", buf2, "", "", "", "", NULL }; // check if we want to mute the audio if (!Settings::getInstance()->getBool("VideoAudio") || (float)VolumeControl::getInstance()->getVolume() == 0) @@ -128,14 +183,14 @@ void VideoPlayerComponent::startVideo() if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never") { // if we have chosen to render subtitles - argv[13] = "--subtitles"; - argv[14] = subtitlePath.c_str(); - argv[15] = mPlayingVideoPath.c_str(); + argv[15] = "--subtitles"; + argv[16] = subtitlePath.c_str(); + argv[17] = mPlayingVideoPath.c_str(); } else { // if we have chosen NOT to render subtitles in the screensaver - argv[13] = mPlayingVideoPath.c_str(); + argv[15] = mPlayingVideoPath.c_str(); } } else @@ -145,7 +200,7 @@ void VideoPlayerComponent::startVideo() { argv[6] = "stretch"; } - argv[13] = mPlayingVideoPath.c_str(); + argv[15] = mPlayingVideoPath.c_str(); } argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();