This CL also includes the changes required to fix build errors on Android builds. Change log:03a29cf406..0549de0c2dFull diff:03a29cf406..0549de0c2dChanged dependencies * src/base:58887e6f2a..fe7fd7b2be* src/build:4638e26758..8aa210e09b* src/buildtools/linux64: git_revision:d565aa3e72dd9e81da9595ee8c9d7b24cb45c48b..git_revision:c0a2d23c21e87f27f5af3e5dc2a99f2ef3480b9e * src/buildtools/mac: git_revision:d565aa3e72dd9e81da9595ee8c9d7b24cb45c48b..git_revision:c0a2d23c21e87f27f5af3e5dc2a99f2ef3480b9e * src/buildtools/third_party/libc++abi/trunk:e8bf577fbf..24e92c2bee* src/buildtools/third_party/libunwind/trunk:d7b11d7989..cdb04dc77c* src/buildtools/win: git_revision:d565aa3e72dd9e81da9595ee8c9d7b24cb45c48b..git_revision:c0a2d23c21e87f27f5af3e5dc2a99f2ef3480b9e * src/ios:c172f6d55d..dafd1d1517* src/testing:e6a8848e04..45ed21d9c9* src/third_party:43300033c5..be994fedb5* src/third_party/android_deps/libs/org_jetbrains_kotlin_kotlin_stdlib: version:2@1.5.10.cr0..version:2@1.5.21.cr0 * src/third_party/android_deps/libs/org_jetbrains_kotlin_kotlin_stdlib_common: version:2@1.5.10.cr0..version:2@1.5.21.cr0 * src/third_party/android_sdk/public: 8LZujEmLjSh0g3JciDA3cslSptxKs9HOa_iUPXkOeYQC..tRoD45SCi7UleQqSV7MrMQO1_e5P8ysphkCcj6z_cCQC * src/third_party/android_sdk/public: V__2Ycej-H2-6AcXX5A3gi7sIk74SuN44PBm2uC_N1sC..ZT3JmI6GMG4YVcZ1OtECRVMOLLJAWAdPbi-OclubJLMC * src/third_party/android_sdk/public: A4EvXZUIuQho0QRDJopMUpgyp6NA3aiDQjGKPUKbowMC..gMHhUuoQRKfxr-MBn3fNNXZtkAVXtOwMwT7kfx8jkIgC * src/third_party/android_sdk/public: 8tF0AOj7Dwlv4j7_nfkhxWB0jzrvWWYjEIpirt8FIWYC..qi_k82nm6j9nz4dQosOoqXew4_TFAy8rcGOHDLptx1sC * src/third_party/android_sdk/public: YMUu9EHNZ__2Xcxl-KsaSf-dI5TMt_P62IseUVsxktMC..lL3IGexKjYlwjO_1Ga-xwxgwbE_w-lmi2Zi1uOlWUIAC * src/third_party/android_sdk/public: 4gxhM8E62bvZpQs7Q3d0DinQaW0RLCIefhXrQBFkNy8C..n7svc8KYah-i4s8zwkVa85SI3_H0WFOniP0mpwNdFO0C * src/third_party/androidx: hKpaz7h0NioWOEg8YP2hSuRaZ6uRCUEUcmNcvkxr9aYC..HHo3GgWHTJyTdX1eY15wQ40-pIfmMojudjRzMFoE8JoC * src/third_party/boringssl/src: https://boringssl.googlesource.com/boringssl.git/+log/a10017c548..519c2986c7 * src/third_party/catapult: https://chromium.googlesource.com/catapult.git/+log/9ac1fdf373..10f6e4b89b * src/third_party/freetype/src:801cd842e2..47b1a541cb* src/third_party/googletest/src:4ec4cd23f4..2d924d7a97* src/third_party/libaom/source/libaom: https://aomedia.googlesource.com/aom.git/+log/aba245dde3..d80b8cecab * src/third_party/libvpx/source/libvpx:eebc5cd487..977e77006e* src/third_party/perfetto:13482fe8f9..9edd589321* src/tools:2f3bb89f4e..f7be2d25c7* src/tools/luci-go: git_revision:9ee8b1d719c0d3c268e0e19282351ca78024af2d..git_revision:63874080a20260642c8df82d4f4885ff30b33fb6 * src/tools/luci-go: git_revision:9ee8b1d719c0d3c268e0e19282351ca78024af2d..git_revision:63874080a20260642c8df82d4f4885ff30b33fb6 * src/tools/luci-go: git_revision:9ee8b1d719c0d3c268e0e19282351ca78024af2d..git_revision:63874080a20260642c8df82d4f4885ff30b33fb6 DEPS diff:03a29cf406..0549de0c2d/DEPS Clang version changed llvmorg-13-init-15163-g98033fdc:llvmorg-13-init-15561-gf98ed74f Details:03a29cf406..0549de0c2d/tools/clang/scripts/update.py TBR=xalep@webrtc.org,marpan@webrtc.org, jianj@chromium.org, BUG=None No-Try: True Change-Id: Iceca2600ab3aeff37d325ec68565c06f9db5b0fd Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/227280 Reviewed-by: Andrey Logvin <landrey@webrtc.org> Reviewed-by: Artem Titov <titovartem@webrtc.org> Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34599}
133 lines
4.8 KiB
Java
133 lines
4.8 KiB
Java
/*
|
|
* 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 static org.junit.Assert.assertTrue;
|
|
|
|
import android.os.Environment;
|
|
import androidx.test.filters.SmallTest;
|
|
import java.io.IOException;
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.charset.Charset;
|
|
import java.util.ArrayList;
|
|
import org.chromium.base.test.BaseJUnit4ClassRunner;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
|
|
@RunWith(BaseJUnit4ClassRunner.class)
|
|
public class FileVideoCapturerTest {
|
|
public static class MockCapturerObserver implements CapturerObserver {
|
|
private final ArrayList<VideoFrame> frames = new ArrayList<VideoFrame>();
|
|
|
|
@Override
|
|
public void onCapturerStarted(boolean success) {
|
|
assertTrue(success);
|
|
}
|
|
|
|
@Override
|
|
public void onCapturerStopped() {
|
|
// Empty on purpose.
|
|
}
|
|
|
|
@Override
|
|
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
|
|
@SuppressWarnings("NoSynchronizedMethodCheck")
|
|
public synchronized void onFrameCaptured(VideoFrame frame) {
|
|
frame.retain();
|
|
frames.add(frame);
|
|
notify();
|
|
}
|
|
|
|
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
|
|
@SuppressWarnings("NoSynchronizedMethodCheck")
|
|
public synchronized ArrayList<VideoFrame> getMinimumFramesBlocking(int minFrames)
|
|
throws InterruptedException {
|
|
while (frames.size() < minFrames) {
|
|
wait();
|
|
}
|
|
return new ArrayList<VideoFrame>(frames);
|
|
}
|
|
}
|
|
|
|
@Before
|
|
public void setUp() {
|
|
NativeLibrary.initialize(new NativeLibrary.DefaultLoader(), TestConstants.NATIVE_LIBRARY);
|
|
}
|
|
|
|
@Test
|
|
@SmallTest
|
|
public void testVideoCaptureFromFile() throws InterruptedException, IOException {
|
|
final int FRAME_WIDTH = 4;
|
|
final int FRAME_HEIGHT = 4;
|
|
final int FRAME_CHROMA_WIDTH = (FRAME_WIDTH + 1) / 2;
|
|
final int FRAME_CHROMA_HEIGHT = (FRAME_HEIGHT + 1) / 2;
|
|
final int FRAME_SIZE_Y = FRAME_WIDTH * FRAME_HEIGHT;
|
|
final int FRAME_SIZE_CHROMA = FRAME_CHROMA_WIDTH * FRAME_CHROMA_HEIGHT;
|
|
|
|
final FileVideoCapturer fileVideoCapturer =
|
|
new FileVideoCapturer(Environment.getExternalStorageDirectory().getPath()
|
|
+ "/chromium_tests_root/sdk/android/instrumentationtests/src/org/webrtc/"
|
|
+ "capturetestvideo.y4m");
|
|
final MockCapturerObserver capturerObserver = new MockCapturerObserver();
|
|
fileVideoCapturer.initialize(
|
|
null /* surfaceTextureHelper */, null /* applicationContext */, capturerObserver);
|
|
fileVideoCapturer.startCapture(FRAME_WIDTH, FRAME_HEIGHT, 33 /* fps */);
|
|
|
|
final String[] expectedFrames = {
|
|
"THIS IS JUST SOME TEXT x", "THE SECOND FRAME qwerty.", "HERE IS THE THRID FRAME!"};
|
|
|
|
final ArrayList<VideoFrame> frames =
|
|
capturerObserver.getMinimumFramesBlocking(expectedFrames.length);
|
|
assertEquals(expectedFrames.length, frames.size());
|
|
|
|
fileVideoCapturer.stopCapture();
|
|
fileVideoCapturer.dispose();
|
|
|
|
// Check the content of the frames.
|
|
for (int i = 0; i < expectedFrames.length; ++i) {
|
|
final VideoFrame frame = frames.get(i);
|
|
final VideoFrame.Buffer buffer = frame.getBuffer();
|
|
assertTrue(buffer instanceof VideoFrame.I420Buffer);
|
|
final VideoFrame.I420Buffer i420Buffer = (VideoFrame.I420Buffer) buffer;
|
|
|
|
assertEquals(FRAME_WIDTH, i420Buffer.getWidth());
|
|
assertEquals(FRAME_HEIGHT, i420Buffer.getHeight());
|
|
|
|
final ByteBuffer dataY = i420Buffer.getDataY();
|
|
final ByteBuffer dataU = i420Buffer.getDataU();
|
|
final ByteBuffer dataV = i420Buffer.getDataV();
|
|
|
|
assertEquals(FRAME_SIZE_Y, dataY.remaining());
|
|
assertEquals(FRAME_SIZE_CHROMA, dataU.remaining());
|
|
assertEquals(FRAME_SIZE_CHROMA, dataV.remaining());
|
|
|
|
ByteBuffer frameContents = ByteBuffer.allocate(FRAME_SIZE_Y + 2 * FRAME_SIZE_CHROMA);
|
|
frameContents.put(dataY);
|
|
frameContents.put(dataU);
|
|
frameContents.put(dataV);
|
|
frameContents.rewind(); // Move back to the beginning.
|
|
|
|
assertByteBufferContents(
|
|
expectedFrames[i].getBytes(Charset.forName("US-ASCII")), frameContents);
|
|
frame.release();
|
|
}
|
|
}
|
|
|
|
private static void assertByteBufferContents(byte[] expected, ByteBuffer actual) {
|
|
assertEquals("Unexpected ByteBuffer size.", expected.length, actual.remaining());
|
|
for (int i = 0; i < expected.length; i++) {
|
|
assertEquals("Unexpected byte at index: " + i, expected[i], actual.get());
|
|
}
|
|
}
|
|
}
|