Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(912)

Side by Side Diff: talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java

Issue 1460703002: Implement AndroidTextureBuffer::NativeToI420. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Deleted unused variable Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2015 Google Inc. 3 * Copyright 2015 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 14 matching lines...) Expand all
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 package org.webrtc; 27 package org.webrtc;
28 28
29 import android.graphics.SurfaceTexture; 29 import android.graphics.SurfaceTexture;
30 import android.opengl.GLES20; 30 import android.opengl.GLES20;
31 import android.os.Handler; 31 import android.os.Handler;
32 import android.os.HandlerThread; 32 import android.os.HandlerThread;
33 import android.os.SystemClock; 33 import android.os.SystemClock;
34 import android.test.ActivityTestCase; 34 import android.test.ActivityTestCase;
35 import android.test.MoreAsserts;
35 import android.test.suitebuilder.annotation.MediumTest; 36 import android.test.suitebuilder.annotation.MediumTest;
36 import android.test.suitebuilder.annotation.SmallTest; 37 import android.test.suitebuilder.annotation.SmallTest;
37 38
38 import java.nio.ByteBuffer; 39 import java.nio.ByteBuffer;
39 40
40 public final class SurfaceTextureHelperTest extends ActivityTestCase { 41 public final class SurfaceTextureHelperTest extends ActivityTestCase {
41 /** 42 /**
42 * Mock texture listener with blocking wait functionality. 43 * Mock texture listener with blocking wait functionality.
43 */ 44 */
44 public static final class MockTextureListener 45 public static final class MockTextureListener
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 assertEquals(rgbaData.get() & 0xFF, blue[i]); 159 assertEquals(rgbaData.get() & 0xFF, blue[i]);
159 assertEquals(rgbaData.get() & 0xFF, 255); 160 assertEquals(rgbaData.get() & 0xFF, 255);
160 } 161 }
161 } 162 }
162 163
163 drawer.release(); 164 drawer.release();
164 surfaceTextureHelper.disconnect(); 165 surfaceTextureHelper.disconnect();
165 eglBase.release(); 166 eglBase.release();
166 } 167 }
167 168
169 /** Assert that two integers are close, with difference at most
170 * {@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.
171 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.
172 if (Math.abs(expected - actual) <= threshold)
173 return;
174 failNotEquals("Not close enough, threshold " + threshold, expected, actual);
175 }
176
177 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.
178 if (Math.abs(expected - actual) <= 1)
179 return;
180 failNotSame("Difference of more than one unit: ", expected, actual);
181 }
182
183 @MediumTest
184 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.
185 final int width = 16;
186 final int height = 16;
187
188 final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN);
189
190 // Create SurfaceTextureHelper and listener.
191 final SurfaceTextureHelper surfaceTextureHelper =
192 SurfaceTextureHelper.create(eglBase.getEglBaseContext());
193 final MockTextureListener listener = new MockTextureListener();
194 surfaceTextureHelper.setListener(listener);
195 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height) ;
196
197 // Create resources for stubbing an OES texture producer. |eglBase| has the SurfaceTexture in
198 // |surfaceTextureHelper| as the target EGLSurface.
199
200 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture());
201 assertEquals(eglBase.surfaceWidth(), width);
202 assertEquals(eglBase.surfaceHeight(), height);
203
204 final int red[] = new int[] {79, 144, 185};
205 final int green[] = new int[] {66, 210, 162};
206 final int blue[] = new int[] {161, 117, 158};
207
208 final int ref_y[] = new int[] {81, 180, 168};
209 final int ref_u[] = new int[] {173, 93, 122};
210 final int ref_v[] = new int[] {127, 103, 140};
211
212 // Draw three frames.
213 for (int i = 0; i < 3; ++i) {
214 // Draw a constant color frame onto the SurfaceTexture.
215 eglBase.makeCurrent();
216 GLES20.glClearColor(red[i] / 255.0f, green[i] / 255.0f, blue[i] / 255.0f, 1.0f);
217 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
218 // swapBuffers() will ultimately trigger onTextureFrameAvailable().
219 eglBase.swapBuffers();
220
221 // Wait for an OES texture to arrive.
222 listener.waitForNewFrame();
223
224 ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 3 / 2);
225 surfaceTextureHelper.textureToYUV(buffer, width, height, width,
226 listener.oesTextureId, listener.transformMatrix);
227
228 surfaceTextureHelper.returnTextureFrame();
229
230 // Allow off-by-one differences due to different rounding.
231 while (buffer.position() < width*height) {
232 assertClose(1, buffer.get() & 0xff, ref_y[i]);
233 }
234 while (buffer.hasRemaining()) {
235 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.
236 assertClose(1, buffer.get() & 0xff, ref_u[i]);
237 else
238 assertClose(1, buffer.get() & 0xff, ref_v[i]);
239 }
240 }
241
242 surfaceTextureHelper.disconnect();
243 eglBase.release();
244 }
245
168 /** 246 /**
169 * Test disconnecting the SurfaceTextureHelper while holding a pending texture frame. The pending 247 * Test disconnecting the SurfaceTextureHelper while holding a pending texture frame. The pending
170 * texture frame should still be valid, and this is tested by drawing the text ure frame to a pixel 248 * texture frame should still be valid, and this is tested by drawing the text ure frame to a pixel
171 * buffer and reading it back with glReadPixels(). 249 * buffer and reading it back with glReadPixels().
172 */ 250 */
173 @MediumTest 251 @MediumTest
174 public static void testLateReturnFrame() throws InterruptedException { 252 public static void testLateReturnFrame() throws InterruptedException {
175 final int width = 16; 253 final int width = 16;
176 final int height = 16; 254 final int height = 16;
177 // Create EGL base with a pixel buffer as display output. 255 // Create EGL base with a pixel buffer as display output.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 eglOesBase.release(); 423 eglOesBase.release();
346 424
347 // Wait for an OES texture to arrive. 425 // Wait for an OES texture to arrive.
348 listener.waitForNewFrame(); 426 listener.waitForNewFrame();
349 427
350 surfaceTextureHelper.disconnect(handler); 428 surfaceTextureHelper.disconnect(handler);
351 429
352 surfaceTextureHelper.returnTextureFrame(); 430 surfaceTextureHelper.returnTextureFrame();
353 } 431 }
354 } 432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698