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 532c0166129bd2a5895619e74d072d38911a6ba4..6e768b71254d185ba4f9687290312a5c225698fc 100644 |
--- a/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java |
+++ b/webrtc/examples/androidapp/src/org/appspot/apprtc/PeerConnectionClient.java |
@@ -17,7 +17,11 @@ import android.util.Log; |
import org.appspot.apprtc.AppRTCClient.SignalingParameters; |
import org.webrtc.AudioTrack; |
+import org.webrtc.Camera1Enumerator; |
+import org.webrtc.Camera2Enumerator; |
+import org.webrtc.CameraEnumerator; |
import org.webrtc.CameraEnumerationAndroid; |
+import org.webrtc.CameraVideoCapturer; |
import org.webrtc.DataChannel; |
import org.webrtc.EglBase; |
import org.webrtc.IceCandidate; |
@@ -33,7 +37,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; |
@@ -93,6 +97,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; |
@@ -121,7 +126,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; |
@@ -137,6 +142,8 @@ public class PeerConnectionClient { |
public final boolean videoCallEnabled; |
public final boolean loopback; |
public final boolean tracing; |
+ public final boolean camera2Enabled; |
+ public final boolean camera1Enabled; |
public final int videoWidth; |
public final int videoHeight; |
public final int videoFps; |
@@ -152,13 +159,15 @@ 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 camera2Enabled, |
+ boolean camera1Enabled, 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.camera2Enabled = camera2Enabled; |
+ this.camera1Enabled = camera1Enabled; |
this.loopback = loopback; |
this.tracing = tracing; |
this.videoWidth = videoWidth; |
@@ -247,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; |
@@ -364,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."); |
} |
@@ -453,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) { |
magjed_webrtc
2016/06/29 13:36:45
There is no need for this null check (with the cur
sakal
2016/06/30 09:14:52
I'd rather keep it. It used to be Camera2Enumerato
|
+ 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"); |
@@ -495,15 +536,16 @@ 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 (Camera2Enumerator.isSupported() && peerConnectionParameters.camera2Enabled) { |
+ Logging.d(TAG, "Creating capturer using camera2 API."); |
+ createCapturer(new Camera2Enumerator(context)); |
+ } |
+ |
+ if (videoCapturer == null && peerConnectionParameters.camera1Enabled) { |
+ Logging.d(TAG, "Creating capturer using camera1 API."); |
+ createCapturer(new Camera1Enumerator()); |
} |
- Log.d(TAG, "Opening camera: " + cameraDeviceName); |
- videoCapturer = VideoCapturerAndroid.create(cameraDeviceName, null, |
- peerConnectionParameters.captureToTexture); |
+ |
if (videoCapturer == null) { |
reportError("Failed to open camera"); |
return; |
@@ -784,7 +826,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); |