+
+void
+GLVideoView::start ()
+{
+ _thread = new boost::thread (boost::bind(&GLVideoView::thread, this));
+}
+
+void
+GLVideoView::thread ()
+try
+{
+ /* XXX_b: check all calls and signal emissions in this method & protect them if necessary */
+ {
+ boost::mutex::scoped_lock lm (_context_mutex);
+ _context = new wxGLContext (_canvas);
+ _canvas->SetCurrent (*_context);
+ }
+
+ while (true) {
+ if (!_viewer->film() || !_viewer->playing()) {
+ dcpomatic_sleep_milliseconds (40);
+ continue;
+ }
+
+ dcpomatic::DCPTime const next = _viewer->position() + _viewer->one_video_frame();
+
+ if (next >= _viewer->film()->length()) {
+ _viewer->stop ();
+ _viewer->Finished ();
+ return;
+ }
+
+ get_next_frame (false);
+ set_image (_player_video.first->image(bind(&PlayerVideo::force, _1, AV_PIX_FMT_RGB24), false, true));
+ draw ();
+ _viewer->_video_position = _player_video.second;
+
+ std::cout << "sleep " << _viewer->time_until_next_frame() << "\n";
+ dcpomatic_sleep_milliseconds (_viewer->time_until_next_frame());
+ }
+
+ {
+ boost::mutex::scoped_lock lm (_context_mutex);
+ delete _context;
+ }
+}
+catch (boost::thread_interrupted& e)
+{
+ /* XXX_b: store exceptions here */
+ delete _context;
+ return;
+}
+
+wxGLContext *
+GLVideoView::context () const
+{
+ boost::mutex::scoped_lock lm (_context_mutex);
+ return _context;
+}