Add an option to disable built-in AEC to AppRTC Android Demo
BUG=webrtc:5923 Review-Url: https://codereview.webrtc.org/2002093002 Cr-Commit-Position: refs/heads/master@{#12885}
This commit is contained in:
@ -117,6 +117,12 @@
|
||||
<string name="pref_opensles_dlg">Use OpenSL ES for audio playback.</string>
|
||||
<string name="pref_opensles_default">false</string>
|
||||
|
||||
<string name="pref_disable_built_in_aec_key">disable_built_in_aec_preference</string>
|
||||
<string name="pref_disable_built_in_aec_title">Disable built-in AEC.</string>
|
||||
<string name="pref_disable_built_in_aec_dlg">Disable built-in AEC.</string>
|
||||
<string name="pref_disable_built_in_aec_default">false</string>
|
||||
<string name="pref_built_in_aec_not_available">Built-in AEC is not available</string>
|
||||
|
||||
<string name="pref_miscsettings_key">misc_settings_key</string>
|
||||
<string name="pref_miscsettings_title">Miscellaneous settings.</string>
|
||||
|
||||
|
||||
@ -112,6 +112,12 @@
|
||||
android:title="@string/pref_opensles_title"
|
||||
android:dialogTitle="@string/pref_opensles_dlg"
|
||||
android:defaultValue="@string/pref_opensles_default" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="@string/pref_disable_built_in_aec_key"
|
||||
android:title="@string/pref_disable_built_in_aec_title"
|
||||
android:dialogTitle="@string/pref_disable_built_in_aec_dlg"
|
||||
android:defaultValue="@string/pref_disable_built_in_aec_default" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
||||
@ -78,6 +78,8 @@ public class CallActivity extends Activity
|
||||
"org.appspot.apprtc.AECDUMP";
|
||||
public static final String EXTRA_OPENSLES_ENABLED =
|
||||
"org.appspot.apprtc.OPENSLES";
|
||||
public static final String EXTRA_DISABLE_BUILT_IN_AEC =
|
||||
"org.appspot.apprtc.DISABLE_BUILT_IN_AEC";
|
||||
public static final String EXTRA_DISPLAY_HUD =
|
||||
"org.appspot.apprtc.DISPLAY_HUD";
|
||||
public static final String EXTRA_TRACING = "org.appspot.apprtc.TRACING";
|
||||
@ -234,7 +236,8 @@ public class CallActivity extends Activity
|
||||
intent.getStringExtra(EXTRA_AUDIOCODEC),
|
||||
intent.getBooleanExtra(EXTRA_NOAUDIOPROCESSING_ENABLED, false),
|
||||
intent.getBooleanExtra(EXTRA_AECDUMP_ENABLED, false),
|
||||
intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false));
|
||||
intent.getBooleanExtra(EXTRA_OPENSLES_ENABLED, false),
|
||||
intent.getBooleanExtra(EXTRA_DISABLE_BUILT_IN_AEC, false));
|
||||
commandLineRun = intent.getBooleanExtra(EXTRA_CMDLINE, false);
|
||||
runTimeMs = intent.getIntExtra(EXTRA_RUNTIME, 0);
|
||||
|
||||
|
||||
@ -69,6 +69,7 @@ public class ConnectActivity extends Activity {
|
||||
private String keyprefNoAudioProcessingPipeline;
|
||||
private String keyprefAecDump;
|
||||
private String keyprefOpenSLES;
|
||||
private String keyprefDisableBuiltInAec;
|
||||
private String keyprefDisplayHud;
|
||||
private String keyprefTracing;
|
||||
private String keyprefRoomServerUrl;
|
||||
@ -99,6 +100,7 @@ public class ConnectActivity extends Activity {
|
||||
keyprefNoAudioProcessingPipeline = getString(R.string.pref_noaudioprocessing_key);
|
||||
keyprefAecDump = getString(R.string.pref_aecdump_key);
|
||||
keyprefOpenSLES = getString(R.string.pref_opensles_key);
|
||||
keyprefDisableBuiltInAec = getString(R.string.pref_disable_built_in_aec_key);
|
||||
keyprefDisplayHud = getString(R.string.pref_displayhud_key);
|
||||
keyprefTracing = getString(R.string.pref_tracing_key);
|
||||
keyprefRoomServerUrl = getString(R.string.pref_room_server_url_key);
|
||||
@ -286,6 +288,11 @@ public class ConnectActivity extends Activity {
|
||||
keyprefOpenSLES,
|
||||
Boolean.valueOf(getString(R.string.pref_opensles_default)));
|
||||
|
||||
// Check Disable built-in AEC flag.
|
||||
boolean disableBuiltInAEC = sharedPref.getBoolean(
|
||||
keyprefDisableBuiltInAec,
|
||||
Boolean.valueOf(getString(R.string.pref_disable_built_in_aec_default)));
|
||||
|
||||
// Get video resolution from settings.
|
||||
int videoWidth = 0;
|
||||
int videoHeight = 0;
|
||||
@ -370,6 +377,7 @@ public class ConnectActivity extends Activity {
|
||||
noAudioProcessing);
|
||||
intent.putExtra(CallActivity.EXTRA_AECDUMP_ENABLED, aecDump);
|
||||
intent.putExtra(CallActivity.EXTRA_OPENSLES_ENABLED, useOpenSLES);
|
||||
intent.putExtra(CallActivity.EXTRA_DISABLE_BUILT_IN_AEC, disableBuiltInAEC);
|
||||
intent.putExtra(CallActivity.EXTRA_AUDIO_BITRATE, audioStartBitrate);
|
||||
intent.putExtra(CallActivity.EXTRA_AUDIOCODEC, audioCodec);
|
||||
intent.putExtra(CallActivity.EXTRA_DISPLAY_HUD, displayHud);
|
||||
|
||||
@ -38,6 +38,7 @@ import org.webrtc.VideoRenderer;
|
||||
import org.webrtc.VideoSource;
|
||||
import org.webrtc.VideoTrack;
|
||||
import org.webrtc.voiceengine.WebRtcAudioManager;
|
||||
import org.webrtc.voiceengine.WebRtcAudioUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -148,13 +149,15 @@ public class PeerConnectionClient {
|
||||
public final boolean noAudioProcessing;
|
||||
public final boolean aecDump;
|
||||
public final boolean useOpenSLES;
|
||||
public final boolean disableBuiltInAEC;
|
||||
|
||||
public PeerConnectionParameters(
|
||||
boolean videoCallEnabled, boolean loopback, boolean tracing,
|
||||
int videoWidth, int videoHeight, int videoFps, int videoStartBitrate,
|
||||
String videoCodec, boolean videoCodecHwAcceleration, boolean captureToTexture,
|
||||
int audioStartBitrate, String audioCodec,
|
||||
boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES) {
|
||||
boolean noAudioProcessing, boolean aecDump, boolean useOpenSLES,
|
||||
boolean disableBuiltInAEC) {
|
||||
this.videoCallEnabled = videoCallEnabled;
|
||||
this.loopback = loopback;
|
||||
this.tracing = tracing;
|
||||
@ -170,6 +173,7 @@ public class PeerConnectionClient {
|
||||
this.noAudioProcessing = noAudioProcessing;
|
||||
this.aecDump = aecDump;
|
||||
this.useOpenSLES = useOpenSLES;
|
||||
this.disableBuiltInAEC = disableBuiltInAEC;
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,6 +343,14 @@ public class PeerConnectionClient {
|
||||
WebRtcAudioManager.setBlacklistDeviceForOpenSLESUsage(false);
|
||||
}
|
||||
|
||||
if (peerConnectionParameters.disableBuiltInAEC) {
|
||||
Log.d(TAG, "Disable built-in AEC even if device supports it");
|
||||
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(true);
|
||||
} else {
|
||||
Log.d(TAG, "Enable built-in AEC if device supports it");
|
||||
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(false);
|
||||
}
|
||||
|
||||
// Create peer connection factory.
|
||||
if (!PeerConnectionFactory.initializeAndroidGlobals(context, true, true,
|
||||
peerConnectionParameters.videoCodecHwAcceleration)) {
|
||||
|
||||
@ -16,6 +16,8 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
|
||||
import org.webrtc.voiceengine.WebRtcAudioUtils;
|
||||
|
||||
/**
|
||||
* Settings activity for AppRTC.
|
||||
*/
|
||||
@ -38,6 +40,7 @@ public class SettingsActivity extends Activity
|
||||
private String keyprefNoAudioProcessing;
|
||||
private String keyprefAecDump;
|
||||
private String keyprefOpenSLES;
|
||||
private String keyprefDisableBuiltInAEC;
|
||||
|
||||
private String keyPrefRoomServerUrl;
|
||||
private String keyPrefDisplayHud;
|
||||
@ -62,6 +65,7 @@ public class SettingsActivity extends Activity
|
||||
keyprefNoAudioProcessing = getString(R.string.pref_noaudioprocessing_key);
|
||||
keyprefAecDump = getString(R.string.pref_aecdump_key);
|
||||
keyprefOpenSLES = getString(R.string.pref_opensles_key);
|
||||
keyprefDisableBuiltInAEC = getString(R.string.pref_disable_built_in_aec_key);
|
||||
|
||||
keyPrefRoomServerUrl = getString(R.string.pref_room_server_url_key);
|
||||
keyPrefDisplayHud = getString(R.string.pref_displayhud_key);
|
||||
@ -99,10 +103,23 @@ public class SettingsActivity extends Activity
|
||||
updateSummaryB(sharedPreferences, keyprefNoAudioProcessing);
|
||||
updateSummaryB(sharedPreferences, keyprefAecDump);
|
||||
updateSummaryB(sharedPreferences, keyprefOpenSLES);
|
||||
updateSummaryB(sharedPreferences, keyprefDisableBuiltInAEC);
|
||||
|
||||
updateSummary(sharedPreferences, keyPrefRoomServerUrl);
|
||||
updateSummaryB(sharedPreferences, keyPrefDisplayHud);
|
||||
updateSummaryB(sharedPreferences, keyPrefTracing);
|
||||
|
||||
// Disable forcing WebRTC based AEC so it won't affect our value.
|
||||
// Otherwise, if it was enabled, isAcousticEchoCancelerSupported would always return false.
|
||||
WebRtcAudioUtils.setWebRtcBasedAcousticEchoCanceler(false);
|
||||
if (!WebRtcAudioUtils.isAcousticEchoCancelerSupported()) {
|
||||
Preference disableBuiltInAECPreference =
|
||||
settingsFragment.findPreference(keyprefDisableBuiltInAEC);
|
||||
|
||||
|
||||
disableBuiltInAECPreference.setSummary(getString(R.string.pref_built_in_aec_not_available));
|
||||
disableBuiltInAECPreference.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -135,6 +152,7 @@ public class SettingsActivity extends Activity
|
||||
|| key.equals(keyprefNoAudioProcessing)
|
||||
|| key.equals(keyprefAecDump)
|
||||
|| key.equals(keyprefOpenSLES)
|
||||
|| key.equals(keyprefDisableBuiltInAEC)
|
||||
|| key.equals(keyPrefDisplayHud)) {
|
||||
updateSummaryB(sharedPreferences, key);
|
||||
}
|
||||
|
||||
@ -263,9 +263,24 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
|
||||
private PeerConnectionParameters createParametersForAudioCall() {
|
||||
PeerConnectionParameters peerConnectionParameters =
|
||||
new PeerConnectionParameters(
|
||||
false, true, false, // videoCallEnabled, loopback, tracing.
|
||||
0, 0, 0, 0, "", true, false, // video codec parameters.
|
||||
0, "OPUS", false, false, false); // audio codec parameters.
|
||||
false, /* videoCallEnabled */
|
||||
true, /* loopback */
|
||||
false, /* tracing */
|
||||
// Video codec parameters.
|
||||
0, /* videoWidth */
|
||||
0, /* videoHeight */
|
||||
0, /* videoFps */
|
||||
0, /* videoStartBitrate */
|
||||
"", /* videoCodec */
|
||||
true, /* videoCodecHwAcceleration */
|
||||
false, /* captureToToTexture */
|
||||
// Audio codec parameters.
|
||||
0, /* audioStartBitrate */
|
||||
"OPUS", /* audioCodec */
|
||||
false, /* noAudioProcessing */
|
||||
false, /* aecDump */
|
||||
false /* useOpenSLES */,
|
||||
false /* disableBuiltInAEC */);
|
||||
return peerConnectionParameters;
|
||||
}
|
||||
|
||||
@ -273,9 +288,24 @@ public class PeerConnectionClientTest extends InstrumentationTestCase
|
||||
String videoCodec, boolean captureToTexture) {
|
||||
PeerConnectionParameters peerConnectionParameters =
|
||||
new PeerConnectionParameters(
|
||||
true, true, false, // videoCallEnabled, loopback, tracing.
|
||||
0, 0, 0, 0, videoCodec, true, captureToTexture, // video codec parameters.
|
||||
0, "OPUS", false, false, false); // audio codec parameters.
|
||||
true, /* videoCallEnabled */
|
||||
true, /* loopback */
|
||||
false, /* tracing */
|
||||
// Video codec parameters.
|
||||
0, /* videoWidth */
|
||||
0, /* videoHeight */
|
||||
0, /* videoFps */
|
||||
0, /* videoStartBitrate */
|
||||
videoCodec, /* videoCodec */
|
||||
true, /* videoCodecHwAcceleration */
|
||||
captureToTexture, /* captureToToTexture */
|
||||
// Audio codec parameters.
|
||||
0, /* audioStartBitrate */
|
||||
"OPUS", /* audioCodec */
|
||||
false, /* noAudioProcessing */
|
||||
false, /* aecDump */
|
||||
false /* useOpenSLES */,
|
||||
false /* disableBuiltInAEC */);
|
||||
return peerConnectionParameters;
|
||||
}
|
||||
|
||||
|
||||
@ -42,13 +42,6 @@ class WebRtcAudioEffects {
|
||||
private static final UUID AOSP_NOISE_SUPPRESSOR =
|
||||
UUID.fromString("c06c8400-8e06-11e0-9cb6-0002a5d5c51b");
|
||||
|
||||
// Static Boolean objects used to avoid expensive queries more than once.
|
||||
// The first result is cached in these members and then reused if needed.
|
||||
// Each member is null until it has been evaluated/set for the first time.
|
||||
private static Boolean canUseAcousticEchoCanceler = null;
|
||||
private static Boolean canUseAutomaticGainControl = null;
|
||||
private static Boolean canUseNoiseSuppressor = null;
|
||||
|
||||
// Contains the audio effect objects. Created in enable() and destroyed
|
||||
// in release().
|
||||
private AcousticEchoCanceler aec = null;
|
||||
@ -160,44 +153,38 @@ class WebRtcAudioEffects {
|
||||
// Returns true if all conditions for supporting the HW AEC are fulfilled.
|
||||
// It will not be possible to enable the HW AEC if this method returns false.
|
||||
public static boolean canUseAcousticEchoCanceler() {
|
||||
if (canUseAcousticEchoCanceler == null) {
|
||||
canUseAcousticEchoCanceler = new Boolean(
|
||||
isAcousticEchoCancelerSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler()
|
||||
&& !isAcousticEchoCancelerBlacklisted()
|
||||
&& !isAcousticEchoCancelerExcludedByUUID());
|
||||
Logging.d(TAG, "canUseAcousticEchoCanceler: "
|
||||
+ canUseAcousticEchoCanceler);
|
||||
}
|
||||
boolean canUseAcousticEchoCanceler =
|
||||
isAcousticEchoCancelerSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedAcousticEchoCanceler()
|
||||
&& !isAcousticEchoCancelerBlacklisted()
|
||||
&& !isAcousticEchoCancelerExcludedByUUID();
|
||||
Logging.d(TAG, "canUseAcousticEchoCanceler: "
|
||||
+ canUseAcousticEchoCanceler);
|
||||
return canUseAcousticEchoCanceler;
|
||||
}
|
||||
|
||||
// Returns true if all conditions for supporting the HW AGC are fulfilled.
|
||||
// It will not be possible to enable the HW AGC if this method returns false.
|
||||
public static boolean canUseAutomaticGainControl() {
|
||||
if (canUseAutomaticGainControl == null) {
|
||||
canUseAutomaticGainControl = new Boolean(
|
||||
isAutomaticGainControlSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedAutomaticGainControl()
|
||||
&& !isAutomaticGainControlBlacklisted()
|
||||
&& !isAutomaticGainControlExcludedByUUID());
|
||||
Logging.d(TAG, "canUseAutomaticGainControl: "
|
||||
+ canUseAutomaticGainControl);
|
||||
}
|
||||
boolean canUseAutomaticGainControl =
|
||||
isAutomaticGainControlSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedAutomaticGainControl()
|
||||
&& !isAutomaticGainControlBlacklisted()
|
||||
&& !isAutomaticGainControlExcludedByUUID();
|
||||
Logging.d(TAG, "canUseAutomaticGainControl: "
|
||||
+ canUseAutomaticGainControl);
|
||||
return canUseAutomaticGainControl;
|
||||
}
|
||||
|
||||
// Returns true if all conditions for supporting the HW NS are fulfilled.
|
||||
// It will not be possible to enable the HW NS if this method returns false.
|
||||
public static boolean canUseNoiseSuppressor() {
|
||||
if (canUseNoiseSuppressor == null) {
|
||||
canUseNoiseSuppressor = new Boolean(
|
||||
isNoiseSuppressorSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedNoiseSuppressor()
|
||||
&& !isNoiseSuppressorBlacklisted()
|
||||
&& !isNoiseSuppressorExcludedByUUID());
|
||||
Logging.d(TAG, "canUseNoiseSuppressor: " + canUseNoiseSuppressor);
|
||||
}
|
||||
boolean canUseNoiseSuppressor =
|
||||
isNoiseSuppressorSupported()
|
||||
&& !WebRtcAudioUtils.useWebRtcBasedNoiseSuppressor()
|
||||
&& !isNoiseSuppressorBlacklisted()
|
||||
&& !isNoiseSuppressorExcludedByUUID();
|
||||
Logging.d(TAG, "canUseNoiseSuppressor: " + canUseNoiseSuppressor);
|
||||
return canUseNoiseSuppressor;
|
||||
}
|
||||
|
||||
|
||||
@ -100,6 +100,22 @@ public final class WebRtcAudioUtils {
|
||||
return useWebRtcBasedNoiseSuppressor;
|
||||
}
|
||||
|
||||
// Returns true if the device supports an audio effect (AEC, AGC or NS).
|
||||
// Four conditions must be fulfilled if functions are to return true:
|
||||
// 1) the platform must support the built-in (HW) effect,
|
||||
// 2) explicit use (override) of a WebRTC based version must not be set,
|
||||
// 3) the device must not be blacklisted for use of the effect, and
|
||||
// 4) the UUID of the effect must be approved (some UUIDs can be excluded).
|
||||
public static boolean isAcousticEchoCancelerSupported() {
|
||||
return WebRtcAudioEffects.canUseAcousticEchoCanceler();
|
||||
}
|
||||
public static boolean isAutomaticGainControlSupported() {
|
||||
return WebRtcAudioEffects.canUseAutomaticGainControl();
|
||||
}
|
||||
public static boolean isNoiseSuppressorSupported() {
|
||||
return WebRtcAudioEffects.canUseNoiseSuppressor();
|
||||
}
|
||||
|
||||
// Call this method if the default handling of querying the native sample
|
||||
// rate shall be overridden. Can be useful on some devices where the
|
||||
// available Android APIs are known to return invalid results.
|
||||
|
||||
Reference in New Issue
Block a user