From df85c76b7f8711b15e36973518578e0064657b8e Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 19 Sep 2016 19:58:14 +0200 Subject: client API: revert some relaxations about calling mpv_initialize() My original idea was making mpv_initialize() a no-op, but it seems this can't happen after all. The problem is especially with subtle interactions in option parsing (basically all pre-parse options). Instead, I might go into the opposite direction, and add a new API function that takes over the role of mpv_create+mpv_initialize, and which will take a list of options. This list will be for the purpose of setting options that can be set only at initialization time (such as config-dir). This would also make it more uniform with the command- line player initialization. Maybe. In any case, for now revert parts of commit 453fea87 to remove the initialization-related freedoms it added. Fortunately, this wasn't released yet, so we remove it from the API as if it never happened. (The rest of that commit is still fine, just not the additional freedom.) --- DOCS/client-api-changes.rst | 2 -- player/client.c | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/DOCS/client-api-changes.rst b/DOCS/client-api-changes.rst index 36b0d92368..c76881fbd4 100644 --- a/DOCS/client-api-changes.rst +++ b/DOCS/client-api-changes.rst @@ -35,8 +35,6 @@ API changes --- mpv 0.21.0 --- 1.23 - deprecate setting "no-" options via mpv_set_option*(). For example, instead of "no-video=" you should set "video=no". - - be much more permissive what API calls are allowed before - mpv_initialize(). - do not override the SIGPIPE signal handler anymore. This was done as workaround for the FFmpeg TLS code, which has been fixed long ago. - deprecate mpv_suspend() and mpv_resume(). They will be stubbed out diff --git a/player/client.c b/player/client.c index bed21565a7..f95ad372b5 100644 --- a/player/client.c +++ b/player/client.c @@ -1000,6 +1000,8 @@ static void cmd_fn(void *data) static int run_client_command(mpv_handle *ctx, struct mp_cmd *cmd, mpv_node *res) { + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!cmd) return MPV_ERROR_INVALID_PARAMETER; @@ -1039,6 +1041,8 @@ int mpv_command_string(mpv_handle *ctx, const char *args) static int run_cmd_async(mpv_handle *ctx, uint64_t ud, struct mp_cmd *cmd) { + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!cmd) return MPV_ERROR_INVALID_PARAMETER; @@ -1116,6 +1120,8 @@ static void setproperty_fn(void *arg) int mpv_set_property(mpv_handle *ctx, const char *name, mpv_format format, void *data) { + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!get_mp_type(format)) return MPV_ERROR_PROPERTY_FORMAT; @@ -1145,6 +1151,8 @@ int mpv_set_property_async(mpv_handle *ctx, uint64_t ud, const char *name, mpv_format format, void *data) { const struct m_option *type = get_mp_type(format); + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!type) return MPV_ERROR_PROPERTY_FORMAT; @@ -1257,6 +1265,8 @@ static void getproperty_fn(void *arg) int mpv_get_property(mpv_handle *ctx, const char *name, mpv_format format, void *data) { + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!data) return MPV_ERROR_INVALID_PARAMETER; if (!get_mp_type_get(format)) @@ -1289,6 +1299,8 @@ char *mpv_get_property_osd_string(mpv_handle *ctx, const char *name) int mpv_get_property_async(mpv_handle *ctx, uint64_t ud, const char *name, mpv_format format) { + if (!ctx->mpctx->initialized) + return MPV_ERROR_UNINITIALIZED; if (!get_mp_type_get(format)) return MPV_ERROR_PROPERTY_FORMAT; @@ -1455,6 +1467,8 @@ static void update_prop(void *p) // outstanding property. static bool gen_property_change_event(struct mpv_handle *ctx) { + if (!ctx->mpctx->initialized) + return false; int start = ctx->lowest_changed; ctx->lowest_changed = ctx->num_properties; for (int n = start; n < ctx->num_properties; n++) { @@ -1724,6 +1738,8 @@ int mpv_opengl_cb_render(mpv_opengl_cb_context *ctx, int fbo, int vp[4]) void *mpv_get_sub_api(mpv_handle *ctx, mpv_sub_api sub_api) { + if (!ctx->mpctx->initialized) + return NULL; void *res = NULL; lock_core(ctx); switch (sub_api) { -- cgit v1.2.3