Chromium Code Reviews| 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 final int outputWidth = 64; | |
| 28 final 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 final int inputWidth = 32; | |
| 34 final int inputHeight = 32; | |
| 35 for (int frameIdx = 0; frameIdx < 4; frameIdx++) { | |
| 36 // Same seed everytime | |
| 37 Random random = new Random(frameIdx); | |
|
magjed_webrtc
2016/10/20 14:21:07
You only need to seed once. Please declare the Ran
mandermo
2016/10/24 17:37:20
Done.
| |
| 38 ByteBuffer[] yuvPlanes = new ByteBuffer[3]; | |
| 39 int inputFrameSize = inputWidth * inputHeight * 3 / 2; | |
| 40 int[] planeSizes = { | |
| 41 inputWidth * inputWidth, inputWidth * inputHeight / 4, inputWidth * in putHeight / 4}; | |
| 42 int[] yuvStrides = {inputWidth, inputWidth / 2, inputWidth / 2}; | |
|
magjed_webrtc
2016/10/20 14:21:07
Move this variable closer to where you use it.
mandermo
2016/10/24 17:37:20
Done.
| |
| 43 for (int i = 0; i < 3; i++) { | |
| 44 byte[] planeBytes = new byte[planeSizes[i]]; | |
|
magjed_webrtc
2016/10/20 14:21:08
You can write this whole for loop body simpler wit
mandermo
2016/10/24 17:37:20
Done.
| |
| 45 random.nextBytes(planeBytes); | |
| 46 ByteBuffer buffer = ByteBuffer.allocateDirect(inputFrameSize); | |
|
magjed_webrtc
2016/10/20 14:21:08
This should be planeSizes[i] instead of inputFrame
mandermo
2016/10/24 17:37:20
Done.
| |
| 47 buffer.put(planeBytes); | |
| 48 yuvPlanes[i] = buffer; | |
| 49 } | |
| 50 VideoRenderer.I420Frame frame = | |
| 51 new VideoRenderer.I420Frame(inputWidth, inputHeight, 0, yuvStrides, yu vPlanes, 0); | |
| 52 | |
| 53 videoFileRenderer.renderFrame(frame); | |
| 54 } | |
| 55 videoFileRenderer.release(); | |
| 56 | |
| 57 RandomAccessFile writtenFile = new RandomAccessFile(videoOutpath, "r"); | |
| 58 StringBuilder builder = new StringBuilder(); | |
| 59 // Same seed everytime | |
| 60 Random verificationRandom = new Random(0); | |
| 61 // The expected data at the pseudo randomly choosen positions | |
| 62 final String expectedData = "275E6B837FB545456E49A397DD139B68B84C9760806D798 063"; | |
|
magjed_webrtc
2016/10/20 14:21:07
What's this? Why isn't the expected data based on
mandermo
2016/10/24 17:37:20
Now it is re-designed and compares pixel by pixel.
| |
| 63 for (int i = 0; i < expectedData.length() / 2; i++) { | |
| 64 int pos = verificationRandom.nextInt((int) writtenFile.length()); | |
| 65 writtenFile.seek(pos); | |
| 66 builder.append(String.format("%02X", writtenFile.readByte())); | |
| 67 } | |
| 68 | |
| 69 assertEquals(expectedData, builder.toString()); | |
| 70 | |
| 71 writtenFile.seek(0); | |
| 72 builder = new StringBuilder(); | |
| 73 for (;;) { | |
|
magjed_webrtc
2016/10/20 14:41:03
It looks like you have implemented RandomAccessFil
mandermo
2016/10/24 17:37:20
Done.
| |
| 74 int c = writtenFile.read(); | |
| 75 if (c == -1) { | |
| 76 // End of file reached. | |
| 77 throw new RuntimeException("Found end of file before end of header for f ile"); | |
| 78 } | |
| 79 if (c == '\n') { | |
| 80 // End of header found. | |
| 81 break; | |
| 82 } | |
| 83 builder.append((char) c); | |
| 84 } | |
| 85 | |
| 86 // Assert that the header is correct | |
| 87 assertEquals("YUV4MPEG2 C420 W64 H64 Ip F30:1 A1:1", builder.toString()); | |
|
magjed_webrtc
2016/10/20 14:21:08
It feels more natural to check the header before c
mandermo
2016/10/24 17:37:20
Done.
| |
| 88 } | |
|
magjed_webrtc
2016/10/20 14:21:08
You need to clean up after the test and remove /sd
mandermo
2016/10/24 17:37:20
Done.
| |
| 89 } | |
| OLD | NEW |