diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c index 724a6914b9e5e990db87cde5b009aaeabaf8d554..ab619b24ac90e66e988c28761c5af80f29a0a8d8 100644 --- a/src/module/module_sdl2.c +++ b/src/module/module_sdl2.c @@ -29,16 +29,13 @@ struct module_sdl2_window { /* Mpv related */ volatile mpv_handle *mpv; 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 mpv_time_pos; /* Don't write it in the database */ + volatile int mpv_duration; /* Because don't need to be persistent */ /* Thread related */ pthread_mutex_t mtx; struct lkt_thread self; - volatile int launched; - - /* SDL you sucks */ - volatile int is_sdl_init; + volatile int launched; /* SDL you sucks */ }; /* Private functions. */ @@ -118,9 +115,9 @@ sdl_thread__(struct lkt_thread_arg *arg) RETURN_UNLESS(sdl2->window, "Failed to create the window", NULL); sdl2->glcontext = SDL_GL_CreateContext((SDL_Window *) sdl2->window); RETURN_UNLESS(sdl2->glcontext, "Failed to create the SDL context", NULL); - sdl2->is_sdl_init = 1; /* Init mpv here */ + RETURN_IF(init_mpv__((mpv_handle **) & sdl2->mpv), "Failed to init mpv", false); @@ -142,9 +139,7 @@ sdl_thread__(struct lkt_thread_arg *arg) {0} }; - /* Init mpv_gl here */ - RETURN_IF(init_mpv_gl__((mpv_handle *) sdl2->mpv, - (mpv_render_context **) &sdl2->mpv_gl, params), + RETURN_IF(init_mpv_gl__((mpv_handle *) sdl2->mpv, (mpv_render_context **) &sdl2->mpv_gl, params), "Failed to init mpv_gl", false); while (!sdl2->launched) @@ -260,14 +255,11 @@ module_sdl2_new(struct lkt_win *const win) struct lkt_thread_arg *arg = calloc(1, sizeof(struct lkt_thread_arg)); RETURN_UNLESS(arg, "Out of memory", false); arg->args = win; - RETURN_IF(lkt_th_new(&((struct module_sdl2_window *) win->window)->self, LKT_DEFAULT_LIST_SIZE, sdl_thread__, - arg), + RETURN_IF(lkt_th_new(&((struct module_sdl2_window *) win->window)->self, + LKT_DEFAULT_LIST_SIZE, sdl_thread__, arg), "Failed to launch the SDL thread", false); } - while (!((struct module_sdl2_window *) win->window)->is_sdl_init) - sched_yield(); - /* Finish */ SDL_SetWindowTitle((SDL_Window *) ((struct module_sdl2_window *) win->window)->window, "Lektord"); SDL_DisableScreenSaver(); @@ -278,8 +270,12 @@ module_sdl2_new(struct lkt_win *const win) void module_sdl2_close(struct lkt_win *const win) { - /* TODO: stop mpv. */ - (void) win; + RETURN_UNLESS(win && win->window, "Invalid arguments", NOTHING); + struct module_sdl2_window *sdl2 = win->window; + RETURN_UNLESS(sdl2->mpv, "Missing mpv ctx", NOTHING); + static const char *cmd[] = { "stop", NULL }; + mpv_command_async((mpv_handle *) sdl2->mpv, 0, cmd); + /* TODO: make the SDL window background be black. */ } void