Sélectionner une révision Git
module_sdl2.c 17,82 Kio
#define _POSIX_C_SOURCE 200809L
#define __LKT_MODULE_MAIN_SOURCE__
#include <lektor/lktmodule.h>
#include "mpv.h"
#include "thread.h"
#include <lektor/internal/icon.xpm>
#include <sqlite3.h>
#include <sched.h>
#include <SDL.h>
#include <SDL_image.h>
#include <mpv/render_gl.h>
#include <mpv/client.h>
#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 */
/* Things from the server */
struct queue *queue;
volatile sqlite3 *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_paussed(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 *, volatile sqlite3 *);
/*********************
* Private functions *
*********************/
static inline void *
get_proc_address_mpv(void UNUSED *fn_ctx, const char *name)
{
return SDL_GL_GetProcAddress(name);
}