Move file capturer/renderer tests to the correct location.
Move file capturer/renderer tests from the AppRTCMobile tests directory to the WebRTC tests directory. These tests do not test AppRTCMobile but rather WebRTC functionality. Therefore, they belong in WebRTC tests directory. BUG=webrtc:6545 Review-Url: https://codereview.webrtc.org/2632233002 Cr-Commit-Position: refs/heads/master@{#16115}
This commit is contained in:
@ -1,117 +0,0 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.support.test.filters.LargeTest;
|
||||
import android.support.test.filters.MediumTest;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import java.io.IOException;
|
||||
import java.lang.Thread;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import org.chromium.base.test.BaseJUnit4ClassRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.webrtc.FileVideoCapturer;
|
||||
import org.webrtc.VideoCapturer;
|
||||
|
||||
@RunWith(BaseJUnit4ClassRunner.class)
|
||||
public class FileVideoCapturerTest {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testVideoCaptureFromFile() throws InterruptedException, IOException {
|
||||
final int FRAME_WIDTH = 4;
|
||||
final int FRAME_HEIGHT = 4;
|
||||
final FileVideoCapturer fileVideoCapturer =
|
||||
new FileVideoCapturer(Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/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 = {
|
||||
"THIS IS JUST SOME TEXT x", "THE SECOND FRAME qwerty.", "HERE IS THE THRID FRAME!"};
|
||||
|
||||
final ArrayList<Frame> frameDatas;
|
||||
frameDatas = capturerObserver.getMinimumFramesBlocking(expectedFrames.length);
|
||||
|
||||
assertEquals(expectedFrames.length, frameDatas.size());
|
||||
|
||||
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);
|
||||
|
||||
byte[] expectedNV12Bytes = new byte[frame.data.length];
|
||||
FileVideoCapturer.nativeI420ToNV21(expectedFrames[i].getBytes(StandardCharsets.US_ASCII),
|
||||
FRAME_WIDTH, FRAME_HEIGHT, expectedNV12Bytes);
|
||||
|
||||
assertTrue(Arrays.equals(expectedNV12Bytes, frame.data));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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 static org.junit.Assert.assertEquals;
|
||||
|
||||
import android.os.Environment;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.lang.Thread;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import org.chromium.base.test.BaseJUnit4ClassRunner;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(BaseJUnit4ClassRunner.class)
|
||||
public class VideoFileRendererTest {
|
||||
@Test
|
||||
@SmallTest
|
||||
public void testYuvRenderingToFile() throws InterruptedException, IOException {
|
||||
EglBase eglBase = EglBase.create();
|
||||
final String videoOutPath = Environment.getExternalStorageDirectory().getPath()
|
||||
+ "/chromium_tests_root/testvideoout.y4m";
|
||||
int frameWidth = 4;
|
||||
int frameHeight = 4;
|
||||
VideoFileRenderer videoFileRenderer =
|
||||
new VideoFileRenderer(videoOutPath, frameWidth, frameHeight, eglBase.getEglBaseContext());
|
||||
|
||||
String[] frames = {
|
||||
"THIS IS JUST SOME TEXT x", "THE SECOND FRAME qwerty.", "HERE IS THE THRID FRAME!"};
|
||||
|
||||
for (String frameStr : frames) {
|
||||
int[] planeSizes = {
|
||||
frameWidth * frameWidth, frameWidth * frameHeight / 4, frameWidth * frameHeight / 4};
|
||||
|
||||
byte[] frameBytes = frameStr.getBytes(StandardCharsets.US_ASCII);
|
||||
ByteBuffer[] yuvPlanes = new ByteBuffer[3];
|
||||
int pos = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
yuvPlanes[i] = ByteBuffer.allocateDirect(planeSizes[i]);
|
||||
yuvPlanes[i].put(frameBytes, pos, planeSizes[i]);
|
||||
pos += planeSizes[i];
|
||||
}
|
||||
|
||||
int[] yuvStrides = {frameWidth, frameWidth / 2, frameWidth / 2};
|
||||
|
||||
VideoRenderer.I420Frame frame =
|
||||
new VideoRenderer.I420Frame(frameWidth, frameHeight, 0, yuvStrides, yuvPlanes, 0);
|
||||
|
||||
videoFileRenderer.renderFrame(frame);
|
||||
}
|
||||
videoFileRenderer.release();
|
||||
|
||||
RandomAccessFile writtenFile = new RandomAccessFile(videoOutPath, "r");
|
||||
try {
|
||||
int length = (int) writtenFile.length();
|
||||
byte[] data = new byte[length];
|
||||
writtenFile.readFully(data);
|
||||
String fileContent = new String(data, StandardCharsets.US_ASCII);
|
||||
String expected = "YUV4MPEG2 C420 W4 H4 Ip F30:1 A1:1\n"
|
||||
+ "FRAME\n"
|
||||
+ "THIS IS JUST SOME TEXT xFRAME\n"
|
||||
+ "THE SECOND FRAME qwerty.FRAME\n"
|
||||
+ "HERE IS THE THRID FRAME!";
|
||||
assertEquals(expected, fileContent);
|
||||
} finally {
|
||||
writtenFile.close();
|
||||
}
|
||||
|
||||
new File(videoOutPath).delete();
|
||||
}
|
||||
}
|
||||
@ -1,5 +0,0 @@
|
||||
YUV4MPEG2 C420 W4 H4 Ip F30:1 A1:1
|
||||
FRAME
|
||||
THIS IS JUST SOME TEXT xFRAME
|
||||
THE SECOND FRAME qwerty.FRAME
|
||||
HERE IS THE THRID FRAME!
|
||||
Reference in New Issue
Block a user