diff --git a/inc/common/queue.h b/inc/common/queue.h index 286dd54618f4b9f9fc606ada852d697f9baa6869..b4a4b67776e8af85e8f8b1604156421c5077dfb7 100644 --- a/inc/common/queue.h +++ b/inc/common/queue.h @@ -9,15 +9,16 @@ #define LKT_PLAY_TOGGLE ((void *) (size_t) 3) enum lkt_event_type { - lkt_event_null = 0, /* NULL */ - lkt_event_play_pos = (1 << 1), /* size_t */ - lkt_event_play_file = (1 << 2), /* const char* */ - lkt_event_play_next = (1 << 3), /* NULL */ - lkt_event_play_prev = (1 << 4), /* NULL */ - lkt_event_play_toggle = (1 << 5), /* size_t, `LKT_PLAY_.*` */ - lkt_event_prop_vol = (1 << 6), /* size_t */ - lkt_event_prop_dur = (1 << 7), /* size_t */ - lkt_event_prop_time = (1 << 8), /* size_t */ + lkt_event_null = 0, // NULL + lkt_event_play_pos = (1 << 1), // size_t + lkt_event_play_file = (1 << 2), // const char* + lkt_event_play_next = (1 << 3), // NULL + lkt_event_play_prev = (1 << 4), // NULL + lkt_event_play_toggle = (1 << 5), // size_t, `LKT_PLAY_.*` + lkt_event_prop_vol = (1 << 6), // size_t + lkt_event_prop_dur = (1 << 7), // size_t + lkt_event_prop_time = (1 << 8), // size_t + lkt_event_skip_current = (1 << 9), // NULL }; #define lkt_event_play (lkt_event_play_pos | lkt_event_play_file | \ diff --git a/inc/lektor/module/mpv.h b/inc/lektor/module/mpv.h index 821bdd12b97d4273bc9b275d821515a92dcff647..2b412b6485dc872cba2fd00d586b3123594f0e18 100644 --- a/inc/lektor/module/mpv.h +++ b/inc/lektor/module/mpv.h @@ -4,8 +4,7 @@ #include <mpv/client.h> #include <common/common.h> #include <common/queue.h> - -struct lkt_win *win; +#include <lektor/window.h> void lmpv_free(mpv_handle **ctx); mpv_handle *lmpv_new(unsigned long int wid, volatile sqlite3 *db); @@ -16,4 +15,5 @@ int lmpv_set_volume(mpv_handle *ctx, int vol); int lmpv_load_file(mpv_handle *ctx, const char *file); int lmpv_toggle_pause(mpv_handle *ctx); int lmpv_handle(struct lkt_win *win, mpv_handle *ctx, struct queue *queue, - volatile int *time_pos, volatile int *time_duration); + volatile int *time_pos, volatile int *time_duration, + volatile int *state); diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index b8fdbe640aeede8ab06551f6ea5b01a26fec37fe..0f97929dee0bc6018bf30e5a08a0a5688a0cfaed 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -34,6 +34,7 @@ struct module_sdl2_window { volatile mpv_render_context *mpv_gl; volatile int mpv_time_pos; /* Don't write it in the database */ volatile int mpv_duration; /* Because don't need to be persistent */ + volatile int state; /* Thread related */ struct poller_thread self; @@ -236,7 +237,8 @@ loop: if (event.type == wakeup_on_mpv_events) lmpv_handle((struct lkt_win *) win, (mpv_handle *) sdl2->mpv, - sdl2->queue, &sdl2->mpv_time_pos, &sdl2->mpv_duration); + sdl2->queue, &sdl2->mpv_time_pos, &sdl2->mpv_duration, + &sdl2->state); } if (redraw) { diff --git a/src/module/mpv.c b/src/module/mpv.c index 2023814497f05de19df397460c041bf13d582e12..919b09d9e022203ab43abfbbf5453337bff3615c 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -10,6 +10,12 @@ #include <unistd.h> #include <sqlite3.h> +enum { + STATE_STOP = 0, + STATE_PLAY = 1, + STATE_PAUSE = 2, +}; + void lmpv_free(mpv_handle **ctx) { @@ -145,10 +151,10 @@ lmpv_toggle_pause(mpv_handle *ctx) int lmpv_handle(struct lkt_win *win, mpv_handle *ctx, struct queue *queue, - volatile int *time_pos, volatile int *time_duration) + volatile int *time_pos, volatile int *time_duration, + volatile int *state) { size_t ao_volume; - struct lkt_queue_state state; mpv_event *event = NULL; mpv_event_property *prop; RETURN_UNLESS(ctx && win, "Invalid argument", 1); @@ -158,12 +164,18 @@ loop: switch (event->event_id) { case MPV_EVENT_PAUSE: + *state = STATE_PAUSE; + lkt_queue_send(queue, lkt_event_play_toggle, LKT_PLAY_TOGGLE); + break; + case MPV_EVENT_UNPAUSE: + *state = STATE_PLAY; lkt_queue_send(queue, lkt_event_play_toggle, LKT_PLAY_TOGGLE); break; case MPV_EVENT_SHUTDOWN: *time_pos = (*time_duration = 0); + *state = STATE_STOP; lkt_queue_send(queue, lkt_event_play_toggle, LKT_PLAY_STOP); win->close(win); return 1; @@ -172,7 +184,7 @@ loop: return 1; case MPV_EVENT_IDLE: - if (state.current > 0 && *time_pos > 0) + if (*state != STATE_STOP && *time_pos > 0) lkt_queue_send(queue, lkt_event_play_next, NULL); break; @@ -200,10 +212,13 @@ loop: // Pause state // if (STR_MATCH(prop->name, "pause") && prop->format == MPV_FORMAT_FLAG) { - if (* (bool *) prop->data) + if (* (bool *) prop->data) { lkt_queue_send(queue, lkt_event_play_toggle, LKT_PLAY_PAUSE); - else + *state = STATE_PAUSE; + } else { lkt_queue_send(queue, lkt_event_play_toggle, LKT_PLAY_PLAY); + *state = STATE_PLAY; + } } break; diff --git a/src/module/repo.c b/src/module/repo.c index 6d71daa95875d5094308fa96b6262a52c67a167e..19f2cf662ea83ae7dcaf41e5dcf76b4b3f69c933 100644 --- a/src/module/repo.c +++ b/src/module/repo.c @@ -413,10 +413,7 @@ do_it: if (current_id == (int) kara.id) { LOG_WARN("REPO", "Update currently playing kara %d, skip it", current_id); - char *current_path = safe_malloc(PATH_MAX * sizeof(char)); - database_queue_skip_current(db, current_path); - srv->win.load_file(&srv->win, current_path); - free(current_path); + lkt_queue_send(&srv->queue, lkt_event_skip_current, NULL); } if (!database_update_add(db, kara.filename, &kara.mdt, kara.id, false)) {