1. java層開啓開關
peerConnectionParameters = new PeerConnectionClient.PeerConnectionParameters();
接口中的useOpensles參數設置爲true
2. /system/etc/permissions/下新增android.hardware.audio.low_latency.xml文件,內容如下:
< ?xml version="1.0" encoding="utf-8"?>
<permissions>
<feature name="android.hardware.audio.low_latency" />
</permissions>
ps:webrtc創建不同的音頻播放方式源碼代碼如下:
audio_device_imp.cc文件 int32_t AudioDeviceModuleImpl::CreatePlatformSpecificObjects()接口
if (audioLayer == kPlatformDefaultAudio) { if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && _audioManagerAndroid->IsLowLatencyRecordSupported()) { // Use OpenSL ES for both playout and recording. audioLayer = kAndroidOpenSLESAudio; } else if (_audioManagerAndroid->IsLowLatencyPlayoutSupported() && !_audioManagerAndroid->IsLowLatencyRecordSupported()) { // Use OpenSL ES for output on devices that only supports the // low-latency output audio path. audioLayer = kAndroidJavaInputAndOpenSLESOutputAudio; } else { // Use Java-based audio in both directions when low-latency output is // not supported. audioLayer = kAndroidJavaAudio; } }
判斷條件源碼在audio_manager.cc
bool AudioManager::IsLowLatencyPlayoutSupported() const { RTC_DCHECK(thread_checker_.CalledOnValidThread()); ALOGD("IsLowLatencyPlayoutSupported()"); // Some devices are blacklisted for usage of OpenSL ES even if they report // that low-latency playout is supported. See b/21485703 for details. return j_audio_manager_->IsDeviceBlacklistedForOpenSLESUsage() ? false : low_latency_playout_; }