Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(489)

Unified Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java

Issue 2077663003: Camera2 in AppRTC Android Demo. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@camera2_only
Patch Set: Create peer connection factory with the target context in the test Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
diff --git a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
index 294b1ef07baeb6e91e6cfe26a3eb66afe8f3c910..0f7ff3532d150643b06c16bc3e34bd82fb9c413a 100644
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java
@@ -19,7 +19,11 @@ import android.util.Log;
import org.webrtc.AudioSource;
import org.webrtc.AudioTrack;
+import org.webrtc.Camera1Enumerator;
+import org.webrtc.Camera2Enumerator;
import org.webrtc.CameraEnumerationAndroid;
+import org.webrtc.CameraEnumerator;
+import org.webrtc.CameraVideoCapturer;
import org.webrtc.DataChannel;
import org.webrtc.EglBase;
import org.webrtc.IceCandidate;
@@ -35,7 +39,7 @@ import org.webrtc.SdpObserver;
import org.webrtc.SessionDescription;
import org.webrtc.StatsObserver;
import org.webrtc.StatsReport;
-import org.webrtc.VideoCapturerAndroid;
+import org.webrtc.VideoCapturer;
import org.webrtc.VideoRenderer;
import org.webrtc.VideoSource;
import org.webrtc.VideoTrack;
@@ -48,7 +52,6 @@ import java.util.EnumSet;
import java.util.LinkedList;
import java.util.Timer;
import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.regex.Matcher;
@@ -95,6 +98,7 @@ public class PeerConnectionClient {
private final SDPObserver sdpObserver = new SDPObserver();
private final ScheduledExecutorService executor;
+ private Context context;
private PeerConnectionFactory factory;
private PeerConnection peerConnection;
PeerConnectionFactory.Options options = null;
@@ -124,7 +128,7 @@ public class PeerConnectionClient {
private SessionDescription localSdp; // either offer or answer SDP
private MediaStream mediaStream;
private int numberOfCameras;
- private VideoCapturerAndroid videoCapturer;
+ private CameraVideoCapturer videoCapturer;
// enableVideo is set to true if video should be rendered and sent.
private boolean renderVideo;
private VideoTrack localVideoTrack;
@@ -140,6 +144,7 @@ public class PeerConnectionClient {
public final boolean videoCallEnabled;
public final boolean loopback;
public final boolean tracing;
+ public final boolean useCamera2;
public final int videoWidth;
public final int videoHeight;
public final int videoFps;
@@ -155,13 +160,14 @@ public class PeerConnectionClient {
public final boolean disableBuiltInAEC;
public PeerConnectionParameters(
- boolean videoCallEnabled, boolean loopback, boolean tracing,
- int videoWidth, int videoHeight, int videoFps, int videoStartBitrate,
- String videoCodec, boolean videoCodecHwAcceleration, boolean captureToTexture,
- int audioStartBitrate, String audioCodec,
+ boolean videoCallEnabled, boolean loopback, boolean tracing, boolean useCamera2,
+ int videoWidth, int videoHeight, int videoFps,
+ int videoStartBitrate, String videoCodec, boolean videoCodecHwAcceleration,
+ boolean captureToTexture, int audioStartBitrate, String audioCodec,
boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES,
boolean disableBuiltInAEC) {
this.videoCallEnabled = videoCallEnabled;
+ this.useCamera2 = useCamera2;
this.loopback = loopback;
this.tracing = tracing;
this.videoWidth = videoWidth;
@@ -250,6 +256,7 @@ public class PeerConnectionClient {
this.events = events;
videoCallEnabled = peerConnectionParameters.videoCallEnabled;
// Reset variables to initial states.
+ this.context = null;
factory = null;
peerConnection = null;
preferIsac = false;
@@ -367,6 +374,7 @@ public class PeerConnectionClient {
if (options != null) {
Log.d(TAG, "Factory networkIgnoreMask option: " + options.networkIgnoreMask);
}
+ this.context = context;
factory = new PeerConnectionFactory(options);
Log.d(TAG, "Peer connection factory created.");
}
@@ -456,6 +464,36 @@ public class PeerConnectionClient {
}
}
+ private void createCapturer(CameraEnumerator enumerator) {
+ final String[] deviceNames = enumerator.getDeviceNames();
+
+ // First, try to find front facing camera
+ Logging.d(TAG, "Looking for front facing cameras.");
+ for (String deviceName : deviceNames) {
+ if (enumerator.isFrontFacing(deviceName)) {
+ Logging.d(TAG, "Creating front facing camera capturer.");
+ videoCapturer = enumerator.createCapturer(deviceName, null);
+
+ if (videoCapturer != null) {
+ return;
+ }
+ }
+ }
+
+ // Front facing camera not found, try something else
+ Logging.d(TAG, "Looking for other cameras.");
+ for (String deviceName : deviceNames) {
+ if (!enumerator.isFrontFacing(deviceName)) {
+ Logging.d(TAG, "Creating other camera capturer.");
+ videoCapturer = enumerator.createCapturer(deviceName, null);
+
+ if (videoCapturer != null) {
+ return;
+ }
+ }
+ }
+ }
+
private void createPeerConnectionInternal(EglBase.Context renderEGLContext) {
if (factory == null || isError) {
Log.e(TAG, "Peerconnection factory is not created");
@@ -498,15 +536,19 @@ public class PeerConnectionClient {
mediaStream = factory.createLocalMediaStream("ARDAMS");
if (videoCallEnabled) {
- String cameraDeviceName = CameraEnumerationAndroid.getDeviceName(0);
- String frontCameraDeviceName =
- CameraEnumerationAndroid.getNameOfFrontFacingDevice();
- if (numberOfCameras > 1 && frontCameraDeviceName != null) {
- cameraDeviceName = frontCameraDeviceName;
+ if (peerConnectionParameters.useCamera2) {
+ if (!peerConnectionParameters.captureToTexture) {
+ reportError(context.getString(R.string.camera2_texture_only_error));
+ return;
+ }
+
+ Logging.d(TAG, "Creating capturer using camera2 API.");
+ createCapturer(new Camera2Enumerator(context));
+ } else {
+ Logging.d(TAG, "Creating capturer using camera1 API.");
+ createCapturer(new Camera1Enumerator(peerConnectionParameters.captureToTexture));
}
- Log.d(TAG, "Opening camera: " + cameraDeviceName);
- videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null,
- peerConnectionParameters.captureToTexture);
+
if (videoCapturer == null) {
reportError("Failed to open camera");
return;
@@ -791,7 +833,7 @@ public class PeerConnectionClient {
return localAudioTrack;
}
- private VideoTrack createVideoTrack(VideoCapturerAndroid capturer) {
+ private VideoTrack createVideoTrack(VideoCapturer capturer) {
videoSource = factory.createVideoSource(capturer, videoConstraints);
localVideoTrack = factory.createVideoTrack(VIDEO_TRACK_ID, videoSource);

Powered by Google App Engine
This is Rietveld 408576698