From: Mikko Rasa Date: Fri, 16 Oct 2015 21:28:48 +0000 (+0300) Subject: Re-display the logo after the stream finishes X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=4761421;p=xinema.git Re-display the logo after the stream finishes Also don't present it as a playing file. --- diff --git a/source/client.cpp b/source/client.cpp index ba0be5b..835dbbd 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); @@ -142,6 +143,11 @@ void Client::stream_created(XineStream &stream) stream_duration_changed(dur); } +void Client::stream_destroyed() +{ + send_reply("ejected"); +} + void Client::stream_state_changed(XineStream::State state) { send_reply(format("state %s", state)); diff --git a/source/client.h b/source/client.h index f8aeb82..f1f4dc1 100644 --- a/source/client.h +++ b/source/client.h @@ -34,6 +34,7 @@ private: void list_directory(const Msp::FS::Path &); void stream_created(XineStream &); + void stream_destroyed(); void stream_state_changed(XineStream::State); void stream_title_changed(const std::string &); void stream_duration_changed(const Msp::Time::TimeDelta &); diff --git a/source/xinema.cpp b/source/xinema.cpp index bc70c41..4991543 100644 --- a/source/xinema.cpp +++ b/source/xinema.cpp @@ -19,7 +19,9 @@ Xinema::Xinema(int, char **): window(display, 1920, 1080), network(*this), engine(0), - stream(0) + stream(0), + logo_mode(false), + pending_logo(false) { window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Xinema::exit), 0)); } @@ -30,7 +32,7 @@ int Xinema::main() display.tick(); engine = new XineEngine(window); - play_file(FS::get_sys_data_dir()/"xinema.png"); + show_logo(); Application::main(); @@ -43,22 +45,35 @@ int Xinema::main() void Xinema::tick() { - bool new_stream = false; - + string mrl; + bool logo; { MutexLock lock(command_mutex); - if(!pending_mrl.empty()) - { - delete stream; - stream = new XineStream(*engine, pending_mrl); - stream->play(); - pending_mrl.clear(); - new_stream = true; - } + mrl = pending_mrl; + logo = pending_logo; + pending_mrl.clear(); + pending_logo = false; } - if(new_stream) - signal_stream_created.emit(*stream); + if(!mrl.empty()) + { + bool had_stream = stream; + + delete stream; + stream = 0; + + if(had_stream && !logo_mode) + signal_stream_destroyed.emit(); + + logo_mode = logo; + stream = new XineStream(*engine, mrl); + if(!logo_mode) + stream->signal_finished.connect(sigc::mem_fun(this, &Xinema::show_logo)); + stream->play(); + + if(!logo_mode) + signal_stream_created.emit(*stream); + } XLockDisplay(display.get_private().display); display.tick(); @@ -73,4 +88,12 @@ void Xinema::play_file(const FS::Path &fn) { MutexLock lock(command_mutex); pending_mrl = "file://"+fn.str(); + pending_logo = false; +} + +void Xinema::show_logo() +{ + MutexLock lock(command_mutex); + pending_mrl = "file://"+(FS::get_sys_data_dir()/"xinema.png").str(); + pending_logo = true; } diff --git a/source/xinema.h b/source/xinema.h index e82f26f..cdb1db8 100644 --- a/source/xinema.h +++ b/source/xinema.h @@ -20,6 +20,7 @@ private: public: sigc::signal signal_stream_created; + sigc::signal signal_stream_destroyed; private: EarlyInit early_init; @@ -28,9 +29,11 @@ private: NetworkInterface network; XineEngine *engine; XineStream *stream; + bool logo_mode; Msp::Mutex command_mutex; std::string pending_mrl; + bool pending_logo; public: Xinema(int, char **); @@ -41,7 +44,10 @@ private: public: void play_file(const Msp::FS::Path &); - XineStream *get_stream() const { return stream; } + XineStream *get_stream() const { return logo_mode ? 0 : stream; } + +private: + void show_logo(); }; #endif