OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 package org.webrtc; | |
12 | |
13 import android.test.InstrumentationTestCase; | |
14 import android.test.suitebuilder.annotation.SmallTest; | |
15 | |
16 import java.io.IOException; | |
17 import java.io.RandomAccessFile; | |
18 import java.lang.Thread; | |
19 import java.nio.ByteBuffer; | |
20 import java.util.ArrayList; | |
21 import java.util.Random; | |
22 | |
23 public class VideoFileRendererTest extends InstrumentationTestCase { | |
24 @SmallTest | |
25 public void testYuvRenderingToFile() throws InterruptedException, IOException { | |
26 EglBase eglBase = EglBase.create(); | |
27 int outputWidth = 64; | |
28 int outputHeight = 64; | |
29 final String videoOutpath = "/sdcard/chromium_tests_root/testvideoout.y4m"; | |
30 VideoFileRenderer videoFileRenderer = | |
31 new VideoFileRenderer(videoOutpath, outputWidth, outputHeight, eglBase.g etEglBaseContext()); | |
32 | |
33 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
| |
34 int inputHeight = 32; | |
35 for (int frameIdx = 0; frameIdx < 4; frameIdx++) { | |
36 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.
| |
37 ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | |
38 int inputFrameSize = inputWidth * inputHeight * 3 / 2; | |
39 int[] planeSizes = { | |
40 inputWidth * inputWidth, inputWidth * inputHeight / 4, inputWidth * in putHeight / 4}; | |
41 int[] yuvStrides = {inputWidth, inputWidth / 2, inputWidth / 2}; | |
42 for (int i = 0; i < 3; i++) { | |
43 byte[] planeBytes = new byte[planeSizes[i]]; | |
44 random.nextBytes(planeBytes); | |
45 ByteBuffer buffer = ByteBuffer.allocateDirect(inputFrameSize); | |
46 buffer.put(planeBytes); | |
47 yuvPlanes[i] = buffer; | |
48 } | |
49 VideoRenderer.I420Frame frame = | |
50 new VideoRenderer.I420Frame(inputWidth, inputHeight, 0, yuvStrides, yu vPlanes, 0); | |
51 | |
52 videoFileRenderer.renderFrame(frame); | |
53 } | |
54 videoFileRenderer.release(); | |
55 | |
56 RandomAccessFile writtenFile = new RandomAccessFile(videoOutpath, "r"); | |
57 StringBuilder builder = new StringBuilder(); | |
58 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.
| |
59 String expectedData = "A5CC23AF39B91850A58176866D597446A49A9BA2C29F65B87B"; | |
kjellander_webrtc
2016/10/13 14:25:12
Same here.
mandermo
2016/10/19 16:38:42
Done.
| |
60 for (int i = 0; i < expectedData.length() / 2; i++) { | |
61 int pos = verificationRandom.nextInt((int) writtenFile.length()); | |
62 writtenFile.seek(pos); | |
63 builder.append(String.format("%02X", writtenFile.readByte())); | |
64 } | |
65 | |
66 assertEquals(expectedData, builder.toString()); | |
67 } | |
68 } | |
OLD | NEW |