[FFmpeg-devel] [PATCH] lavd/sdl2: postpone sdl2 window creation

Xiang, Haihao haihao.xiang at intel.com
Mon Sep 18 09:37:28 EEST 2023


From: Haihao Xiang <haihao.xiang at intel.com>

Since 2d924b3, sdl2_write_header() and sdl2_write_packet() are called
in two different threads. However SDL2 requires window creation and
rendering should be done in the same thread, otherwise it shows nothing
when specifying SDL2 output device.

$ ffmpeg -f lavfi -i yuvtestsrc -pix_fmt yuv420p -f sdl2 "sdl2"

Signed-off-by: Haihao Xiang <haihao.xiang at intel.com>
---
 libavdevice/sdl2.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index 342a253dc0..c9f7f03c28 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -158,6 +158,11 @@ static int sdl2_write_trailer(AVFormatContext *s)
 }
 
 static int sdl2_write_header(AVFormatContext *s)
+{
+    return 0;
+}
+
+static int sdl2_init(AVFormatContext *s)
 {
     SDLContext *sdl = s->priv_data;
     AVStream *st = s->streams[0];
@@ -165,6 +170,9 @@ static int sdl2_write_header(AVFormatContext *s)
     int i, ret = 0;
     int flags  = 0;
 
+    if (sdl->inited)
+        return 0;
+
     if (!sdl->window_title)
         sdl->window_title = av_strdup(s->url);
 
@@ -249,6 +257,11 @@ static int sdl2_write_packet(AVFormatContext *s, AVPacket *pkt)
     int linesize[4];
 
     SDL_Event event;
+
+    ret = sdl2_init(s);
+    if (ret)
+        return ret;
+
     if (SDL_PollEvent(&event)){
         switch (event.type) {
         case SDL_KEYDOWN:
-- 
2.34.1



More information about the ffmpeg-devel mailing list