]> git.tdb.fi Git - xinema.git/blob - source/xinema.cpp
Export some simple playback information to clients
[xinema.git] / source / xinema.cpp
1 #include <sigc++/bind.h>
2 #include <msp/fs/dir.h>
3 #include <msp/time/utils.h>
4 #include "xineengine.h"
5 #include "xinema.h"
6 #include "xinestream.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 Xinema::Xinema(int, char **):
12         window(display, 1920, 1080),
13         network(*this),
14         engine(0),
15         stream(0)
16 {
17         window.signal_close.connect(sigc::bind(sigc::mem_fun(this, &Xinema::exit), 0));
18 }
19
20 int Xinema::main()
21 {
22         window.show();
23         display.tick();
24
25         engine = new XineEngine(window, &display_mutex);
26         play_file(FS::get_sys_data_dir()/"xinema.png");
27
28         Application::main();
29
30         if(stream)
31                 delete stream;
32         delete engine;
33
34         return exit_code;
35 }
36
37 void Xinema::tick()
38 {
39         bool new_stream = false;
40
41         {
42                 MutexLock lock(command_mutex);
43                 if(!pending_mrl.empty())
44                 {
45                         delete stream;
46                         stream = new XineStream(*engine, pending_mrl);
47                         stream->play();
48                         pending_mrl.clear();
49                         new_stream = true;
50                 }
51         }
52
53         if(new_stream)
54                 signal_stream_created.emit(*stream);
55
56         {
57                 MutexLock lock(display_mutex);
58                 display.tick();
59         }
60
61         engine->tick();
62
63         Time::sleep(10*Time::msec);
64 }
65
66 void Xinema::play_file(const FS::Path &fn)
67 {
68         MutexLock lock(command_mutex);
69         pending_mrl = "file://"+fn.str();
70 }