Add enable flag for Android device orientation change event.

There are reports (not reproducible with appRtcDemo) that
outstanding device orientation change event
OrientationEventListener.onOrientationChanged can be
triggered even after these events are disabled by
OrientationEventListener.disable() code.
Avoid calling native code in this case since underlying
C++ class may have already been deleted.

BUG=3564
R=braveyao@webrtc.org

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

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7172 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
glaznev@webrtc.org 2014-09-12 16:48:12 +00:00
parent 192a54ff2f
commit 91ee7468dd

View File

@ -47,6 +47,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
private final int id;
private final Camera.CameraInfo info;
private final OrientationEventListener orientationListener;
private boolean orientationListenerEnabled;
private final long native_capturer; // |VideoCaptureAndroid*| in C++.
private SurfaceTexture cameraSurfaceTexture;
private int[] cameraGlTextures = null;
@ -76,6 +77,9 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
final VideoCaptureAndroid self = this;
orientationListener = new OrientationEventListener(GetContext()) {
@Override public void onOrientationChanged(int degrees) {
if (!self.orientationListenerEnabled) {
return;
}
if (degrees == OrientationEventListener.ORIENTATION_UNKNOWN) {
return;
}
@ -133,6 +137,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
}
});
boolean startResult = exchange(result, false); // |false| is a dummy value.
orientationListenerEnabled = true;
orientationListener.enable();
return startResult;
}
@ -219,6 +224,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback {
private synchronized boolean stopCapture() {
Log.d(TAG, "stopCapture");
orientationListener.disable();
orientationListenerEnabled = false;
final Exchanger<Boolean> result = new Exchanger<Boolean>();
cameraThreadHandler.post(new Runnable() {
@Override public void run() {