Android, fixes crash on devices with only front cameras.

BUG=2807
R=fischman@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/7429004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5415 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
henrike@webrtc.org 2014-01-22 21:31:24 +00:00
parent 570bc3d792
commit 91db93d24f

View File

@ -568,7 +568,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
return useFrontCamera;
}
// Set camera to front if one exists otherwise use back camera.
// Set default camera to front if there is a front camera.
private void setDefaultCamera() {
useFrontCamera = hasFrontCamera();
}
@ -584,7 +584,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
}
private void startCamera() {
CameraDesc cameraInfo = vie.getCaptureDevice(getCameraId());
CameraDesc cameraInfo = vie.getCaptureDevice(getCameraId(getCameraIndex()));
currentCameraHandle = vie.allocateCaptureDevice(cameraInfo);
cameraInfo.dispose();
check(vie.connectCaptureDevice(currentCameraHandle, videoChannel) == 0,
@ -700,11 +700,22 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
"vie StartRtpDump");
}
private int getCameraId() {
private int getCameraIndex() {
return useFrontCamera ? Camera.CameraInfo.CAMERA_FACING_FRONT :
Camera.CameraInfo.CAMERA_FACING_BACK;
}
private int getCameraId(int index) {
for (int i = Camera.getNumberOfCameras() - 1; i >= 0; --i) {
CameraInfo info = new CameraInfo();
Camera.getCameraInfo(i, info);
if (index == info.facing) {
return i;
}
}
throw new RuntimeException("Index does not match a camera");
}
private void compensateRotation() {
if (svLocal == null) {
// Not rendering (or sending).
@ -714,7 +725,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
return;
}
int cameraRotation = rotationFromRealWorldUp(
cameras[getCameraId()], deviceOrientation);
cameras[getCameraIndex()], deviceOrientation);
// Egress streams should have real world up as up.
check(
vie.setRotateCapturedFrames(currentCameraHandle, cameraRotation) == 0,