Add simple end to end test for video capture and encode using textures.

BUG=webrtc:4993

Review URL: https://codereview.webrtc.org/1482333002

Cr-Commit-Position: refs/heads/master@{#10849}
This commit is contained in:
perkj
2015-11-30 22:59:33 -08:00
committed by Commit bot
parent 021282f8f1
commit 9f8d39d1b6

View File

@ -22,6 +22,7 @@ import org.appspot.apprtc.PeerConnectionClient.PeerConnectionParameters;
import org.appspot.apprtc.util.LooperExecutor;
import org.webrtc.EglBase;
import org.webrtc.IceCandidate;
import org.webrtc.MediaCodecVideoEncoder;
import org.webrtc.PeerConnection;
import org.webrtc.PeerConnectionFactory;
import org.webrtc.SessionDescription;
@ -224,7 +225,7 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
PeerConnectionClient createPeerConnectionClient(
MockRenderer localRenderer, MockRenderer remoteRenderer,
PeerConnectionParameters peerConnectionParameters, boolean decodeToTexture) {
PeerConnectionParameters peerConnectionParameters, boolean useTexures) {
List<PeerConnection.IceServer> iceServers =
new LinkedList<PeerConnection.IceServer>();
SignalingParameters signalingParameters = new SignalingParameters(
@ -239,18 +240,27 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
client.setPeerConnectionFactoryOptions(options);
client.createPeerConnectionFactory(
getInstrumentation().getContext(), peerConnectionParameters, this);
client.createPeerConnection(decodeToTexture ? eglBase.getContext() : null,
client.createPeerConnection(useTexures ? eglBase.getContext() : null,
localRenderer, remoteRenderer, signalingParameters);
client.createOffer();
return client;
}
private PeerConnectionParameters createParameters(boolean enableVideo,
String videoCodec) {
private PeerConnectionParameters createParametersForAudioCall() {
PeerConnectionParameters peerConnectionParameters =
new PeerConnectionParameters(
enableVideo, true, // videoCallEnabled, loopback.
0, 0, 0, 0, videoCodec, true, false, // video codec parameters.
false, true, // videoCallEnabled, loopback.
0, 0, 0, 0, "", true, false, // video codec parameters.
0, "OPUS", false, false); // audio codec parameters.
return peerConnectionParameters;
}
private PeerConnectionParameters createParametersForVideoCall(
String videoCodec, boolean captureToTexture) {
PeerConnectionParameters peerConnectionParameters =
new PeerConnectionParameters(
true, true, // videoCallEnabled, loopback.
0, 0, 0, 0, videoCodec, true, captureToTexture, // video codec parameters.
0, "OPUS", false, false); // audio codec parameters.
return peerConnectionParameters;
}
@ -277,7 +287,8 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
Log.d(TAG, "testSetLocalOfferMakesVideoFlowLocally");
MockRenderer localRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, LOCAL_RENDERER_NAME);
pcClient = createPeerConnectionClient(
localRenderer, new MockRenderer(0, null), createParameters(true, VIDEO_CODEC_VP8), false);
localRenderer, new MockRenderer(0, null),
createParametersForVideoCall(VIDEO_CODEC_VP8, false), false);
// Wait for local SDP and ice candidates set events.
assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
@ -337,46 +348,74 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
}
public void testLoopbackAudio() throws InterruptedException {
doLoopbackTest(createParameters(false, VIDEO_CODEC_VP8), false);
doLoopbackTest(createParametersForAudioCall(), false);
}
public void testLoopbackVp8() throws InterruptedException {
doLoopbackTest(createParameters(true, VIDEO_CODEC_VP8), false);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_VP8, false), false);
}
public void DISABLED_testLoopbackVp9() throws InterruptedException {
doLoopbackTest(createParameters(true, VIDEO_CODEC_VP9), false);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_VP9, false), false);
}
public void testLoopbackH264() throws InterruptedException {
doLoopbackTest(createParameters(true, VIDEO_CODEC_H264), false);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_H264, false), false);
}
public void testLoopbackVp8DecodeToTexture() throws InterruptedException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Log.i(TAG, "Decode to textures is not supported, requires EGL14.");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.i(TAG, "Decode to textures is not supported, requires SDK version 19.");
return;
}
doLoopbackTest(createParameters(true, VIDEO_CODEC_VP8), true);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_VP8, false), true);
}
public void DISABLED_testLoopbackVp9DecodeToTexture() throws InterruptedException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Log.i(TAG, "Decode to textures is not supported, requires EGL14.");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.i(TAG, "Decode to textures is not supported, requires SDK version 19.");
return;
}
doLoopbackTest(createParameters(true, VIDEO_CODEC_VP9), true);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_VP9, false), true);
}
public void testLoopbackH264DecodeToTexture() throws InterruptedException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
Log.i(TAG, "Decode to textures is not supported, requires EGL14.");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.i(TAG, "Decode to textures is not supported, requires SDK version 19.");
return;
}
doLoopbackTest(createParameters(true, VIDEO_CODEC_H264), true);
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_H264, false), true);
}
public void testLoopbackVp8CaptureToTexture() throws InterruptedException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.i(TAG, "Encode to textures is not supported. Requires SDK version 19");
return;
}
// TODO(perkj): If we can always capture to textures, there is no need to check if the
// hardware encoder supports to encode from a texture.
if (!MediaCodecVideoEncoder.isVp8HwSupportedUsingTextures()) {
Log.i(TAG, "VP8 encode to textures is not supported.");
return;
}
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_VP8, true), true);
}
public void testLoopbackH264CaptureToTexture() throws InterruptedException {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.i(TAG, "Encode to textures is not supported. Requires KITKAT");
return;
}
// TODO(perkj): If we can always capture to textures, there is no need to check if the
// hardware encoder supports to encode from a texture.
if (!MediaCodecVideoEncoder.isH264HwSupportedUsingTextures()) {
Log.i(TAG, "H264 encode to textures is not supported.");
return;
}
doLoopbackTest(createParametersForVideoCall(VIDEO_CODEC_H264, true), true);
}
// Checks if default front camera can be switched to back camera and then
// again to front camera.
public void testCameraSwitch() throws InterruptedException {
@ -387,7 +426,7 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE_RENDERER_NAME);
pcClient = createPeerConnectionClient(
localRenderer, remoteRenderer, createParameters(true, VIDEO_CODEC_VP8), false);
localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_VP8, false), false);
// Wait for local SDP, rename it to answer and set as remote SDP.
assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));
@ -433,7 +472,7 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
MockRenderer remoteRenderer = new MockRenderer(EXPECTED_VIDEO_FRAMES, REMOTE_RENDERER_NAME);
pcClient = createPeerConnectionClient(
localRenderer, remoteRenderer, createParameters(true, VIDEO_CODEC_VP8), false);
localRenderer, remoteRenderer, createParametersForVideoCall(VIDEO_CODEC_VP8, false), false);
// Wait for local SDP, rename it to answer and set as remote SDP.
assertTrue("Local SDP was not set.", waitForLocalSDP(WAIT_TIMEOUT));