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"
|
2018-04-20 17:26:04 +00:00
|
|
|
#include "misc/dispatch.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
#include "common/msg.h"
|
|
|
|
#include "options/m_config.h"
|
|
|
|
#include "options/options.h"
|
|
|
|
#include "aspect.h"
|
2018-04-20 17:28:38 +00:00
|
|
|
#include "dr_helper.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
#include "vo.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "sub/osd.h"
|
2018-02-20 12:30:18 +00:00
|
|
|
#include "osdep/atomic.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"
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
#include "libmpv.h"
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
/*
|
2018-02-20 12:30:18 +00:00
|
|
|
* mpv_render_context is managed by the host application - the host application
|
2014-12-09 16:47:02 +00:00
|
|
|
* can access it any time, even if the VO is destroyed (or not created yet).
|
2015-11-09 19:49:30 +00:00
|
|
|
*
|
2018-02-20 12:30:18 +00:00
|
|
|
* - the libmpv user can mix render API and normal API; thus render API
|
2015-11-09 19:49:30 +00:00
|
|
|
* 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
|
2018-02-20 12:30:18 +00:00
|
|
|
* render API user anyway, and the (unlikely) deadlock is avoided with
|
2015-11-09 19:49:30 +00:00
|
|
|
* a timeout
|
2018-02-20 12:30:18 +00:00
|
|
|
*
|
2018-04-20 17:26:04 +00:00
|
|
|
* Locking: mpv core > VO > mpv_render_context.lock > mp_client_api.lock
|
|
|
|
* > mpv_render_context.update_lock
|
2018-02-20 12:30:18 +00:00
|
|
|
* And: render thread > VO (wait for present)
|
|
|
|
* VO > render thread (wait for present done, via timeout)
|
2019-09-20 14:43:17 +00:00
|
|
|
*
|
client API: fix potential deadlock problems by throwing more shit at it
The render API (vo_libmpv) had potential deadlock problems with
MPV_RENDER_PARAM_ADVANCED_CONTROL. This required vd-lavc-dr to be
enabled (the default). I never observed these deadlocks in the wild
(doesn't mean they didn't happen), although I could specifically provoke
them with some code changes.
The problem was mostly about DR (direct rendering, letting the video
decoder write to OpenGL buffer memory). Allocating/freeing a DR image
needs to be done on the OpenGL thread, even though _lots_ of threads are
involved with handling images. Freeing a DR image is a special case that
can happen any time. dr_helper.c does most of the evil magic of
achieving this. Unfortunately, there was a (sort of) circular lock
dependency: freeing an image while certain internal locks are held would
trigger the user's context update callback, which in turn would call
mpv_render_context_update(), which processed all pending free requests,
and then acquire an internal lock - which the caller might not release
until a further DR image could be freed.
"Solve" this by making freeing DR images asynchronous. This is slightly
risky, but actually not much. The DR images will be free'd eventually.
The biggest disadvantage is probably that debugging might get trickier.
Any solution to this problem will probably add images to free to some
sort of queue, and then process it later. I considered making this more
explicit (so there'd be a point where the caller forcibly waits for all
queued items to be free'd), but discarded these ideas as this probably
would only increase complexity.
Another consequence is that freeing DR images on the GL thread is not
synchronous anymore. Instead, it mpv_render_context_update() will do it
with a delay. This seems roundabout, but doesn't actually change
anything, and avoids additional code.
This also fixes that the render API required the render API user to
remain on the same thread, even though this wasn't documented. As such,
it was a bug. OpenGL essentially forces you to do all GL usage on a
single thread, but in theory the API user could for example move the GL
context to another thread.
The API bump is because I think you can't make enough noise about this.
Since we don't backport fixes to old versions, I'm specifically stating
that old versions are broken, and I'm supplying workarounds.
Internally, dr_helper_create() does not use pthread_self() anymore, thus
the vo.c change. I think it's better to make binding to the current
thread as explicit as possible.
Of course it's not sure that this fixes all deadlocks (probably not).
2019-09-26 12:07:33 +00:00
|
|
|
* Locking gets more complex with advanced_control enabled. Use
|
|
|
|
* mpv_render_context.dispatch with care; synchronous calls can add lock
|
|
|
|
* dependencies.
|
2014-12-09 16:47:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct vo_priv {
|
2018-04-20 17:26:04 +00:00
|
|
|
struct mpv_render_context *ctx; // immutable after init
|
2014-12-09 16:47:02 +00:00
|
|
|
};
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
struct mpv_render_context {
|
2014-12-09 16:47:02 +00:00
|
|
|
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
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
atomic_bool in_use;
|
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
// --- Immutable after init
|
2019-09-20 12:52:49 +00:00
|
|
|
struct mp_dispatch_queue *dispatch;
|
2018-04-20 17:26:04 +00:00
|
|
|
bool advanced_control;
|
2018-04-20 17:28:38 +00:00
|
|
|
struct dr_helper *dr; // NULL if advanced_control disabled
|
2018-04-20 17:26:04 +00:00
|
|
|
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
pthread_mutex_t control_lock;
|
2018-04-20 17:26:04 +00:00
|
|
|
// --- Protected by control_lock
|
2018-02-20 12:30:18 +00:00
|
|
|
mp_render_cb_control_fn control_cb;
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
void *control_cb_ctx;
|
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_mutex_t update_lock;
|
|
|
|
pthread_cond_t update_cond; // paired with update_lock
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
// --- Protected by update_lock
|
2018-02-20 12:30:18 +00:00
|
|
|
mpv_render_update_fn update_cb;
|
2014-12-09 16:47:02 +00:00
|
|
|
void *update_cb_ctx;
|
2018-04-20 17:26:04 +00:00
|
|
|
|
|
|
|
pthread_mutex_t lock;
|
|
|
|
pthread_cond_t video_wait; // paired with lock
|
|
|
|
|
|
|
|
// --- Protected by lock
|
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;
|
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 imgfmt_supported[IMGFMT_END - IMGFMT_START];
|
2018-02-20 12:30:18 +00:00
|
|
|
bool need_reconfig;
|
|
|
|
bool need_resize;
|
|
|
|
bool need_reset;
|
|
|
|
bool need_update_external;
|
|
|
|
struct vo *vo;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
// --- Mostly immutable after init.
|
2016-05-09 17:42:03 +00:00
|
|
|
struct mp_hwdec_devices *hwdec_devs;
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
// --- All of these can only be accessed from mpv_render_*() API, for
|
|
|
|
// which the user makes sure they're called synchronized.
|
|
|
|
struct render_backend *renderer;
|
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
|
|
|
};
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
const struct render_backend_fns *render_backends[] = {
|
|
|
|
&render_backend_gpu,
|
2020-07-08 19:55:24 +00:00
|
|
|
&render_backend_sw,
|
2018-02-20 12:30:18 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-04-20 18:37:56 +00:00
|
|
|
static void update(struct mpv_render_context *ctx)
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ctx->update_lock);
|
|
|
|
if (ctx->update_cb)
|
|
|
|
ctx->update_cb(ctx->update_cb_ctx);
|
|
|
|
|
|
|
|
pthread_cond_broadcast(&ctx->update_cond);
|
|
|
|
pthread_mutex_unlock(&ctx->update_lock);
|
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
void *get_mpv_render_param(mpv_render_param *params, mpv_render_param_type type,
|
|
|
|
void *def)
|
|
|
|
{
|
|
|
|
for (int n = 0; params && params[n].type; n++) {
|
|
|
|
if (params[n].type == type)
|
|
|
|
return params[n].data;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
2015-01-08 16:06:17 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
static void forget_frames(struct mpv_render_context *ctx, bool all)
|
2015-01-08 16:06:17 +00:00
|
|
|
{
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_cond_broadcast(&ctx->video_wait);
|
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
|
|
|
}
|
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
static void dispatch_wakeup(void *ptr)
|
|
|
|
{
|
|
|
|
struct mpv_render_context *ctx = ptr;
|
|
|
|
|
|
|
|
update(ctx);
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:28:38 +00:00
|
|
|
static struct mp_image *render_get_image(void *ptr, int imgfmt, int w, int h,
|
|
|
|
int stride_align)
|
|
|
|
{
|
|
|
|
struct mpv_render_context *ctx = ptr;
|
|
|
|
|
|
|
|
return ctx->renderer->fns->get_image(ctx->renderer, imgfmt, w, h, stride_align);
|
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
int mpv_render_context_create(mpv_render_context **res, mpv_handle *mpv,
|
|
|
|
mpv_render_param *params)
|
2014-12-22 11:45:43 +00:00
|
|
|
{
|
2018-02-20 12:30:18 +00:00
|
|
|
mpv_render_context *ctx = talloc_zero(NULL, mpv_render_context);
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
pthread_mutex_init(&ctx->control_lock, NULL);
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_init(&ctx->lock, NULL);
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_mutex_init(&ctx->update_lock, NULL);
|
|
|
|
pthread_cond_init(&ctx->update_cond, NULL);
|
|
|
|
pthread_cond_init(&ctx->video_wait, NULL);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
ctx->global = mp_client_get_global(mpv);
|
|
|
|
ctx->client_api = ctx->global->client_api;
|
|
|
|
ctx->log = mp_log_new(ctx, ctx->global->log, "libmpv_render");
|
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
|
|
|
|
2019-09-20 12:52:49 +00:00
|
|
|
ctx->dispatch = mp_dispatch_create(ctx);
|
|
|
|
mp_dispatch_set_wakeup_fn(ctx->dispatch, dispatch_wakeup, ctx);
|
|
|
|
|
|
|
|
if (GET_MPV_RENDER_PARAM(params, MPV_RENDER_PARAM_ADVANCED_CONTROL, int, 0))
|
2018-04-20 17:26:04 +00:00
|
|
|
ctx->advanced_control = true;
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
int err = MPV_ERROR_NOT_IMPLEMENTED;
|
|
|
|
for (int n = 0; render_backends[n]; n++) {
|
|
|
|
ctx->renderer = talloc_zero(NULL, struct render_backend);
|
|
|
|
*ctx->renderer = (struct render_backend){
|
|
|
|
.global = ctx->global,
|
|
|
|
.log = ctx->log,
|
|
|
|
.fns = render_backends[n],
|
|
|
|
};
|
|
|
|
err = ctx->renderer->fns->init(ctx->renderer, params);
|
|
|
|
if (err >= 0)
|
|
|
|
break;
|
|
|
|
ctx->renderer->fns->destroy(ctx->renderer);
|
|
|
|
talloc_free(ctx->renderer->priv);
|
|
|
|
TA_FREEP(&ctx->renderer);
|
|
|
|
if (err != MPV_ERROR_NOT_IMPLEMENTED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err < 0) {
|
|
|
|
mpv_render_context_free(ctx);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->hwdec_devs = ctx->renderer->hwdec_devs;
|
|
|
|
|
|
|
|
for (int n = IMGFMT_START; n < IMGFMT_END; n++) {
|
|
|
|
ctx->imgfmt_supported[n - IMGFMT_START] =
|
|
|
|
ctx->renderer->fns->check_format(ctx->renderer, n);
|
|
|
|
}
|
|
|
|
|
2019-09-20 12:52:49 +00:00
|
|
|
if (ctx->renderer->fns->get_image && ctx->advanced_control)
|
2018-04-20 17:28:38 +00:00
|
|
|
ctx->dr = dr_helper_create(ctx->dispatch, render_get_image, ctx);
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
if (!mp_set_main_render_context(ctx->client_api, ctx, true)) {
|
|
|
|
MP_ERR(ctx, "There is already a mpv_render_context set.\n");
|
|
|
|
mpv_render_context_free(ctx);
|
|
|
|
return MPV_ERROR_GENERIC;
|
|
|
|
}
|
|
|
|
|
|
|
|
*res = ctx;
|
|
|
|
return 0;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
void mpv_render_context_set_update_callback(mpv_render_context *ctx,
|
|
|
|
mpv_render_update_fn callback,
|
|
|
|
void *callback_ctx)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_mutex_lock(&ctx->update_lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
ctx->update_cb = callback;
|
|
|
|
ctx->update_cb_ctx = callback_ctx;
|
2018-04-20 17:26:04 +00:00
|
|
|
if (ctx->update_cb)
|
|
|
|
ctx->update_cb(ctx->update_cb_ctx);
|
|
|
|
pthread_mutex_unlock(&ctx->update_lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
void mp_render_context_set_control_callback(mpv_render_context *ctx,
|
|
|
|
mp_render_cb_control_fn callback,
|
|
|
|
void *callback_ctx)
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ctx->control_lock);
|
|
|
|
ctx->control_cb = callback;
|
|
|
|
ctx->control_cb_ctx = callback_ctx;
|
|
|
|
pthread_mutex_unlock(&ctx->control_lock);
|
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
void mpv_render_context_free(mpv_render_context *ctx)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
2018-02-20 12:30:18 +00:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
// From here on, ctx becomes invisible and cannot be newly acquired. Only
|
|
|
|
// a VO could still hold a reference.
|
|
|
|
mp_set_main_render_context(ctx->client_api, ctx, false);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
if (atomic_load(&ctx->in_use)) {
|
2019-09-20 14:31:53 +00:00
|
|
|
// Start destroy the VO, and also bring down the decoder etc., which
|
|
|
|
// still might be using the hwdec context or use DR images. The above
|
|
|
|
// mp_set_main_render_context() call guarantees it can't come back (so
|
|
|
|
// ctx->vo can't change to non-NULL).
|
|
|
|
// In theory, this races with vo_libmpv exiting and another VO being
|
|
|
|
// used, which is a harmless grotesque corner case.
|
2019-05-26 08:58:25 +00:00
|
|
|
kill_video_async(ctx->client_api);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
|
|
|
while (atomic_load(&ctx->in_use)) {
|
2019-09-20 14:31:53 +00:00
|
|
|
// As a nasty detail, we need to wait until the VO is released, but
|
|
|
|
// also need to react to update() calls during it (the update calls
|
|
|
|
// are supposed to trigger processing ctx->dispatch). We solve this
|
|
|
|
// by making the VO uninit function call mp_dispatch_interrupt().
|
|
|
|
//
|
|
|
|
// Other than that, processing ctx->dispatch is needed to serve the
|
|
|
|
// video decoder, which might still not be fully destroyed, and e.g.
|
|
|
|
// performs calls to release DR images (or, as a grotesque corner
|
|
|
|
// case may even try to allocate new ones).
|
|
|
|
//
|
|
|
|
// Once the VO is released, ctx->dispatch becomes truly inactive.
|
|
|
|
// (The libmpv API user could call mpv_render_context_update() while
|
|
|
|
// mpv_render_context_free() is being called, but of course this is
|
|
|
|
// invalid.)
|
|
|
|
mp_dispatch_queue_process(ctx->dispatch, INFINITY);
|
2018-04-20 17:26:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-09 20:31:45 +00:00
|
|
|
|
2019-09-20 14:31:53 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
// Barrier - guarantee uninit() has left the lock region. It will access ctx
|
|
|
|
// until the lock has been released, so we must not proceed with destruction
|
|
|
|
// before we can acquire the lock. (The opposite, uninit() acquiring the
|
|
|
|
// lock, can not happen anymore at this point - we've waited for VO uninit,
|
|
|
|
// and prevented that new VOs can be created.)
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
assert(!atomic_load(&ctx->in_use));
|
|
|
|
assert(!ctx->vo);
|
2015-01-08 16:06:17 +00:00
|
|
|
|
client API: fix potential deadlock problems by throwing more shit at it
The render API (vo_libmpv) had potential deadlock problems with
MPV_RENDER_PARAM_ADVANCED_CONTROL. This required vd-lavc-dr to be
enabled (the default). I never observed these deadlocks in the wild
(doesn't mean they didn't happen), although I could specifically provoke
them with some code changes.
The problem was mostly about DR (direct rendering, letting the video
decoder write to OpenGL buffer memory). Allocating/freeing a DR image
needs to be done on the OpenGL thread, even though _lots_ of threads are
involved with handling images. Freeing a DR image is a special case that
can happen any time. dr_helper.c does most of the evil magic of
achieving this. Unfortunately, there was a (sort of) circular lock
dependency: freeing an image while certain internal locks are held would
trigger the user's context update callback, which in turn would call
mpv_render_context_update(), which processed all pending free requests,
and then acquire an internal lock - which the caller might not release
until a further DR image could be freed.
"Solve" this by making freeing DR images asynchronous. This is slightly
risky, but actually not much. The DR images will be free'd eventually.
The biggest disadvantage is probably that debugging might get trickier.
Any solution to this problem will probably add images to free to some
sort of queue, and then process it later. I considered making this more
explicit (so there'd be a point where the caller forcibly waits for all
queued items to be free'd), but discarded these ideas as this probably
would only increase complexity.
Another consequence is that freeing DR images on the GL thread is not
synchronous anymore. Instead, it mpv_render_context_update() will do it
with a delay. This seems roundabout, but doesn't actually change
anything, and avoids additional code.
This also fixes that the render API required the render API user to
remain on the same thread, even though this wasn't documented. As such,
it was a bug. OpenGL essentially forces you to do all GL usage on a
single thread, but in theory the API user could for example move the GL
context to another thread.
The API bump is because I think you can't make enough noise about this.
Since we don't backport fixes to old versions, I'm specifically stating
that old versions are broken, and I'm supplying workarounds.
Internally, dr_helper_create() does not use pthread_self() anymore, thus
the vo.c change. I think it's better to make binding to the current
thread as explicit as possible.
Of course it's not sure that this fixes all deadlocks (probably not).
2019-09-26 12:07:33 +00:00
|
|
|
// With the dispatch queue not being served anymore, allow frame free
|
|
|
|
// requests from this thread to be served directly.
|
|
|
|
if (ctx->dr)
|
|
|
|
dr_helper_acquire_thread(ctx->dr);
|
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
// Possibly remaining outstanding work.
|
2019-09-20 12:52:49 +00:00
|
|
|
mp_dispatch_queue_process(ctx->dispatch, 0);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
2015-07-01 17:24:28 +00:00
|
|
|
forget_frames(ctx, true);
|
2014-12-31 19:31:19 +00:00
|
|
|
|
2019-03-07 11:23:11 +00:00
|
|
|
if (ctx->renderer) {
|
|
|
|
ctx->renderer->fns->destroy(ctx->renderer);
|
|
|
|
talloc_free(ctx->renderer->priv);
|
|
|
|
talloc_free(ctx->renderer);
|
|
|
|
}
|
2018-04-20 17:28:38 +00:00
|
|
|
talloc_free(ctx->dr);
|
2018-04-20 17:26:04 +00:00
|
|
|
talloc_free(ctx->dispatch);
|
2014-12-31 19:31:19 +00:00
|
|
|
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_cond_destroy(&ctx->update_cond);
|
|
|
|
pthread_cond_destroy(&ctx->video_wait);
|
|
|
|
pthread_mutex_destroy(&ctx->update_lock);
|
2018-02-20 12:30:18 +00:00
|
|
|
pthread_mutex_destroy(&ctx->lock);
|
|
|
|
pthread_mutex_destroy(&ctx->control_lock);
|
2014-12-31 19:31:19 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
talloc_free(ctx);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
// Try to mark the context as "in exclusive use" (e.g. by a VO).
|
|
|
|
// Note: the function must not acquire any locks, because it's called with an
|
|
|
|
// external leaf lock held.
|
|
|
|
bool mp_render_context_acquire(mpv_render_context *ctx)
|
2014-12-09 16:47:02 +00:00
|
|
|
{
|
2018-02-20 12:30:18 +00:00
|
|
|
bool prev = false;
|
|
|
|
return atomic_compare_exchange_strong(&ctx->in_use, &prev, true);
|
|
|
|
}
|
2017-08-07 17:14:18 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
int mpv_render_context_render(mpv_render_context *ctx, mpv_render_param *params)
|
|
|
|
{
|
2014-12-09 16:47:02 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
int do_render =
|
|
|
|
!GET_MPV_RENDER_PARAM(params, MPV_RENDER_PARAM_SKIP_RENDERING, int, 0);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
if (do_render) {
|
|
|
|
int vp_w, vp_h;
|
|
|
|
int err = ctx->renderer->fns->get_target_size(ctx->renderer, params,
|
|
|
|
&vp_w, &vp_h);
|
|
|
|
if (err < 0) {
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ctx->vo && (ctx->vp_w != vp_w || ctx->vp_h != vp_h ||
|
|
|
|
ctx->need_resize))
|
|
|
|
{
|
|
|
|
ctx->vp_w = vp_w;
|
|
|
|
ctx->vp_h = vp_h;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
m_config_cache_update(ctx->vo_opts_cache);
|
2017-01-17 12:37:56 +00:00
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
struct mp_rect src, dst;
|
|
|
|
struct mp_osd_res osd;
|
|
|
|
mp_get_src_dst_rects(ctx->log, ctx->vo_opts, ctx->vo->driver->caps,
|
|
|
|
&ctx->img_params, vp_w, abs(vp_h),
|
|
|
|
1.0, &src, &dst, &osd);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
ctx->renderer->fns->resize(ctx->renderer, &src, &dst, &osd);
|
|
|
|
}
|
|
|
|
ctx->need_resize = false;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
if (ctx->need_reconfig)
|
|
|
|
ctx->renderer->fns->reconfig(ctx->renderer, &ctx->img_params);
|
|
|
|
ctx->need_reconfig = false;
|
|
|
|
|
|
|
|
if (ctx->need_update_external)
|
2018-04-20 22:26:58 +00:00
|
|
|
ctx->renderer->fns->update_external(ctx->renderer, ctx->vo);
|
2018-02-20 12:30:18 +00:00
|
|
|
ctx->need_update_external = false;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
if (ctx->need_reset) {
|
|
|
|
ctx->renderer->fns->reset(ctx->renderer);
|
2015-10-14 18:38:30 +00:00
|
|
|
if (ctx->cur_frame)
|
|
|
|
ctx->cur_frame->still = true;
|
|
|
|
}
|
2018-02-20 12:30:18 +00:00
|
|
|
ctx->need_reset = false;
|
2015-10-14 18:38:30 +00:00
|
|
|
|
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;
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_cond_broadcast(&ctx->video_wait);
|
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");
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (do_render)
|
|
|
|
err = ctx->renderer->fns->render(ctx->renderer, params, frame);
|
2014-12-09 16:47:02 +00:00
|
|
|
|
2015-07-01 17:24:28 +00:00
|
|
|
if (frame != &dummy)
|
|
|
|
talloc_free(frame);
|
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
if (GET_MPV_RENDER_PARAM(params, MPV_RENDER_PARAM_BLOCK_FOR_TARGET_TIME,
|
|
|
|
int, 1))
|
|
|
|
{
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
while (wait_present_count > ctx->present_count)
|
|
|
|
pthread_cond_wait(&ctx->video_wait, &ctx->lock);
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
}
|
2015-01-08 16:06:17 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
return err;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
void mpv_render_context_report_swap(mpv_render_context *ctx)
|
2015-04-09 17:30:26 +00:00
|
|
|
{
|
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;
|
2018-04-20 17:26:04 +00:00
|
|
|
pthread_cond_broadcast(&ctx->video_wait);
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t mpv_render_context_update(mpv_render_context *ctx)
|
|
|
|
{
|
|
|
|
uint64_t res = 0;
|
|
|
|
|
2019-09-20 12:52:49 +00:00
|
|
|
mp_dispatch_queue_process(ctx->dispatch, 0);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
if (ctx->next_frame)
|
|
|
|
res |= MPV_RENDER_UPDATE_FRAME;
|
2015-04-09 17:30:26 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 17:26:04 +00:00
|
|
|
return res;
|
2018-02-20 12:30:18 +00:00
|
|
|
}
|
2015-04-09 17:30:26 +00:00
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
int mpv_render_context_set_parameter(mpv_render_context *ctx,
|
|
|
|
mpv_render_param param)
|
|
|
|
{
|
2018-04-20 19:54:03 +00:00
|
|
|
return ctx->renderer->fns->set_parameter(ctx->renderer, param);
|
2015-04-09 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 22:26:58 +00:00
|
|
|
int mpv_render_context_get_info(mpv_render_context *ctx,
|
|
|
|
mpv_render_param param)
|
|
|
|
{
|
|
|
|
int res = MPV_ERROR_NOT_IMPLEMENTED;
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
|
|
|
|
switch (param.type) {
|
|
|
|
case MPV_RENDER_PARAM_NEXT_FRAME_INFO: {
|
|
|
|
mpv_render_frame_info *info = param.data;
|
|
|
|
*info = (mpv_render_frame_info){0};
|
|
|
|
struct vo_frame *frame = ctx->next_frame;
|
|
|
|
if (frame) {
|
|
|
|
info->flags =
|
|
|
|
MPV_RENDER_FRAME_INFO_PRESENT |
|
|
|
|
(frame->redraw ? MPV_RENDER_FRAME_INFO_REDRAW : 0) |
|
|
|
|
(frame->repeat ? MPV_RENDER_FRAME_INFO_REPEAT : 0) |
|
|
|
|
(frame->display_synced && !frame->redraw ?
|
|
|
|
MPV_RENDER_FRAME_INFO_BLOCK_VSYNC : 0);
|
|
|
|
info->target_time = frame->pts;
|
|
|
|
}
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:;
|
|
|
|
}
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
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;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
2015-07-01 17:24:28 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
assert(!ctx->next_frame);
|
|
|
|
ctx->next_frame = vo_frame_ref(frame);
|
|
|
|
ctx->expected_flip_count = ctx->flip_count + 1;
|
|
|
|
ctx->redrawing = frame->redraw || !frame->current;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
update(ctx);
|
2015-07-01 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
static void flip_page(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
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
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2015-11-09 19:49:30 +00:00
|
|
|
|
|
|
|
// Wait until frame was rendered
|
2018-04-20 19:29:58 +00:00
|
|
|
while (ctx->next_frame) {
|
|
|
|
if (pthread_cond_timedwait(&ctx->video_wait, &ctx->lock, &ts)) {
|
|
|
|
if (ctx->next_frame) {
|
2018-02-20 12:30:18 +00:00
|
|
|
MP_VERBOSE(vo, "mpv_render_context_render() not being called "
|
|
|
|
"or stuck.\n");
|
2016-10-30 17:29:24 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2015-11-10 13:35:13 +00:00
|
|
|
}
|
2015-11-09 19:49:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
// Unblock mpv_render_context_render().
|
2018-04-20 19:29:58 +00:00
|
|
|
ctx->present_count += 1;
|
|
|
|
pthread_cond_broadcast(&ctx->video_wait);
|
2015-11-09 19:49:30 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
if (ctx->redrawing)
|
2015-11-12 21:40:02 +00:00
|
|
|
goto done; // do not block for redrawing
|
|
|
|
|
2015-11-09 19:49:30 +00:00
|
|
|
// Wait until frame was presented
|
2018-04-20 19:29:58 +00:00
|
|
|
while (ctx->expected_flip_count > ctx->flip_count) {
|
2018-02-20 12:30:18 +00:00
|
|
|
// mpv_render_report_swap() is declared as optional API.
|
2015-11-09 19:49:30 +00:00
|
|
|
// Assume the user calls it consistently _if_ it's called at all.
|
2018-04-20 19:29:58 +00:00
|
|
|
if (!ctx->flip_count)
|
2015-05-12 20:16:19 +00:00
|
|
|
break;
|
2018-04-20 19:29:58 +00:00
|
|
|
if (pthread_cond_timedwait(&ctx->video_wait, &ctx->lock, &ts)) {
|
2018-02-20 12:30:18 +00:00
|
|
|
MP_VERBOSE(vo, "mpv_render_report_swap() not being called.\n");
|
2015-11-10 13:35:13 +00:00
|
|
|
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.
|
2018-04-20 19:29:58 +00:00
|
|
|
if (ctx->next_frame) {
|
|
|
|
talloc_free(ctx->cur_frame);
|
|
|
|
ctx->cur_frame = ctx->next_frame;
|
|
|
|
ctx->next_frame = NULL;
|
|
|
|
ctx->present_count += 2;
|
|
|
|
pthread_cond_signal(&ctx->video_wait);
|
2015-11-09 19:49:30 +00:00
|
|
|
vo_increment_drop_count(vo, 1);
|
|
|
|
}
|
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_unlock(&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;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
bool ok = false;
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2014-12-31 18:12:44 +00:00
|
|
|
if (format >= IMGFMT_START && format < IMGFMT_END)
|
2018-04-20 19:29:58 +00:00
|
|
|
ok = ctx->imgfmt_supported[format - IMGFMT_START];
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2015-01-21 21:08:24 +00:00
|
|
|
return ok;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 20:12:29 +00:00
|
|
|
static void run_control_on_render_thread(void *p)
|
|
|
|
{
|
|
|
|
void **args = p;
|
|
|
|
struct mpv_render_context *ctx = args[0];
|
|
|
|
int request = (intptr_t)args[1];
|
|
|
|
void *data = args[2];
|
|
|
|
int ret = VO_NOTIMPL;
|
|
|
|
|
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_SCREENSHOT: {
|
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
struct vo_frame *frame = vo_frame_ref(ctx->cur_frame);
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
|
|
|
if (frame && ctx->renderer->fns->screenshot)
|
|
|
|
ctx->renderer->fns->screenshot(ctx->renderer, frame, data);
|
|
|
|
talloc_free(frame);
|
|
|
|
break;
|
|
|
|
}
|
2018-06-04 17:13:15 +00:00
|
|
|
case VOCTRL_PERFORMANCE_DATA: {
|
|
|
|
if (ctx->renderer->fns->perfdata) {
|
|
|
|
ctx->renderer->fns->perfdata(ctx->renderer, data);
|
|
|
|
ret = VO_TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-04-20 20:12:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*(int *)args[3] = ret;
|
|
|
|
}
|
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
static int control(struct vo *vo, uint32_t request, void *data)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
|
|
|
switch (request) {
|
2015-10-14 18:38:30 +00:00
|
|
|
case VOCTRL_RESET:
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
forget_frames(ctx, false);
|
|
|
|
ctx->need_reset = true;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 19:54:03 +00:00
|
|
|
vo->want_redraw = true;
|
2015-10-14 18:38:30 +00:00
|
|
|
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:
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
ctx->need_resize = true;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 19:54:03 +00:00
|
|
|
vo->want_redraw = true;
|
2014-12-09 16:47:02 +00:00
|
|
|
return VO_TRUE;
|
2016-09-02 13:59:40 +00:00
|
|
|
case VOCTRL_UPDATE_RENDER_OPTS:
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
ctx->need_update_external = true;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 19:54:03 +00:00
|
|
|
vo->want_redraw = true;
|
2016-09-02 13:59:40 +00:00
|
|
|
return VO_TRUE;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 20:12:29 +00:00
|
|
|
// VOCTRLs to be run on the renderer thread (if possible at all).
|
2019-09-20 12:52:49 +00:00
|
|
|
if (ctx->advanced_control) {
|
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_SCREENSHOT:
|
|
|
|
case VOCTRL_PERFORMANCE_DATA: {
|
2018-04-20 20:12:29 +00:00
|
|
|
int ret;
|
|
|
|
void *args[] = {ctx, (void *)(intptr_t)request, data, &ret};
|
|
|
|
mp_dispatch_run(ctx->dispatch, run_control_on_render_thread, args);
|
|
|
|
return ret;
|
|
|
|
}
|
2018-06-04 17:13:15 +00:00
|
|
|
}
|
2018-04-20 20:12:29 +00:00
|
|
|
}
|
|
|
|
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
int r = VO_NOTIMPL;
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->control_lock);
|
|
|
|
if (ctx->control_cb) {
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
int events = 0;
|
2018-05-01 14:39:00 +00:00
|
|
|
r = p->ctx->control_cb(vo, p->ctx->control_cb_ctx,
|
|
|
|
&events, request, data);
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
vo_event(vo, events);
|
|
|
|
}
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_unlock(&ctx->control_lock);
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2018-04-20 17:28:38 +00:00
|
|
|
static struct mp_image *get_image(struct vo *vo, int imgfmt, int w, int h,
|
|
|
|
int stride_align)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
2018-04-20 17:28:38 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
if (ctx->dr)
|
|
|
|
return dr_helper_get_image(ctx->dr, imgfmt, w, h, stride_align);
|
2018-04-20 17:28:38 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
static int reconfig(struct vo *vo, struct mp_image_params *params)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
forget_frames(ctx, true);
|
|
|
|
ctx->img_params = *params;
|
|
|
|
ctx->need_reconfig = true;
|
|
|
|
ctx->need_resize = true;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
control(vo, VOCTRL_RECONFIG, NULL);
|
|
|
|
|
|
|
|
return 0;
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx = p->ctx;
|
2014-12-09 16:47:02 +00:00
|
|
|
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
control(vo, VOCTRL_UNINIT, NULL);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
forget_frames(ctx, true);
|
|
|
|
ctx->img_params = (struct mp_image_params){0};
|
|
|
|
ctx->need_reconfig = true;
|
|
|
|
ctx->need_resize = true;
|
|
|
|
ctx->need_update_external = true;
|
|
|
|
ctx->need_reset = true;
|
|
|
|
ctx->vo = NULL;
|
2018-02-20 12:30:18 +00:00
|
|
|
|
2019-09-20 14:31:53 +00:00
|
|
|
// The following do not normally need ctx->lock, however, ctx itself may
|
|
|
|
// become invalid once we release ctx->lock.
|
|
|
|
bool prev_in_use = atomic_exchange(&ctx->in_use, false);
|
|
|
|
assert(prev_in_use); // obviously must have been set
|
|
|
|
mp_dispatch_interrupt(ctx->dispatch);
|
2018-04-20 17:26:04 +00:00
|
|
|
|
2019-09-20 14:31:53 +00:00
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2014-12-09 16:47:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int preinit(struct vo *vo)
|
|
|
|
{
|
|
|
|
struct vo_priv *p = vo->priv;
|
2018-02-20 12:30:18 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
struct mpv_render_context *ctx =
|
|
|
|
mp_client_api_acquire_render_context(vo->global->client_api);
|
|
|
|
p->ctx = ctx;
|
2018-02-20 12:30:18 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
if (!ctx) {
|
2018-02-12 23:49:13 +00:00
|
|
|
if (!vo->probing)
|
2018-02-20 12:30:18 +00:00
|
|
|
MP_FATAL(vo, "No render context set.\n");
|
2014-12-31 18:12:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
pthread_mutex_lock(&ctx->lock);
|
|
|
|
ctx->vo = vo;
|
|
|
|
ctx->need_resize = true;
|
|
|
|
ctx->need_update_external = true;
|
|
|
|
pthread_mutex_unlock(&ctx->lock);
|
2014-12-31 18:12:44 +00:00
|
|
|
|
2018-04-20 19:29:58 +00:00
|
|
|
vo->hwdec_devs = ctx->hwdec_devs;
|
cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.
- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations
all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.
this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.
this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.
some credit goes to @pigoz for the initial swift build support which
i could improve upon.
Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 11:28:19 +00:00
|
|
|
control(vo, VOCTRL_PREINIT, NULL);
|
2016-05-09 17:42:03 +00:00
|
|
|
|
2014-12-09 16:47:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-20 12:30:18 +00:00
|
|
|
const struct vo_driver video_out_libmpv = {
|
|
|
|
.description = "render API for libmpv",
|
|
|
|
.name = "libmpv",
|
2014-12-09 16:47:02 +00:00
|
|
|
.caps = VO_CAP_ROTATE90,
|
|
|
|
.preinit = preinit,
|
|
|
|
.query_format = query_format,
|
|
|
|
.reconfig = reconfig,
|
|
|
|
.control = control,
|
2018-04-20 17:28:38 +00:00
|
|
|
.get_image_ts = get_image,
|
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),
|
|
|
|
};
|