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..2d54a5cb1f0971e7ce8611a09f8fc0ae0e5ce0cf |
--- /dev/null |
+++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
@@ -0,0 +1,109 @@ |
+/* |
+ * 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; |
+ |
+public class FileVideoCapturerTest extends InstrumentationTestCase { |
+ private static class Frame { |
+ public byte[] data; |
+ public int width; |
+ public int height; |
+ } |
+ |
+ public class MockCapturerObserver implements VideoCapturer.CapturerObserver { |
+ private final ArrayList<Frame> frameDatas = new ArrayList<Frame>(); |
+ |
+ @Override |
+ public void onCapturerStarted(boolean success) { |
+ assertTrue(success); |
+ } |
+ |
+ @Override |
+ public void onCapturerStopped() { |
+ // Empty on purpose. |
+ } |
+ |
+ @Override |
+ 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(); |
+ } |
+ |
+ @Override |
+ public void onTextureFrameCaptured(int width, int height, int oesTextureId, |
+ float[] transformMatrix, int rotation, long timestamp) { |
+ // Empty on purpose. |
+ } |
+ |
+ 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 = 4; |
+ final int FRAME_HEIGHT = 4; |
+ final FileVideoCapturer fileVideoCapturer = new FileVideoCapturer( |
+ "/sdcard/chromium_tests_root/webrtc/examples/androidtests/src/org/appspot/apprtc/test/capturetestvideo.y4m"); |
+ final MockCapturerObserver capturerObserver = new MockCapturerObserver(); |
+ fileVideoCapturer.initialize(null, null, capturerObserver); |
+ fileVideoCapturer.startCapture(FRAME_WIDTH, FRAME_HEIGHT, 33); |
+ |
+ final String[] expectedFrames = {"54484953204953204A55535420534F4D5845542020547845", |
+ "544845205345434F4E44204652414D457220747179772E65", |
+ "4845524520495320544845205448524941444D2045462152"}; |
+ |
+ final ArrayList<Frame> frameDatas; |
+ frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length); |
+ |
+ assertTrue(expectedFrames.length == frameDatas.size()); |
magjed_webrtc
2016/10/26 11:20:00
nit: Use assertEquals instead
|
+ |
+ fileVideoCapturer.stopCapture(); |
+ fileVideoCapturer.dispose(); |
+ |
+ for (int i = 0; i < expectedFrames.length; ++i) { |
+ Frame frame = frameDatas.get(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 (byte b : frame.data) { |
+ builder.append(String.format("%02X", b)); |
+ } |
+ |
+ assertEquals(expectedFrames[i], builder.toString()); |
+ } |
+ } |
+} |