#endif
}
+void
+dcpomatic_sleep_milliseconds (int ms)
+{
+#ifdef DCPOMATIC_POSIX
+ usleep (ms * 1000);
+#endif
+#ifdef DCPOMATIC_WINDOWS
+ Sleep (ms);
+#endif
+}
+
/** @return A string of CPU information (model name etc.) */
string
cpu_info ()
struct AVIOContext;
void dcpomatic_sleep_seconds (int);
+void dcpomatic_sleep_milliseconds (int);
extern std::string cpu_info ();
extern void run_ffprobe (boost::filesystem::path, boost::filesystem::path);
extern std::list<std::pair<std::string, std::string> > mount_info ();
#include <wx/preferences.h>
#include <wx/splash.h>
#include <wx/wxhtml.h>
+#ifdef __WXGTK__
+#include <X11/Xlib.h>
+#endif
#ifdef __WXMSW__
#include <shellapi.h>
#endif
: wxApp ()
, _frame (0)
, _splash (0)
- {}
+ {
+#ifdef DCPOMATIC_LINUX
+ XInitThreads ();
+#endif
+ }
private:
#include <wx/preferences.h>
#include <wx/progdlg.h>
#include <wx/display.h>
+#ifdef __WXGTK__
+#include <X11/Xlib.h>
+#endif
#ifdef __WXOSX__
#include <ApplicationServices/ApplicationServices.h>
#endif
App ()
: wxApp ()
, _frame (0)
- {}
+ {
+#ifdef DCPOMATIC_LINUX
+ XInitThreads ();
+#endif
+ }
private:
obj.uselib += ' WXWIDGETS'
if not bld.env.TARGET_OSX:
obj.uselib += ' GL GLU'
+ if bld.env.TARGET_LINUX:
+ obj.uselib += ' X11'
obj.includes = ['..']
obj.use = ['libdcpomatic2', 'libdcpomatic2-wx']
obj.source = '%s.cc' % t
/* XXX_b: to remove */
friend class SimpleVideoView;
+ friend class GLVideoView;
+ friend class VideoView;
void video_view_sized ();
void calculate_sizes ();
#include "lib/image.h"
#include "lib/dcpomatic_assert.h"
#include "lib/exceptions.h"
+#include "lib/cross.h"
+#include "lib/player_video.h"
#include <boost/bind.hpp>
#include <iostream>
GLVideoView::GLVideoView (FilmViewer* viewer, wxWindow *parent)
: VideoView (viewer)
, _vsync_enabled (false)
+ , _thread (0)
{
_canvas = new wxGLCanvas (parent, wxID_ANY, 0, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE);
- _context = new wxGLContext (_canvas);
_canvas->Bind (wxEVT_PAINT, boost::bind(&GLVideoView::paint, this));
_canvas->Bind (wxEVT_SIZE, boost::bind(boost::ref(Sized)));
GLVideoView::~GLVideoView ()
{
+ if (_thread) {
+ _thread->interrupt ();
+ _thread->join ();
+ }
+ delete _thread;
+
glDeleteTextures (1, &_id);
- delete _context;
}
static void
void
GLVideoView::paint ()
{
+ /* XXX_b: can't do this yet */
+#if 0
_viewer->state_timer().set("paint-panel");
_canvas->SetCurrent (*_context);
wxPaintDC dc (_canvas);
draw ();
_viewer->state_timer().unset();
+#endif
}
void
if (!_canvas->IsShownOnScreen()) {
return;
}
- wxClientDC dc (_canvas);
- draw ();
+ /* XXX_b */
+// wxClientDC dc (_canvas);
+// draw ();
}
void
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
check_gl_error ("glTexParameterf");
}
+
+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;
+}
#include <wx/glcanvas.h>
#include <dcp/util.h>
#include <boost/shared_ptr.hpp>
+#include <boost/thread.hpp>
#undef None
#undef Success
return _canvas;
}
void update ();
+ void start ();
bool vsync_enabled () const {
return _vsync_enabled;
}
private:
- void paint ();
- void draw ();
+ void paint ();
+ void draw ();
+ void thread ();
+ wxGLContext* context () const;
wxGLCanvas* _canvas;
- wxGLContext* _context;
- GLuint _id;
- boost::optional<dcp::Size> _size;
+
+ wxGLContext* _context;
+ mutable boost::mutex _context_mutex;
+
+ GLuint _id;
+ boost::optional<dcp::Size> _size;
bool _vsync_enabled;
+ boost::thread* _thread;
};
}
LOG_DEBUG_PLAYER("%1 -> %2; delay %3", next.seconds(), _viewer->time().seconds(), max((next.seconds() - _viewer->time().seconds()) * 1000, 1.0));
- _timer.Start (_viewer->time_until_next_frame()), wxTIMER_ONE_SHOT);
+ _timer.Start (_viewer->time_until_next_frame(), wxTIMER_ONE_SHOT);
if (_viewer->butler()) {
_viewer->butler()->rethrow ();
bool
SimpleVideoView::get (bool lazy)
{
- DCPOMATIC_ASSERT (_viewer->butler());
- _viewer->_gets++;
-
- do {
- Butler::Error e;
- _player_video = _viewer->butler()->get_video (!lazy, &e);
- if (!_player_video.first && e == Butler::AGAIN) {
- if (lazy) {
- /* No video available; return saying we failed */
- return false;
- } else {
- /* Player was suspended; come back later */
- signal_manager->when_idle (boost::bind(&SimpleVideoView::get, this, false));
- return false;
- }
+ bool r = get_next_frame (lazy);
+ if (!r) {
+ if (lazy) {
+ /* No video available; return saying we failed */
+ return false;
+ } else {
+ /* Player was suspended; come back later */
+ signal_manager->when_idle (boost::bind(&SimpleVideoView::get, this, false));
+ return false;
}
- } while (
- _player_video.first &&
- _viewer->film()->three_d() &&
- _viewer->_eyes != _player_video.first->eyes() &&
- _player_video.first->eyes() != EYES_BOTH
- );
-
- try {
- _viewer->butler()->rethrow ();
- } catch (DecodeError& e) {
- error_dialog (get(), e.what());
}
display_player_video ();
*/
#include "video_view.h"
+#include "wx_util.h"
+#include "film_viewer.h"
+#include "lib/butler.h"
void
VideoView::clear ()
_player_video.first.reset ();
_player_video.second = dcpomatic::DCPTime ();
}
+
+/** @param non_blocking true to return false quickly if no video is available quickly.
+ * @return false if we gave up because it would take too long, otherwise true.
+ */
+bool
+VideoView::get_next_frame (bool non_blocking)
+{
+ DCPOMATIC_ASSERT (_viewer->butler());
+ _viewer->_gets++;
+
+ do {
+ Butler::Error e;
+ _player_video = _viewer->butler()->get_video (!non_blocking, &e);
+ if (!_player_video.first && e == Butler::AGAIN) {
+ return false;
+ }
+ } while (
+ _player_video.first &&
+ _viewer->film()->three_d() &&
+ _viewer->_eyes != _player_video.first->eyes() &&
+ _player_video.first->eyes() != EYES_BOTH
+ );
+
+ try {
+ _viewer->butler()->rethrow ();
+ } catch (DecodeError& e) {
+ error_dialog (get(), e.what());
+ }
+
+ return true;
+}
/* XXX_b: to remove */
friend class FilmViewer;
+ bool get_next_frame (bool non_blocking);
+
FilmViewer* _viewer;
std::pair<boost::shared_ptr<PlayerVideo>, dcpomatic::DCPTime> _player_video;
conf.env['CXXFLAGS_AVCODEC'] = []
conf.env['CXXFLAGS_AVUTIL'] = []
+ if conf.env.TARGET_LINUX:
+ conf.env.LIB_X11 = ['X11']
+
# Boost
if conf.options.static_boost:
conf.env.STLIB_BOOST_THREAD = ['boost_thread']