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

Added DisplayText DBUS support #595

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
25 changes: 25 additions & 0 deletions OMXControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ OMXControlResult OMXControl::handle_event(DBusMessage *m)
//Does nothing
return KeyConfig::ACTION_BLANK;
}
else if (dbus_message_is_method_call(m, OMXPLAYER_DBUS_INTERFACE_ROOT, "DisplayText"))
{
DBusError error;
dbus_error_init(&error);

const char *msg;
int64_t duration;

dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &msg, DBUS_TYPE_INT64, &duration, DBUS_TYPE_INVALID);

// Make sure values are sent for setting DisplayText
if (dbus_error_is_set(&error))
{
CLog::Log(LOGWARNING, "DisplayText D-Bus Error: %s", error.message );
dbus_error_free(&error);
dbus_respond_ok(m);
return KeyConfig::ACTION_BLANK;
}
else
{
subtitles->DisplayText(msg, duration);
dbus_respond_ok(m);
return KeyConfig::ACTION_BLANK;
}
}
//Properties Get method:
//TODO: implement GetAll
else if (dbus_message_is_method_call(m, DBUS_INTERFACE_PROPERTIES, "Get"))
Expand Down
20 changes: 9 additions & 11 deletions OMXPlayerSubtitles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ OMXPlayerSubtitles::OMXPlayerSubtitles() BOOST_NOEXCEPT
m_ghost_box(),
m_lines(),
m_av_clock(),
#ifndef NDEBUG
m_open()
#endif
{}

OMXPlayerSubtitles::~OMXPlayerSubtitles() BOOST_NOEXCEPT
Expand Down Expand Up @@ -91,9 +89,7 @@ bool OMXPlayerSubtitles::Open(size_t stream_count,

SendToRenderer(Message::Flush{m_external_subtitles});

#ifndef NDEBUG
m_open = true;
#endif

return true;
}
Expand All @@ -109,9 +105,7 @@ void OMXPlayerSubtitles::Close() BOOST_NOEXCEPT
m_mailbox.clear();
m_subtitle_buffers.clear();

#ifndef NDEBUG
m_open = false;
#endif
}

void OMXPlayerSubtitles::Process()
Expand Down Expand Up @@ -388,8 +382,9 @@ void OMXPlayerSubtitles::SetDelay(int value) BOOST_NOEXCEPT

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

if (!m_open)
return;

if(visible)
{
if (!m_visible)
Expand All @@ -410,7 +405,9 @@ void OMXPlayerSubtitles::SetVisible(bool visible) BOOST_NOEXCEPT

void OMXPlayerSubtitles::SetActiveStream(size_t index) BOOST_NOEXCEPT
{
assert(m_open);
if (!m_open)
return;

assert(index < m_subtitle_buffers.size());

m_active_index = index;
Expand Down Expand Up @@ -490,8 +487,9 @@ bool OMXPlayerSubtitles::AddPacket(OMXPacket *pkt, size_t stream_index) BOOST_NO

void OMXPlayerSubtitles::DisplayText(const std::string& text, int duration) BOOST_NOEXCEPT
{
assert(m_open);

if (!m_open)
return;

vector<string> text_lines;
split(text_lines, text, is_any_of("\n"));
SendToRenderer(Message::DisplayText{std::move(text_lines), duration});
Expand Down
9 changes: 4 additions & 5 deletions OMXPlayerSubtitles.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class OMXPlayerSubtitles : public OMXThread

size_t GetActiveStream() BOOST_NOEXCEPT
{
assert(m_open);
if (!m_open)
return;

assert(!m_subtitle_buffers.empty());
return m_active_index;
}
Expand Down Expand Up @@ -174,8 +176,5 @@ class OMXPlayerSubtitles : public OMXThread
OMXClock* m_av_clock;
int m_display;
int m_layer;

#ifndef NDEBUG
bool m_open;
#endif
bool m_open;
};
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ No effect.
Params | Type
:-------------: | -------
Return | `null`

##### DisplayText

Display a message for the specified amount of time. If omxplayer is run with
--no-osd, no message is displayed

Params | Type | Description
:-------------: | ----------| ------------------
1 | `string` | Message to display
2 | `int64` | Microseconds to display
Return | `null` |

#### Properties

Expand Down
4 changes: 4 additions & 0 deletions dbuscontrol.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export DBUS_SESSION_BUS_PID=`cat $OMXPLAYER_DBUS_PID`
[ -z "$DBUS_SESSION_BUS_ADDRESS" ] && { echo "Must have DBUS_SESSION_BUS_ADDRESS" >&2; exit 1; }

case $1 in
displaytext)
dbus-send --print-reply=literal --session --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.DisplayText string:"$2" int64:$3 >/dev/null
;;

status)
duration=`dbus-send --print-reply=literal --session --reply-timeout=500 --dest=org.mpris.MediaPlayer2.omxplayer /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:"org.mpris.MediaPlayer2.Player" string:"Duration"`
[ $? -ne 0 ] && exit 1
Expand Down
2 changes: 1 addition & 1 deletion omxplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extern "C" {
// when we repeatedly seek, rather than play continuously
#define TRICKPLAY(speed) (speed < 0 || speed > 4 * DVD_PLAYSPEED_NORMAL)

#define DISPLAY_TEXT(text, ms) if(m_osd) m_player_subtitles.DisplayText(text, ms)
#define DISPLAY_TEXT(text, ms) if(m_osd) m_player_subtitles.DisplayText(text, ms)

#define DISPLAY_TEXT_SHORT(text) DISPLAY_TEXT(text, 1000)
#define DISPLAY_TEXT_LONG(text) DISPLAY_TEXT(text, 2000)
Expand Down