summaryrefslogtreecommitdiffstats
path: root/player/client.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-03-09 06:00:51 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-03-15 00:00:04 -0700
commita7f3cf473707b19bff9ea80b227490c8b305b601 (patch)
treeb094e1b8237d9ee09770e76809895b5d0e2eceaa /player/client.c
parent410a1b49edfbbf7d528fd7dd06b73d06e2f9fce4 (diff)
downloadmpv-a7f3cf473707b19bff9ea80b227490c8b305b601.tar.bz2
mpv-a7f3cf473707b19bff9ea80b227490c8b305b601.tar.xz
client API: add mpv_create_weak_client()
Diffstat (limited to 'player/client.c')
-rw-r--r--player/client.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/player/client.c b/player/client.c
index a887a16d2a..d347033fe5 100644
--- a/player/client.c
+++ b/player/client.c
@@ -136,6 +136,7 @@ struct mpv_handle {
uint64_t property_event_masks; // or-ed together event masks of all properties
bool fuzzy_initialized; // see scripting.c wait_loaded()
+ bool is_weak; // can not keep core alive on its own
struct mp_log_buffer *messages;
};
@@ -269,6 +270,13 @@ struct mpv_handle *mp_new_client(struct mp_client_api *clients, const char *name
return client;
}
+void mp_client_set_weak(struct mpv_handle *ctx)
+{
+ pthread_mutex_lock(&ctx->lock);
+ ctx->is_weak = true;
+ pthread_mutex_unlock(&ctx->lock);
+}
+
const char *mpv_client_name(mpv_handle *ctx)
{
return ctx->name;
@@ -416,8 +424,11 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
if (mpctx->is_cli) {
terminate = false;
} else {
- // If the last mpv_handle got destroyed, destroy the core.
- if (clients->num_clients == 0)
+ // If the last strong mpv_handle got destroyed, destroy the core.
+ bool has_strong_ref = false;
+ for (int n = 0; n < clients->num_clients; n++)
+ has_strong_ref |= !clients->clients[n]->is_weak;
+ if (!has_strong_ref)
terminate = true;
// Reserve the right to destroy mpctx for us.
@@ -550,6 +561,14 @@ mpv_handle *mpv_create_client(mpv_handle *ctx, const char *name)
return new;
}
+mpv_handle *mpv_create_weak_client(mpv_handle *ctx, const char *name)
+{
+ mpv_handle *new = mpv_create_client(ctx, name);
+ if (new)
+ mp_client_set_weak(new);
+ return new;
+}
+
int mpv_initialize(mpv_handle *ctx)
{
lock_core(ctx);