fix: Fix first Frame not being written in Video (#2228)

* fix: Fix first Frame not being written in Video

* Update Podfile.lock
This commit is contained in:
Marc Rousavy 2023-11-28 12:10:21 +01:00 committed by GitHub
parent fc5fba1234
commit c68da4540d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 18 deletions

View File

@ -507,7 +507,7 @@ PODS:
- libwebp (~> 1.0) - libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10) - SDWebImage/Core (~> 5.10)
- SocketRocket (0.6.1) - SocketRocket (0.6.1)
- VisionCamera (3.6.9): - VisionCamera (3.6.11):
- React - React
- React-callinvoker - React-callinvoker
- React-Core - React-Core
@ -747,9 +747,9 @@ SPEC CHECKSUMS:
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17 SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
VisionCamera: aa2ce576c146a5e9afcbfe30e5464a311e275b8a VisionCamera: b35fc51a521ce0a9b9da41d8b13127e3d414d195
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce
PODFILE CHECKSUM: 27f53791141a3303d814e09b55770336416ff4eb PODFILE CHECKSUM: 27f53791141a3303d814e09b55770336416ff4eb
COCOAPODS: 1.14.2 COCOAPODS: 1.14.3

View File

@ -194,11 +194,7 @@ class RecordingSession {
- Use bufferType to specify if this is a video or audio frame. - Use bufferType to specify if this is a video or audio frame.
*/ */
func appendBuffer(_ buffer: CMSampleBuffer, clock _: CMClock, type bufferType: BufferType) { func appendBuffer(_ buffer: CMSampleBuffer, clock _: CMClock, type bufferType: BufferType) {
// 1. Check if the data is even ready // 1. Prepare the data
guard let startTimestamp = startTimestamp else {
// Session not yet started
return
}
guard !isFinishing else { guard !isFinishing else {
// Session is already finishing, can't write anything more // Session is already finishing, can't write anything more
return return
@ -212,15 +208,8 @@ class RecordingSession {
return 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) 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, if let stopTimestamp = stopTimestamp,
timestamp >= stopTimestamp { timestamp >= stopTimestamp {
// This Frame is exactly at, or after the point in time when RecordingSession.stop() has been called. // 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. // already wrote last Video Frame before, so skip this one.
return return
} }
hasWrittenLastVideoFrame = true // flip to true, then write it hasWrittenLastVideoFrame = true // flip to true, then fallthrough & write it
case .audio: case .audio:
if hasWrittenLastAudioFrame { if hasWrittenLastAudioFrame {
// already wrote last Audio Frame before, so skip this one. // already wrote last Audio Frame before, so skip this one.
return return
} }
hasWrittenLastAudioFrame = true // flip to true, then write it hasWrittenLastAudioFrame = true // flip to true, then fallthrough & write it
} }
} }