]> git.tdb.fi Git - xinema.git/blobdiff - source/client.cpp
Also send the current position when a client connects
[xinema.git] / source / client.cpp
index 835dbbd91597f234ad794571dd3e14d56b2ec1d8..0130846f92c888a6838756a499f33df4357425d8 100644 (file)
@@ -74,6 +74,14 @@ XineStream &Client::get_stream() const
        throw runtime_error("No stream");
 }
 
+int Client::convert_channel(const string &arg)
+{
+       if(arg=="off")
+               return XineStream::OFF;
+       else
+               return lexical_cast<unsigned>(arg);
+}
+
 void Client::process_command(const string &cmd)
 {
        string::size_type space = cmd.find(' ');
@@ -94,6 +102,10 @@ void Client::process_command(const string &cmd)
                get_stream().pause();
        else if(keyword=="stop")
                get_stream().stop();
+       else if(keyword=="select_audio")
+               get_stream().select_audio_channel(convert_channel(args));
+       else if(keyword=="select_spu")
+               get_stream().select_spu_channel(convert_channel(args));
        else
                throw runtime_error("Invalid command");
 }
@@ -124,6 +136,8 @@ void Client::list_directory(const FS::Path &dn)
                else
                        send_reply("file "+*i);
        }
+
+       send_reply("directory_end");
 }
 
 void Client::stream_created(XineStream &stream)
@@ -132,7 +146,11 @@ 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));
+       stream.signal_channels_changed.connect(sigc::mem_fun(this, &Client::stream_channels_changed));
+       stream.signal_current_audio_channel_changed.connect(sigc::mem_fun(this, &Client::stream_audio_channel_changed));
+       stream.signal_current_spu_channel_changed.connect(sigc::mem_fun(this, &Client::stream_spu_channel_changed));
 
+       MutexLock lock(stream.get_mutex());
        stream_state_changed(stream.get_state());
 
        string title = stream.get_title();
@@ -140,7 +158,14 @@ void Client::stream_created(XineStream &stream)
                send_reply("title "+title);
 
        if(const Time::TimeDelta &dur = stream.get_duration())
+       {
                stream_duration_changed(dur);
+               stream_position_changed(stream.get_position());
+       }
+
+       stream_channels_changed();
+       stream_audio_channel_changed(stream.get_current_audio_channel());
+       stream_spu_channel_changed(stream.get_current_spu_channel());
 }
 
 void Client::stream_destroyed()
@@ -171,3 +196,36 @@ void Client::stream_position_changed(const Time::TimeDelta &pos)
                last_position = pos;
        }
 }
+
+void Client::stream_channels_changed()
+{
+       XineStream &stream = get_stream();
+
+       const vector<string> &audio_channels = stream.get_audio_channels();
+       send_reply(format("audio_count %d", audio_channels.size()));
+       for(unsigned i=0; i<audio_channels.size(); ++i)
+               send_reply(format("audio %d %s", i, audio_channels[i]));
+
+       const vector<string> &spu_channels = stream.get_spu_channels();
+       send_reply(format("spu_count %d", spu_channels.size()));
+       for(unsigned i=0; i<spu_channels.size(); ++i)
+               send_reply(format("spu %d %s", i, spu_channels[i]));
+
+       send_reply("channels_end");
+}
+
+void Client::stream_audio_channel_changed(int chan)
+{
+       if(chan==XineStream::OFF)
+               send_reply("current_audio off");
+       else
+               send_reply(format("current_audio %d", chan));
+}
+
+void Client::stream_spu_channel_changed(int chan)
+{
+       if(chan==XineStream::OFF)
+               send_reply("current_spu off");
+       else
+               send_reply(format("current_spu %d", chan));
+}