[FFmpeg-devel] [PATCH] lavd/sdl: allow to change window size

Stefano Sabatini stefasab at gmail.com
Mon Nov 25 13:37:51 CET 2013


---
 libavdevice/sdl.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/libavdevice/sdl.c b/libavdevice/sdl.c
index 47b8ef5..ae66925 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;
 
@@ -189,6 +191,20 @@ 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;
+            }
+            compute_overlay_rect(s);
+            SDL_UnlockMutex(sdl->mutex);
+            break;
+
         default:
             break;
         }
@@ -299,8 +315,6 @@ static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt)
     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 +326,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;
 }
-- 
1.8.1.2



More information about the ffmpeg-devel mailing list