Chromium Code Reviews| Index: webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
| diff --git a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d2648b01808cc9b93f048800cb1a0618d0fe2b3a |
| --- /dev/null |
| +++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
| @@ -0,0 +1,122 @@ |
| +/* |
| + * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +package org.appspot.apprtc.test; |
| + |
| +import android.test.InstrumentationTestCase; |
| +import android.test.suitebuilder.annotation.LargeTest; |
| +import android.test.suitebuilder.annotation.MediumTest; |
| +import android.test.suitebuilder.annotation.SmallTest; |
| + |
| +import org.webrtc.FileVideoCapturer; |
| +import org.webrtc.VideoCapturer; |
| + |
| +import java.io.IOException; |
| +import java.lang.Thread; |
| +import java.util.ArrayList; |
| +import java.util.Random; |
| + |
| +public class FileVideoCapturerTest extends InstrumentationTestCase { |
| + private static class Frame { |
| + byte[] data; |
| + int width; |
| + int height; |
| + } |
| + |
| + public class MockCapturerObserver implements VideoCapturer.CapturerObserver { |
| + private ArrayList<Frame> frameDatas = new ArrayList<Frame>(); |
| + |
| + public void onCapturerStarted(boolean success) { |
| + // Empty on purpose |
| + } |
| + |
| + public void onCapturerStopped() { |
| + // Empty on purpose |
| + } |
| + |
| + public synchronized void onByteBufferFrameCaptured(byte[] data, int width, int height, int rotation, |
| + long timeStamp) { |
| + Frame frame = new Frame(); |
| + frame.data = data; |
| + frame.width = width; |
| + frame.height = height; |
| + assertTrue(data.length != 0); |
| + frameDatas.add(frame); |
| + notify(); |
| + } |
| + |
| + public void onTextureFrameCaptured( |
| + int width, int height, int oesTextureId, float[] transformMatrix, int rotation, |
| + long timestamp) { |
| + // Empty on purpose |
| + } |
| + |
| + public void onOutputFormatRequest(int width, int height, int framerate) { |
| + // Empty on purpose |
| + } |
| + |
| + public synchronized ArrayList<Frame> getFrames() { |
| + return new ArrayList<Frame>(frameDatas); |
| + } |
| + |
| + public synchronized ArrayList<Frame> getMinimunFramesBlocking( |
|
kjellander_webrtc
2016/10/12 01:00:23
getMinimunFramesBlocking -> getMinimumFramesBlocki
|
| + int minFrames) throws InterruptedException { |
| + while (frameDatas.size() < minFrames) { |
| + wait(); |
| + } |
| + return new ArrayList<Frame>(frameDatas); |
| + } |
| + } |
| + |
| + @SmallTest |
| + public void testVideoCaptureFromFile() throws InterruptedException, IOException { |
| + final int FRAME_WIDTH = 640; |
| + final int FRAME_HEIGHT = 360; |
| + FileVideoCapturer fileVideoCapturer = new FileVideoCapturer("/storage/emulated/0/reference_video_640x360_30fps_4frames.y4m"); |
| + MockCapturerObserver capturerObserver = new MockCapturerObserver(); |
| + fileVideoCapturer.initialize(null, null, capturerObserver); |
| + fileVideoCapturer.startCapture(4, 4, 33); |
| + |
| + String[] expectedFrames = { |
| + "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
| + "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
| + "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
| + "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB"}; |
| + |
| + ArrayList<Frame> frameDatas; |
| + try { |
| + frameDatas = capturerObserver.getMinimunFramesBlocking(expectedFrames.length); |
| + } |
| + catch (InterruptedException e) { |
|
kjellander_webrtc
2016/10/12 01:00:23
move to line above, e.g.
} catch (InterruptedExcep
|
| + throw new RuntimeException(e); |
| + } |
| + assertTrue(expectedFrames.length <= frameDatas.size()); |
| + |
| + fileVideoCapturer.stopCapture(); |
| + |
| + for (int i=0; i<expectedFrames.length; ++i) { |
| + Frame frame = frameDatas.get(i); |
| + Random random = new Random(42*i); |
| + |
| + assertEquals(FRAME_WIDTH, frame.width); |
| + assertEquals(FRAME_HEIGHT, frame.height); |
| + assertEquals(FRAME_WIDTH * FRAME_HEIGHT * 3 / 2, frame.data.length); |
| + |
| + StringBuilder b = new StringBuilder(); |
| + for (int k = 0; k < expectedFrames[i].length() / 2; ++k) { |
| + int pos = random.nextInt(frame.data.length); |
| + int v = frame.data[pos] & 0xFF; |
| + b.append(String.format("%02X", frame.data[k])); |
| + } |
| + |
| + assertEquals(expectedFrames[i], b.toString()); |
| + } |
| + } |
| +} |