Improved implementation of toggling of speaker phone and clearing of communication device
Added NS check to AEC and AGC check function
This commit is contained in:
@@ -17,6 +17,7 @@ import android.media.AudioManager
|
|||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.media.audiofx.AcousticEchoCanceler
|
import android.media.audiofx.AcousticEchoCanceler
|
||||||
import android.media.audiofx.AutomaticGainControl
|
import android.media.audiofx.AutomaticGainControl
|
||||||
|
import android.media.audiofx.NoiseSuppressor
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
@@ -929,15 +930,13 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
val isSpeakerOn = if (Build.VERSION.SDK_INT >= 31) {
|
||||||
if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
|
am.communicationDevice?.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER
|
||||||
setSpeakerPhone(executor, am, false)
|
|
||||||
else
|
|
||||||
setSpeakerPhone(executor, am, true)
|
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
setSpeakerPhone(executor, am, !am.isSpeakerphoneOn)
|
am.isSpeakerphoneOn
|
||||||
}
|
}
|
||||||
|
setSpeakerPhone(executor, am, !isSpeakerOn)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearCommunicationDevice(am: AudioManager) {
|
fun clearCommunicationDevice(am: AudioManager) {
|
||||||
@@ -945,7 +944,6 @@ object Utils {
|
|||||||
am.clearCommunicationDevice()
|
am.clearCommunicationDevice()
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
if (am.isSpeakerphoneOn)
|
|
||||||
am.isSpeakerphoneOn = false
|
am.isSpeakerphoneOn = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -984,10 +982,10 @@ object Utils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aecAgcCheck() {
|
fun aecAgcNsCheck() {
|
||||||
val sessionId = Api.AAudio_open_stream()
|
val sessionId = Api.AAudio_open_stream()
|
||||||
if (sessionId == -1) {
|
if (sessionId <= 0) {
|
||||||
Log.e(TAG, "Failed to open AAudio stream")
|
Log.e(TAG, "Failed to open AAudio stream or invalid sessionId ($sessionId)")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1017,6 +1015,19 @@ object Utils {
|
|||||||
else
|
else
|
||||||
Log.i(TAG, "Hardware AGC is NOT available")
|
Log.i(TAG, "Hardware AGC is NOT available")
|
||||||
|
|
||||||
|
if (NoiseSuppressor.isAvailable()) {
|
||||||
|
val ns = NoiseSuppressor.create(sessionId)
|
||||||
|
if (ns != null) {
|
||||||
|
BaresipService.nsAvailable = true
|
||||||
|
ns.release()
|
||||||
|
Log.d(TAG, "Creation of hardware NS for $sessionId succeeded")
|
||||||
|
} else {
|
||||||
|
Log.w(TAG, "Creation of hardware NS for $sessionId failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Log.i(TAG, "Hardware NS is NOT available")
|
||||||
|
|
||||||
Api.AAudio_close_stream()
|
Api.AAudio_close_stream()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user