SPU region access data race at pre-render
Regression from f1c9a45b. Reproduce with any playback.
Since the region's picture scaling is handled internally, regions are accessed without any lock and are causing a race condition.
TSAN report:
WARNING: ThreadSanitizer: data race (pid=83745)
Write of size 8 at 0x7b18000311c0 by thread T25:
#0 vlc_list_add_between ../../include/vlc_list.h:75 (libvlccore.so.9+0x113626) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#1 vlc_list_add_before ../../include/vlc_list.h:100 (libvlccore.so.9+0x113693) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#2 vlc_list_append ../../include/vlc_list.h:112 (libvlccore.so.9+0x1136ca) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#3 OSDTextUpdate ../../src/video_output/video_text.c:64 (libvlccore.so.9+0x113867) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#4 subpicture_Update ../../src/misc/subpicture.c:176 (libvlccore.so.9+0x179712) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#5 spu_PrerenderText ../../src/video_output/vout_subpictures.c:1613 (libvlccore.so.9+0x121627) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#6 spu_PrerenderThread ../../src/video_output/vout_subpictures.c:1676 (libvlccore.so.9+0x121dfe) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
Previous read of size 8 at 0x7b18000311c0 by thread T39:
#0 vlc_list_it_start_const ../../include/vlc_list.h:223 (libvlccore.so.9+0x119511) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#1 spu_entry_EnsureScaledSize ../../src/video_output/vout_subpictures.c:705 (libvlccore.so.9+0x11c411) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#2 spu_SelectSubpictures ../../src/video_output/vout_subpictures.c:830 (libvlccore.so.9+0x11cf17) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#3 spu_Render ../../src/video_output/vout_subpictures.c:2122 (libvlccore.so.9+0x123df3) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#4 RenderSPUs ../../src/video_output/video_output.c:1123 (libvlccore.so.9+0x10e282) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#5 PrerenderPicture ../../src/video_output/video_output.c:1287 (libvlccore.so.9+0x10effa) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#6 RenderPicture ../../src/video_output/video_output.c:1313 (libvlccore.so.9+0x10f17d) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#7 DisplayPicture ../../src/video_output/video_output.c:1522 (libvlccore.so.9+0x10ff8d) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#8 Thread ../../src/video_output/video_output.c:1846 (libvlccore.so.9+0x11160d) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
Location is heap block of size 96 at 0x7b18000311a0 allocated by thread T17:
#0 calloc <null> (libtsan.so.2+0x3d575) (BuildId: 55eb683d17c2bc85d9bab3257ece4f974b770a39)
#1 subpicture_New ../../src/misc/subpicture.c:44 (libvlccore.so.9+0x178e7a) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#2 vout_OSDText ../../src/video_output/video_text.c:120 (libvlccore.so.9+0x113ddd) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#3 vout_DisplayTitle ../../src/video_output/video_output.c:297 (libvlccore.so.9+0x10a3d5) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#4 VoutSetAndDeduplicateTitle ../../src/input/resource.c:170 (libvlccore.so.9+0xe2585) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#5 DisplayVoutTitle ../../src/input/resource.c:214 (libvlccore.so.9+0xe281b) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#6 input_resource_RequestVout ../../src/input/resource.c:511 (libvlccore.so.9+0xe392b) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#7 ModuleThread_UpdateVideoFormat ../../src/input/decoder.c:683 (libvlccore.so.9+0x80b77) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#8 decoder_UpdateVideoOutput ../../src/input/decoder_helpers.c:156 (libvlccore.so.9+0x8bf00) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#9 lavc_GetFrame ../../modules/codec/avcodec/video.c:1834 (libavcodec_plugin.so+0xece4) (BuildId: 0e7dad0d6dd4a01c64c60a816b1c820a0cffff01)
#10 ff_get_buffer <null> (libavcodec.so.58+0x220782) (BuildId: ca3659d22f45f37f3ddea337574c07136c0d1ff7)
Thread T25 'vlc-spu-prerend' (tid=83793, running) created by thread T17 at:
#0 pthread_create <null> (libtsan.so.2+0x3e006) (BuildId: 55eb683d17c2bc85d9bab3257ece4f974b770a39)
#1 vlc_clone_attr ../../src/posix/thread.c:180 (libvlccore.so.9+0x17f6b2) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#2 vlc_clone ../../src/posix/thread.c:191 (libvlccore.so.9+0x17f732) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#3 spu_Create ../../src/video_output/vout_subpictures.c:1836 (libvlccore.so.9+0x122c72) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#4 vout_Create ../../src/video_output/video_output.c:2080 (libvlccore.so.9+0x1123fc) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#5 RequestVoutRsc ../../src/input/resource.c:429 (libvlccore.so.9+0xe34ed) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#6 input_resource_RequestVout ../../src/input/resource.c:466 (libvlccore.so.9+0xe368b) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#7 CreateVoutIfNeeded ../../src/input/decoder.c:789 (libvlccore.so.9+0x8157c) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#8 ModuleThread_GetDecoderDevice ../../src/input/decoder.c:821 (libvlccore.so.9+0x8176d) (BuildId: d3a883377f6f5bac86bf3b55b85785a63053ada6)
#9 decoder_GetDecoderDevice ../../include/vlc_codec.h:336 (libavcodec_plugin.so+0x4416) (BuildId: 0e7dad0d6dd4a01c64c60a816b1c820a0cffff01)
#10 lavc_UpdateVideoFormat ../../modules/codec/avcodec/video.c:326 (libavcodec_plugin.so+0x8249) (BuildId: 0e7dad0d6dd4a01c64c60a816b1c820a0cffff01)
#11 ffmpeg_OpenVa ../../modules/codec/avcodec/video.c:645 (libavcodec_plugin.so+0x9eda) (BuildId: 0e7dad0d6dd4a01c64c60a816b1c820a0cffff01)
#12 ffmpeg_GetFormat ../../modules/codec/avcodec/video.c:1980 (libavcodec_plugin.so+0xf793) (BuildId: 0e7dad0d6dd4a01c64c60a816b1c820a0cffff01)
#13 ff_get_format <null> (libavcodec.so.58+0x21b567) (BuildId: ca3659d22f45f37f3ddea337574c07136c0d1ff7)