我在webrtc stats API网站上阅读了关于音频级文档:
Identifiers for WebRTC's Statistics API
在此网站上,他们将AudioLevel值描述为0..1。当我获得音频流的统计数据并打印到控制台时。结果如下:
▿ 29 key/value pairs
▿ (2 elements)
- key: "ssrc"
- value: "2726297394"
▿ (2 elements)
- key: "googDecodingPLC"
- value: "18"
▿ (2 elements)
- key: "googSecondaryDecodedRate"
- value: "0"
▿ (2 elements)
- key: "googDecodingCTN"
- value: "911"
▿ (2 elements)
- key: "googJitterReceived"
- value: "5"
▿ (2 elements)
- key: "transportId"
- value: "Channel-audio-1"
▿ (2 elements)
- key: "googExpandRate"
- value: "0.0194092"
▿ (2 elements)
- key: "packetsReceived"
- value: "439"
▿ (2 elements)
- key: "audioOutputLevel"
- value: "28025"
▿ (2 elements)
- key: "googDecodingMuted"
- value: "43"
▿ (2 elements)
- key: "googDecodingPLCCNG"
- value: "44"
▿ (2 elements)
- key: "totalSamplesDuration"
- value: "9.11"
▿ (2 elements)
- key: "googPreemptiveExpandRate"
- value: "0.0101318"
▿ (2 elements)
- key: "googSpeechExpandRate"
- value: "0.0194092"
▿ (2 elements)
- key: "packetsLost"
- value: "1"
▿ (2 elements)
- key: "googPreferredJitterBufferMs"
- value: "120"
▿ (2 elements)
- key: "googDecodingCTSG"
- value: "0"
▿ (2 elements)
- key: "googCurrentDelayMs"
- value: "158"
▿ (2 elements)
- key: "googCaptureStartNtpTimeMs"
- value: "0"
▿ (2 elements)
- key: "mediaType"
- value: "audio"
▿ (2 elements)
- key: "bytesReceived"
- value: "41628"
▿ (2 elements)
- key: "googCodecName"
- value: "opus"
▿ (2 elements)
- key: "googDecodingCNG"
- value: "0"
▿ (2 elements)
- key: "totalAudioEnergy"
- value: "3.47756"
▿ (2 elements)
- key: "googJitterBufferMs"
- value: "120"
▿ (2 elements)
- key: "googSecondaryDiscardedRate"
- value: "0"
▿ (2 elements)
- key: "googAccelerateRate"
- value: "0.00354004"
▿ (2 elements)
- key: "googDecodingNormal"
- value: "849"
▿ (2 elements)
- key: "googTrackId"
- value: "OCVMXiq8"
我没有找到关键的“audioLevel”作为文档描述,但找到了“audioOutputLevel”。然后,这个值意味着什么,或者它可以转换为“audioLevel”值,如上文所述
更新以下是我用来获取统计数据的示例代码
for receive in (self.client!.peerConnection!.receivers) {
self.client!.peerConnection!.stats(for: receive.track!, statsOutputLevel: .debug, completionHandler: { reports in
for report in reports {
print("-------- report id \(report.reportId) in time \(Date().timeIntervalSince1970)")
dump(report.values)
print("-----------------------------------------")
}
})
}
您似乎正在使用“遗留”getStats API,即您调用
pc.getStats(function(res) {
// show result
})
其中这称为aduioOutputLevel。如果你使用
pc.getStats().then(function(stats) {
// show result
})
它应该显示为audioLevel。
https://webrtc.github.io/samples/src/content/peerconnection/constraints/展示了一个完整的例子。