diff --git a/tools/winscope/src/test/e2e/viewer_screen_recording_test.ts b/tools/winscope/src/test/e2e/viewer_screen_recording_test.ts index 65baa48a0..d71fdc8af 100644 --- a/tools/winscope/src/test/e2e/viewer_screen_recording_test.ts +++ b/tools/winscope/src/test/e2e/viewer_screen_recording_test.ts @@ -20,20 +20,21 @@ describe('Viewer ScreenRecording', () => { beforeAll(async () => { browser.manage().timeouts().implicitlyWait(1000); browser.get('file://' + E2eTestUtils.getProductionIndexHtmlPath()); - }), - it('processes trace and renders view', async () => { - await E2eTestUtils.uploadFixture( - 'traces/elapsed_and_real_timestamp/screen_recording_metadata_v2.mp4' - ); - await E2eTestUtils.closeSnackBarIfNeeded(); - await E2eTestUtils.clickViewTracesButton(); + }); - const viewer = element(by.css('viewer-screen-recording')); - expect(await viewer.isPresent()).toBeTruthy(); + it('processes trace and renders view', async () => { + await E2eTestUtils.uploadFixture( + 'traces/elapsed_and_real_timestamp/screen_recording_metadata_v2.mp4' + ); + await E2eTestUtils.closeSnackBarIfNeeded(); + await E2eTestUtils.clickViewTracesButton(); - const video = element(by.css('viewer-screen-recording video')); - expect(await video.isPresent()).toBeTruthy(); - expect(await video.getAttribute('src')).toContain('blob:'); - expect(await video.getAttribute('currentTime')).toEqual('0'); - }); + const viewer = element(by.css('viewer-screen-recording')); + expect(await viewer.isPresent()).toBeTruthy(); + + const video = element(by.css('viewer-screen-recording video')); + expect(await video.isPresent()).toBeTruthy(); + expect(await video.getAttribute('src')).toContain('blob:'); + expect(await video.getAttribute('currentTime')).toBeCloseTo(0, 0.001); + }); }); diff --git a/tools/winscope/src/trace/screen_recording_utils.ts b/tools/winscope/src/trace/screen_recording_utils.ts index c6bb2a924..e882f8c84 100644 --- a/tools/winscope/src/trace/screen_recording_utils.ts +++ b/tools/winscope/src/trace/screen_recording_utils.ts @@ -17,12 +17,17 @@ import {Timestamp} from './timestamp'; class ScreenRecordingUtils { + // Video time correction epsilon. Without correction, we could display the previous frame. + // This correction was already present in the legacy Winscope. + private static readonly EPSILON_SECONDS = 0.00001; + static timestampToVideoTimeSeconds(firstTimestamp: Timestamp, currentTimestamp: Timestamp) { if (firstTimestamp.getType() !== currentTimestamp.getType()) { throw new Error('Attempted to use timestamps with different type'); } const videoTimeSeconds = - Number(currentTimestamp.getValueNs() - firstTimestamp.getValueNs()) / 1000000000; + Number(currentTimestamp.getValueNs() - firstTimestamp.getValueNs()) / 1000000000 + + ScreenRecordingUtils.EPSILON_SECONDS; return videoTimeSeconds; } }