Repository navigation
mac-capture: Wait for SCK stop and fence callbacks before free - #125
Conversation
|
Thanks. Before this can merge, the project needs a RED→GREEN automated test. ScreenCaptureKit itself can't run in CI, but the ordering logic can: factor the stop/fence wait and the free decision into a small plain-C (or Objective-C-free) helper driven by fake callbacks, and add a cmocka test that fails on the current code (frees before the callbacks fire) and passes with the fix, as #109 did for PipeWire. Avoid |
|
Thanks @zackees, done the way you suggested. Sorry this needed a second round; the first version didn't come with its own test.
Evidence
|
The ScreenCaptureKit destroy paths free the capture and the stop event without waiting for stopCaptureWithCompletionHandler, so output and stop callbacks can still run on freed memory (#93). Adds the plain-C wait and free decision in mac-sck-stop.[ch] as a stub that never waits and always frees, and test_sck_stop_wait, which drives it with real os_event objects. 3 of 4 tests fail. Co-Authored-By: Claude Opus 5.5 <[email protected]>
sck_video_capture_destroy and sck_audio_capture_destroy now wait, with a timeout, on an os_event for the stop completion, as the start path does. A delegate-owned sc_mutex is held by every output and stop callback for its whole body, and the callback re-checks self.sc. Teardown nils delegate.sc under the same lock once the stream stops, so in-flight callbacks finish on live memory and later ones return early. On timeout only the stop event is leaked, because its completion can still fire, and teardown completes. Fixes #93 Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=35006dd3da66707269135c5bbd2537f7932adced secs=102 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791698615,"gate":"rust/all/fmt","host":"linux-x86_64","key":"65c83ff6730b90bb3a4a89a824863f0011918f8f49514ec949471975367863e9","lane":"lint","parents":["85d86e025d94bec6d9871c10cf1b49be0444634d"],"secs":11,"stamp":"7b67d7151da9b98b65db1bc8a745ffd8","tree":"35006dd3da66707269135c5bbd2537f7932adced","v":1,"via":"run"} Ci-Attestation: {"at":1791698615,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"65c83ff6730b90bb3a4a89a824863f0011918f8f49514ec949471975367863e9","lane":"lint","parents":["85d86e025d94bec6d9871c10cf1b49be0444634d"],"secs":11,"stamp":"e34c35a684486d59a79fb42915bc1048","tree":"35006dd3da66707269135c5bbd2537f7932adced","v":1,"via":"run"} Ci-Attestation: {"at":1791698615,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"ef3b1129fe2ce339d95ce9308db0409d12cf2583e1c0b497fa38ad1ed4cabdb2","lane":"rust-test","parents":["85d86e025d94bec6d9871c10cf1b49be0444634d"],"secs":27,"stamp":"738f56b24f8838906be278603b35ef90","tree":"35006dd3da66707269135c5bbd2537f7932adced","v":1,"via":"run"} Ci-Attestation: {"at":1791698615,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a66a6dbca36c004bf605335daa33ab914b4859a6c16b948b44daa15d2a9b0dca","lane":"tier2-linux","parents":["85d86e025d94bec6d9871c10cf1b49be0444634d"],"secs":64,"stamp":"a7b64dae2f78a93686b82a4777df945b","tree":"35006dd3da66707269135c5bbd2537f7932adced","v":1,"via":"run"}
|
I restructured this into RED then GREEN on current master. You're kept as the author of both commits. The new head is
Limits: the test covers the wait and free decision only. The |
6defb47 to
4664b0b
Compare
sck_video_capture_destroy/sck_audio_capture_destroyissued an asyncstopCaptureWithCompletionHandler, then released the delegate andbfreedscreen_capturewhile ScreenCaptureKit could still deliverdidOutputSampleBuffer:/didStopWithError:on the output queue — each dereferencing the rawself.scback-pointer into freed memory.os_eventfor the stop completion, matching the start pathsc_mutex: every callback holds it for its whole body and re-checksself.sc; teardown nilsdelegate.scunder the same lock after the stream stops, so in-flight callbacks finish on live memory and later ones exit earlyApplied to both video and audio capture sources.
Fixes #93