Skip to content
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
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ ffmpeg
help.h
keys.h
patch.flag
.cproject
.project
.settings
omxplayer-dist
omxplayer-dist.tgz
omxplayer.1
version.h
MAN
22 changes: 21 additions & 1 deletion KeyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,21 @@ int convertStringToAction(string str_action)
return KeyConfig::ACTION_SHOW_SUBTITLES;
if(str_action == "HIDE_SUBTITLES")
return KeyConfig::ACTION_HIDE_SUBTITLES;

if(str_action == "TOGGLE_TITLE")
return KeyConfig::ACTION_TOGGLE_TITLE;
if(str_action == "SHOW_TITLE")
return KeyConfig::ACTION_SHOW_TITLE;
if(str_action == "HIDE_TITLE")
return KeyConfig::ACTION_HIDE_TITLE;
if(str_action == "TOGGLE_TIME")
return KeyConfig::ACTION_TOGGLE_TIME;
if(str_action == "SHOW_TIME")
return KeyConfig::ACTION_SHOW_TIME;
if(str_action == "HIDE_TIME")
return KeyConfig::ACTION_HIDE_TIME;
if(str_action == "SET_TITLE")
return KeyConfig::ACTION_SET_TITLE;

return -1;
}
/* Grabs the substring prior to the ':', this is the Action */
Expand Down Expand Up @@ -128,6 +142,12 @@ map<int, int> KeyConfig::buildDefaultKeymap()
keymap['v'] = ACTION_STEP;
keymap['w'] = ACTION_SHOW_SUBTITLES;
keymap['x'] = ACTION_HIDE_SUBTITLES;
keymap['t'] = ACTION_TOGGLE_TITLE;
keymap['e'] = ACTION_SHOW_TITLE;
keymap['r'] = ACTION_HIDE_TITLE;
keymap['y'] = ACTION_TOGGLE_TIME;
keymap['g'] = ACTION_SHOW_TIME;
keymap['h'] = ACTION_HIDE_TIME;

return keymap;
}
Expand Down
7 changes: 7 additions & 0 deletions KeyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class KeyConfig
ACTION_PLAY = 36,
ACTION_CHANGE_FILE = 37,
ACTION_SET_LAYER = 38,
ACTION_TOGGLE_TITLE = 39,
ACTION_HIDE_TITLE = 40,
ACTION_SHOW_TITLE = 41,
ACTION_TOGGLE_TIME = 42,
ACTION_HIDE_TIME = 43,
ACTION_SHOW_TIME = 44,
ACTION_SET_TITLE = 45
};

#define KEY_LEFT 0x5b44
Expand Down
50 changes: 50 additions & 0 deletions OMXControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,56 @@ OMXControlResult OMXControl::handle_event(DBusMessage *m)
dbus_respond_ok(m);
return KeyConfig::ACTION_HIDE_SUBTITLES;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "SetTitle"))
{
DBusError error;
dbus_error_init(&error);

const char *title;
dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &title, DBUS_TYPE_INVALID);

if (dbus_error_is_set(&error))
{
CLog::Log(LOGWARNING, "Set title D-Bus Error: %s", error.message );
dbus_error_free(&error);
dbus_respond_ok(m);
return KeyConfig::ACTION_BLANK;
}
else
{
dbus_respond_string(m, title);
return OMXControlResult(KeyConfig::ACTION_SET_TITLE, title);
}
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "GetTitle"))
{
dbus_respond_string(m, subtitles->GetTitle().c_str());
return KeyConfig::ACTION_BLANK;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ShowTitle"))
{
subtitles->SetTitleVisible(true);
dbus_respond_ok(m);
return KeyConfig::ACTION_SHOW_TITLE;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideTitle"))
{
subtitles->SetTitleVisible(false);
dbus_respond_ok(m);
return KeyConfig::ACTION_HIDE_TITLE;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "ShowTime"))
{
subtitles->SetTimeVisible(true);
dbus_respond_ok(m);
return KeyConfig::ACTION_SHOW_TIME;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "HideTime"))
{
subtitles->SetTimeVisible(false);
dbus_respond_ok(m);
return KeyConfig::ACTION_HIDE_TIME;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_PLAYER, "OpenUri"))
{
DBusError error;
Expand Down
135 changes: 129 additions & 6 deletions OMXPlayerSubtitles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "utils/ScopeExit.h"
#include "utils/Clamp.h"
#include "utils/log.h"
#include "utils/Strprintf.h"

#include <boost/algorithm/string.hpp>
#include <utility>
Expand All @@ -41,6 +42,7 @@ OMXPlayerSubtitles::OMXPlayerSubtitles() BOOST_NOEXCEPT
m_thread_stopped(),
m_font_size(),
m_centered(),
m_title_centered(),
m_ghost_box(),
m_lines(),
m_av_clock(),
Expand All @@ -58,12 +60,17 @@ bool OMXPlayerSubtitles::Open(size_t stream_count,
vector<Subtitle>&& external_subtitles,
const string& font_path,
const string& italic_font_path,
const string& title_font_path,
float font_size,
float title_font_size,
bool centered,
bool title_centered,
bool ghost_box,
unsigned int lines,
int display, int layer,
OMXClock* clock) BOOST_NOEXCEPT
OMXClock* clock,
const string& title,
bool show_time) BOOST_NOEXCEPT
{
assert(!m_open);

Expand All @@ -78,18 +85,27 @@ bool OMXPlayerSubtitles::Open(size_t stream_count,

m_font_path = font_path;
m_italic_font_path = italic_font_path;
m_title_font_path = title_font_path;
m_font_size = font_size;
m_title_font_size = title_font_size;
m_centered = centered;
m_title_centered = title_centered;
m_ghost_box = ghost_box;
m_lines = lines;
m_av_clock = clock;
m_display = display;
m_layer = layer;
m_title = title;
m_show_title = (title != "");
m_show_time = show_time;

if(!Create())
return false;

SendToRenderer(Message::Flush{m_external_subtitles});
SendToRenderer(Message::SetTitle{m_title});
SendToRenderer(Message::SetShowTitle{m_show_title});
SendToRenderer(Message::SetShowTime{m_show_time});

#ifndef NDEBUG
m_open = true;
Expand Down Expand Up @@ -118,8 +134,8 @@ void OMXPlayerSubtitles::Process()
{
try
{
RenderLoop(m_font_path, m_italic_font_path, m_font_size, m_centered,
m_ghost_box, m_lines, m_av_clock);
RenderLoop(m_font_path, m_italic_font_path, m_title_font_path, m_font_size, m_title_font_size,
m_centered, m_title_centered, m_ghost_box, m_lines, m_av_clock);
}
catch(Enforce_error& e)
{
Expand All @@ -146,18 +162,24 @@ Iterator FindSubtitle(Iterator begin, Iterator end, int time)
void OMXPlayerSubtitles::
RenderLoop(const string& font_path,
const string& italic_font_path,
const string& title_font_path,
float font_size,
float title_font_size,
bool centered,
bool title_centered,
bool ghost_box,
unsigned int lines,
OMXClock* clock)
{
SubtitleRenderer renderer(m_display, m_layer,
font_path,
italic_font_path,
title_font_path,
font_size,
0.01f, 0.06f,
title_font_size,
0.06f, 0.06f,
centered,
title_centered,
0xDD,
ghost_box ? 0x80 : 0,
lines);
Expand All @@ -174,12 +196,36 @@ RenderLoop(const string& font_path,
bool osd{};
chrono::time_point<std::chrono::steady_clock> osd_stop;
int delay{};
bool show_time{};

auto GetCurrentTime = [&]
{
return static_cast<int>(clock->OMXMediaTime()/1000) - delay;
};

auto PrepareTime = [&]
{
extern OMXReader m_omx_reader;
auto t = (unsigned) (m_av_clock->OMXMediaTime()*1e-3);
auto dur = m_omx_reader.GetStreamLength() / 1000;

std::string time_curr;
std::string time_total;
int hours = t/3600000;
if (hours)
time_curr = strprintf("%02d:%02d:%02d", hours, (t/60000)%60, (t/1000)%60);
else
time_curr = strprintf("%02d:%02d", (t/60000)%60, (t/1000)%60);

hours = dur/3600;
if (hours)
time_total = strprintf("%02d:%02d:%02d", hours, (dur/60)%60, dur%60);
else
time_total = strprintf("%02d:%02d", (dur/60)%60, dur%60);

renderer.prepare_time(time_curr + " / " + time_total);
};

auto TryPrepare = [&](int time)
{
for(; next_index != subtitles.size(); ++next_index)
Expand Down Expand Up @@ -214,6 +260,9 @@ RenderLoop(const string& font_path,
}
};

auto show_time_offset = GetCurrentTime() % 1000;
chrono::time_point<std::chrono::steady_clock> show_time_next_update;

for(;;)
{
int timeout = INT_MAX;
Expand All @@ -230,7 +279,18 @@ RenderLoop(const string& font_path,
have_next ? subtitles[next_index].start - now
: INT_MAX;

timeout = min(min(till_stop, till_next_start), 1000);
int till_next_show_time = 1000;
if (show_time)
till_next_show_time = 1000 - (GetCurrentTime() % 1000) + show_time_offset;

timeout = min(min(till_next_show_time, min(till_stop, till_next_start)), 1000);
}

if(show_time)
{
procrustes(timeout,
chrono::duration_cast<std::chrono::milliseconds>(
show_time_next_update - chrono::steady_clock::now()).count());
}

if(osd)
Expand Down Expand Up @@ -269,6 +329,8 @@ RenderLoop(const string& font_path,
[&](Message::DisplayText&& args)
{
renderer.prepare(args.text_lines);
if (show_time)
PrepareTime(); // Also regenerate displayed time.
renderer.show_next();
showing = true;
osd = true;
Expand All @@ -279,6 +341,33 @@ RenderLoop(const string& font_path,
[&](Message::SetRect&& args)
{
renderer.set_rect(args.x1, args.y1, args.x2, args.y2);
},
[&](Message::SetTitle&& args)
{
m_title = args.title;
if (m_show_title)
renderer.prepare_title(m_title);
else
renderer.prepare_title("");
renderer.redraw();
},
[&](Message::SetShowTitle&& args)
{
m_show_title = args.show;
if (m_show_title)
renderer.prepare_title(m_title);
else
renderer.prepare_title("");
renderer.redraw();
},
[&](Message::SetShowTime&& args)
{
show_time = args.show;
if (show_time)
PrepareTime();
else
renderer.prepare_time("");
renderer.redraw();
});

if(exit) break;
Expand All @@ -299,11 +388,20 @@ RenderLoop(const string& font_path,
if(osd && chrono::steady_clock::now() >= osd_stop)
osd = false;

bool redraw_needed = false;

if (show_time && chrono::steady_clock::now() >= show_time_next_update) {
show_time_next_update = chrono::steady_clock::now() + chrono::seconds(1);
PrepareTime();
redraw_needed = true;
}

if(!osd && current_stop <= now)
{
if(have_next && subtitles[next_index].start <= now)
{
renderer.show_next();
redraw_needed = false;
// printf("show error: %i ms\n", now - subtitles[next_index].start);
showing = true;
current_stop = subtitles[next_index].stop;
Expand All @@ -315,10 +413,14 @@ RenderLoop(const string& font_path,
else if(showing)
{
renderer.hide();
redraw_needed = false;
// printf("hide error: %i ms\n", now - current_stop);
showing = false;
}
}

if(redraw_needed)
renderer.redraw();
}
}

Expand Down Expand Up @@ -408,6 +510,27 @@ void OMXPlayerSubtitles::SetVisible(bool visible) BOOST_NOEXCEPT
}
}

void OMXPlayerSubtitles::SetTitle(std::string line) BOOST_NOEXCEPT
{
assert(m_open);

SendToRenderer(Message::SetTitle{line});
}

void OMXPlayerSubtitles::SetTitleVisible(bool visible) BOOST_NOEXCEPT
{
assert(m_open);

SendToRenderer(Message::SetShowTitle{visible});
}

void OMXPlayerSubtitles::SetTimeVisible(bool visible) BOOST_NOEXCEPT
{
assert(m_open);

SendToRenderer(Message::SetShowTime{visible});
}

void OMXPlayerSubtitles::SetActiveStream(size_t index) BOOST_NOEXCEPT
{
assert(m_open);
Expand Down Expand Up @@ -500,4 +623,4 @@ void OMXPlayerSubtitles::DisplayText(const std::string& text, int duration) BOOS
void OMXPlayerSubtitles::SetSubtitleRect(int x1, int y1, int x2, int y2) BOOST_NOEXCEPT
{
SendToRenderer(Message::SetRect{x1, y1, x2, y2});
}
}
Loading