Skip to content
Extraits de code Groupes Projets
Vérifiée Valider bed922f4 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

Factorise code of the sdl2 module

parent d9758bca
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!57Resolve "SDL2 module"
......@@ -36,14 +36,14 @@ die(const char *msg)
exit(1);
}
static void *
static inline void *
get_proc_address_mpv(void *fn_ctx, const char *name)
{
(void) fn_ctx;
return SDL_GL_GetProcAddress(name);
}
static void
static inline void
on_mpv_events(void *ctx)
{
(void) ctx;
......@@ -51,7 +51,7 @@ on_mpv_events(void *ctx)
SDL_PushEvent(&event);
}
static void
static inline void
on_mpv_render_update(void *ctx)
{
(void) ctx;
......@@ -370,9 +370,7 @@ module_sdl2_close(struct lkt_win *const win)
{
if (win == NULL || win->window == NULL)
return;
struct module_sdl2_window *const sdl2 = win->window;
lmpv_free(&sdl2->mpv);
lmpv_free(&((struct module_sdl2_window *)win->window)->mpv);
}
void
......@@ -386,24 +384,9 @@ module_sdl2_toggle_pause(struct lkt_win *const win, bool *new_paused)
{
if (win == NULL || win->window == NULL)
return false;
mpv_handle *ctx = ((struct module_sdl2_window *) win->window)->mpv;
if (!ctx) {
fprintf(stderr, " ! module_sdl2_toggle_pause: failed due to missing mpv ctx\n");
return false;
}
const char *cmd[] = {"cycle", "pause", "up", NULL};
int status;
if ((status = mpv_command(ctx, cmd)) < 0) {
fprintf(stderr, "module_sdl2_toggle_pause: Failed issue command: %s\n",
mpv_error_string(status));
return false;
}
return module_sdl2_is_paused(win, new_paused);
int pause, ret = ! lmpv_toggle_pause(((struct module_sdl2_window *) win->window)->mpv, &pause);
*new_paused = pause;
return ret;
}
bool
......@@ -411,34 +394,11 @@ module_sdl2_load_file(struct lkt_win *const win, const char *filepath)
{
if (win == NULL || win->window == NULL)
return false;
struct module_sdl2_window *sdl2 = win->window;
mpv_handle *ctx = sdl2->mpv;
if (!ctx) {
fprintf(stderr, " ! module_sdl2_load_file: failed due to missing mpv ctx\n");
return false;
}
if (access(filepath, R_OK)) {
fprintf(stderr, " ! module_sdl2_load_file: Faild to read file: %s\n", filepath);
return false;
}
const char *cmd[] = {"loadfile", filepath, "replace", NULL};
int status;
if ((status = mpv_command(ctx, cmd)) < 0) {
fprintf(stderr, " ! module_sdl2_load_file: Failed to add '%s': %s\n",
filepath, mpv_error_string(status));
return false;
}
bool ret = ! lmpv_load_file(sdl2->mpv, filepath);
sdl2->mpv_duration = 0;
sdl2->mpv_time_pos = 0;
fprintf(stderr, " . module_x11_load_file: added file %s\n", filepath);
return true;
return ret;
}
bool
......@@ -446,27 +406,7 @@ module_sdl2_set_volume(struct lkt_win *const win, int vol)
{
if (win == NULL || win->window == NULL)
return false;
mpv_handle *ctx = ((struct module_sdl2_window *) win->window)->mpv;
if (!ctx) {
fprintf(stderr, " ! module_sdl2_set_volume: failed due to missing mpv ctx\n");
return false;
}
int status;
char str[5];
memset(str, 0, 5);
snprintf(str, 4, "%d", vol);
const char *cmd[] = {"set", "ao-volume", str, NULL};
if ((status = mpv_command(ctx, cmd)) < 0) {
fprintf(stderr, " ! module_x11_set_volume: Failed to execute command: %s\n",
mpv_error_string(status));
return false;
}
return true;
return ! lmpv_set_volume(((struct module_sdl2_window *) win->window)->mpv, vol);
}
bool
......@@ -474,22 +414,9 @@ module_sdl2_is_paused(struct lkt_win *const win, bool *ret)
{
if (win == NULL || win->window == NULL)
return false;
mpv_handle *ctx = ((struct module_sdl2_window *) win->window)->mpv;
int status;
if (!ctx) {
fprintf(stderr, " ! module_sdl2_is_paused: failed due to missing mpv ctx\n");
return false;
}
if ((status = mpv_get_property(ctx, "pause", MPV_FORMAT_FLAG, &ret)) < 0) {
fprintf(stderr, "module_sdl2_is_paused: Failed to get pause property: %s\n",
mpv_error_string(status));
return false;
}
return true;
int ret_, sta = ! lmpv_is_paused(((struct module_sdl2_window *) win->window)->mpv, &ret_);
*ret = ret_;
return sta;
}
bool
......@@ -497,10 +424,7 @@ module_sdl2_get_duration(struct lkt_win *const win, int *dur_sec)
{
if (win == NULL || win->window == NULL)
return false;
struct module_sdl2_window *sdl2 = win->window;
*dur_sec = sdl2->mpv_duration;
*dur_sec = ((struct module_sdl2_window *) win->window)->mpv_duration;
return true;
}
......@@ -509,10 +433,7 @@ module_sdl2_get_elapsed(struct lkt_win *const win, int *elapsed_sec)
{
if (win == NULL || win->window == NULL)
return false;
struct module_sdl2_window *sdl2 = win->window;
*elapsed_sec = sdl2->mpv_time_pos;
*elapsed_sec = ((struct module_sdl2_window *) win->window)->mpv_time_pos;
return true;
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter