diff --git a/CMakeLists.txt b/CMakeLists.txt index d388a55511b36434c2d6a0af336bc25bd183a886..17a9efa99be44b96fcf58414dfe03467ccb398e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,6 @@ set(Clang_C_FLAGS -Wno-missing-variable-declarations -Wno-unknown-warning-option -Wno-declaration-after-statement - -Wno-double-promotion # Because of SDL2... -fcolor-diagnostics ) set(Clang_CXX_FLAGS @@ -95,8 +94,6 @@ set(GNU_C_FLAGS find_library(MPV_LIBRARY mpv REQUIRED) # tested with 0.32.0 find_library(SQLITE3_LIBRARY sqlite3 REQUIRED version>=3.31.0) # tested with 3.34.1 -find_package(SDL2 REQUIRED) # tested with 2.0.14 -find_package(SDL2_image REQUIRED) # same as above ^ find_package(CURL REQUIRED HTTP HTTPS) # tested with 7.74.0 find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED) @@ -177,7 +174,6 @@ set(lektor_module_SOURCES src/module/module_repo.c src/module/module_repo_rs.c src/module/mpv.c - src/module/module_sdl2.c src/module/thread.c src/module/module_qt_window.cc @@ -237,6 +233,7 @@ set(common_DEFINITIONS LKT_STATIC_MODULE=1 # Only build static modules with cmake _POSIX_C_SOURCE=200809L # POSIX 2008/09 LKT_VERSION="${LKT_VERSION}" + MPV_ENABLE_DEPRECATED=0 ) set(SQL_GENERATED_FILE ${CMAKE_CURRENT_BINARY_DIR}/disk_sql.c) @@ -299,9 +296,7 @@ target_link_libraries(lektord PRIVATE ${MPV_LIBRARY} ${CMAKE_DL_LIBS} ${SQLITE3_LIBRARY} - ${SDL2_LIBRARIES} ${CURL_LIBRARIES} - ${SDL2_IMAGE_LIBRARIES} Qt${QT_VERSION_MAJOR}::Widgets ) target_link_libraries(lkt PRIVATE @@ -311,8 +306,6 @@ target_link_libraries(lkt PRIVATE target_include_directories(lkt PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc) target_include_directories(lektord PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/inc - ${SDL2_INCLUDE_DIRS} - ${SDL2_IMAGE_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ) diff --git a/src/main/server.c b/src/main/server.c index 78d6faecb24685592e9f3c039717888d297bb883..7d9225c13d5cc3c2bae72abf645185dbcfefad8b 100644 --- a/src/main/server.c +++ b/src/main/server.c @@ -16,7 +16,6 @@ #include <termios.h> #if defined(LKT_STATIC_MODULE) -REG_DECLARE(sdl2_reg) REG_DECLARE(qt_window_reg) REG_DECLARE(repo_reg) REG_DECLARE(repo_rs_reg) @@ -41,7 +40,6 @@ main(int argc, char *argv[]) #if defined(LKT_STATIC_MODULE) REG_REGISTER("repo_rs", repo_rs_reg) REG_REGISTER("repo", repo_reg) - REG_REGISTER("sdl2", sdl2_reg) REG_REGISTER("qt", qt_window_reg) #endif REG_END() diff --git a/src/module/module_sdl2.c b/src/module/module_sdl2.c deleted file mode 100644 index e42df9eead1b103a2e62f80d336ff56a722bfa97..0000000000000000000000000000000000000000 --- a/src/module/module_sdl2.c +++ /dev/null @@ -1,606 +0,0 @@ -#define __LKT_MODULE_MAIN_SOURCE__ -#include <lektor/lktmodule.h> - -#include "mpv.h" -#include "thread.h" - -#include <lektor/internal/icon.xpm> - -#include <sched.h> -#include <mpv/render_gl.h> -#include <mpv/client.h> - -LKT_PUSH -LKT_IGNORE_WARN_FALLTHROUGH -#include <SDL.h> -#include <SDL_image.h> -LKT_POP - -#define WIDTH 400 -#define HEIGHT 200 - -static volatile Uint32 wakeup_on_mpv_render_update, wakeup_on_mpv_events; - -struct module_sdl2_window { - /* Related to SDL2 */ - volatile SDL_Window *window; - volatile SDL_GLContext glcontext; - int is_fullscreen; - - /* 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 state; - volatile int hinib; - volatile int set_seek; - - /* Thread related */ - struct poller_thread self; - volatile int launched; /* SDL you sucks */ - volatile bool is_in_preparation; /* Inside the MPV & SDL init */ - volatile bool has_preparation_failed; /* The init failed */ - - /* Things from the server */ - struct queue *queue; - lkt_db *db; -}; - -/************************ - * Function definitions * - ************************/ - -static bool module_sdl2_get_elapsed(struct module_sdl2_window *, int *); -static bool module_sdl2_get_duration(struct module_sdl2_window *, int *); -static bool module_sdl2_set_paused(struct module_sdl2_window *, int); -static bool module_sdl2_set_volume(struct module_sdl2_window *, int); -static bool module_sdl2_set_position(struct module_sdl2_window *, int); -static bool module_sdl2_load_file(struct module_sdl2_window *, const char *); -static bool module_sdl2_toggle_pause(struct module_sdl2_window *); -static void module_sdl2_free(struct module_sdl2_window *); -static void module_sdl2_close(struct module_sdl2_window *); -static bool module_sdl2_new(struct module_sdl2_window **, struct queue *, lkt_db *); - -/********************* - * Private functions * - *********************/ - -PRIVATE_FUNCTION void * -get_proc_address_mpv(void UNUSED *fn_ctx, const char *name) -{ - return SDL_GL_GetProcAddress(name); -} - -PRIVATE_FUNCTION void -on_mpv_events(void UNUSED *ctx) -{ - SDL_Event event = { .type = wakeup_on_mpv_events }; - SDL_PushEvent(&event); -} - -PRIVATE_FUNCTION void -on_mpv_render_update(void UNUSED *ctx) -{ - SDL_Event event = { .type = wakeup_on_mpv_render_update }; - SDL_PushEvent(&event); -} - -PRIVATE_FUNCTION bool -init_mpv__(mpv_handle **ctx, lkt_db *db) -{ - *ctx = lmpv_prepare(db); - int status; - RETURN_IF((status = mpv_initialize(*ctx)) < 0, mpv_error_string(status), 1); - RETURN_UNLESS(lmpv_observe_properties(*ctx), "Observe prop failed", 1); - return 0; -} - -PRIVATE_FUNCTION bool -init_mpv_gl__(mpv_handle *mpv, mpv_render_context **mpv_gl, mpv_render_param *params) -{ - int status; - RETURN_IF((status = mpv_render_context_create(mpv_gl, mpv, params)) < 0, - mpv_error_string(status), 1); - - wakeup_on_mpv_render_update = SDL_RegisterEvents(1); - wakeup_on_mpv_events = SDL_RegisterEvents(1); - if (wakeup_on_mpv_render_update == (Uint32)-1 || wakeup_on_mpv_events == (Uint32)-1) { - LOG_ERROR("WINDOW", "Failed to register event"); - return 1; - } - - mpv_set_wakeup_callback(mpv, on_mpv_events, NULL); - mpv_render_context_set_update_callback(*mpv_gl, on_mpv_render_update, NULL); - return 0; -} - -/******************************** - * va_list version of functions * - ********************************/ - -static int -mod_new(va_list *va) -{ - va_list copy; - struct module_sdl2_window **win; - va_copy(copy, *va); - win = (struct module_sdl2_window **)va_arg(copy, void **); - struct queue *queue = va_arg(copy, struct queue *); - lkt_db *db = va_arg(copy, lkt_db *); - bool ret = module_sdl2_new(win, queue, db); - va_end(copy); - return !ret; -} - -static int -mod_close(va_list *va) -{ - va_list copy; - va_copy(copy, *va); - struct module_sdl2_window **win = (struct module_sdl2_window **)va_arg(copy, void **); - module_sdl2_close(*win); - va_end(copy); - return 0; -} - -static int -mod_free(va_list *va) -{ - va_list copy; - va_copy(copy, *va); - struct module_sdl2_window **win = (struct module_sdl2_window **)va_arg(copy, void **); - module_sdl2_free(*win); - va_end(copy); - return 0; -} - -static int -mod_toggle_pause(va_list *va) -{ - va_list copy; - struct module_sdl2_window **win; - va_copy(copy, *va); - win = (struct module_sdl2_window **)va_arg(copy, void **); - bool ret = module_sdl2_toggle_pause(*win); - va_end(copy); - return !ret; -} - -static int -mod_load_file(va_list *va) -{ - va_list copy; - struct module_sdl2_window **win; - va_copy(copy, *va); - win = (struct module_sdl2_window **)va_arg(copy, void **); - const char *file = va_arg(copy, const char *); - const bool ret = module_sdl2_load_file(*win, file); - va_end(copy); - return !ret; -} - -static int -mod_set_volume(va_list *va) -{ - va_list copy; - va_copy(copy, *va); - struct module_sdl2_window **win = (struct module_sdl2_window **)va_arg(copy, void **); - const int volume = va_arg(copy, int); - const bool ret = module_sdl2_set_volume(*win, volume); - va_end(copy); - return !ret; -} - -static int -mod_set_paused(va_list *va) -{ - va_list copy; - va_copy(copy, *va); - struct module_sdl2_window **win = (struct module_sdl2_window **)va_arg(copy, void **); - const int state = va_arg(copy, int); - const bool ret = module_sdl2_set_paused(*win, state); - va_end(copy); - return !ret; -} - -static int -mod_set_position(va_list *va) -{ - va_list copy; - va_copy(copy, *va); - struct module_sdl2_window **win = (struct module_sdl2_window **)va_arg(copy, void **); - const int seconds = va_arg(copy, int); - const bool ret = module_sdl2_set_position(*win, seconds); - va_end(copy); - return !ret; -} - -static int -mod_get_duration(va_list *va) -{ - va_list copy; - struct module_sdl2_window **win; - va_copy(copy, *va); - win = (struct module_sdl2_window **)va_arg(copy, void **); - int *duration = va_arg(copy, int *); - bool ret = module_sdl2_get_duration(*win, duration); - va_end(copy); - return !ret; -} - -static int -mod_get_elapsed(va_list *va) -{ - va_list copy; - struct module_sdl2_window **win; - va_copy(copy, *va); - win = (struct module_sdl2_window **)va_arg(copy, void **); - int *elapsed = va_arg(copy, int *); - const bool ret = module_sdl2_get_elapsed(*win, elapsed); - va_end(copy); - return !ret; -} - -/******************** - * The module stuff * - ********************/ - -REG_BEGIN(sdl2_reg) -REG_ADD_NAMED("new", mod_new) -REG_ADD_NAMED("free", mod_free) -REG_ADD_NAMED("close", mod_close) -REG_ADD_NAMED("toggle", mod_toggle_pause) -REG_ADD_NAMED("load", mod_load_file) -REG_ADD_NAMED("set_paused", mod_set_paused) -REG_ADD_NAMED("set_position", mod_set_position) -REG_ADD_NAMED("set_volume", mod_set_volume) -REG_ADD_NAMED("get_duration", mod_get_duration) -REG_ADD_NAMED("get_elapsed", mod_get_elapsed) -REG_END() -#if !defined(LKT_STATIC_MODULE) -REG_EXPORT(sdl2_reg) -#endif - -/**************************** - * Private helper functions * - ****************************/ - -static void -set_window_title(struct module_sdl2_window *win) -{ - struct kara_metadata kara_mdt; - int changed_kara = 0; - char *kara_title = NULL; - char window_title[LKT_LINE_MAX]; - - if (database_queue_current_kara(win->db, &kara_mdt, &changed_kara)) { - mdtcat(&kara_mdt, &kara_title); - safe_snprintf(window_title, LKT_LINE_MAX, "[Lektord] %d: %s", changed_kara, kara_title); - LOG_DEBUG("WINDOW", "Set window title to: %s", window_title); - SDL_SetWindowTitle((SDL_Window *)win->window, window_title); - free(kara_title); - } - - else { - LOG_ERROR("WINDOW", "Failed to get current kara, can't change window title"); - } -} - -static void -unset_window_title(struct module_sdl2_window *win) -{ - static const char *window_title = "[Lektord] Stopped"; - LOG_DEBUG("WINDOW", "Set window title to: %s", window_title); - SDL_SetWindowTitle((SDL_Window *)win->window, window_title); -} - -/*************************** - * Function implementation * - ***************************/ - -static void * -sdl_thread__(struct poller_thread_arg *arg) -{ - struct module_sdl2_window *sdl2 = arg->args; - int redraw = 0; - bool ctrl = false; - sdl2->has_preparation_failed = true; // For now, will be cleared if no goto to end_of_init - - SDL_Event event; - uint64_t flags; - int w, h; - const Uint8 *state; - - free(arg); - - struct lkt_module module = { - .handle = NULL, - .reg = sdl2_reg, - .data = sdl2, - }; - - lkt_thread_set_name("lektord/sdl-mod"); - - /* Init the SDL window - Yeah, SDL you sucks */ - - SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "no"); /* It seems that sdl sucks. */ - RETURN_IF(SDL_Init(SDL_INIT_VIDEO) < 0, "Failed to init SDL", NULL); - RETURN_IF(IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG) < 0, "Failed to init", NULL) - - const Uint32 window_flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE; - sdl2->window = SDL_CreateWindow("lektord", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, - WIDTH, HEIGHT, window_flags); - 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); - - /* Set window icon */ - SDL_Surface *window_icon = IMG_ReadXPMFromArray(icon); - if (NULL == window_icon) { - LOG_ERROR("WINDOW", "Failed to load xpm icon: %s", IMG_GetError()); - } else { - SDL_SetWindowIcon((SDL_Window *)sdl2->window, window_icon); - SDL_FreeSurface(window_icon); - } - - /* Init mpv here */ - - { - GOTO_IF(init_mpv__((mpv_handle **)&sdl2->mpv, sdl2->db), "Failed to init mpv", end_of_init); - - mpv_render_param params[] = { { MPV_RENDER_PARAM_API_TYPE, MPV_RENDER_API_TYPE_OPENGL }, - { MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, - &(mpv_opengl_init_params){ - .get_proc_address = get_proc_address_mpv, - } }, - { MPV_RENDER_PARAM_ADVANCED_CONTROL, &(int){ 1 } }, - { 0 } }; - - GOTO_IF(init_mpv_gl__((mpv_handle *)sdl2->mpv, (mpv_render_context **)&sdl2->mpv_gl, - params), - "Failed to init mpv_gl", end_of_init); - } - - sdl2->has_preparation_failed = false; -end_of_init: - while (!sdl2->launched) - sched_yield(); - sdl2->is_in_preparation = 0; - if (sdl2->has_preparation_failed) - pthread_exit(NULL); - - unset_window_title(sdl2); - LOG_INFO("WINDOW", "Started SDL thread"); - - struct lmpv_handle_arg handle_args = { - .time_pos = &sdl2->mpv_time_pos, - .time_duration = &sdl2->mpv_duration, - .state = &sdl2->state, - .hinib = &sdl2->hinib, - .set_seek = &sdl2->set_seek, - }; -loop: - SDL_WaitEvent(&event); - if (sdl2->launched == 2) - goto end; - - switch (event.type) { - case SDL_QUIT: break; - - case SDL_WINDOWEVENT: - if (event.window.event == SDL_WINDOWEVENT_EXPOSED) { - lkt_queue_make_available(sdl2->queue, (LKT_EVENT_TYPE)LKT_EVENT_PLAY); - lkt_queue_make_available(sdl2->queue, (LKT_EVENT_TYPE)LKT_EVENT_PROP); - redraw = 1; - } - break; - - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_LEFT && ctrl) { - const char *cmd_seek[] = { "seek", "-5", "relative", NULL }; - mpv_command_async((mpv_handle *)sdl2->mpv, 0, cmd_seek); - } else if (event.key.keysym.sym == SDLK_RIGHT && ctrl) { - const char *cmd_seek[] = { "seek", "+5", "relative", NULL }; - mpv_command_async((mpv_handle *)sdl2->mpv, 0, cmd_seek); - } - break; - - case SDL_KEYUP: - state = SDL_GetKeyboardState(NULL); - ctrl = state[SDL_SCANCODE_LCTRL] || state[SDL_SCANCODE_RCTRL]; - - if (ctrl && event.key.keysym.sym == SDLK_SPACE) - lkt_queue_send(sdl2->queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_TOGGLE); - - else if (event.key.keysym.sym == SDLK_n && ctrl) - lkt_queue_send(sdl2->queue, LKT_EVENT_PLAY_NEXT, NULL); - - else if (event.key.keysym.sym == SDLK_p && ctrl) - lkt_queue_send(sdl2->queue, LKT_EVENT_PLAY_PREV, NULL); - - else if ((event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_RETURN2 || - event.key.keysym.sym == SDLK_KP_ENTER) && - ctrl) - lkt_queue_send(sdl2->queue, LKT_EVENT_PLAY_NEXT, NULL); - - else if (event.key.keysym.sym == SDLK_F11) { - if (sdl2->is_fullscreen) - SDL_SetWindowFullscreen((SDL_Window *)sdl2->window, 0); - else - SDL_SetWindowFullscreen((SDL_Window *)sdl2->window, SDL_WINDOW_FULLSCREEN); - /* May use SDL_WINDOW_FULLSCREEN_DESKTOP, need to check. */ - sdl2->is_fullscreen = 1 - sdl2->is_fullscreen; - } - break; - - case SDL_TEXTINPUT: break; - - default: - if (event.type == wakeup_on_mpv_render_update) { - flags = mpv_render_context_update((mpv_render_context *)sdl2->mpv_gl); - if (flags & MPV_RENDER_UPDATE_FRAME) - redraw = 1; - } - - if (event.type == wakeup_on_mpv_events) { - lmpv_handle(&module, (mpv_handle *)sdl2->mpv, sdl2->queue, &handle_args); - } - } - - if (redraw) { - SDL_GetWindowSize((SDL_Window *)sdl2->window, &w, &h); - /* Specify the default framebuffer (0) as target. This will - render onto the entire screen. If you want to show the video - in a smaller rectangle or apply fancy transformations, you'll - need to render into a separate FBO and draw it manually. */ - mpv_render_param params[] = { { MPV_RENDER_PARAM_OPENGL_FBO, - &(mpv_opengl_fbo){ - .fbo = 0, - .w = w, - .h = h, - } }, - { MPV_RENDER_PARAM_FLIP_Y, &(int){ 1 } }, - { 0 } }; - mpv_render_context_render((mpv_render_context *)sdl2->mpv_gl, params); - SDL_GL_SwapWindow((SDL_Window *)sdl2->window); - redraw = 0; - } - - sched_yield(); - goto loop; /* A loop without indentation. */ -end: - sdl2->launched = 0; - return NULL; -} - -static bool -module_sdl2_new(struct module_sdl2_window **win, struct queue *queue, lkt_db *db) -{ - RETURN_UNLESS(win, "Invalid arguments", false); - struct poller_thread_arg *arg; - setlocale(LC_NUMERIC, "C"); - - if (*win == NULL) { - *win = calloc(1, sizeof(struct module_sdl2_window)); - RETURN_UNLESS(*win, "Out of memory", false); - memset(*win, 0, sizeof(struct module_sdl2_window)); - - (*win)->queue = queue; - (*win)->db = db; - (*win)->set_seek = -1; - (*win)->is_in_preparation = true; - - /* Start the SDL thread */ - arg = LKT_ALLOC_STRUCT(poller_thread_arg); - RETURN_UNLESS(arg, "Out of memory", false); - arg->args = *win; - RETURN_IF(poller_new(&(*win)->self, sdl_thread__, arg), "Failed to launch the SDL thread", - false); - } else - LOG_DEBUG("WINDOW", "SDL window already created"); - - /* Finish */ - SDL_DisableScreenSaver(); - (*win)->launched = 1; - while ((*win)->is_in_preparation) - sched_yield(); - return !((*win)->has_preparation_failed); -} - -static void -module_sdl2_close(struct module_sdl2_window *win) -{ - RETURN_UNLESS(win && win->window, "Invalid arguments", NOTHING); - win->mpv_time_pos = win->mpv_duration = 0; - SET_STATE_FLAG(win->state, STOP); - RETURN_UNLESS(win->mpv, "Missing mpv ctx", NOTHING); - static const char *cmd[] = { "stop", NULL }; - mpv_command_async((mpv_handle *)win->mpv, 0, cmd); - unset_window_title(win); - LOG_INFO("WINDOW", "Module closed"); -} - -static void -module_sdl2_free(struct module_sdl2_window *win) -{ - RETURN_UNLESS(win, "Invalid arguments", NOTHING); - module_sdl2_close(win); - LOG_INFO("WINDOW", "Waiting for window thread"); - win->launched = 2; - while (win->launched) - sched_yield(); - poller_join(&win->self, NULL); - LOG_INFO("WINDOW", "Module terminated"); -} - -static bool -module_sdl2_toggle_pause(struct module_sdl2_window *win) -{ - RETURN_UNLESS(win, "Invalid arguments", false); - return !lmpv_toggle_pause((mpv_handle *)win->mpv); -} - -static bool -module_sdl2_load_file(struct module_sdl2_window *win, const char *filepath) -{ - RETURN_UNLESS(win, "Invalid arguments", false); - const bool ret = !lmpv_load_file((mpv_handle *)win->mpv, filepath); - win->mpv_duration = 0; - win->mpv_time_pos = 0; - win->hinib = true; - - if (ret) { - LOG_DEBUG("WINDOW", "Loaded file: %s", filepath); - set_window_title(win); - } else { - LOG_ERROR("WINDOW", "Failed to load kara with path: %s", filepath); - } - - LOG_DEBUG("WINDOW", "Hinib flag at %d", win->hinib); - return ret; -} - -static bool -module_sdl2_set_paused(struct module_sdl2_window *win, int paused) -{ - RETURN_UNLESS(win && win->window, "Invalid arguments", false); - if (((!paused) && win->state == STATE_PAUSE) || (win->state == STATE_PLAY && paused)) { - return !lmpv_toggle_pause((struct mpv_handle *)win->mpv); - } else { - LOG_DEBUG("WINDOW", "No need to toggle paused state, already what was asked"); - return true; - } -} - -static bool -module_sdl2_set_volume(struct module_sdl2_window *win, int vol) -{ - RETURN_UNLESS(win && win->window, "Invalid arguments", false); - return !lmpv_set_volume((mpv_handle *)win->mpv, vol); -} - -static bool -module_sdl2_set_position(struct module_sdl2_window *win, int sec) -{ - RETURN_UNLESS(win && win->window, "Invalid arguments", false); - win->set_seek = sec; - return true; -} - -static bool -module_sdl2_get_duration(struct module_sdl2_window *win, int *dur_sec) -{ - RETURN_UNLESS(win, "Invalid arguments", false); - *dur_sec = win->mpv_duration; - return true; -} - -static bool -module_sdl2_get_elapsed(struct module_sdl2_window *win, int *elapsed_sec) -{ - RETURN_UNLESS(win, "Invalid arguments", false); - *elapsed_sec = win->mpv_time_pos; - return true; -} diff --git a/src/module/mpv.c b/src/module/mpv.c index 9b69c3ef250321834588bda88e9e86d5cea9b8c3..5462d8af641608bc6c1c49595203db5fca2bdb7b 100644 --- a/src/module/mpv.c +++ b/src/module/mpv.c @@ -165,127 +165,3 @@ lmpv_toggle_pause(mpv_handle *ctx) } return 0; } - -int -lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, - struct lmpv_handle_arg *arg) -{ - size_t ao_volume; - mpv_event *event = NULL; - mpv_event_property *prop; - RETURN_UNLESS(ctx, "Invalid argument", 1); - -loop: - event = mpv_wait_event(ctx, 0); - - switch (event->event_id) { - case MPV_EVENT_PAUSE: - SET_STATE_FLAG(*(arg->state), PAUSE); - lkt_queue_send(queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PAUSE); - break; - - case MPV_EVENT_UNPAUSE: - SET_STATE_FLAG(*(arg->state), PLAY); - lkt_queue_send(queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY); - break; - - case MPV_EVENT_SHUTDOWN: - *(arg->time_pos) = 0; - *(arg->time_duration) = 0; - SET_STATE_FLAG(*(arg->state), STOP); - lkt_queue_send(queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_STOP); - reg_call(mod->reg, "close", 1, mod->data); - return 1; - - case MPV_EVENT_NONE: return 1; - - case MPV_EVENT_START_FILE: - SET_STATE_FLAG(*(arg->state), PLAY); - *(arg->hinib) = false; - LOG_DEBUG("WINDOW", "Start of file!"); - break; - - case MPV_EVENT_END_FILE: - LOG_DEBUG("WINDOW", "End of file!"); - if (((*(arg->state)) != STATE_STOP) && !(*(arg->hinib))) { - LOG_DEBUG("WINDOW", "Send play_next event"); - lkt_queue_send(queue, LKT_EVENT_PLAY_NEXT, NULL); - } else - LOG_DEBUG("WINDOW", "Don't send play_next event, hinib is %d and state is %s", - *(arg->hinib), - (*(arg->state) == STATE_STOP) ? "STOP" - : (*(arg->state) == STATE_PLAY) ? "PLAY" - : (*(arg->state) == STATE_PAUSE) ? "PAUSE" - : "UNKNOWN"); - break; - - case MPV_EVENT_PROPERTY_CHANGE: - prop = (mpv_event_property *)event->data; - if (prop->format == MPV_FORMAT_NONE) - break; - /* MPV volume (BUG: The flag is not MPV_FORMAT_NONE only at the end of the song...) */ - if (STR_MATCH(prop->name, "ao-volume") && prop->format == MPV_FORMAT_INT64) { - ao_volume = (size_t) * (int *)prop->data; - lkt_queue_send(queue, LKT_EVENT_PROP_VOL, (void *)ao_volume); - } - /* File duration */ - if (STR_MATCH(prop->name, "duration") && prop->format == MPV_FORMAT_INT64) { - *(arg->time_duration) = *(int *)prop->data; - lkt_queue_send(queue, LKT_EVENT_PROP_DUR, (void *)(size_t) * (arg->time_duration)); - } - if (STR_MATCH(prop->name, "time-pos") && prop->format == MPV_FORMAT_INT64) { - *(arg->time_pos) = *(int *)prop->data; - lkt_queue_send(queue, LKT_EVENT_PROP_TIME, (void *)(size_t) * (arg->time_pos)); - } - /* Pause state */ - if (STR_MATCH(prop->name, "pause") && prop->format == MPV_FORMAT_FLAG) { - if (*(bool *)prop->data) { - lkt_queue_send(queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PAUSE); - SET_STATE_FLAG(*(arg->state), PAUSE); - } else { - lkt_queue_send(queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY); - SET_STATE_FLAG(*(arg->state), PLAY); - } - } - break; - - case MPV_EVENT_COMMAND_REPLY: free((void *)event->reply_userdata); break; - - /* Ignored */ - case MPV_EVENT_VIDEO_RECONFIG: - case MPV_EVENT_AUDIO_RECONFIG: - case MPV_EVENT_IDLE: - case MPV_EVENT_TRACKS_CHANGED: - case MPV_EVENT_FILE_LOADED: - case MPV_EVENT_METADATA_UPDATE: - case MPV_EVENT_PLAYBACK_RESTART: - break; - - /* Forgot to ignore an event, or it should not be ignored and should be - * handled, or a new event is present in the API */ - case MPV_EVENT_LOG_MESSAGE: - case MPV_EVENT_GET_PROPERTY_REPLY: - case MPV_EVENT_SET_PROPERTY_REPLY: - case MPV_EVENT_TRACK_SWITCHED: - case MPV_EVENT_TICK: - case MPV_EVENT_SCRIPT_INPUT_DISPATCH: - case MPV_EVENT_CLIENT_MESSAGE: - case MPV_EVENT_SEEK: - case MPV_EVENT_CHAPTER_CHANGE: - case MPV_EVENT_QUEUE_OVERFLOW: - case MPV_EVENT_HOOK: - LOG_WARN("WINDOW", "Unhandled mpv event '%s'", mpv_event_name(event->event_id)); - break; - } - - /* Can I seek? */ - if (*(arg->set_seek) >= 0 && *(arg->state) != STATE_STOP) { - const bool ok = lmpv_set_position(ctx, *(arg->set_seek)); - LOG_DEBUG_IF(ok, "WINDOW", "Failed to seek the mpv context to %s", *(arg->set_seek)); - LOG_DEBUG_IF(!ok, "WINDOW", "Seeking the mpv context to %s", *(arg->set_seek)); - *(arg->set_seek) = -1; - } - - /* A loop without indentation. Ugly but better for not-really-wide screens */ - goto loop; -} diff --git a/src/module/mpv.h b/src/module/mpv.h index 708937634fbea784ec72531ed085129713a5b967..5ea318c0fe060eeb047c561ac453fa8316dc1fdb 100644 --- a/src/module/mpv.h +++ b/src/module/mpv.h @@ -20,16 +20,6 @@ int lmpv_set_position(mpv_handle *ctx, int pos); int lmpv_load_file(mpv_handle *ctx, const char *file); int lmpv_toggle_pause(mpv_handle *ctx); -struct lmpv_handle_arg { - volatile int *time_pos; - volatile int *time_duration; - volatile int *state; - volatile int *hinib; - volatile int *set_seek; -}; -int lmpv_handle(struct lkt_module *mod, mpv_handle *ctx, struct queue *queue, - struct lmpv_handle_arg *); - enum { STATE_STOP = 0, STATE_PLAY = 1, diff --git a/src/module/qt_window/mpvwidget.cc b/src/module/qt_window/mpvwidget.cc index 7917c9b6c91b30593b11add472655fb8f8d5fcc9..ad86c0cbb60e04c8f94243407a5725e45a0741c3 100644 --- a/src/module/qt_window/mpvwidget.cc +++ b/src/module/qt_window/mpvwidget.cc @@ -195,14 +195,6 @@ apply_unpause: LOG_DEBUG("WINDOW", "Applying unpause"); lkt_queue_send(m_queue, LKT_EVENT_PLAY_TOGGLE, LKT_PLAY_PLAY); break; - - // TODO: deprecated events that are now monitored with observe_property but that we didn't use - // Check if we want to observe them or not - //case MPV_EVENT_TRACKS_CHANGED: - //case MPV_EVENT_TRACK_SWITCHED: - //case MPV_EVENT_TICK: - //case MPV_EVENT_METADATA_UPDATE: - //case MPV_EVENT_CHAPTER_CHANGE: } case MPV_EVENT_LOG_MESSAGE: @@ -211,7 +203,6 @@ apply_unpause: case MPV_EVENT_NONE: case MPV_EVENT_COMMAND_REPLY: case MPV_EVENT_FILE_LOADED: - case MPV_EVENT_SCRIPT_INPUT_DISPATCH: case MPV_EVENT_CLIENT_MESSAGE: case MPV_EVENT_VIDEO_RECONFIG: case MPV_EVENT_AUDIO_RECONFIG: