1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-22 06:42:03 +00:00

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.
This commit is contained in:
wm4 2015-04-09 19:30:26 +02:00
parent 4e8ee522f4
commit 8dc7156bc0
8 changed files with 48 additions and 1 deletions

View File

@ -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.

View File

@ -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) {

View File

@ -37,6 +37,7 @@ public:
public slots:
void command(const QVariant& params);
void sync();
void swapped();
void cleanup();
signals:
void onUpdate();

View File

@ -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.

View File

@ -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

View File

@ -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.
*

View File

@ -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;

View File

@ -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;