FFmpeg: RecordingEngine - Fix race on encoders during finalization


When a source reports end-of-stream from a thread other than the
RecordingEngine's own, handleSourceEndOfStream() is invoked through a
queued connection. If the recording is finalized before that queued call
is processed, handleSourceEndOfStream() iterates the encoders while the
EncodingFinalizer thread is deleting them, which may crash.

With autoStop enabled, this can happen when a QVideoFrameInput or
QAudioBufferInput reports end-of-stream from a worker thread while the
recorder is stopping. It will also happen for window and screen capture
on macOS, once ScreenCaptureKit emits end-of-stream frames from its
frame queue: the deactivation then reports end-of-stream both directly,
which auto-stops the recording, and through the queued connection.

This patch makes handleSourceEndOfStream() return early once the engine
is finalizing, since the encoders are then owned by the finalizer thread
and the recording is stopping anyway.

We add a test that reproduces the race by sending the end-of-stream frame
from another thread right before stopping the recorder.

Pick-to: 6.12
Change-Id: Ie5993b733e9c64356609e551b652ac34249f9972
Reviewed-by: Tim Blechmann <tim.blechmann@qt.io>
commitaba7299af4c4c6de59cefe83a6bf8366bb803c67
parentfe815c8c8afe2d05caa6af8082ed2756438257f5
authorNils Petter Skålerud <nils.petter.skalerud@qt.io>
committerNils Petter Skålerud <nils.petter.skalerud@qt.io>
commit timeWed, 7 Oct 2026 06:38:28 +0000