]> git.tdb.fi Git - xinema.git/blobdiff - source/xinema.cpp
Re-display the logo after the stream finishes
[xinema.git] / source / xinema.cpp
index 267f6a4eeb42b1dbebce1d71e67fc106133fe397..499154387e67eef838531e017ca944afe03007ea 100644 (file)
@@ -1,5 +1,6 @@
 #include <sigc++/bind.h>
 #include <msp/fs/dir.h>
+#include <msp/graphics/display_private.h>
 #include <msp/time/utils.h>
 #include "xineengine.h"
 #include "xinema.h"
@@ -8,11 +9,19 @@
 using namespace std;
 using namespace Msp;
 
+Xinema::EarlyInit::EarlyInit()
+{
+       XInitThreads();
+}
+
+
 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));
 }
@@ -22,8 +31,8 @@ int Xinema::main()
        window.show();
        display.tick();
 
-       engine = new XineEngine(window, &display_mutex);
-       play_file(FS::get_sys_data_dir()/"xinema.png");
+       engine = new XineEngine(window);
+       show_logo();
 
        Application::main();
 
@@ -36,28 +45,40 @@ 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())
        {
-               MutexLock lock(display_mutex);
-               display.tick();
+               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();
+       XUnlockDisplay(display.get_private().display);
+
        engine->tick();
 
        Time::sleep(10*Time::msec);
@@ -67,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;
 }