Chromium Code Reviews| Index: talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java |
| diff --git a/talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java b/talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java |
| index 60832add2ee386419ead8b8f81d7860aacc781a6..4ae163167126c10b47abb0ab0853546faddaf115 100644 |
| --- a/talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java |
| +++ b/talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java |
| @@ -32,6 +32,7 @@ import android.os.Handler; |
| import android.os.HandlerThread; |
| import android.os.SystemClock; |
| import android.test.ActivityTestCase; |
| +import android.test.MoreAsserts; |
| import android.test.suitebuilder.annotation.MediumTest; |
| import android.test.suitebuilder.annotation.SmallTest; |
| @@ -165,6 +166,83 @@ public final class SurfaceTextureHelperTest extends ActivityTestCase { |
| eglBase.release(); |
| } |
| + /** Assert that two integers are close, with difference at most |
| + * {@code threshold}. Maybe belongs in MoreAsserts.java. */ |
|
perkj_webrtc
2015/12/10 10:15:52
Remove comment Maybe belongs....
nisse-webrtc
2015/12/10 12:14:56
Done.
|
| + public static void assertClose(int threshold, int expected, int actual) { |
|
perkj_webrtc
2015/12/10 10:15:53
Move up to before the first test.
|
| + if (Math.abs(expected - actual) <= threshold) |
| + return; |
| + failNotEquals("Not close enough, threshold " + threshold, expected, actual); |
| + } |
| + |
| + static public void assertEqualsButOne(int expected, int actual) { |
|
perkj_webrtc
2015/12/10 10:15:52
This looks like assertClose but with tresh hold 1.
perkj_webrtc
2015/12/10 10:15:53
public static?
nisse-webrtc
2015/12/10 12:14:56
assertEqualsButOne is a left-over. Deleted.
|
| + if (Math.abs(expected - actual) <= 1) |
| + return; |
| + failNotSame("Difference of more than one unit: ", expected, actual); |
| + } |
| + |
| + @MediumTest |
| + public static void testTexturetoYUV() throws InterruptedException { |
|
perkj_webrtc
2015/12/10 10:15:53
Move to the end of this file.
nisse-webrtc
2015/12/10 12:14:56
Done.
|
| + final int width = 16; |
| + final int height = 16; |
| + |
| + final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN); |
| + |
| + // Create SurfaceTextureHelper and listener. |
| + final SurfaceTextureHelper surfaceTextureHelper = |
| + SurfaceTextureHelper.create(eglBase.getEglBaseContext()); |
| + final MockTextureListener listener = new MockTextureListener(); |
| + surfaceTextureHelper.setListener(listener); |
| + surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height); |
| + |
| + // Create resources for stubbing an OES texture producer. |eglBase| has the SurfaceTexture in |
| + // |surfaceTextureHelper| as the target EGLSurface. |
| + |
| + eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
| + assertEquals(eglBase.surfaceWidth(), width); |
| + assertEquals(eglBase.surfaceHeight(), height); |
| + |
| + final int red[] = new int[] {79, 144, 185}; |
| + final int green[] = new int[] {66, 210, 162}; |
| + final int blue[] = new int[] {161, 117, 158}; |
| + |
| + final int ref_y[] = new int[] {81, 180, 168}; |
| + final int ref_u[] = new int[] {173, 93, 122}; |
| + final int ref_v[] = new int[] {127, 103, 140}; |
| + |
| + // Draw three frames. |
| + for (int i = 0; i < 3; ++i) { |
| + // Draw a constant color frame onto the SurfaceTexture. |
| + eglBase.makeCurrent(); |
| + GLES20.glClearColor(red[i] / 255.0f, green[i] / 255.0f, blue[i] / 255.0f, 1.0f); |
| + GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
| + // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
| + eglBase.swapBuffers(); |
| + |
| + // Wait for an OES texture to arrive. |
| + listener.waitForNewFrame(); |
| + |
| + ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 3 / 2); |
| + surfaceTextureHelper.textureToYUV(buffer, width, height, width, |
| + listener.oesTextureId, listener.transformMatrix); |
| + |
| + surfaceTextureHelper.returnTextureFrame(); |
| + |
| + // Allow off-by-one differences due to different rounding. |
| + while (buffer.position() < width*height) { |
| + assertClose(1, buffer.get() & 0xff, ref_y[i]); |
| + } |
| + while (buffer.hasRemaining()) { |
| + if (buffer.position() % width < width/2) |
|
perkj_webrtc
2015/12/10 10:15:53
Add a comment here to about the memory layout plea
nisse-webrtc
2015/12/10 12:14:56
Done.
|
| + assertClose(1, buffer.get() & 0xff, ref_u[i]); |
| + else |
| + assertClose(1, buffer.get() & 0xff, ref_v[i]); |
| + } |
| + } |
| + |
| + surfaceTextureHelper.disconnect(); |
| + eglBase.release(); |
| + } |
| + |
| /** |
| * Test disconnecting the SurfaceTextureHelper while holding a pending texture frame. The pending |
| * texture frame should still be valid, and this is tested by drawing the texture frame to a pixel |