TSan detected data race in get_format_hwdec

Open
#18,806 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
46/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, macos

Research direction

Start by reading get_format_hwdec and prepare_decoding in the video decoder code, then trace how the hardware decode format is accessed across the decoder threads. Reproduce with ThreadSanitizer on macOS using hardware decoding and the supplied H.264 sample. Done means the reported race no longer occurs while hardware decoding remains functional.

Written by the indexing model from the issue text.

Description

os:mac
mpv Information
mpv v0.42.0-36-gd075ec2a2 Copyright © 2000-2026 mpv/MPlayer/mplayer2 projects
 built on Nov 10 2026 09:07:29
libplacebo version: v7.391.0 (v7.387.0-37-gc2cf6e72)
FFmpeg version: n9.0.2
FFmpeg library versions:
   libavcodec      63.1.102
   libavdevice     63.1.102
   libavfilter     12.1.102
   libavformat     63.1.102
   libavutil       61.1.102
   libswresample   7.1.102
   libswscale      10.1.102
Other Information
- macOS version: macOS 27.2 (26B123)
- Source of mpv: Local build
- Latest known working version: Unknown
- Issue started after the following happened: I built with TSan
Reproduction Steps
  • Download a H.264 encoded copy of Big Buck Bunny from here using this link

  • Use mpv-build to build mpv with TSan enabled:

    • Save any existing mpv_options file you already have

    • Run the following commands in Terminal to configure mpv-build to build with the ThreadSanitizer enabled:

      printf "%s\n" -Dbuildtype=debug > mpv_options
      printf "%s\n" -Db_sanitize=thread >> mpv_options

    • Build mpv

  • Play the downloaded video with mpv built with TSan with the hwdec option set to auto like so:

    mpv/build/mpv --no-config --gpu-debug --log-file=output.txt --hwdec=auto ~/Movies/big_buck_bunny_1080p_h264.mov

  • TSan reports the following error:

    SUMMARY: ThreadSanitizer: data race (mpv:arm64+0x1002a1138) in get_format_hwdec+0x2b8

Expected Behavior

TSan does not detect any data races.

Actual Behavior

When hardware decoding is in use TSan reports a data race in get_format_hwdec. Full console output below.

Console output with TSan errors:
low-batt@gag mpv-build (master %=)$ mpv/build/mpv --no-config --gpu-debug --log-file=output.txt --hwdec=auto ~/Movies/big_buck_bunny_1080p_h264.mov 
[lavf] Failed to convert channel layout 6 channels (FC+FL+FR+SL+SR+LFE) to mpv one!
● Video  --vid=1  --vlang=eng  (h264 1920x1080 24 fps 9283 kbps) [default]
● Audio  --aid=1  --alang=eng  (aac 48000 Hz 438 kbps) [default]
==================
WARNING: ThreadSanitizer: data race (pid=24303)
  Write of size 1 at 0x000114f32930 by thread T26 (mutexes: write M0):
    #0 get_format_hwdec <null> (mpv:arm64+0x1002a1138)
    #1 ff_get_format <null> (mpv:arm64+0x1005ccc1c)

  Previous read of size 1 at 0x000114f32930 by thread T4:
    #0 prepare_decoding <null> (mpv:arm64+0x10029de4c)
    #1 send_packet <null> (mpv:arm64+0x10029d0f8)
    #2 lavc_process <null> (mpv:arm64+0x10016be3c)
    #3 vd_lavc_process <null> (mpv:arm64+0x10029ca40)
    #4 mp_filter_graph_run <null> (mpv:arm64+0x100188100)
    #5 run_playloop <null> (mpv:arm64+0x1002499fc)
    #6 play_current_file <null> (mpv:arm64+0x100237bc0)
    #7 mp_play_files <null> (mpv:arm64+0x100235724)
    #8 mpv_main <null> (mpv:arm64+0x10023e824)
    #9 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Location is heap block of size 568 at 0x000114f32780 allocated by thread T4:
    #0 calloc <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x67ff4)
    #1 ta_zalloc_size <null> (mpv:arm64+0x100341ad4)
    #2 mp_filter_create_with_params <null> (mpv:arm64+0x10018c014)
    #3 mp_filter_create <null> (mpv:arm64+0x10018d084)
    #4 create <null> (mpv:arm64+0x10029b1f8)
    #5 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #6 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #7 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #8 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #9 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #10 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #11 play_current_file <null> (mpv:arm64+0x100237418)
    #12 mp_play_files <null> (mpv:arm64+0x100235724)
    #13 mpv_main <null> (mpv:arm64+0x10023e824)
    #14 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Mutex M0 (0x00010de078a8) created at:
    #0 pthread_mutex_init <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x35664)
    #1 ff_pthread_init <null> (mpv:arm64+0x1013beacc)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Thread T26 (tid=6526072, running) created by thread T4 at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x33bac)
    #1 init_thread <null> (mpv:arm64+0x1013bf134)
    #2 reinit <null> (mpv:arm64+0x10029c8c0)
    #3 create <null> (mpv:arm64+0x10029b5c0)
    #4 reinit_decoder <null> (mpv:arm64+0x100168e50)
    #5 mp_decoder_wrapper_reinit <null> (mpv:arm64+0x100168844)
    #6 init_video_decoder <null> (mpv:arm64+0x100256da8)
    #7 vo_chain_init_decoder <null> (mpv:arm64+0x1002579e8)
    #8 reinit_video_chain_src <null> (mpv:arm64+0x10025765c)
    #9 reinit_video_chain <null> (mpv:arm64+0x100257130)
    #10 play_current_file <null> (mpv:arm64+0x100237418)
    #11 mp_play_files <null> (mpv:arm64+0x100235724)
    #12 mpv_main <null> (mpv:arm64+0x10023e824)
    #13 closure #1 in variable initialization expression of Application.playbackThread <null> (mpv:arm64+0x100017924)

  Thread T4 (tid=6525992, running) created by main thread at:
    #0 pthread_create <null> (libclang_rt.tsan_osx_dynamic.dylib:arm64e+0x33bac)
    #1 Application.main(_:_:) <null> (mpv:arm64+0x100017e8c)
    #2 main <null> (mpv:arm64+0x1003a0e90)

SUMMARY: ThreadSanitizer: data race (mpv:arm64+0x1002a1138) in get_format_hwdec+0x2b8
==================
AO: [coreaudio] 48000Hz fr-fl (stereo) 2ch floatp
Using hardware decoding (videotoolbox).
VO: [gpu-next] 1920x1080 videotoolbox[nv12]
AV: 00:00:03 / 00:09:56 (1%) A-V:  0.000 Dropped: 1 
Exiting... (Quit)
ThreadSanitizer: reported 1 warnings
Abort trap: 6
low-batt@gag mpv-build (master %=)$ 
Log File

output.txt

Sample Files

To trigger the problem requires a video that uses a codec supported by the Media Engine of the Mac being used. The problem does not occur if software decoding is used.

I downloaded a H.264 encoded copy of Big Buck Bunny from here using this link to reproduce the problem.

I carefully read all instruction and confirm that I did the following:
  • I tested and confirmed that the issue exists with the latest release version or newer.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
Dominant language
C
Stars
38.2k
Forks
3.7k
Avg merge
1d 13h
Merged PRs (30d)
76

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from mpv-player/mpv

All issues in mpv-player/mpv

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.