From: Mikko Rasa Date: Fri, 16 Oct 2015 15:26:43 +0000 (+0300) Subject: Inform clients of stream title changes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3bd92c1fa7a85b47356cd6f2bad23893955a0785;p=xinema.git Inform clients of stream title changes --- diff --git a/source/client.cpp b/source/client.cpp index f116892..f042c66 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -90,6 +90,7 @@ void Client::list_directory(const FS::Path &dn) void Client::stream_created(XineStream &stream) { + stream.signal_title_changed.connect(sigc::mem_fun(this, &Client::stream_title_changed)); stream.signal_duration_changed.connect(sigc::mem_fun(this, &Client::stream_duration_changed)); stream.signal_position_changed.connect(sigc::mem_fun(this, &Client::stream_position_changed)); string title = stream.get_title(); @@ -97,6 +98,11 @@ void Client::stream_created(XineStream &stream) send_reply("title "+title); } +void Client::stream_title_changed(const string &title) +{ + send_reply("title "+title); +} + void Client::stream_duration_changed(const Time::TimeDelta &dur) { send_reply(format("duration %.3f", dur/Time::sec)); diff --git a/source/client.h b/source/client.h index fa2ea8d..31bdbec 100644 --- a/source/client.h +++ b/source/client.h @@ -32,6 +32,7 @@ private: void list_directory(const Msp::FS::Path &); void stream_created(XineStream &); + void stream_title_changed(const std::string &); void stream_duration_changed(const Msp::Time::TimeDelta &); void stream_position_changed(const Msp::Time::TimeDelta &); }; diff --git a/source/xinestream.cpp b/source/xinestream.cpp index d152f51..5614dd0 100644 --- a/source/xinestream.cpp +++ b/source/xinestream.cpp @@ -13,6 +13,8 @@ XineStream::XineStream(XineEngine &e, const string &mrl): queue = xine_event_new_queue(stream); + check_info(); + engine.add_stream(*this); } @@ -25,12 +27,6 @@ XineStream::~XineStream() xine_dispose(stream); } -string XineStream::get_title() const -{ - const char *title = xine_get_meta_info(stream, XINE_META_INFO_TITLE); - return (title ? title : string()); -} - void XineStream::play() { xine_play(stream, 0, 0); @@ -49,6 +45,26 @@ void XineStream::tick() xine_event_free(event); } + check_info(); +} + +void XineStream::check_info() +{ + const char *xt = xine_get_meta_info(stream, XINE_META_INFO_TITLE); + if(xt) + { + if(title.compare(xt)) + { + title = xt; + signal_title_changed.emit(title); + } + } + else if(!title.empty()) + { + title.clear(); + signal_title_changed.emit(title); + } + int dur_msec, pos_msec; xine_get_pos_length(stream, 0, &pos_msec, &dur_msec); Time::TimeDelta dur = dur_msec*Time::msec; diff --git a/source/xinestream.h b/source/xinestream.h index 0b9bbd6..c1f27f7 100644 --- a/source/xinestream.h +++ b/source/xinestream.h @@ -10,6 +10,7 @@ class XineEngine; class XineStream { public: + sigc::signal signal_title_changed; sigc::signal signal_duration_changed; sigc::signal signal_position_changed; @@ -17,6 +18,7 @@ private: XineEngine &engine; xine_stream_t *stream; xine_event_queue_t *queue; + std::string title; Msp::Time::TimeDelta duration; Msp::Time::TimeDelta position; @@ -26,13 +28,14 @@ public: const Msp::Time::TimeDelta &get_duration() const { return duration; } const Msp::Time::TimeDelta &get_position() const { return position; } - std::string get_title() const; + const std::string &get_title() const { return title; } void play(); void stop(); void tick(); private: + void check_info(); void handle_event(const xine_event_t &); };