Removed deprecated code for handling video subtitles.

This commit is contained in:
Leon Styhre 2020-10-17 16:06:01 +02:00
parent 0beb40d9c9
commit 35c7c7ec09
11 changed files with 56 additions and 186 deletions

View file

@ -50,17 +50,13 @@ SystemScreenSaver::SystemScreenSaver(
mStopBackgroundAudio(true)
{
mWindow->setScreenSaver(this);
std::string path = getTitleFolder();
if (!Utils::FileSystem::exists(path))
Utils::FileSystem::createDirectory(path);
srand((unsigned int)time(nullptr));
mVideoChangeTime = 30000;
}
SystemScreenSaver::~SystemScreenSaver()
{
// Delete subtitle file, if it exists.
remove(getTitlePath().c_str());
mCurrentGame = nullptr;
delete mVideoScreensaver;
delete mImageScreensaver;
@ -108,11 +104,11 @@ void SystemScreenSaver::startScreenSaver()
#if defined(_RPI_)
// Create the correct type of video component
if (Settings::getInstance()->getBool("ScreenSaverOmxPlayer"))
mVideoScreensaver = new VideoPlayerComponent(mWindow, getTitlePath());
mVideoScreensaver = new VideoPlayerComponent(mWindow);
else
mVideoScreensaver = new VideoVlcComponent(mWindow, getTitlePath());
mVideoScreensaver = new VideoVlcComponent(mWindow);
#else
mVideoScreensaver = new VideoVlcComponent(mWindow, getTitlePath());
mVideoScreensaver = new VideoVlcComponent(mWindow);
#endif
mVideoScreensaver->topWindow(true);
@ -332,12 +328,6 @@ void SystemScreenSaver::pickGameListNode(unsigned long index,
mCurrentGame = (*itf);
// End of getting FileData.
#if defined(_RPI_)
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never")
writeSubtitle(mGameName.c_str(), mSystemName.c_str(),
(Settings::getInstance()->getString("ScreenSaverGameInfo") ==
"always"));
#endif
return;
}
}

View file

@ -42,45 +42,45 @@ GuiVideoScreensaverOptions::GuiVideoScreensaverOptions(Window* window, const cha
addSaveFunc([ss_omx, this] { Settings::getInstance()->
setBool("ScreenSaverOmxPlayer", ss_omx->getState()); });
// TEMPORARY - Disabled for now (except for RPI), need to find a proper way to make an
// overlay on top of the videos. The solution with rendering subtitles is not a good solution.
// TEMPORARY - Disabled for now, need to find a proper way to make an overlay on top of
// the videos. The solution with rendering subtitles is not a good solution.
// And as well the VLC video player subtitles seem to be somehow broken.
// Render video game name as subtitles.
auto ss_info = std::make_shared<OptionListComponent<std::string>>
(mWindow,getHelpStyle(), "SHOW GAME INFO", false);
std::vector<std::string> info_type;
info_type.push_back("always");
info_type.push_back("start & end");
info_type.push_back("never");
for (auto it = info_type.cbegin(); it != info_type.cend(); it++)
ss_info->add(*it, *it, Settings::getInstance()->getString("ScreenSaverGameInfo") == *it);
addWithLabel("SHOW GAME INFO ON SCREENSAVER", ss_info);
addSaveFunc([ss_info, this] { Settings::getInstance()->
setString("ScreenSaverGameInfo", ss_info->getSelected()); });
// auto ss_info = std::make_shared<OptionListComponent<std::string>>
// (mWindow,getHelpStyle(), "SHOW GAME INFO", false);
// std::vector<std::string> info_type;
// info_type.push_back("always");
// info_type.push_back("start & end");
// info_type.push_back("never");
// for (auto it = info_type.cbegin(); it != info_type.cend(); it++)
// ss_info->add(*it, *it, Settings::getInstance()->getString("ScreenSaverGameInfo") == *it);
// addWithLabel("SHOW GAME INFO ON SCREENSAVER", ss_info);
// addSaveFunc([ss_info, this] { Settings::getInstance()->
// setString("ScreenSaverGameInfo", ss_info->getSelected()); });
ComponentListRow row;
// ComponentListRow row;
// Set subtitle position.
auto ss_omx_subs_align = std::make_shared<OptionListComponent<std::string>>
(mWindow, getHelpStyle(), "GAME INFO ALIGNMENT", false);
std::vector<std::string> align_mode;
align_mode.push_back("left");
align_mode.push_back("center");
for (auto it = align_mode.cbegin(); it != align_mode.cend(); it++)
ss_omx_subs_align->add(*it, *it, Settings::getInstance()->
getString("SubtitleAlignment") == *it);
addWithLabel("GAME INFO ALIGNMENT", ss_omx_subs_align);
addSaveFunc([ss_omx_subs_align, this] { Settings::getInstance()->
setString("SubtitleAlignment", ss_omx_subs_align->getSelected()); });
// auto ss_omx_subs_align = std::make_shared<OptionListComponent<std::string>>
// (mWindow, getHelpStyle(), "GAME INFO ALIGNMENT", false);
// std::vector<std::string> align_mode;
// align_mode.push_back("left");
// align_mode.push_back("center");
// for (auto it = align_mode.cbegin(); it != align_mode.cend(); it++)
// ss_omx_subs_align->add(*it, *it, Settings::getInstance()->
// getString("SubtitleAlignment") == *it);
// addWithLabel("GAME INFO ALIGNMENT", ss_omx_subs_align);
// addSaveFunc([ss_omx_subs_align, this] { Settings::getInstance()->
// setString("SubtitleAlignment", ss_omx_subs_align->getSelected()); });
// Set font size.
auto ss_omx_font_size = std::make_shared<SliderComponent>(mWindow, 1.f, 64.f, 1.f, "h");
ss_omx_font_size->setValue((float)(Settings::getInstance()->getInt("SubtitleSize")));
addWithLabel("GAME INFO FONT SIZE", ss_omx_font_size);
addSaveFunc([ss_omx_font_size] {
int subSize = (int)Math::round(ss_omx_font_size->getValue());
Settings::getInstance()->setInt("SubtitleSize", subSize);
});
// auto ss_omx_font_size = std::make_shared<SliderComponent>(mWindow, 1.f, 64.f, 1.f, "h");
// ss_omx_font_size->setValue((float)(Settings::getInstance()->getInt("SubtitleSize")));
// addWithLabel("GAME INFO FONT SIZE", ss_omx_font_size);
// addSaveFunc([ss_omx_font_size] {
// int subSize = (int)Math::round(ss_omx_font_size->getValue());
// Settings::getInstance()->setInt("SubtitleSize", subSize);
// });
#endif
auto ss_video_audio = std::make_shared<SwitchComponent>(mWindow);
@ -104,27 +104,6 @@ GuiVideoScreensaverOptions::GuiVideoScreensaverOptions(Window* window, const cha
addSaveFunc([render_blur] { Settings::getInstance()->
setBool("ScreenSaverVideoBlur", render_blur->getState()); });
#endif
#if defined(_RPI_)
// Define subtitle font.
auto ss_omx_font_file = std::make_shared<TextComponent>(mWindow, "",
Font::get(FONT_SIZE_SMALL), 0x777777FF);
addEditableTextComponent(row, "PATH TO FONT FILE", ss_omx_font_file,
Settings::getInstance()->getString("SubtitleFont"));
addSaveFunc([ss_omx_font_file] {
Settings::getInstance()->setString("SubtitleFont", ss_omx_font_file->getValue());
});
// Define subtitle italic font.
auto ss_omx_italic_font_file = std::make_shared<TextComponent>(mWindow, "",
Font::get(FONT_SIZE_SMALL), 0x777777FF);
addEditableTextComponent(row, "PATH TO ITALIC FONT FILE", ss_omx_italic_font_file,
Settings::getInstance()->getString("SubtitleItalicFont"));
addSaveFunc([ss_omx_italic_font_file] {
Settings::getInstance()->setString("SubtitleItalicFont",
ss_omx_italic_font_file->getValue());
});
#endif
}
GuiVideoScreensaverOptions::~GuiVideoScreensaverOptions()

View file

@ -58,11 +58,11 @@ GridGameListView::GridGameListView(
// Create the correct type of video window.
#if defined(_RPI_)
if (Settings::getInstance()->getBool("VideoOmxPlayer"))
mVideo = new VideoPlayerComponent(window, "");
mVideo = new VideoPlayerComponent(window);
else
mVideo = new VideoVlcComponent(window, getTitlePath());
mVideo = new VideoVlcComponent(window);
#else
mVideo = new VideoVlcComponent(window, getTitlePath());
mVideo = new VideoVlcComponent(window);
#endif
mGrid.setPosition(mSize.x() * 0.1f, mSize.y() * 0.1f);

View file

@ -59,11 +59,11 @@ VideoGameListView::VideoGameListView(
// Create the correct type of video window.
#if defined(_RPI_)
if (Settings::getInstance()->getBool("VideoOmxPlayer"))
mVideo = new VideoPlayerComponent(window, "");
mVideo = new VideoPlayerComponent(window);
else
mVideo = new VideoVlcComponent(window, getTitlePath());
mVideo = new VideoVlcComponent(window);
#else
mVideo = new VideoVlcComponent(window, getTitlePath());
mVideo = new VideoVlcComponent(window);
#endif
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y());
@ -262,7 +262,6 @@ void VideoGameListView::initMDValues()
void VideoGameListView::updateInfoPanel()
{
FileData* file = (mList.size() == 0 || mList.isScrolling()) ? nullptr : mList.getSelected();
Utils::FileSystem::removeFile(getTitlePath());
// If the game data has already been rendered to the info panel, then skip it this time.
if (file == mLastUpdated) {

View file

@ -191,11 +191,6 @@ void Settings::setDefaults()
#if defined(_RPI_)
// We're defaulting to OMX Player for full screen video on the Pi.
mBoolMap["ScreenSaverOmxPlayer"] = true;
// Use OMX Player defaults.
mStringMap["SubtitleFont"] = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
mStringMap["SubtitleItalicFont"] = "/usr/share/fonts/truetype/freefont/FreeSansOblique.ttf";
mIntMap["SubtitleSize"] = 55;
mStringMap["SubtitleAlignment"] = "left";
#else
mBoolMap["ScreenSaverOmxPlayer"] = false;
#endif

View file

@ -18,41 +18,6 @@
#define SCREENSAVER_FADE_IN_TIME 800
std::string getTitlePath() {
std::string titleFolder = getTitleFolder();
return titleFolder + "last_title.srt";
}
std::string getTitleFolder() {
std::string home = Utils::FileSystem::getHomePath();
return home + "/.emulationstation/tmp/";
}
void writeSubtitle(const char* gameName, const char* systemName, bool always)
{
FILE* file = fopen(getTitlePath().c_str(), "w");
int end = static_cast<int>((Settings::getInstance()->
getInt("ScreenSaverSwapVideoTimeout") / (1000)));
if (always)
fprintf(file, "1\n00:00:01,000 --> 00:00:%d,000\n", end);
else
fprintf(file, "1\n00:00:01,000 --> 00:00:08,000\n");
fprintf(file, "%s\n", gameName);
fprintf(file, "<i>%s</i>\n\n", systemName);
if (!always) {
if (end > 12)
fprintf(file, "2\n00:00:%d,000 --> 00:00:%d,000\n%s\n<i>%s</i>\n",
end-4, end, gameName, systemName);
}
fflush(file);
fclose(file);
file = nullptr;
}
void VideoComponent::setScreensaverMode(bool isScreensaver)
{
mScreensaverMode = isScreensaver;
@ -84,19 +49,12 @@ VideoComponent::VideoComponent(
if (mWindow->getGuiStackSize() > 1)
topWindow(false);
std::string path = getTitleFolder();
if (!Utils::FileSystem::exists(path))
Utils::FileSystem::createDirectory(path);
}
VideoComponent::~VideoComponent()
{
// Stop any currently running video.
stopVideo();
// Delete subtitle file, if existing.
remove(getTitlePath().c_str());
}
void VideoComponent::onOriginChanged()

View file

@ -16,10 +16,6 @@
class TextureResource;
std::string getTitlePath();
std::string getTitleFolder();
void writeSubtitle(const char* gameName, const char* systemName, bool always);
class VideoComponent : public GuiComponent
{
// Structure that groups together the configuration of the video component.

View file

@ -25,10 +25,9 @@ public:
int getVolume() const;
};
VideoPlayerComponent::VideoPlayerComponent(Window* window, std::string path) :
VideoPlayerComponent::VideoPlayerComponent(Window* window) :
VideoComponent(window),
mPlayerPid(-1),
subtitlePath(path)
mPlayerPid(-1)
{
}
@ -176,45 +175,13 @@ void VideoPlayerComponent::startVideo()
argv[8] = std::to_string(OMXVolume).c_str();
}
// Test if there's a path for possible subtitles, meaning we're a screensaver video.
if (!subtitlePath.empty()) {
// If we are rendering a screensaver.
// Check if we want to stretch the image.
if (Settings::getInstance()->getBool("ScreenSaverStretchVideos"))
argv[6] = "stretch";
if (Settings::getInstance()->getString("ScreenSaverGameInfo") != "never") {
// If we have chosen to render subtitles.
argv[15] = "--subtitles";
argv[16] = subtitlePath.c_str();
argv[17] = mPlayingVideoPath.c_str();
argv[18] = "--font";
argv[19] = Settings::getInstance()->getString("SubtitleFont").c_str();
argv[20] = "--italic-font";
argv[21] = Settings::getInstance()->
getString("SubtitleItalicFont").c_str();
argv[22] = "--font-size";
argv[23] = std::to_string(Settings::getInstance()->
getInt("SubtitleSize")).c_str();
argv[24] = "--align";
argv[25] = Settings::getInstance()->
getString("SubtitleAlignment").c_str();
}
else {
// If we have chosen NOT to render subtitles in the screensaver.
argv[15] = mPlayingVideoPath.c_str();
}
}
else {
// If we are rendering a video gamelist.
if (!mTargetIsMax)
argv[6] = "stretch";
argv[15] = mPlayingVideoPath.c_str();
}
// If we are rendering a video gamelist.
if (!mTargetIsMax)
argv[6] = "stretch";
argv[15] = mPlayingVideoPath.c_str();
argv[10] = Settings::getInstance()->getString("OMXAudioDev").c_str();
//const char* argv[] = args;
const char* env[] = { "LD_LIBRARY_PATH=/opt/vc/libs:/usr/lib/omxplayer", NULL };
// Redirect stdout.

View file

@ -17,7 +17,7 @@ void catch_child(int sig_num);
class VideoPlayerComponent : public VideoComponent
{
public:
VideoPlayerComponent(Window* window, std::string path);
VideoPlayerComponent(Window* window);
virtual ~VideoPlayerComponent();
void render(const Transform4x4f& parentTrans) override;
@ -41,7 +41,6 @@ private:
private:
pid_t mPlayerPid;
std::string subtitlePath;
};
#endif // ES_CORE_COMPONENTS_VIDEO_PLAYER_COMPONENT_H

View file

@ -50,14 +50,14 @@ static void display(void* /*data*/, void* /*id*/) {
// Data to be displayed.
}
VideoVlcComponent::VideoVlcComponent(Window* window, std::string subtitles)
VideoVlcComponent::VideoVlcComponent(Window* window)
: VideoComponent(window), mMediaPlayer(nullptr), mContext({})
{
// Get an empty texture for rendering the video.
mTexture = TextureResource::get("");
// Make sure VLC has been initialized.
setupVLC(subtitles);
setupVLC();
}
VideoVlcComponent::~VideoVlcComponent()
@ -209,23 +209,11 @@ void VideoVlcComponent::freeContext()
}
}
void VideoVlcComponent::setupVLC(std::string subtitles)
void VideoVlcComponent::setupVLC()
{
// If VLC hasn't been initialised yet then do it now.
if (!mVLC) {
const char** args;
const char* newargs[] = { "--quiet", "--sub-file", subtitles.c_str() };
const char* singleargs[] = { "--quiet" };
int argslen = 0;
if (!subtitles.empty()) {
argslen = sizeof(newargs) / sizeof(newargs[0]);
args = newargs;
}
else {
argslen = sizeof(singleargs) / sizeof(singleargs[0]);
args = singleargs;
}
const char* args[] = { "--quiet" };
#if defined(__APPLE__)
// It's required to set the VLC_PLUGIN_PATH variable on macOS, or the libVLC
@ -237,7 +225,7 @@ void VideoVlcComponent::setupVLC(std::string subtitles)
setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins/", 1);
#endif
mVLC = libvlc_new(argslen, args);
mVLC = libvlc_new(1, args);
}
}
@ -319,7 +307,6 @@ void VideoVlcComponent::startVideo()
libvlc_media_tracks_release(tracks, track_count);
// Make sure we found a valid video track.
if ((mVideoWidth > 0) && (mVideoHeight > 0)) {
PowerSaver::pause();
setupContext();

View file

@ -36,9 +36,9 @@ class VideoVlcComponent : public VideoComponent
};
public:
static void setupVLC(std::string subtitles);
static void setupVLC();
VideoVlcComponent(Window* window, std::string subtitles);
VideoVlcComponent(Window* window);
virtual ~VideoVlcComponent();
void render(const Transform4x4f& parentTrans) override;