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..56015077c7c92abe52555ae1301e2591f84ced3f |
--- /dev/null |
+++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
@@ -0,0 +1,120 @@ |
+/* |
+ * 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 { |
sakal
2016/10/19 10:59:32
Have you looked into if it possible to make this a
mandermo
2016/10/19 17:02:03
The problem is that native code is used by FileVid
|
+ private static class Frame { |
+ byte[] data; |
sakal
2016/10/19 10:59:32
nit: make these public
mandermo
2016/10/19 17:02:03
Done.
|
+ 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() { |
sakal
2016/10/19 10:59:32
This is never actually used, please remove.
mandermo
2016/10/19 17:02:03
Done.
|
+ return new ArrayList<Frame>(frameDatas); |
+ } |
+ |
+ public synchronized ArrayList<Frame> getMinimumFramesBlocking(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( |
+ "/sdcard/chromium_tests_root/resources/reference_video_640x360_30fps_4frames.y4m"); |
+ MockCapturerObserver capturerObserver = new MockCapturerObserver(); |
+ fileVideoCapturer.initialize(null, null, capturerObserver); |
+ fileVideoCapturer.startCapture(4, 4, 33); |
+ |
+ String[] expectedFrames = { |
+ "7C543C7D7C6C86B31055787FA03F5CE7B0507D5AA42A7B5E867E4462977F99707F958DADA67F7D7B8F6B5535939BA98F2C307D73757C7A4A7A44897DEA84A37A7C647F7F7C6677B37AB71E9C7C5775497D986C49C2398D80827EDE707D7F876988782D72", |
+ "86808A91829B8042762FA4EB8B3BA17480597F2E91A9657F7F7FA1697CED8087DB79865D6A6F32EA332D7E8072876F7676757B7DE07D7E7F83947874702132AF717E25777339A4816D727D3D80CB5C7987967F38467D745932445526807F7C7F7290B29B", |
+ "6D4A4F7F52847760358C71EB7F42AB789B6E3E6E35679A437E473E407F4677A87B5F8F5092447F82837F7E727980763D857D217E368982837F4661C8807B76A2AF7A91733B847D7DEBBC80466F816E80B35976738F7C4355877680EE431F0D7DA223807E", |
+ "7FCE8B938B4B88847F227D29909E8F837EC3525C3D807E91738E8A733D36885326743A808680B47E57804AAB72413824776A367628EB784F3A7DD8EB7A6731935E95685B7C408081A7EB7DE4528D9A1F9195892E7D457880887A308C8C106A91D38F7E7E"}; |
+ |
+ ArrayList<Frame> frameDatas; |
+ try { |
+ frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length); |
+ } catch (InterruptedException e) { |
+ 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 builder = new StringBuilder(); |
+ for (int k = 0; k < expectedFrames[i].length() / 2; ++k) { |
+ int pos = random.nextInt(frame.data.length); |
+ builder.append(String.format("%02X", frame.data[pos])); |
+ } |
+ |
+ assertEquals(expectedFrames[i], builder.toString()); |
+ } |
+ } |
+} |