1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 00:02:13 +00:00

client API: implement mpv_suspend/resume slightly differently

Why do these API calls even still exist? I don't know, and maybe they
don't make any sense anymore. But whether they should be removed or not
is not a decision I want to make now. I want to get rid of
mp_dispatch_suspend/resume(), though. So implement the client APIs
slightly differently.
This commit is contained in:
wm4 2016-09-04 15:43:12 +02:00
parent d889d1fbaa
commit 2619d8eff4
5 changed files with 20 additions and 10 deletions

View File

@ -230,7 +230,7 @@ void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout)
// not a synchronization mechanism; it merely makes sure the target thread does
// not leave mp_dispatch_queue_process(), even if it's done. mp_dispatch_lock()
// can be used for exclusive access.
void mp_dispatch_suspend(struct mp_dispatch_queue *queue)
static void mp_dispatch_suspend(struct mp_dispatch_queue *queue)
{
pthread_mutex_lock(&queue->lock);
queue->suspend_requested++;
@ -247,7 +247,7 @@ void mp_dispatch_suspend(struct mp_dispatch_queue *queue)
}
// Undo mp_dispatch_suspend().
void mp_dispatch_resume(struct mp_dispatch_queue *queue)
static void mp_dispatch_resume(struct mp_dispatch_queue *queue)
{
pthread_mutex_lock(&queue->lock);
assert(queue->suspended);

View File

@ -15,8 +15,6 @@ void mp_dispatch_enqueue_autofree(struct mp_dispatch_queue *queue,
void mp_dispatch_run(struct mp_dispatch_queue *queue,
mp_dispatch_fn fn, void *fn_data);
void mp_dispatch_queue_process(struct mp_dispatch_queue *queue, double timeout);
void mp_dispatch_suspend(struct mp_dispatch_queue *queue);
void mp_dispatch_resume(struct mp_dispatch_queue *queue);
void mp_dispatch_lock(struct mp_dispatch_queue *queue);
void mp_dispatch_unlock(struct mp_dispatch_queue *queue);

View File

@ -330,8 +330,11 @@ void mpv_suspend(mpv_handle *ctx)
}
pthread_mutex_unlock(&ctx->lock);
if (do_suspend)
mp_dispatch_suspend(ctx->mpctx->dispatch);
if (do_suspend) {
mp_dispatch_lock(ctx->mpctx->dispatch);
ctx->mpctx->suspend_count++;
mp_dispatch_unlock(ctx->mpctx->dispatch);
}
}
void mpv_resume(mpv_handle *ctx)
@ -347,8 +350,11 @@ void mpv_resume(mpv_handle *ctx)
}
pthread_mutex_unlock(&ctx->lock);
if (do_resume)
mp_dispatch_resume(ctx->mpctx->dispatch);
if (do_resume) {
mp_dispatch_lock(ctx->mpctx->dispatch);
ctx->mpctx->suspend_count--;
mp_dispatch_unlock(ctx->mpctx->dispatch);
}
}
void mp_resume_all(mpv_handle *ctx)
@ -358,8 +364,11 @@ void mp_resume_all(mpv_handle *ctx)
ctx->suspend_count = 0;
pthread_mutex_unlock(&ctx->lock);
if (do_resume)
mp_dispatch_resume(ctx->mpctx->dispatch);
if (do_resume) {
mp_dispatch_lock(ctx->mpctx->dispatch);
ctx->mpctx->suspend_count--;
mp_dispatch_unlock(ctx->mpctx->dispatch);
}
}
static void lock_core(mpv_handle *ctx)

View File

@ -224,6 +224,7 @@ enum playback_status {
typedef struct MPContext {
bool initialized;
bool autodetach;
int suspend_count;
struct mpv_global *global;
struct MPOpts *opts;
struct mp_log *log;

View File

@ -70,6 +70,8 @@ void mp_process_input(struct MPContext *mpctx)
mp_cmd_free(cmd);
mp_dispatch_queue_process(mpctx->dispatch, 0);
}
while (mpctx->suspend_count)
mp_dispatch_queue_process(mpctx->dispatch, 100);
}
double get_relative_time(struct MPContext *mpctx)