Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(android) use hardware video decoders by default

Saúl Ibarra Corretgé9d27c705f69c
diff --git a/android/app/src/main/java/org/jitsi/meet/MainActivity.java b/android/app/src/main/java/org/jitsi/meet/MainActivity.java
index 319ff5cda0..3b18fca0b3 100644
--- a/android/app/src/main/java/org/jitsi/meet/MainActivity.java
+++ b/android/app/src/main/java/org/jitsi/meet/MainActivity.java
@@ -30,9 +30,12 @@ import android.view.KeyEvent;
import androidx.annotation.Nullable;
+import com.oney.WebRTCModule.WebRTCModuleOptions;
+
import org.jitsi.meet.sdk.JitsiMeet;
import org.jitsi.meet.sdk.JitsiMeetActivity;
import org.jitsi.meet.sdk.JitsiMeetConferenceOptions;
+import org.webrtc.Logging;
import java.lang.reflect.Method;
import java.net.URL;
@@ -79,6 +82,10 @@ public class MainActivity extends JitsiMeetActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
JitsiMeet.showSplashScreen(this);
+
+ WebRTCModuleOptions options = WebRTCModuleOptions.getInstance();
+ options.loggingSeverity = Logging.Severity.LS_ERROR;
+
super.onCreate(null);
}
diff --git a/android/sdk/build.gradle b/android/sdk/build.gradle
index 8edee29f5e..6dbf47bb6a 100644
--- a/android/sdk/build.gradle
+++ b/android/sdk/build.gradle
@@ -89,9 +89,11 @@ dependencies {
implementation project(':react-native-splash-screen')
implementation project(':react-native-svg')
implementation project(':react-native-video')
- implementation project(':react-native-webrtc')
implementation project(':react-native-webview')
+ // Use `api` here so consumers can use WebRTCModuleOptions.
+ api project(':react-native-webrtc')
+
testImplementation 'junit:junit:4.12'
}
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoDecoderFactory.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoDecoderFactory.java
new file mode 100644
index 0000000000..6971e73d7f
--- /dev/null
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoDecoderFactory.java
@@ -0,0 +1,80 @@
+package org.jitsi.meet.sdk;
+
+/*
+ * Copyright 2017 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+import androidx.annotation.Nullable;
+
+import com.oney.WebRTCModule.webrtcutils.SoftwareVideoDecoderFactoryProxy;
+
+import org.webrtc.EglBase;
+import org.webrtc.HardwareVideoDecoderFactory;
+import org.webrtc.PlatformSoftwareVideoDecoderFactory;
+import org.webrtc.VideoCodecInfo;
+import org.webrtc.VideoDecoder;
+import org.webrtc.VideoDecoderFactory;
+import org.webrtc.VideoDecoderFallback;
+
+import java.util.Arrays;
+import java.util.LinkedHashSet;
+
+/**
+ * Custom decoder factory which uses HW decoders and falls back to SW.
+ */
+public class JitsiVideoDecoderFactory implements VideoDecoderFactory {
+ private final VideoDecoderFactory hardwareVideoDecoderFactory;
+ private final VideoDecoderFactory softwareVideoDecoderFactory = new SoftwareVideoDecoderFactoryProxy();
+ private final @Nullable VideoDecoderFactory platformSoftwareVideoDecoderFactory;
+
+ /**
+ * Create decoder factory using default hardware decoder factory.
+ */
+ public JitsiVideoDecoderFactory(@Nullable EglBase.Context eglContext) {
+ this.hardwareVideoDecoderFactory = new HardwareVideoDecoderFactory(eglContext);
+ this.platformSoftwareVideoDecoderFactory = new PlatformSoftwareVideoDecoderFactory(eglContext);
+ }
+
+ /**
+ * Create decoder factory using explicit hardware decoder factory.
+ */
+ JitsiVideoDecoderFactory(VideoDecoderFactory hardwareVideoDecoderFactory) {
+ this.hardwareVideoDecoderFactory = hardwareVideoDecoderFactory;
+ this.platformSoftwareVideoDecoderFactory = null;
+ }
+
+ @Override
+ public @Nullable VideoDecoder createDecoder(VideoCodecInfo codecType) {
+ VideoDecoder softwareDecoder = softwareVideoDecoderFactory.createDecoder(codecType);
+ final VideoDecoder hardwareDecoder = hardwareVideoDecoderFactory.createDecoder(codecType);
+ if (softwareDecoder == null && platformSoftwareVideoDecoderFactory != null) {
+ softwareDecoder = platformSoftwareVideoDecoderFactory.createDecoder(codecType);
+ }
+ if (hardwareDecoder != null && softwareDecoder != null) {
+ // Both hardware and software supported, wrap it in a software fallback
+ return new VideoDecoderFallback(
+ /* fallback= */ softwareDecoder, /* primary= */ hardwareDecoder);
+ }
+ return hardwareDecoder != null ? hardwareDecoder : softwareDecoder;
+ }
+
+ @Override
+ public VideoCodecInfo[] getSupportedCodecs() {
+ LinkedHashSet<VideoCodecInfo> supportedCodecInfos = new LinkedHashSet<>();
+
+ supportedCodecInfos.addAll(Arrays.asList(softwareVideoDecoderFactory.getSupportedCodecs()));
+ supportedCodecInfos.addAll(Arrays.asList(hardwareVideoDecoderFactory.getSupportedCodecs()));
+ if (platformSoftwareVideoDecoderFactory != null) {
+ supportedCodecInfos.addAll(
+ Arrays.asList(platformSoftwareVideoDecoderFactory.getSupportedCodecs()));
+ }
+
+ return supportedCodecInfos.toArray(new VideoCodecInfo[supportedCodecInfos.size()]);
+ }
+}
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoEncoderFactory.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoEncoderFactory.java
new file mode 100644
index 0000000000..5d075ab75d
--- /dev/null
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiVideoEncoderFactory.java
@@ -0,0 +1,16 @@
+package org.jitsi.meet.sdk;
+
+import androidx.annotation.Nullable;
+
+import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoEncoderFactory;
+
+import org.webrtc.EglBase;
+
+/**
+ * Custom encoder factory which uses HW for H.264 and SW for everything else.
+ */
+public class JitsiVideoEncoderFactory extends H264AndSoftwareVideoEncoderFactory {
+ public JitsiVideoEncoderFactory(@Nullable EglBase.Context eglContext) {
+ super(eglContext);
+ }
+}
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java
index ff06167b1b..15990a7bd3 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java
@@ -16,8 +16,8 @@
package org.jitsi.meet.sdk;
+import android.annotation.SuppressLint;
import android.app.Activity;
-import android.util.Log;
import androidx.annotation.Nullable;
@@ -32,12 +32,10 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.uimanager.ViewManager;
import com.oney.WebRTCModule.EglUtils;
import com.oney.WebRTCModule.WebRTCModuleOptions;
-import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoDecoderFactory;
-import com.oney.WebRTCModule.webrtcutils.H264AndSoftwareVideoEncoderFactory;
import org.devio.rn.splashscreen.SplashScreenModule;
+import org.jitsi.meet.sdk.log.JitsiMeetLogger;
import org.webrtc.EglBase;
-import org.webrtc.Logging;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
@@ -126,31 +124,31 @@ class ReactInstanceManagerHolder {
// AmplitudeReactNativePackage
try {
Class<?> amplitudePackageClass = Class.forName("com.amplitude.reactnative.AmplitudeReactNativePackage");
- Constructor constructor = amplitudePackageClass.getConstructor();
+ Constructor<?> constructor = amplitudePackageClass.getConstructor();
packages.add((ReactPackage)constructor.newInstance());
} catch (Exception e) {
// Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.
- Log.d(TAG, "Not loading AmplitudeReactNativePackage");
+ JitsiMeetLogger.d(TAG, "Not loading AmplitudeReactNativePackage");
}
// GiphyReactNativeSdkPackage
try {
Class<?> giphyPackageClass = Class.forName("com.giphyreactnativesdk.GiphyReactNativeSdkPackage");
- Constructor constructor = giphyPackageClass.getConstructor();
+ Constructor<?> constructor = giphyPackageClass.getConstructor();
packages.add((ReactPackage)constructor.newInstance());
} catch (Exception e) {
// Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.
- Log.d(TAG, "Not loading GiphyReactNativeSdkPackage");
+ JitsiMeetLogger.d(TAG, "Not loading GiphyReactNativeSdkPackage");
}
// RNGoogleSignInPackage
try {
Class<?> googlePackageClass = Class.forName("com.reactnativegooglesignin.RNGoogleSigninPackage");
- Constructor constructor = googlePackageClass.getConstructor();
+ Constructor<?> constructor = googlePackageClass.getConstructor();
packages.add((ReactPackage)constructor.newInstance());
} catch (Exception e) {
// Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.
- Log.d(TAG, "Not loading RNGoogleSignInPackage");
+ JitsiMeetLogger.d(TAG, "Not loading RNGoogleSignInPackage");
}
return packages;
@@ -169,7 +167,7 @@ class ReactInstanceManagerHolder {
= ReactInstanceManagerHolder.getReactInstanceManager();
if (reactInstanceManager != null) {
- ReactContext reactContext
+ @SuppressLint("VisibleForTests") ReactContext reactContext
= reactInstanceManager.getCurrentReactContext();
if (reactContext != null) {
@@ -192,7 +190,7 @@ class ReactInstanceManagerHolder {
*/
static <T extends NativeModule> T getNativeModule(
Class<T> nativeModuleClass) {
- ReactContext reactContext
+ @SuppressLint("VisibleForTests") ReactContext reactContext
= reactInstanceManager != null
? reactInstanceManager.getCurrentReactContext() : null;
@@ -219,15 +217,18 @@ class ReactInstanceManagerHolder {
// Initialize the WebRTC module options.
WebRTCModuleOptions options = WebRTCModuleOptions.getInstance();
-
- EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
-
- options.videoDecoderFactory = new H264AndSoftwareVideoDecoderFactory(eglContext);
- options.videoEncoderFactory = new H264AndSoftwareVideoEncoderFactory(eglContext);
options.enableMediaProjectionService = true;
-// options.loggingSeverity = Logging.Severity.LS_INFO;
+ if (options.videoDecoderFactory == null || options.videoEncoderFactory == null) {
+ EglBase.Context eglContext = EglUtils.getRootEglBaseContext();
+ if (options.videoDecoderFactory == null) {
+ options.videoDecoderFactory = new JitsiVideoDecoderFactory(eglContext);
+ }
+ if (options.videoEncoderFactory == null) {
+ options.videoEncoderFactory = new JitsiVideoEncoderFactory(eglContext);
+ }
+ }
- Log.d(TAG, "initializing RN with Activity");
+ JitsiMeetLogger.d(TAG, "initializing RN");
reactInstanceManager
= ReactInstanceManager.builder()