Skip to content

libobs: Fix monitoring for media with cover art - #2531

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/upstream-cover-art-monitoring
Oct 26, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/upstream-cover-art-monitoring

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2530

What and why

On Windows, audio monitoring of a Media Source playing a song with embedded cover art goes silent after the source restarts: the scene is shown again, visibility is toggled, or the file loops. The stream and recordings still get the audio, and switching monitoring off and on brings it back until the next restart (upstream obs-studio issues 9428 and 11739). This is a port of the one-line upstream fix, obs-studio PR 14091, which is open there with no reviews yet.

The WASAPI monitor holds a source's audio back while it runs ahead of the source's video, and stops syncing once the video timestamp has stood still for 100 ms. Cover art is one picture, so its timestamp stands still. When the timestamp changed, the monitor reset its count but kept the old timestamp. After a restart the cover gets a new timestamp, so every later packet saw it as new, the count stayed at 0, and the audio, ever further ahead of the still cover, was held back for good.

  • RED moves that timestamp tracking, unchanged, out of process_audio_delay() in libobs/audio-monitoring/win32/wasapi-output.c.h into a shared header, libobs/audio-monitoring/monitor-video-sync.h (one static inline function, no OS code, included through libobs-windows.pch.h). The 100 ms limit becomes AUDIO_MONITOR_VIDEO_STALL_NS. This lets the decision run on every platform.
  • GREEN stores the new timestamp (the upstream line), and adds the docs/features.md line under Fixed upstream bugs, Audio.

Linux and macOS are not affected: the PulseAudio and CoreAudio monitors have no such check. The program audio is not affected on any OS.

Tests (both new; no existing test changed):

  • test_monitor_video_sync (test graph, every platform, no libobs): a still cover, a restart with a new cover timestamp, repeated restarts, and a guard with moving video (a new frame every 33 ms never counts as still).
  • test_media_cover_art_monitor (tests.d, Linux, under Xvfb, skips without a display): real libobs and the real ffmpeg_source play a generated MP3 (when an MP3 encoder is available) and FLAC, each with a JPEG cover as an attached picture. The files are written at run time, not committed. The test runs the monitor's decision in the source's audio capture callback, where the WASAPI monitor runs it, with the source's real last_frame_ts, for 1 s of first play and 1 s after the program went to another scene and back (restart on activate).

The WASAPI output itself can't run on Linux, so the Windows device path is covered by the Windows build in PR CI, not by a run. The Windows unity group (libobs.windows+.h.c) passes a MinGW syntax check locally.

RED → GREEN

  • RED commit: 7b700e9. test_monitor_video_sync: cover_art_restart_stalls_again and cover_art_every_restart_stalls fail ("video stood still but only 0 ms counted (stall after 100 ms)"); the first-play and moving-video guards pass. test_media_cover_art_monitor: both cases fail in 5 of 5 runs on hybrid libobs and on libobs-c-reference: after the restart the cover is at a new timestamp, the monitor still holds the first one, and the still cover counts 0 ms (first play: 768 to 888 ms). In one run on libobs-c-reference, the FLAC case already counted 0 ms on first play, the same trap when the video timestamp moves once after the first packet.
  • GREEN: eb794a3. Both tests pass on hybrid libobs and libobs-c-reference (test_media_cover_art_monitor 6 of 6 runs each; after the restart the monitor holds the new timestamp and counts 768 to 888 ms). The media, monitoring and cover-art ctests (-R 'media|monitor|cover') pass on both lanes: 39 of 39 on libobs-c-reference, 41 of 41 on hybrid libobs. uv run ci/local_gate.py --lane lint, --test-diff origin/master (4531 passed) and --lane cross pass.
  • Real app (UI, protocol output or logging changes): N/A, Windows-only audio path; no UI or log change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together) — no characterization commit: this is a bug fix, not a port, so its new tests start RED (coordination.md: "Bug fixes need a failing test first")
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe
rdoupe requested a review from zackees as a code owner October 26, 2026 21:09

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed:

  • The RED commit moves the tracking out without changing it.
  • GREEN adds the upstream line that saves the new timestamp.
  • Behaviour change: util_mul_div64 is now computed on every packet, where before it ran only when the timestamp stood still. It has no side effects and costs very little.
  • The header has no OS code. The new tests cover first play, restarts and moving video, plus a real ffmpeg_source run with a cover-art file.
  • No existing test was changed, and the ledger line is present.

Queuing; it goes in when CI is green.

@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

The Windows Rust Tier 2 failure here (LNK2005 on matrix4_* in test_graphics_state_stacks_rust) comes from master, not this PR. #2534 fixes it, and once it lands this PR needs a rebase or re-run.

rdoupe and others added 2 commits October 26, 2026 15:11
Move the WASAPI monitor's video timestamp tracking into the shared
header monitor-video-sync.h, unchanged, so it runs on every platform,
and test it: test_monitor_video_sync feeds it a still cover, a restart
with a new cover timestamp and moving video; test_media_cover_art_monitor
feeds it the real ffmpeg_source's last_frame_ts from an audio capture
callback, for an MP3 and a FLAC with cover art, before and after the
scene is shown again.

After the restart the timestamp has moved, the monitor resets its
count but keeps the old timestamp, so the still cover never counts as
still and the Windows monitor holds the audio back for good.

Refs obs-rust#2530
The WASAPI monitor stops syncing a source's audio to its video once
the video timestamp has stood still for 100 ms, as for an audio file
with embedded cover art. On a new timestamp it reset the count but did
not store the timestamp, so after the source restarted (the scene was
shown again, or the file looped) and the cover got a new timestamp,
every packet saw it as new and the count stayed at 0. The audio, ever
further ahead of the still cover, was held back for good and monitoring
went silent until it was switched off and on. Store the new timestamp.

Port of upstream obs-studio PR 14091.

Fixes obs-rust#2530

Co-Authored-By: prgmitchell <[email protected]>
@zackees
zackees force-pushed the fix/upstream-cover-art-monitoring branch from b977e42 to eb794a3 Compare October 26, 2026 22:11
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit e8bdfee Oct 26, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: audio monitoring goes silent after a Media Source with cover art restarts (upstream #9428)

2 participants