X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavdevice%2Fsdl2.c;h=d6fc74a66c7650098c1f90e890235d95e4bb33d1;hb=337f777f378cfcc0d6f0d01fb7125905e8b0da55;hp=48ed977bebd3518e0cdc3eaafff4419e5e97a0ef;hpb=6dea6c4b9718132fbe32984942bcafaeb2712f73;p=ffmpeg diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c index 48ed977bebd..d6fc74a66c7 100644 --- a/libavdevice/sdl2.c +++ b/libavdevice/sdl2.c @@ -40,8 +40,10 @@ typedef struct { SDL_Renderer *renderer; char *window_title; int window_width, window_height; /**< size of the window */ + int window_x, window_y; /**< position of the window */ int window_fullscreen; int window_borderless; + int enable_quit_action; SDL_Texture *texture; int texture_fmt; @@ -154,8 +156,6 @@ static int sdl2_write_trailer(AVFormatContext *s) return 0; } -#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_WINDOW_RESIZABLE) - static int sdl2_write_header(AVFormatContext *s) { SDLContext *sdl = s->priv_data; @@ -195,8 +195,9 @@ static int sdl2_write_header(AVFormatContext *s) } /* resize texture to width and height from the codec context information */ - flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | - (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : 0); + flags = SDL_WINDOW_HIDDEN | + (sdl->window_fullscreen ? SDL_WINDOW_FULLSCREEN : 0) | + (sdl->window_borderless ? SDL_WINDOW_BORDERLESS : SDL_WINDOW_RESIZABLE); /* initialization */ if (!sdl->inited){ @@ -206,9 +207,7 @@ static int sdl2_write_header(AVFormatContext *s) } } - sdl->window_width = sdl->texture_rect.w = codecpar->width; - sdl->window_height = sdl->texture_rect.h = codecpar->height; - sdl->texture_rect.x = sdl->texture_rect.y = 0; + compute_texture_rect(s); if (SDL_CreateWindowAndRenderer(sdl->window_width, sdl->window_height, flags, &sdl->window, &sdl->renderer) != 0){ @@ -217,9 +216,11 @@ static int sdl2_write_header(AVFormatContext *s) } SDL_SetWindowTitle(sdl->window, sdl->window_title); + SDL_SetWindowPosition(sdl->window, sdl->window_x, sdl->window_y); + SDL_ShowWindow(sdl->window); sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING, - sdl->window_width, sdl->window_height); + codecpar->width, codecpar->height); if (!sdl->texture) { av_log(sdl, AV_LOG_ERROR, "Unable to set create mode: %s\n", SDL_GetError()); @@ -279,7 +280,7 @@ static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt) } } - if (quit) { + if (quit && sdl->enable_quit_action) { sdl2_write_trailer(s); return AVERROR(EIO); } @@ -338,8 +339,11 @@ static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt) static const AVOption options[] = { { "window_title", "set SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, { "window_size", "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_x", "set SDL window x position", OFFSET(window_x), AV_OPT_TYPE_INT, { .i64 = SDL_WINDOWPOS_CENTERED }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_y", "set SDL window y position", OFFSET(window_y), AV_OPT_TYPE_INT, { .i64 = SDL_WINDOWPOS_CENTERED }, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, { "window_fullscreen", "set SDL window fullscreen", OFFSET(window_fullscreen), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, { "window_borderless", "set SDL window border off", OFFSET(window_borderless), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, + { "window_enable_quit", "set if quit action is available", OFFSET(enable_quit_action), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, { NULL }, };