SurfaceViewRendererOnMeasureTest: Wait for frame size change to take effect
SurfaceViewRendererOnMeasureTest#testFrame1280x720 is currently flaky because of a race. This issue was introduced here: https://codereview.webrtc.org/2111933002/. That CL moved the function updateFrameDimensionsAndReportEvents() from renderFrame() to renderFrameOnRenderThread(). The OnMeasureTest currently just calls renderFrame() with a new frame size and immediately starts testing the measured size, which might be before renderFrameOnRenderThread() is executed. This CL waits for the RendererEvents.onFrameResolutionChanged() callback before starting the test to fix this race. BUG=webrtc:6089 Review-Url: https://codereview.webrtc.org/2147463002 Cr-Commit-Position: refs/heads/master@{#13448}
This commit is contained in:
@ -112,10 +112,37 @@ public final class SurfaceViewRendererOnMeasureTest extends ActivityTestCase {
|
||||
* Test how SurfaceViewRenderer.onMeasure() behaves with a 1280x720 frame.
|
||||
*/
|
||||
@MediumTest
|
||||
public void testFrame1280x720() {
|
||||
public void testFrame1280x720() throws InterruptedException {
|
||||
final SurfaceViewRenderer surfaceViewRenderer =
|
||||
new SurfaceViewRenderer(getInstrumentation().getContext());
|
||||
surfaceViewRenderer.init((EglBase.Context) null, null);
|
||||
/**
|
||||
* Mock renderer events with blocking wait functionality for frame size changes.
|
||||
*/
|
||||
class MockRendererEvents implements RendererCommon.RendererEvents {
|
||||
private int frameWidth;
|
||||
private int frameHeight;
|
||||
private int rotation;
|
||||
|
||||
public synchronized void waitForFrameSize(int frameWidth, int frameHeight, int rotation)
|
||||
throws InterruptedException {
|
||||
while (this.frameWidth != frameWidth || this.frameHeight != frameHeight
|
||||
|| this.rotation != rotation) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFirstFrameRendered() {}
|
||||
|
||||
public synchronized void onFrameResolutionChanged(
|
||||
int frameWidth, int frameHeight, int rotation) {
|
||||
this.frameWidth = frameWidth;
|
||||
this.frameHeight = frameHeight;
|
||||
this.rotation = rotation;
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
final MockRendererEvents rendererEvents = new MockRendererEvents();
|
||||
surfaceViewRenderer.init((EglBase.Context) null, rendererEvents);
|
||||
|
||||
// Test different rotation degress, but same rotated size.
|
||||
for (int rotationDegree : new int[] {0, 90, 180, 270}) {
|
||||
@ -130,6 +157,7 @@ public final class SurfaceViewRendererOnMeasureTest extends ActivityTestCase {
|
||||
final String frameDimensions =
|
||||
unrotatedWidth + "x" + unrotatedHeight + " with rotation " + rotationDegree;
|
||||
surfaceViewRenderer.renderFrame(frame);
|
||||
rendererEvents.waitForFrameSize(unrotatedWidth, unrotatedHeight, rotationDegree);
|
||||
|
||||
// Test forcing to zero size.
|
||||
for (RendererCommon.ScalingType scalingType : scalingTypes) {
|
||||
|
||||
Reference in New Issue
Block a user