From c68da4540d25187e94d2090b424d23dee5c091be Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 28 Nov 2023 12:10:21 +0100 Subject: [PATCH] fix: Fix first Frame not being written in Video (#2228) * fix: Fix first Frame not being written in Video * Update Podfile.lock --- package/example/ios/Podfile.lock | 6 +++--- package/ios/Core/RecordingSession.swift | 19 ++++--------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/package/example/ios/Podfile.lock b/package/example/ios/Podfile.lock index 5cb87c2..219a6db 100644 --- a/package/example/ios/Podfile.lock +++ b/package/example/ios/Podfile.lock @@ -507,7 +507,7 @@ PODS: - libwebp (~> 1.0) - SDWebImage/Core (~> 5.10) - SocketRocket (0.6.1) - - VisionCamera (3.6.9): + - VisionCamera (3.6.11): - React - React-callinvoker - React-Core @@ -747,9 +747,9 @@ SPEC CHECKSUMS: SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 - VisionCamera: aa2ce576c146a5e9afcbfe30e5464a311e275b8a + VisionCamera: b35fc51a521ce0a9b9da41d8b13127e3d414d195 Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce PODFILE CHECKSUM: 27f53791141a3303d814e09b55770336416ff4eb -COCOAPODS: 1.14.2 +COCOAPODS: 1.14.3 diff --git a/package/ios/Core/RecordingSession.swift b/package/ios/Core/RecordingSession.swift index caf3419..22b80d0 100644 --- a/package/ios/Core/RecordingSession.swift +++ b/package/ios/Core/RecordingSession.swift @@ -194,11 +194,7 @@ class RecordingSession { - Use bufferType to specify if this is a video or audio frame. */ func appendBuffer(_ buffer: CMSampleBuffer, clock _: CMClock, type bufferType: BufferType) { - // 1. Check if the data is even ready - guard let startTimestamp = startTimestamp else { - // Session not yet started - return - } + // 1. Prepare the data guard !isFinishing else { // Session is already finishing, can't write anything more return @@ -212,15 +208,8 @@ class RecordingSession { return } - // 2. Check the timing of the buffer and make sure it's within our session start and stop times + // 2. Check the timing of the buffer and make sure it's not after we requested a session stop let timestamp = CMSampleBufferGetPresentationTimeStamp(buffer) - if timestamp < startTimestamp { - // Don't write this Frame, it was captured before we even started recording. - // The reason this can happen is because the capture pipeline can have a delay, e.g. because of stabilization. - let delay = CMTimeSubtract(startTimestamp, timestamp) - ReactLogger.log(level: .info, message: "Capture Pipeline has a delay of \(delay.seconds) seconds. Skipping this late Frame...") - return - } if let stopTimestamp = stopTimestamp, timestamp >= stopTimestamp { // This Frame is exactly at, or after the point in time when RecordingSession.stop() has been called. @@ -231,13 +220,13 @@ class RecordingSession { // already wrote last Video Frame before, so skip this one. return } - hasWrittenLastVideoFrame = true // flip to true, then write it + hasWrittenLastVideoFrame = true // flip to true, then fallthrough & write it case .audio: if hasWrittenLastAudioFrame { // already wrote last Audio Frame before, so skip this one. return } - hasWrittenLastAudioFrame = true // flip to true, then write it + hasWrittenLastAudioFrame = true // flip to true, then fallthrough & write it } }