From 26661f7ea192e5065fd1412048e5409713ad515f Mon Sep 17 00:00:00 2001 From: Iwan Timmer Date: Sun, 16 Aug 2015 20:58:09 +0200 Subject: [PATCH] Initialize video in same thread as decoding --- src/sdl.c | 6 ------ src/video/sdl.c | 34 ++++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/sdl.c b/src/sdl.c index 9bc83e0..33e9572 100644 --- a/src/sdl.c +++ b/src/sdl.c @@ -37,12 +37,6 @@ void sdl_init(int width, int height) { 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_SetRelativeMouseMode(SDL_TRUE); sdlinput_init(); } diff --git a/src/video/sdl.c b/src/video/sdl.c index 90ec3b7..186795a 100644 --- a/src/video/sdl.c +++ b/src/video/sdl.c @@ -45,18 +45,8 @@ static void sdl_setup(int width, int height, int redrawRate, void* context, int exit(1); } - 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); - } + screen_width = width; + screen_height = height; } static void sdl_cleanup() { @@ -64,6 +54,26 @@ static void sdl_cleanup() { } static int sdl_submit_decode_unit(PDECODE_UNIT decodeUnit) { + if (window == NULL) { + window = SDL_CreateWindow("Moonlight", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, SDL_WINDOW_OPENGL); + if(!window) { + fprintf(stderr, "SDL: could not create window - exiting\n"); + exit(1); + } + SDL_SetRelativeMouseMode(SDL_TRUE); + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); + if (!renderer) { + printf("SDL_CreateRenderer failed: %s\n", SDL_GetError()); + exit(1); + } + + bmp = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_YV12, SDL_TEXTUREACCESS_STREAMING, 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;