package org.webrtc.audio; import android.media.audiofx.AcousticEchoCanceler; import android.media.audiofx.AudioEffect; import android.media.audiofx.NoiseSuppressor; import java.util.UUID; import org.webrtc.Logging; /* loaded from: classes3.dex */ class WebRtcAudioEffects { private static final UUID AOSP_ACOUSTIC_ECHO_CANCELER = UUID.fromString("bb392ec0-8d4d-11e0-a896-0002a5d5c51b"); private static final UUID AOSP_NOISE_SUPPRESSOR = UUID.fromString("c06c8400-8e06-11e0-9cb6-0002a5d5c51b"); private static final boolean DEBUG = false; private static final String TAG = "WebRtcAudioEffectsExternal"; private static AudioEffect.Descriptor[] cachedEffects; private AcousticEchoCanceler aec; private NoiseSuppressor ns; private boolean shouldEnableAec; private boolean shouldEnableNs; public static boolean isAcousticEchoCancelerSupported() { return isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_AEC, AOSP_ACOUSTIC_ECHO_CANCELER); } public static boolean isNoiseSuppressorSupported() { return isEffectTypeAvailable(AudioEffect.EFFECT_TYPE_NS, AOSP_NOISE_SUPPRESSOR); } public WebRtcAudioEffects() { Logging.d(TAG, "ctor" + WebRtcAudioUtils.getThreadInfo()); } public boolean setAEC(boolean z) { Logging.d(TAG, "setAEC(" + z + ")"); if (!isAcousticEchoCancelerSupported()) { Logging.w(TAG, "Platform AEC is not supported"); this.shouldEnableAec = false; return false; } if (this.aec == null || z == this.shouldEnableAec) { this.shouldEnableAec = z; return true; } Logging.e(TAG, "Platform AEC state can't be modified while recording"); return false; } public boolean setNS(boolean z) { Logging.d(TAG, "setNS(" + z + ")"); if (!isNoiseSuppressorSupported()) { Logging.w(TAG, "Platform NS is not supported"); this.shouldEnableNs = false; return false; } if (this.ns == null || z == this.shouldEnableNs) { this.shouldEnableNs = z; return true; } Logging.e(TAG, "Platform NS state can't be modified while recording"); return false; } public void enable(int i) { Logging.d(TAG, "enable(audioSession=" + i + ")"); assertTrue(this.aec == null); assertTrue(this.ns == null); if (isAcousticEchoCancelerSupported()) { AcousticEchoCanceler create = AcousticEchoCanceler.create(i); this.aec = create; if (create != null) { boolean enabled = create.getEnabled(); boolean z = this.shouldEnableAec && isAcousticEchoCancelerSupported(); if (this.aec.setEnabled(z) != 0) { Logging.e(TAG, "Failed to set the AcousticEchoCanceler state"); } Logging.d(TAG, "AcousticEchoCanceler: was " + (enabled ? "enabled" : "disabled") + ", enable: " + z + ", is now: " + (this.aec.getEnabled() ? "enabled" : "disabled")); } else { Logging.e(TAG, "Failed to create the AcousticEchoCanceler instance"); } } if (isNoiseSuppressorSupported()) { NoiseSuppressor create2 = NoiseSuppressor.create(i); this.ns = create2; if (create2 != null) { boolean enabled2 = create2.getEnabled(); boolean z2 = this.shouldEnableNs && isNoiseSuppressorSupported(); if (this.ns.setEnabled(z2) != 0) { Logging.e(TAG, "Failed to set the NoiseSuppressor state"); } Logging.d(TAG, "NoiseSuppressor: was " + (enabled2 ? "enabled" : "disabled") + ", enable: " + z2 + ", is now: " + (this.ns.getEnabled() ? "enabled" : "disabled")); return; } Logging.e(TAG, "Failed to create the NoiseSuppressor instance"); } } public void release() { Logging.d(TAG, "release"); AcousticEchoCanceler acousticEchoCanceler = this.aec; if (acousticEchoCanceler != null) { acousticEchoCanceler.release(); this.aec = null; } NoiseSuppressor noiseSuppressor = this.ns; if (noiseSuppressor != null) { noiseSuppressor.release(); this.ns = null; } } private boolean effectTypeIsVoIP(UUID uuid) { return (AudioEffect.EFFECT_TYPE_AEC.equals(uuid) && isAcousticEchoCancelerSupported()) || (AudioEffect.EFFECT_TYPE_NS.equals(uuid) && isNoiseSuppressorSupported()); } private static void assertTrue(boolean z) { if (!z) { throw new AssertionError("Expected condition to be true"); } } private static AudioEffect.Descriptor[] getAvailableEffects() { AudioEffect.Descriptor[] descriptorArr = cachedEffects; if (descriptorArr != null) { return descriptorArr; } AudioEffect.Descriptor[] queryEffects = AudioEffect.queryEffects(); cachedEffects = queryEffects; return queryEffects; } private static boolean isEffectTypeAvailable(UUID uuid, UUID uuid2) { AudioEffect.Descriptor[] availableEffects = getAvailableEffects(); if (availableEffects == null) { return false; } for (AudioEffect.Descriptor descriptor : availableEffects) { if (descriptor.type.equals(uuid)) { return !r4.uuid.equals(uuid2); } } return false; } }