]> git.tdb.fi Git - xinema.git/blob - source/xinema.cpp
025ec562ad85fff87c414f5b023ceeb6cec62eb8
[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         {
40                 MutexLock lock(command_mutex);
41                 if(!pending_mrl.empty())
42                 {
43                         delete stream;
44                         stream = new XineStream(*engine, pending_mrl);
45                         stream->play();
46                         pending_mrl.clear();
47                 }
48         }
49
50         {
51                 MutexLock lock(display_mutex);
52                 display.tick();
53         }
54
55         engine->tick();
56
57         Time::sleep(10*Time::msec);
58 }
59
60 void Xinema::play_file(const FS::Path &fn)
61 {
62         MutexLock lock(command_mutex);
63         pending_mrl = "file://"+fn.str();
64 }