Index: webrtc/examples/androidtests/src/org/appspot/apprtc/test/VideoFileRendererTest.java |
diff --git a/webrtc/examples/androidtests/src/org/appspot/apprtc/test/VideoFileRendererTest.java b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/VideoFileRendererTest.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..be0c2e234d930c1bf2f394602bac4d872975b4e1 |
--- /dev/null |
+++ b/webrtc/examples/androidtests/src/org/appspot/apprtc/test/VideoFileRendererTest.java |
@@ -0,0 +1,68 @@ |
+/* |
+ * 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.webrtc; |
+ |
+import android.test.InstrumentationTestCase; |
+import android.test.suitebuilder.annotation.SmallTest; |
+ |
+import java.io.IOException; |
+import java.io.RandomAccessFile; |
+import java.lang.Thread; |
+import java.nio.ByteBuffer; |
+import java.util.ArrayList; |
+import java.util.Random; |
+ |
+public class VideoFileRendererTest extends InstrumentationTestCase { |
+ @SmallTest |
+ public void testYuvRenderingToFile() throws InterruptedException, IOException { |
+ EglBase eglBase = EglBase.create(); |
+ int outputWidth = 64; |
+ int outputHeight = 64; |
+ final String videoOutpath = "/sdcard/chromium_tests_root/testvideoout.y4m"; |
+ VideoFileRenderer videoFileRenderer = |
+ new VideoFileRenderer(videoOutpath, outputWidth, outputHeight, eglBase.getEglBaseContext()); |
+ |
+ int inputWidth = 32; |
kjellander_webrtc
2016/10/13 14:25:12
Why is input width different than output? It seems
mandermo
2016/10/19 16:38:42
There is no separate code paths for scaling, so th
|
+ int inputHeight = 32; |
+ for (int frameIdx = 0; frameIdx < 4; frameIdx++) { |
+ Random random = new Random(frameIdx * 42); |
kjellander_webrtc
2016/10/13 14:25:12
Where does 42 come from?
mandermo
2016/10/19 16:38:42
Cleaned up and commented.
|
+ ByteBuffer[] yuvPlanes = new ByteBuffer[3]; |
+ int inputFrameSize = inputWidth * inputHeight * 3 / 2; |
+ int[] planeSizes = { |
+ inputWidth * inputWidth, inputWidth * inputHeight / 4, inputWidth * inputHeight / 4}; |
+ int[] yuvStrides = {inputWidth, inputWidth / 2, inputWidth / 2}; |
+ for (int i = 0; i < 3; i++) { |
+ byte[] planeBytes = new byte[planeSizes[i]]; |
+ random.nextBytes(planeBytes); |
+ ByteBuffer buffer = ByteBuffer.allocateDirect(inputFrameSize); |
+ buffer.put(planeBytes); |
+ yuvPlanes[i] = buffer; |
+ } |
+ VideoRenderer.I420Frame frame = |
+ new VideoRenderer.I420Frame(inputWidth, inputHeight, 0, yuvStrides, yuvPlanes, 0); |
+ |
+ videoFileRenderer.renderFrame(frame); |
+ } |
+ videoFileRenderer.release(); |
+ |
+ RandomAccessFile writtenFile = new RandomAccessFile(videoOutpath, "r"); |
+ StringBuilder builder = new StringBuilder(); |
+ Random verificationRandom = new Random(23423); |
kjellander_webrtc
2016/10/13 14:25:12
Please explain where this number comes from and/or
mandermo
2016/10/19 16:38:42
Made it cleaner and commented.
|
+ String expectedData = "A5CC23AF39B91850A58176866D597446A49A9BA2C29F65B87B"; |
kjellander_webrtc
2016/10/13 14:25:12
Same here.
mandermo
2016/10/19 16:38:42
Done.
|
+ for (int i = 0; i < expectedData.length() / 2; i++) { |
+ int pos = verificationRandom.nextInt((int) writtenFile.length()); |
+ writtenFile.seek(pos); |
+ builder.append(String.format("%02X", writtenFile.readByte())); |
+ } |
+ |
+ assertEquals(expectedData, builder.toString()); |
+ } |
+} |