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..e69c5ca8fecb5cbc9793a5ec0b9d005ec5c1a281 |
| --- /dev/null |
| +++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/FileVideoCapturerTest.java |
| @@ -0,0 +1,119 @@ |
| +/* |
| + * 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 { |
| + public byte[] data; |
| + public int width; |
| + public int height; |
| + } |
| + |
| + public class MockCapturerObserver implements VideoCapturer.CapturerObserver { |
| + private ArrayList<Frame> frameDatas = new ArrayList<Frame>(); |
|
magjed_webrtc
2016/10/20 14:55:33
Make this variable final.
mandermo
2016/10/24 18:08:02
Done.
|
| + |
| + public void onCapturerStarted(boolean success) { |
|
magjed_webrtc
2016/10/20 14:55:33
Annotate every function with @Override.
mandermo
2016/10/24 18:08:02
Done.
|
| + // Empty on purpose |
|
magjed_webrtc
2016/10/20 14:55:33
assertTrue on success
mandermo
2016/10/24 18:08:02
Done.
|
| + } |
| + |
| + public void onCapturerStopped() { |
| + // Empty on purpose |
|
magjed_webrtc
2016/10/20 14:55:33
Add a dot at the end of every sentence in comments
mandermo
2016/10/24 18:08:02
Done.
|
| + } |
| + |
| + 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) { |
|
magjed_webrtc
2016/10/20 14:55:33
This function is no longer part of the interface,
|
| + // 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 = 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); |
| + |
| + // The expected data at the pseudo randomly choosen positions |
| + String[] expectedFrames = { |
| + "7C543C7D7C6C86B31055787FA03F5CE7B0507D5AA42A7B5E867E4462977F99707F95", |
| + "CF864F7F7E6C416975871E687673857CA56B88DA7E6F4D991C62A4B7537B7D978E95", |
| + "918CA66F877DDE7473A8817E7F7C7E38807D7971E7977F6B877D417B7E7C808E408F", |
| + "597D8B4772436380A6388380B6AC7E869E58B46A7B78AB722E6C298B6C66A8678375"}; |
| + |
| + ArrayList<Frame> frameDatas; |
| + try { |
| + frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length); |
| + } catch (InterruptedException e) { |
| + throw new RuntimeException(e); |
| + } |
| + assertTrue(expectedFrames.length == frameDatas.size()); |
| + |
| + fileVideoCapturer.stopCapture(); |
| + fileVideoCapturer.dispose(); |
| + |
| + for (int i = 0; i < expectedFrames.length; ++i) { |
|
magjed_webrtc
2016/10/20 14:55:33
Since it's impossible to verify this manually anyw
mandermo
2016/10/24 18:08:02
Now use hashing approach. Using small file is also
magjed_webrtc
2016/10/25 08:02:47
Yes, a small file would be optimal. Can you do the
|
| + Frame frame = frameDatas.get(i); |
| + // Same seed everytime |
| + Random random = new Random(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()); |
| + } |
| + } |
| +} |