Initialize media device support on Android when using e10s r=pehrsons draft
authorJames Willcox <snorp@snorp.net>
Mon, 30 Apr 2018 14:56:16 -0500
changeset 791181 30e562d835a0e598901bf49c3bf4bd8d498322c8
parent 791180 42aca52b4651a496b486cc5e494b902f2ca4d257
child 791182 9adf8673cf9f0fa3efae249b2356cecd39b4a562
push id108724
push userbmo:snorp@snorp.net
push dateThu, 03 May 2018 17:29:34 +0000
reviewerspehrsons
milestone61.0a1
Initialize media device support on Android when using e10s r=pehrsons MozReview-Commit-ID: BP9U5jkdnUh
dom/media/systemservices/CamerasParent.cpp
--- a/dom/media/systemservices/CamerasParent.cpp
+++ b/dom/media/systemservices/CamerasParent.cpp
@@ -23,16 +23,20 @@
 
 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
 
 #if defined(_WIN32)
 #include <process.h>
 #define getpid() _getpid()
 #endif
 
+#ifdef MOZ_WIDGET_ANDROID
+#include "AndroidBridge.h"
+#endif
+
 #undef LOG
 #undef LOG_VERBOSE
 #undef LOG_ENABLED
 mozilla::LazyLogModule gCamerasParentLog("CamerasParent");
 #define LOG(args) MOZ_LOG(gCamerasParentLog, mozilla::LogLevel::Debug, args)
 #define LOG_VERBOSE(args) MOZ_LOG(gCamerasParentLog, mozilla::LogLevel::Verbose, args)
 #define LOG_ENABLED() MOZ_LOG_TEST(gCamerasParentLog, mozilla::LogLevel::Debug)
 
@@ -1091,16 +1095,27 @@ CamerasParent::CamerasParent()
   MOZ_ASSERT(mPBackgroundEventTarget != nullptr,
              "GetCurrentThreadEventTarget failed");
 
   LOG(("Spinning up WebRTC Cameras Thread"));
 
   RefPtr<CamerasParent> self(this);
   RefPtr<Runnable> threadStart =
     media::NewRunnableFrom([self]() -> nsresult {
+#ifdef MOZ_WIDGET_ANDROID
+      // get the JVM
+      JavaVM* jvm;
+      JNIEnv* const env = jni::GetEnvForThread();
+      MOZ_ALWAYS_TRUE(!env->GetJavaVM(&jvm));
+
+      if (!jvm || mozilla::camera::VideoEngine::SetAndroidObjects(jvm)) {
+        LOG(("VideoEngine::SetAndroidObjects Failed"));
+      }
+#endif
+
       // Register thread shutdown observer
       nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
       if (NS_WARN_IF(!obs)) {
         return NS_ERROR_FAILURE;
       }
       nsresult rv =
         obs->AddObserver(self, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID, false);
       if (NS_WARN_IF(NS_FAILED(rv))) {