Use embedded libopus encoder for devices that somehow lack the official one
This commit is contained in:
parent
daacf35411
commit
0a1c7561bd
1
changelog.d/7010.feature
Normal file
1
changelog.d/7010.feature
Normal file
@ -0,0 +1 @@
|
||||
Try to detect devices that lack Opus encoder support, use bundled libopus library for those.
|
@ -48,7 +48,7 @@ class AudioMessageHelper @Inject constructor(
|
||||
) {
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private var currentPlayingId: String? = null
|
||||
private var voiceRecorder: VoiceRecorder = voiceRecorderProvider.provideVoiceRecorder()
|
||||
private val voiceRecorder: VoiceRecorder by lazy { voiceRecorderProvider.provideVoiceRecorder() }
|
||||
|
||||
private val amplitudeList = mutableListOf<Int>()
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
package im.vector.app.features.voice
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaCodecList
|
||||
import android.media.MediaFormat
|
||||
import android.os.Build
|
||||
import im.vector.app.features.VectorFeatures
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -27,10 +29,20 @@ class VoiceRecorderProvider @Inject constructor(
|
||||
private val vectorFeatures: VectorFeatures,
|
||||
) {
|
||||
fun provideVoiceRecorder(): VoiceRecorder {
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && vectorFeatures.forceUsageOfOpusEncoder().not()) {
|
||||
VoiceRecorderQ(context)
|
||||
} else {
|
||||
return if (useFallbackRecorder()) {
|
||||
VoiceRecorderL(context, Dispatchers.IO)
|
||||
} else {
|
||||
VoiceRecorderQ(context)
|
||||
}
|
||||
}
|
||||
|
||||
private fun useFallbackRecorder(): Boolean {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || !hasOpusEncoder() || vectorFeatures.forceUsageOfOpusEncoder()
|
||||
}
|
||||
|
||||
private fun hasOpusEncoder(): Boolean {
|
||||
val codecList = MediaCodecList(MediaCodecList.ALL_CODECS)
|
||||
val format = MediaFormat.createAudioFormat(MediaFormat.MIMETYPE_AUDIO_OPUS, 48000, 1)
|
||||
return codecList.findEncoderForFormat(format) != null
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user