Skip to content

Commit

Permalink
Disable hardware acceleration on Samsung
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Danic <[email protected]>
  • Loading branch information
mario committed Jan 13, 2018
1 parent 413e962 commit 22cc8fc
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
targetSdkVersion 27
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

versionCode 12
versionName "1.0.3"
versionCode 13
versionName "1.0.4"

// Enabling multidex support.
multiDexEnabled true
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/nextcloud/talk/activities/CallActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand Down Expand Up @@ -75,6 +76,7 @@
import com.nextcloud.talk.webrtc.MagicAudioManager;
import com.nextcloud.talk.webrtc.MagicPeerConnectionWrapper;
import com.nextcloud.talk.webrtc.MagicWebRTCUtils;
import com.nextcloud.talk.webrtc.MagicWebRtcLists;

import org.apache.commons.lang3.StringEscapeUtils;
import org.greenrobot.eventbus.EventBus;
Expand Down Expand Up @@ -438,7 +440,8 @@ private void createCameraEnumerator() {
if (camera2EnumeratorIsSupported) {
cameraEnumerator = new Camera2Enumerator(this);
} else {
cameraEnumerator = new Camera1Enumerator(true);
cameraEnumerator = new Camera1Enumerator(!MagicWebRtcLists.HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build
.MANUFACTURER.toLowerCase()));
}
}

Expand Down Expand Up @@ -559,8 +562,10 @@ private void basicInitialization() {
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
peerConnectionFactory = new PeerConnectionFactory(options);

peerConnectionFactory.setVideoHwAccelerationOptions(rootEglBase.getEglBaseContext(),
rootEglBase.getEglBaseContext());
if (!MagicWebRtcLists.HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build.MANUFACTURER.toLowerCase())) {
peerConnectionFactory.setVideoHwAccelerationOptions(rootEglBase.getEglBaseContext(),
rootEglBase.getEglBaseContext());
}

//Create MediaConstraints - Will be useful for specifying video and audio constraints.
audioConstraints = new MediaConstraints();
Expand Down Expand Up @@ -1000,7 +1005,6 @@ private void hangup(boolean dueToNetworkChange) {
}

if (peerConnectionFactory != null) {
peerConnectionFactory.dispose();
peerConnectionFactory = null;
}

Expand Down Expand Up @@ -1115,6 +1119,8 @@ private void gotRemoteStream(MediaStream stream, String session) {
Log.d(TAG, "Failed to create a new video view");
}
}

callControls.setZ(100.0f);
}

@Override
Expand Down Expand Up @@ -1212,6 +1218,8 @@ private void removeMediaStream(String sessionId) {
remoteRenderersLayout.invalidate();
}
}

callControls.setZ(100.0f);
}

@Subscribe(threadMode = ThreadMode.MAIN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import com.nextcloud.talk.jobs.PushRegistrationJob;
import com.nextcloud.talk.jobs.creator.MagicJobCreator;
import com.nextcloud.talk.utils.database.user.UserModule;
import com.nextcloud.talk.webrtc.MagicWebRtcLists;
import com.squareup.leakcanary.LeakCanary;
import com.squareup.leakcanary.RefWatcher;

Expand All @@ -51,8 +52,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.GeneralSecurityException;
import java.util.HashSet;
import java.util.Set;

import javax.inject.Singleton;

Expand Down Expand Up @@ -109,52 +108,24 @@ private void useCompatVectorIfNeeded() {
addDelegate.invoke(drawableManager, "vector", vdcInflateDelegate);
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
InvocationTargetException | IllegalAccessException e) {
Log.d(TAG, "Failed to use reflection to enable proper vector scaling");
Log.e(TAG, "Failed to use reflection to enable proper vector scaling");
}
}
}

/*
AEC blacklist and SL_ES_WHITELIST are borrowed from Signal
https://github.com/WhisperSystems/Signal-Android/blob/551470123d006b76a68d705d131bb12513a5e683/src/org/thoughtcrime/securesms/ApplicationContext.java
*/
private void initializeWebRtc() {
try {
Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{
add("D6503"); // Sony Xperia Z2 D6503
add("ONE A2005"); // OnePlus 2
add("MotoG3"); // Moto G (3rd Generation)
add("Nexus 6P"); // Nexus 6p
add("Pixel"); // Pixel
add("Pixel XL"); // Pixel XL
add("MI 4LTE"); // Xiami Mi4
add("Redmi Note 3"); // Redmi Note 3
add("Redmi Note 4"); // Redmi Note 4
add("SM-G900F"); // Samsung Galaxy S5
add("g3_kt_kr"); // LG G3
add("SM-G930F"); // Samsung Galaxy S7
add("Xperia SP"); // Sony Xperia SP
add("Nexus 6"); // Nexus 6
add("ONE E1003"); // OnePlus X
add("One"); // OnePlus One
add("Moto G5");
}};

Set<String> OPEN_SL_ES_WHITELIST = new HashSet<String>() {{
add("Pixel");
add("Pixel XL");
}};

if (HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) {
if (MagicWebRtcLists.HARDWARE_AEC_BLACKLIST.contains(Build.MODEL)) {
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
}

if (!OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) {
if (!MagicWebRtcLists.OPEN_SL_ES_WHITELIST.contains(Build.MODEL)) {
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(true);
}

PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions.builder(this)
.setEnableVideoHwAcceleration(true)
.setEnableVideoHwAcceleration(!MagicWebRtcLists.HARDWARE_ACCELERATION_VENDOR_BLACKLIST.contains(Build
.MANUFACTURER.toLowerCase()))
.createInitializationOptions());
} catch (UnsatisfiedLinkError e) {
Log.w(TAG, e);
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/nextcloud/talk/webrtc/MagicWebRtcLists.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.nextcloud.talk.webrtc;

import java.util.HashSet;
import java.util.Set;

public class MagicWebRtcLists {
/*
AEC blacklist and SL_ES_WHITELIST are borrowed from Signal
https://github.com/WhisperSystems/Signal-Android/blob/551470123d006b76a68d705d131bb12513a5e683/src/org/thoughtcrime/securesms/ApplicationContext.java
*/
public static Set<String> HARDWARE_AEC_BLACKLIST = new HashSet<String>() {{
add("D6503"); // Sony Xperia Z2 D6503
add("ONE A2005"); // OnePlus 2
add("MotoG3"); // Moto G (3rd Generation)
add("Nexus 6P"); // Nexus 6p
add("Pixel"); // Pixel
add("Pixel XL"); // Pixel XL
add("MI 4LTE"); // Xiami Mi4
add("Redmi Note 3"); // Redmi Note 3
add("Redmi Note 4"); // Redmi Note 4
add("SM-G900F"); // Samsung Galaxy S5
add("g3_kt_kr"); // LG G3
add("SM-G930F"); // Samsung Galaxy S7
add("Xperia SP"); // Sony Xperia SP
add("Nexus 6"); // Nexus 6
add("ONE E1003"); // OnePlus X
add("One"); // OnePlus One
add("Moto G5");
}};

public static Set<String> OPEN_SL_ES_WHITELIST = new HashSet<String>() {{
add("Pixel");
add("Pixel XL");
}};

public static Set<String> HARDWARE_ACCELERATION_DEVICE_BLACKLIST = new HashSet<String>() {{
}};

public static Set<String> HARDWARE_ACCELERATION_VENDOR_BLACKLIST = new HashSet<String>() {{
add("samsung");
}};
}

0 comments on commit 22cc8fc

Please sign in to comment.