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..b410a59da99e1beb35259487660d1f9d1003dc6c |
--- /dev/null |
+++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
@@ -0,0 +1,114 @@ |
+/* |
+ * 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 { |
kjellander_webrtc
2016/10/07 20:24:02
nit: add blank line
|
+ //private ArrayList<byte[]> frameDatas = new ArrayList<byte[]>(); |
kjellander_webrtc
2016/10/07 20:24:02
Remove commented code.
|
+ 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); |
+ } |
+ |
+ 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); |
+ } |
+ } |
+ |
+ char toHex(int x) { |
+ if (x >= 10) { |
+ return (char)((x-10) + (int)'A'); |
+ } |
+ return (char)(x + (int)'0'); |
+ } |
+ @SmallTest |
kjellander_webrtc
2016/10/07 20:24:02
nit: add blank line
|
+ public void testVideoCaptureFromFile() throws InterruptedException, IOException { |
+ FileVideoCapturer fileVideoCapturer = new FileVideoCapturer("/storage/emulated/0/reference_video_640x360_30fps_4frames.y4m"); |
kjellander_webrtc
2016/10/07 20:24:02
I think this should be either /sdcard/chromium_tes
|
+ MockCapturerObserver capturerObserver = new MockCapturerObserver(); |
+ fileVideoCapturer.initialize(null, null, capturerObserver); |
+ fileVideoCapturer.startCapture(4, 4, 33); |
+ Thread.sleep(1000); |
kjellander_webrtc
2016/10/07 20:24:02
Is there another way to implement this instead of
|
+ fileVideoCapturer.stopCapture(); |
+ |
+ String[] expectedFrames = { |
+ "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
+ "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
+ "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB", |
+ "EBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEBEBEBEBEBEBEBEBEBEBEBEBEEDD1E0D10101010101010100D1EDDEEEBEBEEDD1E0D10100D1EDDEEEBEBEB"}; |
+ |
+ // TODO use monitor to start verification when enough frames have been collected. |
+ ArrayList<Frame> frameDatas = capturerObserver.getFrames(); |
+ assertTrue(4 < frameDatas.size()); |
+ |
+ final int FRAME_WIDTH = 640; |
kjellander_webrtc
2016/10/07 20:24:02
move these constants up to line 77 so it's easier
|
+ final int FRAME_HEIGHT = 360; |
+ 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()); |
+ } |
+ } |
+} |