From 3395325533a8a8c26e891b3b8fe17d1fe633f74f Mon Sep 17 00:00:00 2001 From: Cosmin Sabou Date: Wed, 6 Mar 2024 21:19:05 +0200 Subject: [PATCH] Backed out 2 changesets (bug 1808705) for gv-junit failures on VideoCaptureTest. CLOSED TREE Backed out changeset eb9bd67b5b8f (bug 1808705) Backed out changeset cb9a6fdf3e6c (bug 1808705) --- .../videoengine/VideoCaptureAndroid.java | 35 +++++----- .../video_capture_android.cc | 12 ++-- .../geckoview/test/VideoCaptureTest.kt | 66 ------------------- 3 files changed, 20 insertions(+), 93 deletions(-) delete mode 100644 mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt diff --git a/dom/media/systemservices/android_video_capture/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java b/dom/media/systemservices/android_video_capture/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java index b4cc65ec9c46..cc54009a7b44 100644 --- a/dom/media/systemservices/android_video_capture/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java +++ b/dom/media/systemservices/android_video_capture/java/src/org/webrtc/videoengine/VideoCaptureAndroid.java @@ -17,7 +17,6 @@ import android.content.Context; import android.util.Log; import android.view.Surface; import android.view.WindowManager; -import androidx.annotation.NonNull; import java.util.concurrent.CountDownLatch; @@ -38,8 +37,10 @@ public class VideoCaptureAndroid implements CameraVideoCapturer.CameraEventsHand private final String deviceName; private volatile long native_capturer; // |VideoCaptureAndroid*| in C++. - private final Context context; + private Context context; private CameraVideoCapturer cameraVideoCapturer; + private EglBase eglBase; + private SurfaceTextureHelper surfaceTextureHelper; // This class is recreated everytime we start/stop capture, so we // can safely create the CountDownLatches here. @@ -47,16 +48,8 @@ public class VideoCaptureAndroid implements CameraVideoCapturer.CameraEventsHand private boolean capturerStartedSucceeded = false; private final CountDownLatch capturerStopped = new CountDownLatch(1); - @WebRTCJNITarget - public static VideoCaptureAndroid create(@NonNull final String deviceName) { - final Context context = GetContext(); - return new VideoCaptureAndroid(context, deviceName, - Camera2Enumerator.isSupported(context) - ? new Camera2Enumerator(context) - : new Camera1Enumerator()); - } - - private VideoCaptureAndroid(@NonNull final Context context, @NonNull final String deviceName, @NonNull final CameraEnumerator enumerator) { + @WebRTCJNITarget + public VideoCaptureAndroid(String deviceName) { // Remove the camera facing information from the name. String[] parts = deviceName.split("Facing (front|back):"); if (parts.length == 2) { @@ -65,14 +58,20 @@ public class VideoCaptureAndroid implements CameraVideoCapturer.CameraEventsHand Log.e(TAG, "VideoCaptureAndroid: Expected facing mode as part of name: " + deviceName); this.deviceName = deviceName; } - this.context = context; + this.context = GetContext(); + CameraEnumerator enumerator; + if (Camera2Enumerator.isSupported(context)) { + enumerator = new Camera2Enumerator(context); + } else { + enumerator = new Camera1Enumerator(); + } try { cameraVideoCapturer = enumerator.createCapturer(this.deviceName, this); - final EglBase eglBase = EglBase.create(); - final SurfaceTextureHelper surfaceTextureHelper = SurfaceTextureHelper.create("VideoCaptureAndroidSurfaceTextureHelper", eglBase.getEglBaseContext()); + eglBase = EglBase.create(); + surfaceTextureHelper = SurfaceTextureHelper.create("VideoCaptureAndroidSurfaceTextureHelper", eglBase.getEglBaseContext()); cameraVideoCapturer.initialize(surfaceTextureHelper, context, this); - } catch (java.lang.RuntimeException e) { + } catch (java.lang.IllegalArgumentException e) { Log.e(TAG, "VideoCaptureAndroid: Exception while creating capturer: " + e); } } @@ -81,10 +80,6 @@ public class VideoCaptureAndroid implements CameraVideoCapturer.CameraEventsHand @WebRTCJNITarget private static native Context GetContext(); - public boolean canCapture() { - return cameraVideoCapturer != null; - } - // Called by native code. Returns true if capturer is started. // // Note that this actually opens the camera, and Camera callbacks run on the diff --git a/dom/media/systemservices/android_video_capture/video_capture_android.cc b/dom/media/systemservices/android_video_capture/video_capture_android.cc index cd5a73ceb64f..da0715db2745 100644 --- a/dom/media/systemservices/android_video_capture/video_capture_android.cc +++ b/dom/media/systemservices/android_video_capture/video_capture_android.cc @@ -177,14 +177,12 @@ int32_t VideoCaptureAndroid::Init(const char* deviceUniqueIdUTF8) { AttachThreadScoped ats(g_jvm_capture); JNIEnv* env = ats.env(); - jmethodID factory = - env->GetStaticMethodID(g_java_capturer_class, "create", - "(Ljava/lang/String;)" - "Lorg/webrtc/videoengine/VideoCaptureAndroid;"); - assert(factory); + jmethodID ctor = env->GetMethodID(g_java_capturer_class, "", + "(Ljava/lang/String;)V"); + assert(ctor); jstring j_deviceName = env->NewStringUTF(_deviceUniqueId); - _jCapturer = env->NewGlobalRef(env->CallStaticObjectMethod( - g_java_capturer_class, factory, j_deviceName)); + _jCapturer = env->NewGlobalRef( + env->NewObject(g_java_capturer_class, ctor, j_deviceName)); assert(_jCapturer); return 0; } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt deleted file mode 100644 index e8b755ae1d2a..000000000000 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/VideoCaptureTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -package org.mozilla.geckoview.test - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.filters.SmallTest -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith -import org.webrtc.CameraEnumerationAndroid.CaptureFormat -import org.webrtc.CameraEnumerator -import org.webrtc.CameraVideoCapturer -import org.webrtc.CameraVideoCapturer.CameraEventsHandler -import org.webrtc.videoengine.VideoCaptureAndroid - -@RunWith(AndroidJUnit4::class) -@SmallTest -class VideoCaptureTest { - // Always throw exception. - class BadCameraEnumerator : CameraEnumerator { - override fun getDeviceNames(): Array? { - throw java.lang.RuntimeException("") - } - - override fun isFrontFacing(deviceName: String?): Boolean { - throw java.lang.RuntimeException("") - } - - override fun isBackFacing(deviceName: String?): Boolean { - throw java.lang.RuntimeException("") - } - - override fun isInfrared(deviceName: String?): Boolean { - throw java.lang.RuntimeException("") - } - - override fun getSupportedFormats(deviceName: String?): List? { - throw java.lang.RuntimeException("") - } - - override fun createCapturer( - deviceName: String?, - eventsHandler: CameraEventsHandler?, - ): CameraVideoCapturer? { - throw java.lang.RuntimeException("") - } - } - - @Test - fun create() { - val capture = VideoCaptureAndroid.create("my camera") - assertEquals(capture.canCapture(), true) - } - - @Test - fun constructWithBadEnumerator() { - val ctr = VideoCaptureAndroid::class.java.getDeclaredConstructors()[0].apply { isAccessible = true } - val capture = ctr.newInstance( - arrayOf( - InstrumentationRegistry.getInstrumentation().targetContext, - "my camera", - BadCameraEnumerator(), - ), - ) as VideoCaptureAndroid - assertEquals(capture.canCapture(), false) - } -}