From b23dea27fdb6f16abd35af6b24c899a85e87e6b3 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 25 Nov 2013 13:31:06 +0100 Subject: [PATCH] lavd/sdl: allow to change window size --- libavdevice/sdl.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c index 6328e9f67d..38541b0912 100644 --- a/libavdevice/sdl.c +++ b/libavdevice/sdl.c @@ -124,11 +124,13 @@ static void compute_overlay_rect(AVFormatContext *s) overlay_rect->y = (sdl->window_height - overlay_rect->h) / 2; } +#define SDL_BASE_FLAGS (SDL_SWSURFACE|SDL_RESIZABLE) + static int event_thread(void *arg) { AVFormatContext *s = arg; SDLContext *sdl = s->priv_data; - int flags = SDL_SWSURFACE | (sdl->window_fullscreen ? SDL_FULLSCREEN : 0); + int flags = SDL_BASE_FLAGS | (sdl->window_fullscreen ? SDL_FULLSCREEN : 0); AVStream *st = s->streams[0]; AVCodecContext *encctx = st->codec; @@ -195,6 +197,22 @@ init_end: case SDL_QUIT: sdl->quit = 1; break; + + case SDL_VIDEORESIZE: + sdl->window_width = event.resize.w; + sdl->window_height = event.resize.h; + + SDL_LockMutex(sdl->mutex); + sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height, 24, SDL_BASE_FLAGS); + if (!sdl->surface) { + av_log(s, AV_LOG_ERROR, "Failed to set SDL video mode: %s\n", SDL_GetError()); + sdl->quit = 1; + } else { + compute_overlay_rect(s); + } + SDL_UnlockMutex(sdl->mutex); + break; + default: break; } @@ -292,15 +310,15 @@ static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt) AVPicture pict; int i; - if (sdl->quit) + if (sdl->quit) { + sdl_write_trailer(s); return AVERROR(EIO); + } avpicture_fill(&pict, pkt->data, encctx->pix_fmt, encctx->width, encctx->height); SDL_LockMutex(sdl->mutex); SDL_FillRect(sdl->surface, &sdl->surface->clip_rect, SDL_MapRGB(sdl->surface->format, 0, 0, 0)); - SDL_UnlockMutex(sdl->mutex); - SDL_LockYUVOverlay(sdl->overlay); for (i = 0; i < 3; i++) { sdl->overlay->pixels [i] = pict.data [i]; @@ -312,6 +330,7 @@ static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt) SDL_UpdateRect(sdl->surface, sdl->overlay_rect.x, sdl->overlay_rect.y, sdl->overlay_rect.w, sdl->overlay_rect.h); + SDL_UnlockMutex(sdl->mutex); return 0; }