]> git.tdb.fi Git - xinema.git/blobdiff - source/client.cpp
Export some simple playback information to clients
[xinema.git] / source / client.cpp
index dbe6091df0f6232c9bfb642663921d7505471297..f116892a06b1073401a5c1683007935f29b9bd97 100644 (file)
@@ -1,7 +1,9 @@
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
+#include <msp/strings/format.h>
 #include "client.h"
 #include "xinema.h"
+#include "xinestream.h"
 
 using namespace std;
 using namespace Msp;
@@ -13,6 +15,8 @@ Client::Client(Xinema &x, Net::StreamSocket *s):
 {
        socket->signal_data_available.connect(sigc::mem_fun(this, &Client::data_available));
        socket->signal_end_of_file.connect(sigc::mem_fun(this, &Client::end_of_stream));
+
+       xinema.signal_stream_created.connect(sigc::mem_fun(this, &Client::stream_created));
 }
 
 void Client::data_available()
@@ -83,3 +87,26 @@ void Client::list_directory(const FS::Path &dn)
                        send_reply("file "+*i);
        }
 }
+
+void Client::stream_created(XineStream &stream)
+{
+       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();
+       if(!title.empty())
+               send_reply("title "+title);
+}
+
+void Client::stream_duration_changed(const Time::TimeDelta &dur)
+{
+       send_reply(format("duration %.3f", dur/Time::sec));
+}
+
+void Client::stream_position_changed(const Time::TimeDelta &pos)
+{
+       if(abs(pos-last_position)>=Time::sec)
+       {
+               send_reply(format("position %.3f", pos/Time::sec));
+               last_position = pos;
+       }
+}