@@ -199,16 +199,8 @@ extension RunnerTests {
199199 }
200200 guard input . isReadyForMoreMediaData else { return }
201201 guard let pixelBuffer = makePixelBuffer ( from : cgImage ) else { return }
202- let nowUptime = ProcessInfo . processInfo . systemUptime
203- if recordingStartUptime == nil {
204- recordingStartUptime = nowUptime
205- }
206- let elapsed = max ( 0 , nowUptime - ( recordingStartUptime ?? nowUptime ) )
202+ let timestampValue = timestampValue ( for : ProcessInfo . processInfo . systemUptime )
207203 let timescale = effectiveFps
208- var timestampValue = Int64 ( ( elapsed * Double ( timescale ) ) . rounded ( . down ) )
209- if timestampValue <= lastTimestampValue {
210- timestampValue = lastTimestampValue + 1
211- }
212204 let timestamp = CMTime ( value : timestampValue , timescale : timescale )
213205 if ! adaptor . append ( pixelBuffer , withPresentationTime : timestamp ) {
214206 startError = writer . error ?? NSError (
@@ -221,6 +213,18 @@ extension RunnerTests {
221213 lastTimestampValue = timestampValue
222214 }
223215
216+ private func timestampValue ( for nowUptime : TimeInterval ) -> Int64 {
217+ if recordingStartUptime == nil {
218+ recordingStartUptime = nowUptime
219+ }
220+ let elapsed = max ( 0 , nowUptime - ( recordingStartUptime ?? nowUptime ) )
221+ let timestampValue = Int64 ( ( elapsed * Double ( effectiveFps ) ) . rounded ( . down ) )
222+ if timestampValue <= lastTimestampValue {
223+ return lastTimestampValue + 1
224+ }
225+ return timestampValue
226+ }
227+
224228 private func shouldStop ( ) -> Bool {
225229 lock . lock ( )
226230 defer { lock . unlock ( ) }
@@ -264,25 +268,16 @@ extension RunnerTests {
264268
265269#if AGENT_DEVICE_RUNNER_UNIT_TESTS
266270extension RunnerTests . ScreenRecorder {
267- func startForTesting ( image : RunnerImage ) throws {
268- try start { image }
269- lock . lock ( )
270- timer ? . cancel ( )
271- timer = nil
272- lock . unlock ( )
273- }
274-
275271 @ discardableResult
276- func appendForTesting ( image : RunnerImage , timestampValue : Int64 ) -> Int64 {
272+ func allocateTimestampForTesting ( _ requestedTimestampValue : Int64 ) -> Int64 {
277273 lock . lock ( )
274+ defer { lock . unlock ( ) }
275+ let nowUptime = ProcessInfo . processInfo . systemUptime
278276 recordingStartUptime =
279- ProcessInfo . processInfo . systemUptime - Double ( timestampValue ) / Double ( effectiveFps )
280- lock . unlock ( )
281- append ( image : image )
282- lock . lock ( )
283- let appendedTimestamp = lastTimestampValue
284- lock . unlock ( )
285- return appendedTimestamp
277+ nowUptime - Double ( requestedTimestampValue ) / Double ( effectiveFps )
278+ let allocatedTimestamp = timestampValue ( for : nowUptime )
279+ lastTimestampValue = allocatedTimestamp
280+ return allocatedTimestamp
286281 }
287282}
288283#endif
0 commit comments