Skip to content

Fix camera race crash during Open/Close (and audio crackling after recording) - #1098

Merged
jonoomph merged 2 commits into
developfrom
fix-camera-race-open-close
Sep 15, 2026
Merged

jonoomph merged 2 commits into
developfrom
fix-camera-race-open-close

Conversation

@jonoomph

Copy link
Copy Markdown
Member

No description provided.

Serialize the FFmpeg capture Open path with GetFrame and Close using the
existing recursive mutex. Close still signals cancellation before waiting,
but cannot free a context while avformat_open_input or decoder setup uses it.
Clean up partially initialized resources on failure or cancellation.

Add a hardware-independent regression test that pauses a V4L2 open inside
FFmpeg and requests Close from another thread. It reproduces SIGSEGV with
the original implementation and passes with the fix, including 20 repeated
runs. All 15 camera/screen capture test cases pass (78 assertions).

Real-device AppImage validation remains necessary after rebuilding.
Position PulseAudio and WASAPI loopback samples relative to recording start, dropping stale audio and preserving gaps without delaying subsequent sound. Request smaller PulseAudio fragments and tolerate bounded timestamp jitter to avoid crackling at packet boundaries.

Add regression coverage for both capture clocks, pre-recording buffers, late packets, gaps, queue overflow, reset, and sample continuity.
@jonoomph

Copy link
Copy Markdown
Member Author

@codecov

codecov Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.46256% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.44%. Comparing base (36e822f) to head (dc43f4d).

Files with missing lines Patch % Lines
src/ScreenCaptureReader.cpp 9.09% 30 Missing ⚠️
tests/CameraCaptureReader.cpp 96.00% 2 Missing ⚠️
src/CaptureAudioBuffer.h 98.24% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1098      +/-   ##
===========================================
+ Coverage    71.14%   71.44%   +0.30%     
===========================================
  Files          263      264       +1     
  Lines        34758    34963     +205     
===========================================
+ Hits         24727    24980     +253     
+ Misses       10031     9983      -48     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jonoomph
jonoomph merged commit fb9f92b into develop Sep 15, 2026
13 checks passed
@jonoomph
jonoomph deleted the fix-camera-race-open-close branch September 15, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant