]> git.tdb.fi Git - xinema.git/blob - source/xinestream.cpp
Inform clients of stream title changes
[xinema.git] / source / xinestream.cpp
1 #include <msp/io/print.h>
2 #include "xineengine.h"
3 #include "xinestream.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 XineStream::XineStream(XineEngine &e, const string &mrl):
9         engine(e)
10 {
11         stream = xine_stream_new(engine.get_engine(), engine.get_audio_driver(), engine.get_video_driver());
12         xine_open(stream, mrl.c_str());
13
14         queue = xine_event_new_queue(stream);
15
16         check_info();
17
18         engine.add_stream(*this);
19 }
20
21 XineStream::~XineStream()
22 {
23         engine.remove_stream(*this);
24
25         xine_close(stream);
26         xine_event_dispose_queue(queue);
27         xine_dispose(stream);
28 }
29
30 void XineStream::play()
31 {
32         xine_play(stream, 0, 0);
33 }
34
35 void XineStream::stop()
36 {
37         xine_stop(stream);
38 }
39
40 void XineStream::tick()
41 {
42         while(xine_event_t *event = xine_event_get(queue))
43         {
44                 handle_event(*event);
45                 xine_event_free(event);
46         }
47
48         check_info();
49 }
50
51 void XineStream::check_info()
52 {
53         const char *xt = xine_get_meta_info(stream, XINE_META_INFO_TITLE);
54         if(xt)
55         {
56                 if(title.compare(xt))
57                 {
58                         title = xt;
59                         signal_title_changed.emit(title);
60                 }
61         }
62         else if(!title.empty())
63         {
64                 title.clear();
65                 signal_title_changed.emit(title);
66         }
67
68         int dur_msec, pos_msec;
69         xine_get_pos_length(stream, 0, &pos_msec, &dur_msec);
70         Time::TimeDelta dur = dur_msec*Time::msec;
71         Time::TimeDelta pos = pos_msec*Time::msec;
72         if(dur!=duration)
73         {
74                 duration = dur;
75                 signal_duration_changed.emit(duration);
76         }
77         if(pos!=position)
78         {
79                 position = pos;
80                 signal_position_changed.emit(position);
81         }
82 }
83
84 void XineStream::handle_event(const xine_event_t &event)
85 {
86         switch(event.type)
87         {
88         case XINE_EVENT_PROGRESS:
89                 {
90                         xine_progress_data_t *data = reinterpret_cast<xine_progress_data_t *>(event.data);
91                         IO::print("%s [%d%%]\n", data->description, data->percent);
92                 }
93                 break;
94         }
95 }