client API: preparations for allowing render API to use DR etc.

DR (letting the decoder allocate texture memory) requires running the
allocation on the render thread. This is rather hard with the render
API, because the user controls this thread and when it's entered. It was
not possible until now.

This commit adds a bunch of infrastructure to make this possible. We add
a new optional mode (MPV_RENDER_PARAM_ADVANCED_CONTROL) which basically
lets the user's render thread and libmpv agree how this should be done.

Misuse would lead to deadlocks. To make this less likely, strictly
document thread safety/locking issues. In particular, document which
libmpv functions can be called without issues. (The rest has to be
assumed unsafe.)

The worst issue is destruction of the render context while video is
still active. To avoid certain unintended recursive locks (i.e.
deadlocks, unless we'd make the locks recursive), make the update
callback lock separate. Make "killing" the video chain asynchronous, so
we can do extra work while video is being destroyed.

Because losing wakeups is a big deal, setting the update callback now
triggers a wakeup. (It would have been better if the wakeup callback
were a parameter to mpv_render_context_create(), but too late.)

This commit does not add DR yet; the following commit does this.
This commit is contained in:
wm4
2018-04-20 19:26:04 +02:00
committed by Jan Ekström
parent 76844c9c51
commit 67689ff6b4
8 changed files with 269 additions and 30 deletions

View File

@@ -1749,18 +1749,39 @@ int64_t mpv_get_time_us(mpv_handle *ctx)
#include "video/out/libmpv.h"
// Used by vo_libmpv to synchronously uninitialize video.
void kill_video(struct mp_client_api *client_api)
struct kill_ctx {
struct MPContext *mpctx;
void (*fin)(void *ctx);
void *fin_ctx;
};
static void do_kill(void *ptr)
{
struct MPContext *mpctx = client_api->mpctx;
mp_dispatch_lock(mpctx->dispatch);
struct kill_ctx *k = ptr;
struct MPContext *mpctx = k->mpctx;
struct track *track = mpctx->vo_chain ? mpctx->vo_chain->track : NULL;
uninit_video_out(mpctx);
if (track) {
mpctx->error_playing = MPV_ERROR_VO_INIT_FAILED;
error_on_track(mpctx, track);
}
mp_dispatch_unlock(mpctx->dispatch);
k->fin(k->fin_ctx);
}
// Used by vo_libmpv to (a)synchronously uninitialize video.
void kill_video_async(struct mp_client_api *client_api, void (*fin)(void *ctx),
void *fin_ctx)
{
struct MPContext *mpctx = client_api->mpctx;
struct kill_ctx *k = talloc_ptrtype(NULL, k);
*k = (struct kill_ctx){
.mpctx = mpctx,
.fin = fin,
.fin_ctx = fin_ctx,
};
mp_dispatch_enqueue_autofree(mpctx->dispatch, do_kill, k);
}
// Used by vo_libmpv to set the current render context.

View File

@@ -48,7 +48,8 @@ bool mp_set_main_render_context(struct mp_client_api *client_api,
struct mpv_render_context *ctx, bool active);
struct mpv_render_context *
mp_client_api_acquire_render_context(struct mp_client_api *ca);
void kill_video(struct mp_client_api *client_api);
void kill_video_async(struct mp_client_api *client_api, void (*fin)(void *ctx),
void *fin_ctx);
bool mp_streamcb_lookup(struct mpv_global *g, const char *protocol,
void **out_user_data, mpv_stream_cb_open_ro_fn *out_fn);