WebRTCDemo: fix out-of-bounds array read.

Also removed the WebRtcCamera class, which has become an empty wrapper around
CameraInfo in the post-rewrite world.

First pointed out by Jeremy Mao <yujie.mao@webrtc.org> in
http://review.webrtc.org/6869004/

R=henrike@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@5377 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
fischman@webrtc.org 2014-01-13 22:15:38 +00:00
parent d7568a08c3
commit dde7aee40f

View File

@ -76,41 +76,20 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
alertDialog.show(); alertDialog.show();
} }
// This class represent the cameras available on the device. // Converts device rotation to camera rotation. Rotation depends on if the
private class WebrtcCamera { // camera is back facing and rotate with the device or front facing and
private final CameraInfo info; // rotating in the opposite direction of the device.
private static int rotationFromRealWorldUp(CameraInfo info,
WebrtcCamera(CameraInfo info) { int deviceRotation) {
this.info = info; int coarseDeviceOrientation =
} (int)(Math.round((double)deviceRotation / 90) * 90) % 360;
if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
// Converts device rotation to camera rotation. Rotation depends on if the // The front camera rotates in the opposite direction of the
// camera is back facing and rotate with the device or front facing and // device.
// rotating in the opposite direction of the device. int inverseDeviceOrientation = 360 - coarseDeviceOrientation;
public int rotationFromRealWorldUp(int deviceRotation) { return (inverseDeviceOrientation + info.orientation) % 360;
int coarseDeviceOrientation = roundRotation(deviceRotation);
if (frontFacing()) {
// The front camera rotates in the opposite direction of the
// device.
int inverseDeviceOrientation = 360 - coarseDeviceOrientation;
return (inverseDeviceOrientation + orientation()) % 360;
}
return (coarseDeviceOrientation + orientation()) % 360;
}
// Rounds rotation to the nearest 90 degree rotation.
private int roundRotation(int rotation) {
return (int)(Math.round((double)rotation / 90) * 90) % 360;
}
public boolean frontFacing() {
return info.facing == CameraInfo.CAMERA_FACING_FRONT;
}
// Rotation of camera with respect to device up.
private int orientation() {
return info.orientation;
} }
return (coarseDeviceOrientation + info.orientation) % 360;
} }
// Shared Audio/Video members. // Shared Audio/Video members.
@ -149,7 +128,8 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
private int videoTxPort; private int videoTxPort;
private int videoRxPort; private int videoRxPort;
private WebrtcCamera cameras[]; // Indexed by CameraInfo.CAMERA_FACING_{BACK,FRONT}.
private CameraInfo cameras[];
private boolean useFrontCamera; private boolean useFrontCamera;
private int currentCameraHandle; private int currentCameraHandle;
private boolean enableNack; private boolean enableNack;
@ -185,11 +165,11 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
check(vie.connectAudioChannel(videoChannel, audioChannel) == 0, check(vie.connectAudioChannel(videoChannel, audioChannel) == 0,
"Failed ConnectAudioChannel"); "Failed ConnectAudioChannel");
cameras = new WebrtcCamera[Camera.getNumberOfCameras()]; cameras = new CameraInfo[2];
CameraInfo info = new CameraInfo(); CameraInfo info = new CameraInfo();
for (int i = 0; i < Camera.getNumberOfCameras(); ++i) { for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
Camera.getCameraInfo(i, info); Camera.getCameraInfo(i, info);
cameras[info.facing] = new WebrtcCamera(info); cameras[info.facing] = info;
} }
setDefaultCamera(); setDefaultCamera();
check(voe.setSpeakerVolume(volumeLevel) == 0, check(voe.setSpeakerVolume(volumeLevel) == 0,
@ -613,12 +593,7 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
} }
private boolean hasFrontCamera() { private boolean hasFrontCamera() {
for (int i = 0; i < cameras.length; ++i) { return cameras[CameraInfo.CAMERA_FACING_FRONT] != null;
if (cameras[i].frontFacing()) {
return true;
}
}
return false;
} }
public SurfaceView getRemoteSurfaceView() { public SurfaceView getRemoteSurfaceView() {
@ -727,9 +702,8 @@ public class MediaEngine implements VideoDecodeEncodeObserver {
if (deviceOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) { if (deviceOrientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
return; return;
} }
int cameraRotation = int cameraRotation = rotationFromRealWorldUp(
cameras[getCameraId()].rotationFromRealWorldUp( cameras[getCameraId()], deviceOrientation);
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,