OLD | NEW |
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 wait(timeRemainingMs); | 90 wait(timeRemainingMs); |
91 final long elapsedTimeMs = SystemClock.elapsedRealtime() - startTimeMs; | 91 final long elapsedTimeMs = SystemClock.elapsedRealtime() - startTimeMs; |
92 timeRemainingMs = timeoutMs - elapsedTimeMs; | 92 timeRemainingMs = timeoutMs - elapsedTimeMs; |
93 } | 93 } |
94 final boolean didReceiveFrame = hasNewFrame; | 94 final boolean didReceiveFrame = hasNewFrame; |
95 hasNewFrame = false; | 95 hasNewFrame = false; |
96 return didReceiveFrame; | 96 return didReceiveFrame; |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
| 100 /** Assert that two integers are close, with difference at most |
| 101 * {@code threshold}. */ |
| 102 public static void assertClose(int threshold, int expected, int actual) { |
| 103 if (Math.abs(expected - actual) <= threshold) |
| 104 return; |
| 105 failNotEquals("Not close enough, threshold " + threshold, expected, actual); |
| 106 } |
| 107 |
100 /** | 108 /** |
101 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early | 109 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early |
102 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel | 110 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel |
103 * buffer and reading it back with glReadPixels(). | 111 * buffer and reading it back with glReadPixels(). |
104 */ | 112 */ |
105 @MediumTest | 113 @MediumTest |
106 public static void testThreeConstantColorFrames() throws InterruptedException
{ | 114 public static void testThreeConstantColorFrames() throws InterruptedException
{ |
107 final int width = 16; | 115 final int width = 16; |
108 final int height = 16; | 116 final int height = 16; |
109 // Create EGL base with a pixel buffer as display output. | 117 // Create EGL base with a pixel buffer as display output. |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 eglOesBase.swapBuffers(); | 352 eglOesBase.swapBuffers(); |
345 eglOesBase.release(); | 353 eglOesBase.release(); |
346 | 354 |
347 // Wait for an OES texture to arrive. | 355 // Wait for an OES texture to arrive. |
348 listener.waitForNewFrame(); | 356 listener.waitForNewFrame(); |
349 | 357 |
350 surfaceTextureHelper.disconnect(handler); | 358 surfaceTextureHelper.disconnect(handler); |
351 | 359 |
352 surfaceTextureHelper.returnTextureFrame(); | 360 surfaceTextureHelper.returnTextureFrame(); |
353 } | 361 } |
| 362 |
| 363 @MediumTest |
| 364 public static void testTexturetoYUV() throws InterruptedException { |
| 365 final int width = 16; |
| 366 final int height = 16; |
| 367 |
| 368 final EglBase eglBase = EglBase.create(null, EglBase.CONFIG_PLAIN); |
| 369 |
| 370 // Create SurfaceTextureHelper and listener. |
| 371 final SurfaceTextureHelper surfaceTextureHelper = |
| 372 SurfaceTextureHelper.create(eglBase.getEglBaseContext()); |
| 373 final MockTextureListener listener = new MockTextureListener(); |
| 374 surfaceTextureHelper.setListener(listener); |
| 375 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; |
| 376 |
| 377 // Create resources for stubbing an OES texture producer. |eglBase| has the
SurfaceTexture in |
| 378 // |surfaceTextureHelper| as the target EGLSurface. |
| 379 |
| 380 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
| 381 assertEquals(eglBase.surfaceWidth(), width); |
| 382 assertEquals(eglBase.surfaceHeight(), height); |
| 383 |
| 384 final int red[] = new int[] {79, 144, 185}; |
| 385 final int green[] = new int[] {66, 210, 162}; |
| 386 final int blue[] = new int[] {161, 117, 158}; |
| 387 |
| 388 final int ref_y[] = new int[] {81, 180, 168}; |
| 389 final int ref_u[] = new int[] {173, 93, 122}; |
| 390 final int ref_v[] = new int[] {127, 103, 140}; |
| 391 |
| 392 // Draw three frames. |
| 393 for (int i = 0; i < 3; ++i) { |
| 394 // Draw a constant color frame onto the SurfaceTexture. |
| 395 eglBase.makeCurrent(); |
| 396 GLES20.glClearColor(red[i] / 255.0f, green[i] / 255.0f, blue[i] / 255.0f,
1.0f); |
| 397 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
| 398 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
| 399 eglBase.swapBuffers(); |
| 400 |
| 401 // Wait for an OES texture to arrive. |
| 402 listener.waitForNewFrame(); |
| 403 |
| 404 // Memory layout: Lines are 16 bytes. First 16 lines are |
| 405 // the Y data. These are followed by 8 lines with 8 bytes of U |
| 406 // data on the left and 8 bytes of V data on the right. |
| 407 // |
| 408 // Offset |
| 409 // 0 YYYYYYYY YYYYYYYY |
| 410 // 16 YYYYYYYY YYYYYYYY |
| 411 // ... |
| 412 // 240 YYYYYYYY YYYYYYYY |
| 413 // 256 UUUUUUUU VVVVVVVV |
| 414 // 272 UUUUUUUU VVVVVVVV |
| 415 // ... |
| 416 // 368 UUUUUUUU VVVVVVVV |
| 417 // 384 buffer end |
| 418 ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 3 / 2); |
| 419 surfaceTextureHelper.textureToYUV(buffer, width, height, width, |
| 420 listener.oesTextureId, listener.transformMatrix); |
| 421 |
| 422 surfaceTextureHelper.returnTextureFrame(); |
| 423 |
| 424 // Allow off-by-one differences due to different rounding. |
| 425 while (buffer.position() < width*height) { |
| 426 assertClose(1, buffer.get() & 0xff, ref_y[i]); |
| 427 } |
| 428 while (buffer.hasRemaining()) { |
| 429 if (buffer.position() % width < width/2) |
| 430 assertClose(1, buffer.get() & 0xff, ref_u[i]); |
| 431 else |
| 432 assertClose(1, buffer.get() & 0xff, ref_v[i]); |
| 433 } |
| 434 } |
| 435 |
| 436 surfaceTextureHelper.disconnect(); |
| 437 eglBase.release(); |
| 438 } |
354 } | 439 } |
OLD | NEW |