diff --git a/src/input/sdlinput.c b/src/input/sdlinput.c index a4da223..d904ff8 100644 --- a/src/input/sdlinput.c +++ b/src/input/sdlinput.c @@ -43,8 +43,7 @@ static int keyboard_modifiers; void sdlinput_init() { memset(gamepads, 0, sizeof(gamepads)); -//SDL_SetRelativeMouseMode(SDL_TRUE); - SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER); + SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER); SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt"); for (int i = 0; i < SDL_NumJoysticks(); ++i) { diff --git a/src/main.c b/src/main.c index 7010cc1..facf836 100644 --- a/src/main.c +++ b/src/main.c @@ -84,7 +84,13 @@ static void stream(PSERVER_DATA server, PCONFIGURATION config, enum platform sys gs_start_app(server, &config->stream, appId, config->sops, config->localaudio); - LiStartConnection(server->address, &config->stream, &connection_callbacks, platform_get_video(system), platform_get_audio(system), NULL, 0, server->serverMajorVersion); + void *context = NULL; + #ifdef HAVE_SDL + if (system == SDL) + context = sdl_window; + #endif + + LiStartConnection(server->address, &config->stream, &connection_callbacks, platform_get_video(system), platform_get_audio(system), context, 0, server->serverMajorVersion); if (IS_EMBEDDED(system)) loop_main(); @@ -207,7 +213,7 @@ int main(int argc, char* argv[]) { } #ifdef HAVE_SDL else if (system == SDL) - sdlinput_init(); + sdl_init(config.stream.width, config.stream.height); #endif stream(&server, &config, system); diff --git a/src/sdl.c b/src/sdl.c index cb0d3f2..370b1a2 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -25,16 +25,29 @@ #include "limelight-common/Limelight.h" #include -#include static bool done; -void sdl_loop() { - SDL_InitSubSystem(SDL_INIT_EVENTS); +SDL_Window *sdl_window; + +void sdl_init(int width, int height) { + if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { + fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); + exit(1); + } + + sdl_window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); + if(!sdl_window) { + fprintf(stderr, "SDL: could not create window - exiting\n"); + exit(1); + } SDL_ShowCursor(SDL_DISABLE); + //SDL_SetRelativeMouseMode(SDL_TRUE); + sdlinput_init(); +} +void sdl_loop() { SDL_Event event; - while(!done && SDL_WaitEvent(&event)) { if (!sdlinput_handle_event(&event)) done = true; diff --git a/src/sdl.h b/src/sdl.h index 477bacf..fb2f962 100644 --- a/src/sdl.h +++ b/src/sdl.h @@ -19,6 +19,11 @@ #ifdef HAVE_SDL +#include + +SDL_Window *sdl_window; + +void sdl_init(int width, int height); void sdl_loop(); #endif /* HAVE_SDL */ diff --git a/src/video/sdl.c b/src/video/sdl.c index d2c82d5..60d8e85 100644 --- a/src/video/sdl.c +++ b/src/video/sdl.c @@ -44,9 +44,19 @@ static void sdl_setup(int width, int height, int redrawRate, void* context, int fprintf(stderr, "Not enough memory\n"); exit(1); } - - screen_width = width; - screen_height = height; + + SDL_Window *window = (SDL_Window*) context; + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + fprintf(stderr, "SDL: could not create renderer - exiting\n"); + exit(1); + } + + bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_TARGET, width, height); + if (!bmp) { + fprintf(stderr, "SDL: could not create texture - exiting\n"); + exit(1); + } } static void sdl_cleanup() { @@ -54,31 +64,6 @@ static void sdl_cleanup() { } static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) { - if (window == NULL) { - if(SDL_Init(SDL_INIT_VIDEO)) { - fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); - exit(1); - } - - window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, 0); - if(!window) { - fprintf(stderr, "SDL: could not create window - exiting\n"); - exit(1); - } - - renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_TARGETTEXTURE); - if (!renderer) { - fprintf(stderr, "SDL: could not create renderer - exiting\n"); - exit(1); - } - - bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_TARGET, screen_width, screen_height); - if (!bmp) { - fprintf(stderr, "SDL: could not create texture - exiting\n"); - exit(1); - } - } - if (decodeUnit->fullLength < DECODER_BUFFER_SIZE) { PLENTRY entry = decodeUnit->bufferList; int length = 0;