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"?>
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_;}