fix: Fully synchronize buffers in RecordingSession to account for late-running frames (#2206)

* fix: Fully synchronize `RecordingSession` to account for late Frames

* Restructure Code

* Update RecordingSession.swift

* Fix last audio timestamp not being used

* fix: Remove `capture/aborted` error

* Update RecordingSession.swift

* Don't log for every Frame

* Format
This commit is contained in:
Marc Rousavy
2023-11-23 18:17:15 +01:00
committed by GitHub
parent 29e649937e
commit 1767e6e881
4 changed files with 171 additions and 81 deletions

View File

@@ -128,7 +128,8 @@ extension CameraSession {
recordingSession.initializeVideoWriter(withSettings: videoSettings)
// start recording session with or without audio.
try recordingSession.startAssetWriter()
// Use Video [AVCaptureSession] clock as a timebase - all other sessions (here; audio) have to be synced to that Clock.
try recordingSession.start(clock: self.captureSession.clock)
self.recordingSession = recordingSession
self.isRecording = true
@@ -150,13 +151,13 @@ extension CameraSession {
*/
func stopRecording(promise: Promise) {
CameraQueues.cameraQueue.async {
self.isRecording = false
withPromise(promise) {
guard let recordingSession = self.recordingSession else {
throw CameraError.capture(.noRecordingInProgress)
}
recordingSession.finish()
// Use Video [AVCaptureSession] clock as a timebase - all other sessions (here; audio) have to be synced to that Clock.
recordingSession.stop(clock: self.captureSession.clock)
// There might be late frames, so maybe we need to still provide more Frames to the RecordingSession. Let's keep isRecording true for now.
return nil
}
}