2 #include <msp/fs/dir.h>
3 #include <msp/graphics/display_private.h>
4 #include <msp/graphics/window_private.h>
5 #include "xineengine.h"
10 XineEngine::XineEngine(const Graphics::Window &w, Mutex *m):
18 FS::Path config_fn = FS::get_home_dir()/".xine"/"config";
19 xine_config_load(engine, config_fn.c_str());
23 audio_driver = xine_open_audio_driver(engine, "auto", 0);
25 throw runtime_error("Could not open audio driver");
27 visual.display = window.get_display().get_private().display;
29 visual.d = window.get_private().window;
30 visual.user_data = this;
31 visual.dest_size_cb = &dest_size_cb;
32 visual.frame_output_cb = &frame_output_cb;
35 visual.lock_display = &lock_cb;
36 visual.unlock_display = &unlock_cb;
40 visual.lock_display = 0;
41 visual.unlock_display = 0;
44 video_driver = xine_open_video_driver(engine, "auto", XINE_VISUAL_TYPE_X11_2, &visual);
46 throw runtime_error("Could not open video driver");
49 XineEngine::~XineEngine()
51 xine_close_video_driver(engine, video_driver);
52 xine_close_audio_driver(engine, audio_driver);
56 void XineEngine::dest_size_cb(void *user_data, int, int, double, int *dest_width, int *dest_height, double *dest_pixel_aspect)
58 XineEngine &engine = *reinterpret_cast<XineEngine *>(user_data);
59 *dest_width = engine.window.get_width();
60 *dest_height = engine.window.get_height();
61 *dest_pixel_aspect = 1.0;
64 void XineEngine::frame_output_cb(void *user_data, int, int, double, int *dest_x, int *dest_y, int *dest_width, int *dest_height, double *dest_pixel_aspect, int *win_x, int *win_y)
66 XineEngine &engine = *reinterpret_cast<XineEngine *>(user_data);
69 *dest_width = engine.window.get_width();
70 *dest_height = engine.window.get_height();
71 *dest_pixel_aspect = 1.0;
76 void XineEngine::lock_cb(void *user_data)
78 XineEngine &engine = *reinterpret_cast<XineEngine *>(user_data);
79 pthread_t tid = pthread_self();
80 if(tid==engine.locked_thread)
84 engine.display_mutex->lock();
85 engine.locked_thread = tid;
86 engine.lock_count = 1;
90 void XineEngine::unlock_cb(void *user_data)
92 XineEngine &engine = *reinterpret_cast<XineEngine *>(user_data);
93 pthread_t tid = pthread_self();
94 if(tid!=engine.locked_thread)
95 throw logic_error("Unlock from non-locked thread");
96 if(!--engine.lock_count)
98 engine.locked_thread = 0;
99 engine.display_mutex->unlock();