]> git.tdb.fi Git - xinema.git/commitdiff
Inform clients of stream title changes
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 15:26:43 +0000 (18:26 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Oct 2015 15:26:43 +0000 (18:26 +0300)
source/client.cpp
source/client.h
source/xinestream.cpp
source/xinestream.h

index f116892a06b1073401a5c1683007935f29b9bd97..f042c66b020b70d31e0c0348c098c25a04540321 100644 (file)
@@ -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));
index fa2ea8d02ebdcfff8002b74e9f8bbb77071d894d..31bdbec4d70ce6a571425a2dc51e2988ee2d29fd 100644 (file)
@@ -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 &);
 };
index d152f518e2cb34941d24521d0e205ed04d532e1e..5614dd00838324e29a3483e70e16459792a02770 100644 (file)
@@ -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;
index 0b9bbd69462cde16370502a63fe9d4ce6e31611c..c1f27f74aa45542318d40a05e8adb28153b874ea 100644 (file)
@@ -10,6 +10,7 @@ class XineEngine;
 class XineStream
 {
 public:
+       sigc::signal<void, const std::string &> signal_title_changed;
        sigc::signal<void, const Msp::Time::TimeDelta &> signal_duration_changed;
        sigc::signal<void, const Msp::Time::TimeDelta &> 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 &);
 };