Fix Android AppRTCDemo failure on devices with one or no camera.
- Disable video call on devices with no camera. - Open default camera and disable camera switch on devices with one camera. BUG=4373 R=braveyao@webrtc.org, wzh@webrtc.org Review URL: https://webrtc-codereview.appspot.com/46539004 Cr-Commit-Position: refs/heads/master@{#8674} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8674 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
4052d88162
commit
fc516077ed
talk
app/webrtc/java/src/org/webrtc
examples/android/src/org/appspot/apprtc
@ -98,6 +98,11 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
return names;
|
||||
}
|
||||
|
||||
// Returns number of cameras on device.
|
||||
public static int getDeviceCount() {
|
||||
return Camera.getNumberOfCameras();
|
||||
}
|
||||
|
||||
public static String getDeviceName(int index) {
|
||||
Camera.CameraInfo info = new Camera.CameraInfo();
|
||||
Camera.getCameraInfo(index, info);
|
||||
@ -114,7 +119,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
|
||||
return getDeviceName(i);
|
||||
}
|
||||
throw new RuntimeException("Front facing camera does not exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getNameOfBackFacingDevice() {
|
||||
@ -124,7 +129,7 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
|
||||
if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK)
|
||||
return getDeviceName(i);
|
||||
}
|
||||
throw new RuntimeException("Back facing camera does not exist.");
|
||||
return null;
|
||||
}
|
||||
|
||||
public static VideoCapturerAndroid create(String name) {
|
||||
|
@ -114,6 +114,7 @@ public class PeerConnectionClient {
|
||||
private boolean isInitiator;
|
||||
private SessionDescription localSdp = null; // either offer or answer SDP
|
||||
private MediaStream mediaStream = null;
|
||||
private int numberOfCameras;
|
||||
private VideoCapturerAndroid videoCapturer = null;
|
||||
// enableVideo is set to true if video should be rendered and sent.
|
||||
private boolean renderVideo = true;
|
||||
@ -235,6 +236,12 @@ public class PeerConnectionClient {
|
||||
if (signalingParameters.videoConstraints == null) {
|
||||
videoCallEnabled = false;
|
||||
}
|
||||
// Check if there is a camera on device and disable video call if not.
|
||||
numberOfCameras = VideoCapturerAndroid.getDeviceCount();
|
||||
if (numberOfCameras == 0) {
|
||||
Log.w(TAG, "No camera on device. Switch to audio only call.");
|
||||
videoCallEnabled = false;
|
||||
}
|
||||
if (videoCallEnabled) {
|
||||
int videoWidth = peerConnectionParameters.videoWidth;
|
||||
int videoHeight = peerConnectionParameters.videoHeight;
|
||||
@ -365,8 +372,14 @@ public class PeerConnectionClient {
|
||||
|
||||
mediaStream = factory.createLocalMediaStream("ARDAMS");
|
||||
if (videoCallEnabled) {
|
||||
videoCapturer = VideoCapturerAndroid.create(
|
||||
VideoCapturerAndroid.getNameOfFrontFacingDevice());
|
||||
String cameraDeviceName = VideoCapturerAndroid.getDeviceName(0);
|
||||
String frontCameraDeviceName =
|
||||
VideoCapturerAndroid.getNameOfFrontFacingDevice();
|
||||
if (numberOfCameras > 1 && frontCameraDeviceName != null) {
|
||||
cameraDeviceName = frontCameraDeviceName;
|
||||
}
|
||||
Log.d(TAG, "Opening camera: " + cameraDeviceName);
|
||||
videoCapturer = VideoCapturerAndroid.create(cameraDeviceName);
|
||||
mediaStream.addTrack(createVideoTrack(videoCapturer));
|
||||
}
|
||||
|
||||
@ -735,8 +748,8 @@ public class PeerConnectionClient {
|
||||
}
|
||||
|
||||
private void switchCameraInternal() {
|
||||
if (!videoCallEnabled) {
|
||||
return; // No video is sent.
|
||||
if (!videoCallEnabled || numberOfCameras < 2) {
|
||||
return; // No video is sent or only one camera is available.
|
||||
}
|
||||
Log.d(TAG, "Switch camera");
|
||||
videoCapturer.switchCamera();
|
||||
|
Loading…
x
Reference in New Issue
Block a user