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:
parent
570bc3d792
commit
91db93d24f
@ -568,7 +568,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
|
|||||||
return useFrontCamera;
|
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() {
|
private void setDefaultCamera() {
|
||||||
useFrontCamera = hasFrontCamera();
|
useFrontCamera = hasFrontCamera();
|
||||||
}
|
}
|
||||||
@ -584,7 +584,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startCamera() {
|
private void startCamera() {
|
||||||
CameraDesc cameraInfo = vie.getCaptureDevice(getCameraId());
|
CameraDesc cameraInfo = vie.getCaptureDevice(getCameraId(getCameraIndex()));
|
||||||
currentCameraHandle = vie.allocateCaptureDevice(cameraInfo);
|
currentCameraHandle = vie.allocateCaptureDevice(cameraInfo);
|
||||||
cameraInfo.dispose();
|
cameraInfo.dispose();
|
||||||
check(vie.connectCaptureDevice(currentCameraHandle, videoChannel) == 0,
|
check(vie.connectCaptureDevice(currentCameraHandle, videoChannel) == 0,
|
||||||
@ -700,11 +700,22 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
|
|||||||
"vie StartRtpDump");
|
"vie StartRtpDump");
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCameraId() {
|
private int getCameraIndex() {
|
||||||
return useFrontCamera ? Camera.CameraInfo.CAMERA_FACING_FRONT :
|
return useFrontCamera ? Camera.CameraInfo.CAMERA_FACING_FRONT :
|
||||||
Camera.CameraInfo.CAMERA_FACING_BACK;
|
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() {
|
private void compensateRotation() {
|
||||||
if (svLocal == null) {
|
if (svLocal == null) {
|
||||||
// Not rendering (or sending).
|
// Not rendering (or sending).
|
||||||
@ -714,7 +725,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int cameraRotation = rotationFromRealWorldUp(
|
int cameraRotation = rotationFromRealWorldUp(
|
||||||
cameras[getCameraId()], deviceOrientation);
|
cameras[getCameraIndex()], deviceOrientation);
|
||||||
// Egress streams should have real world up as up.
|
// Egress streams should have real world up as up.
|
||||||
check(
|
check(
|
||||||
vie.setRotateCapturedFrames(currentCameraHandle, cameraRotation) == 0,
|
vie.setRotateCapturedFrames(currentCameraHandle, cameraRotation) == 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user