2014-12-09 16:47:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
#include "common/common.h"
|
|
|
|
#include "misc/bstr.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "options/m_config.h"
|
|
|
|
#include "options/options.h"
|
|
|
|
#include "aspect.h"
|
|
|
|
#include "vo.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "sub/osd.h"
|
2015-04-09 17:30:26 +00:00
|
|
|
#include "osdep/timer.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
#include "common/global.h"
|
|
|
|
#include "player/client.h"
|
|
|
|
|
2015-08-29 02:12:56 +00:00
|
|
|
#include "opengl/common.h"
|
|
|
|
#include "opengl/video.h"
|
|
|
|
#include "opengl/hwdec.h"
|
2017-08-07 17:14:18 +00:00
|
|
|
#include "opengl/ra_gl.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
#include "libmpv/opengl_cb.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mpv_opengl_cb_context is created by the host application - the host application
|
|
|
|
* can access it any time, even if the VO is destroyed (or not created yet).
|
|
|
|
* The OpenGL object allows initializing the renderer etc. The VO object is only
|
|
|
|
* here to transfer the video frames somehow.
|
2015-11-09 19:49:30 +00:00
|
|
|
*
|
|
|
|
* Locking hierarchy:
|
|
|
|
* - the libmpv user can mix openglcb and normal API; thus openglcb API
|
|
|
|
* functions can wait on the core, but not the reverse
|
|
|
|
* - the core does blocking calls into the VO thread, thus the VO functions
|
|
|
|
* can't wait on the user calling the API functions
|
|
|
|
* - to make video timing work like it should, the VO thread waits on the
|
|
|
|
* openglcb API user anyway, and the (unlikely) deadlock is avoided with
|
|
|
|
* a timeout
|
2014-12-09 16:47:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct vo_priv {
|
|
|
|
struct mpv_opengl_cb_context *ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mpv_opengl_cb_context {
|
|
|
|
struct mp_log *log;
|
2015-11-17 20:07:41 +00:00
|
|
|
struct mpv_global *global;
|
2014-12-31 19:31:19 +00:00
|
|
|
struct mp_client_api *client_api;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
pthread_mutex_t lock;
|
2015-05-12 20:16:19 +00:00
|
|
|
pthread_cond_t wakeup;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
// --- Protected by lock
|
2014-12-31 19:31:19 +00:00
|
|
|
bool initialized;
|
2014-12-09 16:47:02 +00:00
|
|
|
mpv_opengl_cb_update_fn update_cb;
|
|
|
|
void *update_cb_ctx;
|
2015-11-09 19:49:30 +00:00
|
|
|
struct vo_frame *next_frame; // next frame to draw
|
|
|
|
int64_t present_count; // incremented when next frame can be shown
|
|
|
|
int64_t expected_flip_count; // next vsync event for next_frame
|
2015-11-12 21:40:02 +00:00
|
|
|
bool redrawing; // next_frame was a redraw request
|
2015-11-09 19:49:30 +00:00
|
|
|
int64_t flip_count;
|
2015-07-01 17:24:28 +00:00
|
|
|
struct vo_frame *cur_frame;
|
2014-12-09 16:47:02 +00:00
|
|
|
struct mp_image_params img_params;
|
2015-10-14 18:38:30 +00:00
|
|
|
bool reconfigured, reset;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
int vp_w, vp_h;
|
2014-12-09 16:47:02 +00:00
|
|
|
bool flip;
|
|
|
|
bool force_update;
|
|
|
|
bool imgfmt_supported[IMGFMT_END - IMGFMT_START];
|
2015-01-05 14:25:58 +00:00
|
|
|
bool update_new_opts;
|
2015-07-07 12:53:58 +00:00
|
|
|
struct vo *active;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
// --- This is only mutable while initialized=false, during which nothing
|
|
|
|
// except the OpenGL context manager is allowed to access it.
|
|
|
|
struct mp_hwdec_devices *hwdec_devs;
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
// --- All of these can only be accessed from the thread where the host
|
|
|
|
// application's OpenGL context is current - i.e. only while the
|
|
|
|
// host application is calling certain mpv_opengl_cb_* APIs.
|
|
|
|
GL *gl;
|
2017-08-07 17:14:18 +00:00
|
|
|
struct ra *ra;
|
2014-12-09 16:47:02 +00:00
|
|
|
struct gl_video *renderer;
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
struct ra_hwdec *hwdec;
|
2017-01-17 12:37:56 +00:00
|
|
|
struct m_config_cache *vo_opts_cache;
|
|
|
|
struct mp_vo_opts *vo_opts;
|
2014-12-09 16:47:02 +00:00
|
|
|
};
|
|
|
|
|
2015-01-08 16:06:17 +00:00
|
|
|
static void update(struct vo_priv *p);
|
|
|
|
|
2015-07-01 17:24:28 +00:00
|
|
|
static void forget_frames(struct mpv_opengl_cb_context *ctx, bool all)
|
2015-01-08 16:06:17 +00:00
|
|
|
{
|
2015-05-12 20:16:19 +00:00
|
|
|
pthread_cond_broadcast(&ctx->wakeup);
|
2015-07-01 17:24:28 +00:00
|
|
|
if (all) {
|
|
|
|
talloc_free(ctx->cur_frame);
|
|
|
|
ctx->cur_frame = NULL;
|
|
|
|
}
|
2015-01-08 16:06:17 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 11:45:43 +00:00
|
|
|
static void free_ctx(void *ptr)
|
|
|
|
{
|
|
|
|
mpv_opengl_cb_context *ctx = ptr;
|
|
|
|
|
2014-12-31 19:31:19 +00:00
|
|
|
// This can trigger if the client API user doesn't call
|
|
|
|
// mpv_opengl_cb_uninit_gl() properly.
|
|
|
|
assert(!ctx->initialized);
|
|
|
|
|
2015-05-12 20:16:19 +00:00
|
|
|
pthread_cond_destroy(&ctx->wakeup);
|
2014-12-22 11:45:43 +00:00
|
|
|
pthread_mutex_destroy(&ctx->lock);
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
struct mpv_opengl_cb_context *mp_opengl_create(struct mpv_global *g,
|
2014-12-31 19:31:19 +00:00
|
|
|
struct mp_client_api *client_api)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
|
|
|
mpv_opengl_cb_context *ctx = talloc_zero(NULL, mpv_opengl_cb_context);
|
2014-12-22 11:45:43 +00:00
|
|
|
talloc_set_destructor(ctx, free_ctx);
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_init(&ctx->lock, NULL);
|
2015-05-12 20:16:19 +00:00
|
|
|
pthread_cond_init(&ctx->wakeup, NULL);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2015-11-17 20:07:41 +00:00
|
|
|
ctx->global = g;
|
2014-12-31 19:31:19 +00:00
|
|
|
ctx->log = mp_log_new(ctx, g->log, "opengl-cb");
|
|
|
|
ctx->client_api = client_api;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2017-01-17 12:37:56 +00:00
|
|
|
ctx->vo_opts_cache = m_config_cache_alloc(ctx, ctx->global, &vo_sub_opts);
|
|
|
|
ctx->vo_opts = ctx->vo_opts_cache->opts;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mpv_opengl_cb_set_update_callback(struct mpv_opengl_cb_context *ctx,
|
|
|
|
mpv_opengl_cb_update_fn callback,
|
|
|
|
void *callback_ctx)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
ctx->update_cb = callback;
|
|
|
|
ctx->update_cb_ctx = callback_ctx;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
}
|
|
|
|
|
2017-08-05 13:17:18 +00:00
|
|
|
// Reset some GL attributes the user might clobber. For mid-term compatibility
|
|
|
|
// only - we expect both user code and our code to do this correctly.
|
|
|
|
static void reset_gl_state(GL *gl)
|
|
|
|
{
|
|
|
|
gl->ActiveTexture(GL_TEXTURE0);
|
|
|
|
if (gl->mpgl_caps & MPGL_CAP_ROW_LENGTH)
|
|
|
|
gl->PixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
|
|
|
gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
int mpv_opengl_cb_init_gl(struct mpv_opengl_cb_context *ctx, const char *exts,
|
|
|
|
mpv_opengl_cb_get_proc_address_fn get_proc_address,
|
|
|
|
void *get_proc_address_ctx)
|
|
|
|
{
|
|
|
|
if (ctx->renderer)
|
|
|
|
return MPV_ERROR_INVALID_PARAMETER;
|
|
|
|
|
2016-08-03 17:18:00 +00:00
|
|
|
talloc_free(ctx->gl);
|
2016-02-15 13:50:03 +00:00
|
|
|
ctx->gl = talloc_zero(ctx, GL);
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
mpgl_load_functions2(ctx->gl, get_proc_address, get_proc_address_ctx,
|
|
|
|
exts, ctx->log);
|
2016-08-03 17:18:00 +00:00
|
|
|
if (!ctx->gl->version && !ctx->gl->es) {
|
|
|
|
MP_FATAL(ctx, "OpenGL not initialized.\n");
|
|
|
|
return MPV_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
2017-08-07 17:14:18 +00:00
|
|
|
ctx->ra = ra_create_gl(ctx->gl, ctx->log);
|
|
|
|
if (!ctx->ra)
|
2014-12-22 11:49:20 +00:00
|
|
|
return MPV_ERROR_UNSUPPORTED;
|
2014-12-31 19:31:19 +00:00
|
|
|
|
2017-08-07 17:14:18 +00:00
|
|
|
ctx->renderer = gl_video_init(ctx->ra, ctx->log, ctx->global);
|
|
|
|
|
2017-01-17 12:37:56 +00:00
|
|
|
m_config_cache_update(ctx->vo_opts_cache);
|
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
ctx->hwdec_devs = hwdec_devices_create();
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
ctx->hwdec = ra_hwdec_load(ctx->log, ctx->ra, ctx->global,
|
2017-01-17 13:51:08 +00:00
|
|
|
ctx->hwdec_devs, ctx->vo_opts->gl_hwdec_interop);
|
2014-12-09 16:47:02 +00:00
|
|
|
gl_video_set_hwdec(ctx->renderer, ctx->hwdec);
|
2015-01-06 16:34:29 +00:00
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
for (int n = IMGFMT_START; n < IMGFMT_END; n++) {
|
|
|
|
ctx->imgfmt_supported[n - IMGFMT_START] =
|
|
|
|
gl_video_check_format(ctx->renderer, n);
|
|
|
|
}
|
2014-12-31 19:31:19 +00:00
|
|
|
ctx->initialized = true;
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
2017-08-05 13:17:18 +00:00
|
|
|
reset_gl_state(ctx->gl);
|
2014-12-09 16:47:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int mpv_opengl_cb_uninit_gl(struct mpv_opengl_cb_context *ctx)
|
|
|
|
{
|
2016-12-09 20:31:45 +00:00
|
|
|
if (!ctx)
|
|
|
|
return 0;
|
|
|
|
|
2014-12-31 19:31:19 +00:00
|
|
|
// Bring down the decoder etc., which still might be using the hwdec
|
|
|
|
// context. Setting initialized=false guarantees it can't come back.
|
2015-01-08 16:06:17 +00:00
|
|
|
|
2014-12-31 19:31:19 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2015-07-01 17:24:28 +00:00
|
|
|
forget_frames(ctx, true);
|
2014-12-31 19:31:19 +00:00
|
|
|
ctx->initialized = false;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
|
|
|
kill_video(ctx->client_api);
|
|
|
|
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
assert(!ctx->active);
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
gl_video_uninit(ctx->renderer);
|
|
|
|
ctx->renderer = NULL;
|
vo_opengl: separate hwdec context and mapping, port it to use ra
This does two separate rather intrusive things:
1. Make the hwdec context (which does initialization, provides the
device to the decoder, and other basic state) and frame mapping
(getting textures from a mp_image) separate. This is more
flexible, and you could map multiple images at once. It will
help removing some hwdec special-casing from video.c.
2. Switch all hwdec API use to ra. Of course all code is still
GL specific, but in theory it would be possible to support other
backends. The most important change is that the hwdec interop
returns ra objects, instead of anything GL specific. This removes
the last dependency on GL-specific header files from video.c.
I'm mixing these separate changes because both requires essentially
rewriting all the glue code, so better do them at once. For the same
reason, this change isn't done incrementally.
hwdec_ios.m is untested, since I can't test it. Apart from superficial
mistakes, this also requires dealing with Apple's texture format
fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED
and GL_RG. We also need to report the correct format via ra_tex to
the renderer, which is done by find_la_variant(). It's unknown whether
this works correctly.
hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my
RPI out of a dusty pile of devices and cables, so, later.)
2017-08-10 15:48:33 +00:00
|
|
|
ra_hwdec_uninit(ctx->hwdec);
|
2014-12-09 16:47:02 +00:00
|
|
|
ctx->hwdec = NULL;
|
2016-05-09 17:42:03 +00:00
|
|
|
hwdec_devices_destroy(ctx->hwdec_devs);
|
|
|
|
ctx->hwdec_devs = NULL;
|
2017-08-07 17:14:18 +00:00
|
|
|
ra_free(&ctx->ra);
|
2014-12-09 16:47:02 +00:00
|
|
|
talloc_free(ctx->gl);
|
|
|
|
ctx->gl = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-09 17:31:01 +00:00
|
|
|
int mpv_opengl_cb_draw(mpv_opengl_cb_context *ctx, int fbo, int vp_w, int vp_h)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
|
|
|
assert(ctx->renderer);
|
|
|
|
|
2017-08-07 17:14:18 +00:00
|
|
|
if (fbo && !(ctx->gl->mpgl_caps & MPGL_CAP_FB)) {
|
|
|
|
MP_FATAL(ctx, "Rendering to FBO requested, but no FBO extension found!\n");
|
|
|
|
return MPV_ERROR_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct fbodst target = {
|
|
|
|
.tex = ra_create_wrapped_fb(ctx->ra, fbo, vp_w, abs(vp_h)),
|
|
|
|
.flip = vp_h < 0,
|
|
|
|
};
|
|
|
|
|
2017-08-05 13:17:18 +00:00
|
|
|
reset_gl_state(ctx->gl);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
|
|
|
|
struct vo *vo = ctx->active;
|
|
|
|
|
2014-12-09 20:36:45 +00:00
|
|
|
ctx->force_update |= ctx->reconfigured;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
if (ctx->vp_w != vp_w || ctx->vp_h != vp_h)
|
2014-12-09 16:47:02 +00:00
|
|
|
ctx->force_update = true;
|
|
|
|
|
|
|
|
if (ctx->force_update && vo) {
|
|
|
|
ctx->force_update = false;
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
ctx->vp_w = vp_w;
|
|
|
|
ctx->vp_h = vp_h;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2017-01-17 12:37:56 +00:00
|
|
|
m_config_cache_update(ctx->vo_opts_cache);
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
struct mp_rect src, dst;
|
|
|
|
struct mp_osd_res osd;
|
2017-01-17 12:37:56 +00:00
|
|
|
mp_get_src_dst_rects(ctx->log, ctx->vo_opts, vo->driver->caps,
|
vo_opengl: refactor shader generation (part 1)
The basic idea is to use dynamically generated shaders instead of a
single monolithic file + a ton of ifdefs. Instead of having to setup
every aspect of it separately (like compiling shaders, setting uniforms,
perfoming the actual rendering steps, the GLSL parts), we generate the
GLSL on the fly, and perform the rendering at the same time. The GLSL
is regenerated every frame, but the actual compiled OpenGL-level shaders
are cached, which makes it fast again. Almost all logic can be in a
single place.
The new code is significantly more flexible, which allows us to improve
the code clarity, performance and add more features easily.
This commit is incomplete. It drops almost all previous code, and
readds only the most important things (some of them actually buggy).
The next commit will complete it - it's separate to preserve authorship
information.
2015-03-12 20:57:54 +00:00
|
|
|
&ctx->img_params, vp_w, abs(vp_h),
|
2014-12-09 16:47:02 +00:00
|
|
|
1.0, &src, &dst, &osd);
|
|
|
|
|
2017-08-07 17:14:18 +00:00
|
|
|
gl_video_resize(ctx->renderer, &src, &dst, &osd);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 15:32:59 +00:00
|
|
|
if (ctx->reconfigured) {
|
|
|
|
gl_video_set_osd_source(ctx->renderer, vo ? vo->osd : NULL);
|
2015-03-10 13:05:42 +00:00
|
|
|
gl_video_config(ctx->renderer, &ctx->img_params);
|
2015-03-23 15:32:59 +00:00
|
|
|
}
|
2015-03-10 13:05:42 +00:00
|
|
|
if (ctx->update_new_opts) {
|
2016-09-02 13:59:40 +00:00
|
|
|
gl_video_update_options(ctx->renderer);
|
|
|
|
if (vo)
|
|
|
|
gl_video_configure_queue(ctx->renderer, vo);
|
|
|
|
int debug;
|
|
|
|
mp_read_option_raw(ctx->global, "opengl-debug", &m_option_type_flag,
|
|
|
|
&debug);
|
|
|
|
ctx->gl->debug_context = debug;
|
2017-08-07 17:14:18 +00:00
|
|
|
ra_gl_set_debug(ctx->ra, debug);
|
2016-06-05 13:00:07 +00:00
|
|
|
if (gl_video_icc_auto_enabled(ctx->renderer))
|
|
|
|
MP_ERR(ctx, "icc-profile-auto is not available with opengl-cb\n");
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
2015-03-10 13:05:42 +00:00
|
|
|
ctx->reconfigured = false;
|
|
|
|
ctx->update_new_opts = false;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2015-10-14 18:38:30 +00:00
|
|
|
if (ctx->reset) {
|
|
|
|
gl_video_reset(ctx->renderer);
|
|
|
|
ctx->reset = false;
|
|
|
|
if (ctx->cur_frame)
|
|
|
|
ctx->cur_frame->still = true;
|
|
|
|
}
|
|
|
|
|
2015-11-09 19:49:30 +00:00
|
|
|
struct vo_frame *frame = ctx->next_frame;
|
|
|
|
int64_t wait_present_count = ctx->present_count;
|
2015-07-01 17:24:28 +00:00
|
|
|
if (frame) {
|
2015-11-09 19:49:30 +00:00
|
|
|
ctx->next_frame = NULL;
|
2016-10-30 11:16:24 +00:00
|
|
|
if (!(frame->redraw || !frame->current))
|
2016-10-05 10:34:47 +00:00
|
|
|
wait_present_count += 1;
|
2015-11-09 19:49:30 +00:00
|
|
|
pthread_cond_signal(&ctx->wakeup);
|
2015-07-01 17:24:28 +00:00
|
|
|
talloc_free(ctx->cur_frame);
|
|
|
|
ctx->cur_frame = vo_frame_ref(frame);
|
|
|
|
} else {
|
|
|
|
frame = vo_frame_ref(ctx->cur_frame);
|
2015-10-14 18:38:30 +00:00
|
|
|
if (frame)
|
|
|
|
frame->redraw = true;
|
2015-11-04 13:42:50 +00:00
|
|
|
MP_STATS(ctx, "glcb-noframe");
|
2015-05-12 20:16:38 +00:00
|
|
|
}
|
2015-07-01 17:24:28 +00:00
|
|
|
struct vo_frame dummy = {0};
|
|
|
|
if (!frame)
|
|
|
|
frame = &dummy;
|
2015-05-12 20:16:38 +00:00
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
2015-11-04 13:42:50 +00:00
|
|
|
MP_STATS(ctx, "glcb-render");
|
2017-08-07 17:14:18 +00:00
|
|
|
gl_video_render_frame(ctx->renderer, frame, target);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2017-08-05 13:17:18 +00:00
|
|
|
reset_gl_state(ctx->gl);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2015-07-01 17:24:28 +00:00
|
|
|
if (frame != &dummy)
|
|
|
|
talloc_free(frame);
|
|
|
|
|
2015-01-08 16:06:17 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2015-11-09 19:49:30 +00:00
|
|
|
while (wait_present_count > ctx->present_count)
|
|
|
|
pthread_cond_wait(&ctx->wakeup, &ctx->lock);
|
2015-01-08 16:06:17 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
2017-08-07 17:14:18 +00:00
|
|
|
ra_tex_free(ctx->ra, &target.tex);
|
|
|
|
|
2015-11-09 19:49:30 +00:00
|
|
|
return 0;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 17:30:26 +00:00
|
|
|
int mpv_opengl_cb_report_flip(mpv_opengl_cb_context *ctx, int64_t time)
|
|
|
|
{
|
2015-11-04 13:42:50 +00:00
|
|
|
MP_STATS(ctx, "glcb-reportflip");
|
|
|
|
|
2015-04-09 17:30:26 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2015-11-09 19:49:30 +00:00
|
|
|
ctx->flip_count += 1;
|
|
|
|
pthread_cond_signal(&ctx->wakeup);
|
2015-04-09 17:30:26 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-05 14:25:58 +00:00
|
|
|
// Called locked.
|
|
|
|
static void update(struct vo_priv *p)
|
|
|
|
{
|
|
|
|
if (p->ctx->update_cb)
|
|
|
|
p->ctx->update_cb(p->ctx->update_cb_ctx);
|
|
|
|
}
|
|
|
|
|
2015-07-01 17:24:28 +00:00
|
|
|
static void draw_frame(struct vo *vo, struct vo_frame *frame)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
|
|
|
|
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
2015-11-09 19:49:30 +00:00
|
|
|
assert(!p->ctx->next_frame);
|
|
|
|
p->ctx->next_frame = vo_frame_ref(frame);
|
|
|
|
p->ctx->expected_flip_count = p->ctx->flip_count + 1;
|
2016-02-09 20:38:28 +00:00
|
|
|
p->ctx->redrawing = frame->redraw || !frame->current;
|
2015-11-09 19:49:30 +00:00
|
|
|
update(p);
|
2015-07-01 17:24:28 +00:00
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
static void flip_page(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2015-11-09 19:49:30 +00:00
|
|
|
struct timespec ts = mp_rel_time_to_timespec(0.2);
|
2014-12-31 18:12:44 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
2015-11-09 19:49:30 +00:00
|
|
|
|
|
|
|
// Wait until frame was rendered
|
|
|
|
while (p->ctx->next_frame) {
|
2015-11-10 13:35:13 +00:00
|
|
|
if (pthread_cond_timedwait(&p->ctx->wakeup, &p->ctx->lock, &ts)) {
|
2016-10-30 17:29:24 +00:00
|
|
|
if (p->ctx->next_frame) {
|
|
|
|
MP_VERBOSE(vo, "mpv_opengl_cb_draw() not being called or stuck.\n");
|
|
|
|
goto done;
|
|
|
|
}
|
2015-11-10 13:35:13 +00:00
|
|
|
}
|
2015-11-09 19:49:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unblock mpv_opengl_cb_draw().
|
|
|
|
p->ctx->present_count += 1;
|
|
|
|
pthread_cond_signal(&p->ctx->wakeup);
|
|
|
|
|
2015-11-12 21:40:02 +00:00
|
|
|
if (p->ctx->redrawing)
|
|
|
|
goto done; // do not block for redrawing
|
|
|
|
|
2015-11-09 19:49:30 +00:00
|
|
|
// Wait until frame was presented
|
|
|
|
while (p->ctx->expected_flip_count > p->ctx->flip_count) {
|
|
|
|
// mpv_opengl_cb_report_flip() is declared as optional API.
|
|
|
|
// Assume the user calls it consistently _if_ it's called at all.
|
|
|
|
if (!p->ctx->flip_count)
|
2015-05-12 20:16:19 +00:00
|
|
|
break;
|
2015-11-10 13:35:13 +00:00
|
|
|
if (pthread_cond_timedwait(&p->ctx->wakeup, &p->ctx->lock, &ts)) {
|
|
|
|
MP_VERBOSE(vo, "mpv_opengl_cb_report_flip() not being called.\n");
|
|
|
|
goto done;
|
|
|
|
}
|
2015-01-08 16:06:17 +00:00
|
|
|
}
|
2015-11-09 19:49:30 +00:00
|
|
|
|
2015-11-10 13:35:13 +00:00
|
|
|
done:
|
|
|
|
|
|
|
|
// Cleanup after the API user is not reacting, or is being unusually slow.
|
2015-11-09 19:49:30 +00:00
|
|
|
if (p->ctx->next_frame) {
|
2016-10-30 11:00:33 +00:00
|
|
|
talloc_free(p->ctx->cur_frame);
|
|
|
|
p->ctx->cur_frame = p->ctx->next_frame;
|
2015-11-09 19:49:30 +00:00
|
|
|
p->ctx->next_frame = NULL;
|
2015-11-10 13:35:13 +00:00
|
|
|
p->ctx->present_count += 2;
|
2015-11-09 19:49:30 +00:00
|
|
|
pthread_cond_signal(&p->ctx->wakeup);
|
|
|
|
vo_increment_drop_count(vo, 1);
|
|
|
|
}
|
|
|
|
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2015-01-21 21:08:24 +00:00
|
|
|
static int query_format(struct vo *vo, int format)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
|
|
|
|
|
|
|
bool ok = false;
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
|
|
|
if (format >= IMGFMT_START && format < IMGFMT_END)
|
|
|
|
ok = p->ctx->imgfmt_supported[format - IMGFMT_START];
|
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
2015-01-21 21:08:24 +00:00
|
|
|
return ok;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 16:20:16 +00:00
|
|
|
static int reconfig(struct vo *vo, struct mp_image_params *params)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
|
|
|
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
2015-07-01 17:24:28 +00:00
|
|
|
forget_frames(p->ctx, true);
|
2014-12-31 18:12:44 +00:00
|
|
|
p->ctx->img_params = *params;
|
|
|
|
p->ctx->reconfigured = true;
|
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
|
|
|
|
|
|
|
switch (request) {
|
2015-10-14 18:38:30 +00:00
|
|
|
case VOCTRL_RESET:
|
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
|
|
|
forget_frames(p->ctx, false);
|
|
|
|
p->ctx->reset = true;
|
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
return VO_TRUE;
|
|
|
|
case VOCTRL_PAUSE:
|
|
|
|
vo->want_redraw = true;
|
|
|
|
return VO_TRUE;
|
video: redo video equalizer option handling
I really wouldn't care much about this, but some parts of the core code
are under HAVE_GPL, so there's some need to get rid of it. Simply turn
the video equalizer from its current fine-grained handling with vf/vo
fallbacks into global options. This makes updating them much simpler.
This removes any possibility of applying video equalizers in filters,
which affects vf_scale, and the previously removed vf_eq. Not a big
loss, since the preferred VOs have this builtin.
Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and
vo_xv. I'm not going to waste my time on these legacy VOs.
vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which
exists _only_ to trigger a redraw. This seems silly, but for now I feel
like this is less of a pain. The rest of the equalizer using code is
self-updating.
See commit 96b906a51d5 for how some video equalizer code was GPL only.
Some command line option names and ranges can probably be traced back to
a GPL only committer, but we don't consider these copyrightable.
2017-08-22 15:01:35 +00:00
|
|
|
case VOCTRL_SET_EQUALIZER:
|
|
|
|
vo->want_redraw = true;
|
|
|
|
return VO_TRUE;
|
2015-01-06 10:32:08 +00:00
|
|
|
case VOCTRL_SET_PANSCAN:
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
|
|
|
p->ctx->force_update = true;
|
2015-01-05 14:25:58 +00:00
|
|
|
update(p);
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
return VO_TRUE;
|
2016-09-02 13:59:40 +00:00
|
|
|
case VOCTRL_UPDATE_RENDER_OPTS:
|
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
|
|
|
p->ctx->update_new_opts = true;
|
|
|
|
update(p);
|
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
return VO_TRUE;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return VO_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
|
|
|
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
2015-07-01 17:24:28 +00:00
|
|
|
forget_frames(p->ctx, true);
|
2014-12-31 18:12:44 +00:00
|
|
|
p->ctx->img_params = (struct mp_image_params){0};
|
|
|
|
p->ctx->reconfigured = true;
|
|
|
|
p->ctx->active = NULL;
|
2015-03-10 13:05:42 +00:00
|
|
|
update(p);
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int preinit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2014-12-31 18:12:44 +00:00
|
|
|
p->ctx = vo->extra.opengl_cb_context;
|
|
|
|
if (!p->ctx) {
|
|
|
|
MP_FATAL(vo, "No context set.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_lock(&p->ctx->lock);
|
2014-12-31 19:31:19 +00:00
|
|
|
if (!p->ctx->initialized) {
|
|
|
|
MP_FATAL(vo, "OpenGL context not initialized.\n");
|
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
return -1;
|
|
|
|
}
|
2014-12-31 18:12:44 +00:00
|
|
|
p->ctx->active = vo;
|
|
|
|
p->ctx->reconfigured = true;
|
2015-05-12 20:16:07 +00:00
|
|
|
p->ctx->update_new_opts = true;
|
2014-12-31 18:12:44 +00:00
|
|
|
pthread_mutex_unlock(&p->ctx->lock);
|
|
|
|
|
2016-05-09 17:42:03 +00:00
|
|
|
vo->hwdec_devs = p->ctx->hwdec_devs;
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct vo_driver video_out_opengl_cb = {
|
|
|
|
.description = "OpenGL Callbacks for libmpv",
|
|
|
|
.name = "opengl-cb",
|
|
|
|
.caps = VO_CAP_ROTATE90,
|
|
|
|
.preinit = preinit,
|
|
|
|
.query_format = query_format,
|
|
|
|
.reconfig = reconfig,
|
|
|
|
.control = control,
|
2015-07-01 17:24:28 +00:00
|
|
|
.draw_frame = draw_frame,
|
2014-12-09 16:47:02 +00:00
|
|
|
.flip_page = flip_page,
|
|
|
|
.uninit = uninit,
|
|
|
|
.priv_size = sizeof(struct vo_priv),
|
|
|
|
};
|