[FFmpeg-devel] [PATCH WIP 2/2] avdev: add sdl2 device

Marton Balint cus at passwd.hu
Tue May 17 23:10:29 CEST 2016


On Tue, 17 May 2016, Josh de Kock wrote:

> This "works", as in, it will play video fine (I haven't done too much
> testing yet). I was using the command,
> `./ffmpeg_g -f lavfi -i testsrc=size=1280x720:rate=30 -pix_fmt yuv420p -f sdl2 "k"`
> to test.
> It will crash on quit, and the Window bar is frozen. At first I thought
> it was because there was no ratelimiting, so I added a 10ms delay if
> there isn't any events as Marton suggested. However, it didn't seem to
> make any difference.

As far as I see your approach still does not use the event thread for 
updating textures. SDL/SDL2 does not like using render and windowing 
functions in multiple threads, it may work, or it may crash (even with the 
mutexes), who knows. Do everything render/windowing related in the event 
thread (including the cleanup/window destroying part), don't do anything 
with the AVPacket in sdl2_write_packet only pass it to the event thread 
using a custom event and SDL_PushEvent.

Actually probably the best is if you create a new ref to the packet, and 
pass that to the SDL_PushEvent, and free that ref in the event thread once 
you uploaded the contents to the texture.

You don't want multiple frames to pile up in the SDL event queue, so you 
can use SDL_PeepEvents to ensure there are no pending frames in the queue. 
If there are, you will have to block, a loop with a 10ms
delay should be fine for starters, once that works, you may upgrade it to 
SDL_CondSignal and SDL_CondWait if you want.

Regards,
Marton


More information about the ffmpeg-devel mailing list