From 8dc7156bc0271965ea1e6768cfc7bbe67cef1876 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 9 Apr 2015 19:30:26 +0200 Subject: vo_opengl_cb: add a function to report vsync time And also let vo.c know of it. Currently, this does not help much, but will facilitate future improvements. --- DOCS/client-api-changes.rst | 1 + DOCS/client_api_examples/qml_direct/main.cpp | 7 +++++++ DOCS/client_api_examples/qml_direct/main.h | 1 + libmpv/client.h | 2 +- libmpv/mpv.def | 1 + libmpv/opengl_cb.h | 12 ++++++++++++ player/client.c | 4 ++++ video/out/vo_opengl_cb.c | 21 +++++++++++++++++++++ 8 files changed, 48 insertions(+), 1 deletion(-) diff --git a/DOCS/client-api-changes.rst b/DOCS/client-api-changes.rst index 258e9653e2..594cd42968 100644 --- a/DOCS/client-api-changes.rst +++ b/DOCS/client-api-changes.rst @@ -26,6 +26,7 @@ API changes :: --- mpv 0.9.0 will be released --- + 1.16 - add mpv_opengl_cb_report_flip() 1.15 - mpv_initialize() will now load config files. This requires setting the "config" and "config-dir" options. In particular, it will load mpv.conf. diff --git a/DOCS/client_api_examples/qml_direct/main.cpp b/DOCS/client_api_examples/qml_direct/main.cpp index 5f1f1468cf..93a843dfd0 100644 --- a/DOCS/client_api_examples/qml_direct/main.cpp +++ b/DOCS/client_api_examples/qml_direct/main.cpp @@ -96,6 +96,8 @@ void MpvObject::handleWindowChanged(QQuickWindow *win) this, &MpvObject::sync, Qt::DirectConnection); connect(win, &QQuickWindow::sceneGraphInvalidated, this, &MpvObject::cleanup, Qt::DirectConnection); + connect(win, &QQuickWindow::frameSwapped, + this, &MpvObject::swapped, Qt::DirectConnection); win->setClearBeforeRendering(false); } @@ -110,6 +112,11 @@ void MpvObject::sync() renderer->size = window()->size() * window()->devicePixelRatio(); } +void MpvObject::swapped() +{ + mpv_opengl_cb_report_flip(mpv_gl, 0); +} + void MpvObject::cleanup() { if (renderer) { diff --git a/DOCS/client_api_examples/qml_direct/main.h b/DOCS/client_api_examples/qml_direct/main.h index 66fe8c94a5..b0310ff0be 100644 --- a/DOCS/client_api_examples/qml_direct/main.h +++ b/DOCS/client_api_examples/qml_direct/main.h @@ -37,6 +37,7 @@ public: public slots: void command(const QVariant& params); void sync(); + void swapped(); void cleanup(); signals: void onUpdate(); diff --git a/libmpv/client.h b/libmpv/client.h index 2ace0f54cf..511c4794b4 100644 --- a/libmpv/client.h +++ b/libmpv/client.h @@ -195,7 +195,7 @@ extern "C" { * relational operators (<, >, <=, >=). */ #define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL) -#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 15) +#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 16) /** * Return the MPV_CLIENT_API_VERSION the mpv source has been compiled with. diff --git a/libmpv/mpv.def b/libmpv/mpv.def index d4d45874fa..4cdcf6b06b 100644 --- a/libmpv/mpv.def +++ b/libmpv/mpv.def @@ -23,6 +23,7 @@ mpv_initialize mpv_load_config_file mpv_observe_property mpv_opengl_cb_init_gl +mpv_opengl_cb_report_flip mpv_opengl_cb_render mpv_opengl_cb_set_update_callback mpv_opengl_cb_uninit_gl diff --git a/libmpv/opengl_cb.h b/libmpv/opengl_cb.h index 0e679e5edf..225f44fd50 100644 --- a/libmpv/opengl_cb.h +++ b/libmpv/opengl_cb.h @@ -198,6 +198,18 @@ int mpv_opengl_cb_init_gl(mpv_opengl_cb_context *ctx, const char *exts, */ int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4]); +/** + * Tell the renderer that a frame was flipped at the given time. This is + * optional, but can help the player to achieve better timing. + * + * If this is called while no video or no OpenGL is initialized, it is ignored. + * + * @param time The mpv time (using mpv_get_time_us()) at which the flip call + * returned. If 0 is passed, mpv_get_time_us() is used instead. + * @return error code + */ +int mpv_opengl_cb_report_flip(mpv_opengl_cb_context *ctx, int64_t time); + /** * Destroy the mpv OpenGL state. * diff --git a/player/client.c b/player/client.c index 3593b1d99f..ef1aa4f52e 100644 --- a/player/client.c +++ b/player/client.c @@ -1709,6 +1709,10 @@ int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4]) { return MPV_ERROR_NOT_IMPLEMENTED; } +int mpv_opengl_cb_report_flip(mpv_opengl_cb_context *ctx, int64_t time) +{ + return MPV_ERROR_NOT_IMPLEMENTED; +} int mpv_opengl_cb_uninit_gl(mpv_opengl_cb_context *ctx) { return MPV_ERROR_NOT_IMPLEMENTED; diff --git a/video/out/vo_opengl_cb.c b/video/out/vo_opengl_cb.c index 551a650d15..a7f7657889 100644 --- a/video/out/vo_opengl_cb.c +++ b/video/out/vo_opengl_cb.c @@ -19,6 +19,7 @@ #include "vo.h" #include "video/mp_image.h" #include "sub/osd.h" +#include "osdep/timer.h" #include "common/global.h" #include "player/client.h" @@ -76,6 +77,7 @@ struct mpv_opengl_cb_context { struct m_config *new_opts_cfg; bool eq_changed; struct mp_csp_equalizer eq; + int64_t recent_flip; // --- All of these can only be accessed from the thread where the host // application's OpenGL context is current - i.e. only while the @@ -342,6 +344,15 @@ int mpv_opengl_cb_render(struct mpv_opengl_cb_context *ctx, int fbo, int vp[4]) return left; } +int mpv_opengl_cb_report_flip(mpv_opengl_cb_context *ctx, int64_t time) +{ + pthread_mutex_lock(&ctx->lock); + ctx->recent_flip = time > 0 ? time : mp_time_us(); + pthread_mutex_unlock(&ctx->lock); + + return 0; +} + static void draw_image(struct vo *vo, mp_image_t *mpi) { struct vo_priv *p = vo->priv; @@ -486,6 +497,16 @@ static int control(struct vo *vo, uint32_t request, void *data) *arg = p->ctx ? &p->ctx->hwdec_info : NULL; return true; } + case VOCTRL_GET_RECENT_FLIP_TIME: { + int r = VO_FALSE; + pthread_mutex_lock(&p->ctx->lock); + if (p->ctx->recent_flip) { + *(int64_t *)data = p->ctx->recent_flip; + r = VO_TRUE; + } + pthread_mutex_unlock(&p->ctx->lock); + return r; + } } return VO_NOTIMPL; -- cgit v1.2.3