Skip to content

Commit

Permalink
Merge pull request #135 from pjft/RetroPie-OMX-Player
Browse files Browse the repository at this point in the history
Adding OMX Player as experimental option for ES
  • Loading branch information
joolswills committed May 28, 2017
2 parents e27e7cf + 029e8bd commit bc68e0a
Show file tree
Hide file tree
Showing 15 changed files with 797 additions and 391 deletions.
66 changes: 48 additions & 18 deletions es-app/src/guis/GuiMenu.cpp
Expand Up @@ -31,8 +31,8 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
// [version]

auto openScrapeNow = [this] { mWindow->pushGui(new GuiScraperStart(mWindow)); };
addEntry("SCRAPER", 0x777777FF, true,
[this, openScrapeNow] {
addEntry("SCRAPER", 0x777777FF, true,
[this, openScrapeNow] {
auto s = new GuiSettings(mWindow, "SCRAPER");

// scrape from
Expand Down Expand Up @@ -65,7 +65,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
mWindow->pushGui(s);
});

addEntry("SOUND SETTINGS", 0x777777FF, true,
addEntry("SOUND SETTINGS", 0x777777FF, true,
[this] {
auto s = new GuiSettings(mWindow, "SOUND SETTINGS");

Expand All @@ -74,11 +74,11 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
volume->setValue((float)VolumeControl::getInstance()->getVolume());
s->addWithLabel("SYSTEM VOLUME", volume);
s->addSaveFunc([volume] { VolumeControl::getInstance()->setVolume((int)round(volume->getValue())); });

// disable sounds
auto sounds_enabled = std::make_shared<SwitchComponent>(mWindow);
sounds_enabled->setState(Settings::getInstance()->getBool("EnableSounds"));
s->addWithLabel("ENABLE SOUNDS", sounds_enabled);
s->addWithLabel("ENABLE NAVIGATION SOUNDS", sounds_enabled);
s->addSaveFunc([sounds_enabled] { Settings::getInstance()->setBool("EnableSounds", sounds_enabled->getState()); });

mWindow->pushGui(s);
Expand Down Expand Up @@ -147,7 +147,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
s->addWithLabel("THEME SET", theme_set);

Window* window = mWindow;
s->addSaveFunc([window, theme_set]
s->addSaveFunc([window, theme_set]
{
bool needReload = false;
if(Settings::getInstance()->getString("ThemeSet") != theme_set->getSelected())
Expand All @@ -174,13 +174,43 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
bool needReload = false;
if (Settings::getInstance()->getString("GamelistViewStyle") != gamelist_style->getSelected())
needReload = true;
Settings::getInstance()->setString("GamelistViewStyle", gamelist_style->getSelected());
Settings::getInstance()->setString("GamelistViewStyle", gamelist_style->getSelected());
if (needReload)
ViewController::get()->reloadAll();
});
mWindow->pushGui(s);
});

addEntry("VIDEO PLAYER SETTINGS", 0x777777FF, true,
[this] {
auto s = new GuiSettings(mWindow, "VIDEO PLAYER SETTINGS");

#ifdef _RPI_
// Video Player - VideoOmxPlayer
auto omx_player = std::make_shared<SwitchComponent>(mWindow);
omx_player->setState(Settings::getInstance()->getBool("VideoOmxPlayer"));
s->addWithLabel("USE OMX VIDEO PLAYER (HW ACCELERATED)", omx_player);
s->addSaveFunc([omx_player]
{
// need to reload all views to re-create the right video components
bool needReload = false;
if(Settings::getInstance()->getBool("VideoOmxPlayer") != omx_player->getState())
needReload = true;

Settings::getInstance()->setBool("VideoOmxPlayer", omx_player->getState());

if(needReload)
ViewController::get()->reloadAll();
});
#endif
auto video_audio = std::make_shared<SwitchComponent>(mWindow);
video_audio->setState(Settings::getInstance()->getBool("VideoAudio"));
s->addWithLabel("ENABLE VIDEO AUDIO", video_audio);
s->addSaveFunc([video_audio] { Settings::getInstance()->setBool("VideoAudio", video_audio->getState()); });

mWindow->pushGui(s);
});

addEntry("OTHER SETTINGS", 0x777777FF, true,
[this] {
auto s = new GuiSettings(mWindow, "OTHER SETTINGS");
Expand All @@ -205,7 +235,7 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
mWindow->pushGui(s);
});

addEntry("CONFIGURE INPUT", 0x777777FF, true,
addEntry("CONFIGURE INPUT", 0x777777FF, true,
[this] {
Window* window = mWindow;
window->pushGui(new GuiMsgBox(window, "ARE YOU SURE YOU WANT TO CONFIGURE INPUT?", "YES",
Expand All @@ -215,10 +245,10 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
);
});

addEntry("QUIT", 0x777777FF, true,
addEntry("QUIT", 0x777777FF, true,
[this] {
auto s = new GuiSettings(mWindow, "QUIT");

Window* window = mWindow;

ComponentListRow row;
Expand All @@ -234,8 +264,8 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN

row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
[] {
window->pushGui(new GuiMsgBox(window, "REALLY RESTART?", "YES",
[] {
if(quitES("/tmp/es-sysrestart") != 0)
LOG(LogWarning) << "Restart terminated with non-zero result!";
}, "NO", nullptr));
Expand All @@ -245,8 +275,8 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN

row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
[] {
window->pushGui(new GuiMsgBox(window, "REALLY SHUTDOWN?", "YES",
[] {
if(quitES("/tmp/es-shutdown") != 0)
LOG(LogWarning) << "Shutdown terminated with non-zero result!";
}, "NO", nullptr));
Expand All @@ -258,8 +288,8 @@ GuiMenu::GuiMenu(Window* window) : GuiComponent(window), mMenu(window, "MAIN MEN
{
row.elements.clear();
row.makeAcceptInputHandler([window] {
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
[] {
window->pushGui(new GuiMsgBox(window, "REALLY QUIT?", "YES",
[] {
SDL_Event ev;
ev.type = SDL_QUIT;
SDL_PushEvent(&ev);
Expand Down Expand Up @@ -293,7 +323,7 @@ void GuiMenu::onSizeChanged()
void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, const std::function<void()>& func)
{
std::shared_ptr<Font> font = Font::get(FONT_SIZE_MEDIUM);

// populate the list
ComponentListRow row;
row.addElement(std::make_shared<TextComponent>(mWindow, name, font, color), true);
Expand All @@ -303,7 +333,7 @@ void GuiMenu::addEntry(const char* name, unsigned int color, bool add_arrow, con
std::shared_ptr<ImageComponent> bracket = makeArrow(mWindow);
row.addElement(bracket, false);
}

row.makeAcceptInputHandler(func);

mMenu.addRow(row);
Expand Down
46 changes: 31 additions & 15 deletions es-app/src/views/gamelist/VideoGameListView.cpp
Expand Up @@ -4,13 +4,18 @@
#include "animations/LambdaAnimation.h"
#include <sys/stat.h>
#include <fcntl.h>
#ifdef _RPI_
#include "components/VideoPlayerComponent.h"
#include "Settings.h"
#endif
#include "components/VideoVlcComponent.h"

VideoGameListView::VideoGameListView(Window* window, FileData* root) :
BasicGameListView(window, root),
mDescContainer(window), mDescription(window),
mMarquee(window),
mImage(window),
mVideo(window),
mVideo(nullptr),
mVideoPlaying(false),

mLblRating(window), mLblReleaseDate(window), mLblDeveloper(window), mLblPublisher(window),
Expand All @@ -21,6 +26,16 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root) :
{
const float padding = 0.01f;

// Create the correct type of video window
#ifdef _RPI_
if (Settings::getInstance()->getBool("VideoOmxPlayer"))
mVideo = new VideoPlayerComponent(window);
else
mVideo = new VideoVlcComponent(window);
#else
mVideo = new VideoVlcComponent(window);
#endif

mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y());
mList.setSize(mSize.x() * (0.50f - padding), mList.getSize().y());
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
Expand All @@ -42,11 +57,11 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root) :
addChild(&mImage);

// video
mVideo.setOrigin(0.5f, 0.5f);
mVideo.setPosition(mSize.x() * 0.25f, mSize.y() * 0.4f);
mVideo.setSize(mSize.x() * (0.5f - 2*padding), mSize.y() * 0.4f);
mVideo.setDefaultZIndex(30);
addChild(&mVideo);
mVideo->setOrigin(0.5f, 0.5f);
mVideo->setPosition(mSize.x() * 0.25f, mSize.y() * 0.4f);
mVideo->setSize(mSize.x() * (0.5f - 2*padding), mSize.y() * 0.4f);
mVideo->setDefaultZIndex(30);
addChild(mVideo);

// metadata labels + values
mLblRating.setText("Rating: ");
Expand Down Expand Up @@ -91,6 +106,7 @@ VideoGameListView::VideoGameListView(Window* window, FileData* root) :

VideoGameListView::~VideoGameListView()
{
delete mVideo;
}

void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
Expand All @@ -100,7 +116,7 @@ void VideoGameListView::onThemeChanged(const std::shared_ptr<ThemeData>& theme)
using namespace ThemeFlags;
mMarquee.applyTheme(theme, getName(), "md_marquee", POSITION | ThemeFlags::SIZE | Z_INDEX);
mImage.applyTheme(theme, getName(), "md_image", POSITION | ThemeFlags::SIZE | Z_INDEX);
mVideo.applyTheme(theme, getName(), "md_video", POSITION | ThemeFlags::SIZE | ThemeFlags::DELAY | Z_INDEX);
mVideo->applyTheme(theme, getName(), "md_video", POSITION | ThemeFlags::SIZE | ThemeFlags::DELAY | Z_INDEX);

initMDLabels();
std::vector<TextComponent*> labels = getMDLabels();
Expand Down Expand Up @@ -214,8 +230,8 @@ void VideoGameListView::updateInfoPanel()
bool fadingOut;
if(file == NULL)
{
mVideo.setVideo("");
mVideo.setImage("");
mVideo->setVideo("");
mVideo->setImage("");
mVideoPlaying = false;
//mMarquee.setImage("");
//mDescription.setText("");
Expand Down Expand Up @@ -244,13 +260,13 @@ void VideoGameListView::updateInfoPanel()
thumbnail_path.erase(0, 1);
thumbnail_path.insert(0, getHomePath());
}
if (!mVideo.setVideo(video_path))
if (!mVideo->setVideo(video_path))
{
mVideo.setDefaultVideo();
mVideo->setDefaultVideo();
}
mVideoPlaying = true;

mVideo.setImage(thumbnail_path);
mVideo->setImage(thumbnail_path);
mMarquee.setImage(marquee_path);
mImage.setImage(thumbnail_path);

Expand All @@ -275,7 +291,7 @@ void VideoGameListView::updateInfoPanel()

std::vector<GuiComponent*> comps = getMDValues();
comps.push_back(&mMarquee);
comps.push_back(&mVideo);
comps.push_back(mVideo);
comps.push_back(&mDescription);
comps.push_back(&mImage);
std::vector<TextComponent*> labels = getMDLabels();
Expand Down Expand Up @@ -304,7 +320,7 @@ void VideoGameListView::launch(FileData* game)
{
Eigen::Vector3f target(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0);
if(mMarquee.hasImage())
target << mVideo.getCenter().x(), mVideo.getCenter().y(), 0;
target << mVideo->getCenter().x(), mVideo->getCenter().y(), 0;

ViewController::get()->launch(game, target);
}
Expand Down Expand Up @@ -340,7 +356,7 @@ std::vector<GuiComponent*> VideoGameListView::getMDValues()
void VideoGameListView::update(int deltaTime)
{
BasicGameListView::update(deltaTime);
mVideo.update(deltaTime);
mVideo->update(deltaTime);
}

void VideoGameListView::onShow()
Expand Down
2 changes: 1 addition & 1 deletion es-app/src/views/gamelist/VideoGameListView.h
Expand Up @@ -30,7 +30,7 @@ class VideoGameListView : public BasicGameListView
void initMDValues();

ImageComponent mMarquee;
VideoComponent mVideo;
VideoComponent* mVideo;
ImageComponent mImage;

TextComponent mLblRating, mLblReleaseDate, mLblDeveloper, mLblPublisher, mLblGenre, mLblPlayers, mLblLastPlayed, mLblPlayCount;
Expand Down
4 changes: 4 additions & 0 deletions es-core/CMakeLists.txt
Expand Up @@ -43,6 +43,8 @@ set(CORE_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/src/components/TextComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/TextEditComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoPlayerComponent.h
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoVlcComponent.h

# Guis
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiDetectDevice.h
Expand Down Expand Up @@ -99,6 +101,8 @@ set(CORE_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/components/TextComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/TextEditComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoPlayerComponent.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/components/VideoVlcComponent.cpp

# Guis
${CMAKE_CURRENT_SOURCE_DIR}/src/guis/GuiDetectDevice.cpp
Expand Down
18 changes: 17 additions & 1 deletion es-core/src/GuiComponent.cpp
Expand Up @@ -5,7 +5,7 @@
#include "animations/AnimationController.h"
#include "ThemeData.h"

GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
mPosition(Eigen::Vector3f::Zero()), mSize(Eigen::Vector2f::Zero()), mTransform(Eigen::Affine3f::Identity()),
mIsProcessing(false)
{
Expand Down Expand Up @@ -390,4 +390,20 @@ void GuiComponent::onHide()
getChild(i)->onHide();
}

void GuiComponent::onScreenSaverActivate()
{
for(unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->onScreenSaverActivate();
}

void GuiComponent::onScreenSaverDeactivate()
{
for(unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->onScreenSaverDeactivate();
}

void GuiComponent::topWindow(bool isTop)
{
for(unsigned int i = 0; i < getChildCount(); i++)
getChild(i)->topWindow(isTop);
}
9 changes: 6 additions & 3 deletions es-core/src/GuiComponent.h
Expand Up @@ -45,7 +45,7 @@ class GuiComponent
void setSize(const Eigen::Vector2f& size);
void setSize(float w, float h);
virtual void onSizeChanged() {};

float getZIndex() const;
void setZIndex(float zIndex);

Expand Down Expand Up @@ -84,9 +84,12 @@ class GuiComponent

virtual void onFocusGained() {};
virtual void onFocusLost() {};

virtual void onShow();
virtual void onHide();
virtual void onScreenSaverActivate();
virtual void onScreenSaverDeactivate();
virtual void topWindow(bool isTop);

// Default implementation just handles <pos> and <size> tags as normalized float pairs.
// You probably want to keep this behavior for any derived classes as well as add your own.
Expand All @@ -97,7 +100,7 @@ class GuiComponent

// Called whenever help prompts change.
void updateHelpPrompts();

virtual HelpStyle getHelpStyle();

// Returns true if the component is busy doing background processing (e.g. HTTP downloads)
Expand Down
8 changes: 7 additions & 1 deletion es-core/src/Settings.cpp
Expand Up @@ -47,7 +47,7 @@ void Settings::setDefaults()
mBoolMap["SplashScreen"] = true;

#ifdef _RPI_
// don't enable VSync by default on the Pi, since it already
// don't enable VSync by default on the Pi, since it already
// has trouble trying to render things at 60fps in certain menus
mBoolMap["VSync"] = false;
#else
Expand Down Expand Up @@ -76,6 +76,12 @@ void Settings::setDefaults()
mStringMap["ScreenSaverBehavior"] = "dim";
mStringMap["Scraper"] = "TheGamesDB";
mStringMap["GamelistViewStyle"] = "automatic";

// This setting only applies to raspberry pi but set it for all platforms so
// we don't get a warning if we encounter it on a different platform
mBoolMap["VideoOmxPlayer"] = false;
mBoolMap["VideoAudio"] = true;

}

template <typename K, typename V>
Expand Down

0 comments on commit bc68e0a

Please sign in to comment.