Bug 1186657. r=jesup,nchen

This commit is contained in:
Gian-Carlo Pascutto 2015-07-28 08:55:06 +02:00
parent c722fa544d
commit f6d0d49348
2 changed files with 21 additions and 2 deletions

View File

@ -56,7 +56,7 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
private Handler cameraThreadHandler;
private Context context;
private final int id;
private final long native_capturer; // |VideoCaptureAndroid*| in C++.
private volatile long native_capturer; // |VideoCaptureAndroid*| in C++.
private SurfaceTexture cameraSurfaceTexture;
private int[] cameraGlTextures = null;
@ -373,6 +373,15 @@ public class VideoCaptureAndroid implements PreviewCallback, Callback, AppStateL
return status;
}
@WebRTCJNITarget
private void unlinkCapturer() {
// stopCapture might fail. That might leave the callbacks dangling, so make
// sure those don't call into dead code.
// Note that onPreviewCameraFrame isn't synchronized, so there's no point in
// synchronizing us either. ProvideCameraFrame has to do the null check.
native_capturer = 0;
}
private void stopCaptureOnCameraThread(
Exchanger<Boolean> result) {
if (camera == null) {

View File

@ -41,6 +41,8 @@ void JNICALL ProvideCameraFrame(
jint rotation,
jlong timeStamp,
jlong context) {
if (!context)
return;
webrtc::videocapturemodule::VideoCaptureAndroid* captureModule =
reinterpret_cast<webrtc::videocapturemodule::VideoCaptureAndroid*>(
context);
@ -167,7 +169,14 @@ VideoCaptureAndroid::~VideoCaptureAndroid() {
if (_captureStarted)
StopCapture();
AttachThreadScoped ats(g_jvm);
ats.env()->DeleteGlobalRef(_jCapturer);
JNIEnv* env = ats.env();
// Avoid callbacks into ourself even if the above stopCapture fails.
jmethodID j_unlink =
env->GetMethodID(g_java_capturer_class, "unlinkCapturer", "()V");
env->CallVoidMethod(_jCapturer, j_unlink);
env->DeleteGlobalRef(_jCapturer);
}
int32_t VideoCaptureAndroid::StartCapture(
@ -216,6 +225,7 @@ int32_t VideoCaptureAndroid::StopCapture() {
// onIncomingFrame() call.
_apiCs.Leave();
// try to stop the capturer.
jmethodID j_stop =
env->GetMethodID(g_java_capturer_class, "stopCapture", "()Z");
return env->CallBooleanMethod(_jCapturer, j_stop) ? 0 : -1;