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, |
11 * this list of conditions and the following disclaimer in the documentation | 11 * this list of conditions and the following disclaimer in the documentation |
12 * and/or other materials provided with the distribution. | 12 * and/or other materials provided with the distribution. |
13 * 3. The name of the author may not be used to endorse or promote products | 13 * 3. The name of the author may not be used to endorse or promote products |
14 * derived from this software without specific prior written permission. | 14 * derived from this software without specific prior written permission. |
15 * | 15 * |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
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.test.ActivityTestCase; | |
30 import android.test.suitebuilder.annotation.MediumTest; | |
31 import android.test.suitebuilder.annotation.SmallTest; | |
32 import android.graphics.SurfaceTexture; | 29 import android.graphics.SurfaceTexture; |
33 import android.opengl.EGL14; | |
34 import android.opengl.GLES20; | 30 import android.opengl.GLES20; |
35 import android.os.Handler; | 31 import android.os.Handler; |
36 import android.os.HandlerThread; | 32 import android.os.HandlerThread; |
37 import android.os.SystemClock; | 33 import android.os.SystemClock; |
| 34 import android.test.ActivityTestCase; |
| 35 import android.test.suitebuilder.annotation.MediumTest; |
| 36 import android.test.suitebuilder.annotation.SmallTest; |
38 | 37 |
39 import java.nio.ByteBuffer; | 38 import java.nio.ByteBuffer; |
40 | 39 |
| 40 import javax.microedition.khronos.egl.EGL10; |
| 41 |
41 public final class SurfaceTextureHelperTest extends ActivityTestCase { | 42 public final class SurfaceTextureHelperTest extends ActivityTestCase { |
42 /** | 43 /** |
43 * Mock texture listener with blocking wait functionality. | 44 * Mock texture listener with blocking wait functionality. |
44 */ | 45 */ |
45 public static final class MockTextureListener | 46 public static final class MockTextureListener |
46 implements SurfaceTextureHelper.OnTextureFrameAvailableListener { | 47 implements SurfaceTextureHelper.OnTextureFrameAvailableListener { |
47 public int oesTextureId; | 48 public int oesTextureId; |
48 public float[] transformMatrix; | 49 public float[] transformMatrix; |
49 private boolean hasNewFrame = false; | 50 private boolean hasNewFrame = false; |
50 // Thread where frames are expected to be received on. | 51 // Thread where frames are expected to be received on. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 /** | 102 /** |
102 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early | 103 * Test normal use by receiving three uniform texture frames. Texture frames a
re returned as early |
103 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel | 104 * as possible. The texture pixel values are inspected by drawing the texture
frame to a pixel |
104 * buffer and reading it back with glReadPixels(). | 105 * buffer and reading it back with glReadPixels(). |
105 */ | 106 */ |
106 @MediumTest | 107 @MediumTest |
107 public static void testThreeConstantColorFrames() throws InterruptedException
{ | 108 public static void testThreeConstantColorFrames() throws InterruptedException
{ |
108 final int width = 16; | 109 final int width = 16; |
109 final int height = 16; | 110 final int height = 16; |
110 // Create EGL base with a pixel buffer as display output. | 111 // Create EGL base with a pixel buffer as display output. |
111 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 112 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); |
112 eglBase.createPbufferSurface(width, height); | 113 eglBase.createPbufferSurface(width, height); |
113 final GlRectDrawer drawer = new GlRectDrawer(); | 114 final GlRectDrawer drawer = new GlRectDrawer(); |
114 | 115 |
115 // Create SurfaceTextureHelper and listener. | 116 // Create SurfaceTextureHelper and listener. |
116 final SurfaceTextureHelper surfaceTextureHelper = | 117 final SurfaceTextureHelper surfaceTextureHelper = |
117 SurfaceTextureHelper.create(eglBase.getContext()); | 118 SurfaceTextureHelper.create(eglBase.getContext()); |
118 final MockTextureListener listener = new MockTextureListener(); | 119 final MockTextureListener listener = new MockTextureListener(); |
119 surfaceTextureHelper.setListener(listener); | 120 surfaceTextureHelper.setListener(listener); |
120 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; | 121 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; |
121 | 122 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 /** | 169 /** |
169 * Test disconnecting the SurfaceTextureHelper while holding a pending texture
frame. The pending | 170 * 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 | 171 * 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(). | 172 * buffer and reading it back with glReadPixels(). |
172 */ | 173 */ |
173 @MediumTest | 174 @MediumTest |
174 public static void testLateReturnFrame() throws InterruptedException { | 175 public static void testLateReturnFrame() throws InterruptedException { |
175 final int width = 16; | 176 final int width = 16; |
176 final int height = 16; | 177 final int height = 16; |
177 // Create EGL base with a pixel buffer as display output. | 178 // Create EGL base with a pixel buffer as display output. |
178 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); | 179 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PIXEL_BUFFER); |
179 eglBase.createPbufferSurface(width, height); | 180 eglBase.createPbufferSurface(width, height); |
180 | 181 |
181 // Create SurfaceTextureHelper and listener. | 182 // Create SurfaceTextureHelper and listener. |
182 final SurfaceTextureHelper surfaceTextureHelper = | 183 final SurfaceTextureHelper surfaceTextureHelper = |
183 SurfaceTextureHelper.create(eglBase.getContext()); | 184 SurfaceTextureHelper.create(eglBase.getContext()); |
184 final MockTextureListener listener = new MockTextureListener(); | 185 final MockTextureListener listener = new MockTextureListener(); |
185 surfaceTextureHelper.setListener(listener); | 186 surfaceTextureHelper.setListener(listener); |
186 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; | 187 surfaceTextureHelper.getSurfaceTexture().setDefaultBufferSize(width, height)
; |
187 | 188 |
188 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in | 189 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he SurfaceTexture in |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 } | 233 } |
233 | 234 |
234 /** | 235 /** |
235 * Test disconnecting the SurfaceTextureHelper, but keep trying to produce mor
e texture frames. No | 236 * Test disconnecting the SurfaceTextureHelper, but keep trying to produce mor
e texture frames. No |
236 * frames should be delivered to the listener. | 237 * frames should be delivered to the listener. |
237 */ | 238 */ |
238 @MediumTest | 239 @MediumTest |
239 public static void testDisconnect() throws InterruptedException { | 240 public static void testDisconnect() throws InterruptedException { |
240 // Create SurfaceTextureHelper and listener. | 241 // Create SurfaceTextureHelper and listener. |
241 final SurfaceTextureHelper surfaceTextureHelper = | 242 final SurfaceTextureHelper surfaceTextureHelper = |
242 SurfaceTextureHelper.create(EGL14.EGL_NO_CONTEXT); | 243 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT); |
243 final MockTextureListener listener = new MockTextureListener(); | 244 final MockTextureListener listener = new MockTextureListener(); |
244 surfaceTextureHelper.setListener(listener); | 245 surfaceTextureHelper.setListener(listener); |
245 // Create EglBase with the SurfaceTexture as target EGLSurface. | 246 // Create EglBase with the SurfaceTexture as target EGLSurface. |
246 final EglBase eglBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigType
.PLAIN); | 247 final EglBase eglBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigType
.PLAIN); |
247 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 248 eglBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
248 eglBase.makeCurrent(); | 249 eglBase.makeCurrent(); |
249 // Assert no frame has been received yet. | 250 // Assert no frame has been received yet. |
250 assertFalse(listener.waitForNewFrame(1)); | 251 assertFalse(listener.waitForNewFrame(1)); |
251 // Draw and wait for one frame. | 252 // Draw and wait for one frame. |
252 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 253 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
253 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). | 254 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
254 eglBase.swapBuffers(); | 255 eglBase.swapBuffers(); |
255 listener.waitForNewFrame(); | 256 listener.waitForNewFrame(); |
256 surfaceTextureHelper.returnTextureFrame(); | 257 surfaceTextureHelper.returnTextureFrame(); |
(...skipping 11 matching lines...) Expand all Loading... |
268 eglBase.release(); | 269 eglBase.release(); |
269 } | 270 } |
270 | 271 |
271 /** | 272 /** |
272 * Test disconnecting the SurfaceTextureHelper immediately after is has been s
etup to use a | 273 * Test disconnecting the SurfaceTextureHelper immediately after is has been s
etup to use a |
273 * shared context. No frames should be delivered to the listener. | 274 * shared context. No frames should be delivered to the listener. |
274 */ | 275 */ |
275 @SmallTest | 276 @SmallTest |
276 public static void testDisconnectImmediately() { | 277 public static void testDisconnectImmediately() { |
277 final SurfaceTextureHelper surfaceTextureHelper = | 278 final SurfaceTextureHelper surfaceTextureHelper = |
278 SurfaceTextureHelper.create(EGL14.EGL_NO_CONTEXT); | 279 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT); |
279 surfaceTextureHelper.disconnect(); | 280 surfaceTextureHelper.disconnect(); |
280 } | 281 } |
281 | 282 |
282 /** | 283 /** |
283 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and | 284 * Test use SurfaceTextureHelper on a separate thread. A uniform texture frame
is created and |
284 * received on a thread separate from the test thread. | 285 * received on a thread separate from the test thread. |
285 */ | 286 */ |
286 @MediumTest | 287 @MediumTest |
287 public static void testFrameOnSeparateThread() throws InterruptedException { | 288 public static void testFrameOnSeparateThread() throws InterruptedException { |
288 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); | 289 final HandlerThread thread = new HandlerThread("SurfaceTextureHelperTestThre
ad"); |
289 thread.start(); | 290 thread.start(); |
290 final Handler handler = new Handler(thread.getLooper()); | 291 final Handler handler = new Handler(thread.getLooper()); |
291 | 292 |
292 // Create SurfaceTextureHelper and listener. | 293 // Create SurfaceTextureHelper and listener. |
293 final SurfaceTextureHelper surfaceTextureHelper = | 294 final SurfaceTextureHelper surfaceTextureHelper = |
294 SurfaceTextureHelper.create(EGL14.EGL_NO_CONTEXT, handler); | 295 SurfaceTextureHelper.create(EGL10.EGL_NO_CONTEXT, handler); |
295 // Create a mock listener and expect frames to be delivered on |thread|. | 296 // Create a mock listener and expect frames to be delivered on |thread|. |
296 final MockTextureListener listener = new MockTextureListener(thread); | 297 final MockTextureListener listener = new MockTextureListener(thread); |
297 surfaceTextureHelper.setListener(listener); | 298 surfaceTextureHelper.setListener(listener); |
298 | 299 |
299 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he | 300 // Create resources for stubbing an OES texture producer. |eglOesBase| has t
he |
300 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. | 301 // SurfaceTexture in |surfaceTextureHelper| as the target EGLSurface. |
301 final EglBase eglOesBase = new EglBase(EGL14.EGL_NO_CONTEXT, EglBase.ConfigT
ype.PLAIN); | 302 final EglBase eglOesBase = new EglBase(EGL10.EGL_NO_CONTEXT, EglBase.ConfigT
ype.PLAIN); |
302 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); | 303 eglOesBase.createSurface(surfaceTextureHelper.getSurfaceTexture()); |
303 eglOesBase.makeCurrent(); | 304 eglOesBase.makeCurrent(); |
304 // Draw a frame onto the SurfaceTexture. | 305 // Draw a frame onto the SurfaceTexture. |
305 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 306 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
306 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). | 307 // swapBuffers() will ultimately trigger onTextureFrameAvailable(). |
307 eglOesBase.swapBuffers(); | 308 eglOesBase.swapBuffers(); |
308 eglOesBase.release(); | 309 eglOesBase.release(); |
309 | 310 |
310 // Wait for an OES texture to arrive. | 311 // Wait for an OES texture to arrive. |
311 listener.waitForNewFrame(); | 312 listener.waitForNewFrame(); |
312 | 313 |
313 // Return the frame from this thread. | 314 // Return the frame from this thread. |
314 surfaceTextureHelper.returnTextureFrame(); | 315 surfaceTextureHelper.returnTextureFrame(); |
315 surfaceTextureHelper.disconnect(); | 316 surfaceTextureHelper.disconnect(); |
316 thread.quitSafely(); | 317 thread.quitSafely(); |
317 } | 318 } |
318 } | 319 } |
OLD | NEW |