X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fclient.cpp;h=353694e6d6109f943cd05649c59324ed4ad39af9;hb=HEAD;hp=8d61f3fa51e56c9a78d12a322e4ea973c9a479ba;hpb=2e629085885b652a10d775695e63bc4892aa2eca;p=xinema.git diff --git a/source/client.cpp b/source/client.cpp index 8d61f3f..353694e 100644 --- a/source/client.cpp +++ b/source/client.cpp @@ -16,6 +16,7 @@ Client::Client(Xinema &x, Net::StreamSocket *s): 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)); + xinema.signal_stream_destroyed.connect(sigc::mem_fun(this, &Client::stream_destroyed)); XineStream *stream = xinema.get_stream(); if(stream) stream_created(*stream); @@ -24,7 +25,17 @@ Client::Client(Xinema &x, Net::StreamSocket *s): void Client::data_available() { char rbuf[1024]; - unsigned len = socket->read(rbuf, sizeof(rbuf)); + unsigned len; + try + { + len = socket->read(rbuf, sizeof(rbuf)); + } + catch(const std::exception &) + { + stale = true; + return; + } + buffer.append(rbuf, len); string::size_type start = 0; @@ -63,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(arg); +} + void Client::process_command(const string &cmd) { string::size_type space = cmd.find(' '); @@ -83,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"); } @@ -90,8 +113,15 @@ void Client::process_command(const string &cmd) void Client::send_reply(const string &reply) { Msp::MutexLock lock(mutex); - socket->write(reply); - socket->put('\n'); + try + { + socket->write(reply); + socket->put('\n'); + } + catch(const std::exception &) + { + stale = true; + } } void Client::list_directory(const FS::Path &dn) @@ -106,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) @@ -114,7 +146,14 @@ 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_video_size_changed.connect(sigc::mem_fun(this, &Client::stream_size_changed)); + stream.signal_framerate_changed.connect(sigc::mem_fun(this, &Client::stream_framerate_changed)); + stream.signal_codecs_changed.connect(sigc::mem_fun(this, &Client::stream_codecs_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(); @@ -122,7 +161,23 @@ 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_size_changed(stream.get_video_width(), stream.get_video_height()); + stream_framerate_changed(stream.get_framerate()); + stream_codecs_changed(stream.get_video_codec(), stream.get_audio_codec()); + + 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() +{ + send_reply("ejected"); } void Client::stream_state_changed(XineStream::State state) @@ -148,3 +203,52 @@ void Client::stream_position_changed(const Time::TimeDelta &pos) last_position = pos; } } + +void Client::stream_size_changed(unsigned w, unsigned h) +{ + send_reply(format("video_size %d %d", w, h)); +} + +void Client::stream_framerate_changed(float fps) +{ + send_reply(format("framerate %.2f", fps)); +} + +void Client::stream_codecs_changed(const string &vc, const string &ac) +{ + send_reply("video_codec "+vc); + send_reply("audio_codec "+ac); +} + +void Client::stream_channels_changed() +{ + XineStream &stream = get_stream(); + + const vector &audio_channels = stream.get_audio_channels(); + send_reply(format("audio_count %d", audio_channels.size())); + for(unsigned i=0; i &spu_channels = stream.get_spu_channels(); + send_reply(format("spu_count %d", spu_channels.size())); + for(unsigned i=0; i