From 8df9b96528f77828aa6029b012ed38d503537dab Mon Sep 17 00:00:00 2001 From: Kean Mariotti Date: Tue, 17 Jan 2023 14:50:41 +0000 Subject: [PATCH 1/2] Fix format errors Test: npm run format:check Change-Id: Ic9ae610c108703ac0a03751a8eb822a1366a17b5 --- tools/winscope/src/test/unit/utils.ts | 4 +++- .../src/viewers/components/rects/rects_component_test.ts | 6 +++--- .../src/viewers/viewer_surface_flinger/presenter.ts | 2 +- .../src/viewers/viewer_surface_flinger/presenter_test.ts | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/winscope/src/test/unit/utils.ts b/tools/winscope/src/test/unit/utils.ts index df3882f69..de9a8eca7 100644 --- a/tools/winscope/src/test/unit/utils.ts +++ b/tools/winscope/src/test/unit/utils.ts @@ -39,7 +39,9 @@ class UnitTestUtils extends CommonTestUtils { } static async getMultiDisplayLayerTraceEntry(): Promise { - return await UnitTestUtils.getTraceEntry('traces/elapsed_and_real_timestamp/SurfaceFlinger_multidisplay.pb'); + return await UnitTestUtils.getTraceEntry( + 'traces/elapsed_and_real_timestamp/SurfaceFlinger_multidisplay.pb' + ); } static async getImeTraceEntries(): Promise> { diff --git a/tools/winscope/src/viewers/components/rects/rects_component_test.ts b/tools/winscope/src/viewers/components/rects/rects_component_test.ts index e7145f29e..0196e9982 100644 --- a/tools/winscope/src/viewers/components/rects/rects_component_test.ts +++ b/tools/winscope/src/viewers/components/rects/rects_component_test.ts @@ -120,13 +120,13 @@ describe('RectsComponent', () => { fixture.detectChanges(); - const displayButtonContainer = htmlElement.querySelector(".display-button-container"); + const displayButtonContainer = htmlElement.querySelector('.display-button-container'); expect(displayButtonContainer).toBeTruthy(); const buttons = Array.from(displayButtonContainer?.querySelectorAll('button') ?? []); expect(buttons.length).toBe(3); const buttonValues = buttons.map((it) => it.textContent?.trim()); - expect(buttonValues).toEqual(["0", "1", "2"]); - }) + expect(buttonValues).toEqual(['0', '1', '2']); + }); }); diff --git a/tools/winscope/src/viewers/viewer_surface_flinger/presenter.ts b/tools/winscope/src/viewers/viewer_surface_flinger/presenter.ts index 7578974a5..271c33d61 100644 --- a/tools/winscope/src/viewers/viewer_surface_flinger/presenter.ts +++ b/tools/winscope/src/viewers/viewer_surface_flinger/presenter.ts @@ -121,7 +121,7 @@ export class Presenter { }; return rect; }) ?? []; - this.displayIds = this.entry.displays.map((it: any) => it.layerStackId) + this.displayIds = this.entry.displays.map((it: any) => it.layerStackId); this.displayIds.sort(); const rects = this.getLayersForRectsView() .sort(this.compareLayerZ) diff --git a/tools/winscope/src/viewers/viewer_surface_flinger/presenter_test.ts b/tools/winscope/src/viewers/viewer_surface_flinger/presenter_test.ts index e050c5c3f..dab9dd6c3 100644 --- a/tools/winscope/src/viewers/viewer_surface_flinger/presenter_test.ts +++ b/tools/winscope/src/viewers/viewer_surface_flinger/presenter_test.ts @@ -218,7 +218,7 @@ describe('PresenterSurfaceFlinger', () => { presenter.notifyCurrentTraceEntries(await getEntriesWithMultiDisplaySfTrace()); expect(uiData.displayIds.length).toEqual(5); // we want the ids to be sorted - expect(uiData.displayIds).toEqual([0,2,3,4,5]); + expect(uiData.displayIds).toEqual([0, 2, 3, 4, 5]); }); async function getEntriesWithMultiDisplaySfTrace(): Promise> { From f7febbc60609e6c56ef6b49567d31443b56c85f3 Mon Sep 17 00:00:00 2001 From: Kean Mariotti Date: Tue, 17 Jan 2023 14:42:32 +0000 Subject: [PATCH 2/2] Add correction factor in video time calculation Test: npm run build:all && npm run test:all Change-Id: I0cfdff9fbbc15a4ad5d5a21c0f4df44335291830 --- .../test/e2e/viewer_screen_recording_test.ts | 29 ++++++++++--------- .../src/trace/screen_recording_utils.ts | 7 ++++- 2 files changed, 21 insertions(+), 15 deletions(-) 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; } }