新冠疫情期间,多少人都通过网络来远程工作,在网上开会,聊天,进行音视频通话。远程通话毕竟不如面对面那样顺畅,时常会有声音断断续续,视频图像模糊不清或卡顿的情况让人抓狂。
为什么网络通话和视频质量会时好时坏呢?而电话里的声音总是挺清晰,电视图像总是清楚,原因就在于互联网 internet 的带宽有限,互联网上的彼此连通的一个个用户所经过的网络情况千差万别,网络一抖动,一拥塞,通话和视频质量就有可能下降。
怎么解决这些问题呢,这就要牵涉到了 QoS (Quality of Service) 服务质量的度量和优化。 优化是一个大话题,通过压缩编码, Jitter buffer, FEC等手段可以应对网络的不稳定。要优化先需要度量,无度量,不优化。
WebRTC 的 statistics API 提供了诸多的统计度量信息
- RTC 统计类型 RTCStatsType 参见 developer.mozilla.org/en-US/docs/…
| 类别 | 描述 | 实现类 |
|---|---|---|
| codec: 编码 | RTCCodecStatsRTCStats | |
| Inbound-rtp: 流入的 RTP | ||
| outbound-rtp: 流出的 RTP | ||
| remote-inbound-rtp: 远端的流入的 RTP | ||
| remote-outbound-rtp: 远端的流出的 RTP | ||
| csrc: 贡献源 | ||
| peer-connection: 对等连接 | ||
| data-channel: 数据通道 | ||
| stream: 流 | ||
| track: 轨道 | ||
| transceiver: 收发者 | ||
| sender: 发送者 | ||
| receiver: 接收者 | ||
| transport: 通道 | ||
| sctp-transport: SCTP通道 | ||
| candidate-pair: 候选者对 | ||
| local-candidate: 本地候选者 | ||
| remote-candidate: 远端候选者 | ||
| certificate: 认证 | ||
| Ice-server: ICE 服务器 |
对象 WebRTC 的媒体流传输的统计按如下层次区分:
- RTCRtpStreamStats 媒体流统计
- RTCReceivedRtpStreamStats 接收者媒体流统计
- RTCInboundRtpStreamStats 流入的媒体流统计
- RTCOutboundRtpStreamStats 流出的媒体流统计
- RTCSentRtpStreamStats 发送者的媒体流统计
- RTCOutboundRtpStreamStats 流入的媒体流统计
- RTCRemoteOutboundRtpStreamStats 流出的媒体流统计
- RTCReceivedRtpStreamStats 接收者媒体流统计
最主要的统计类, 分别在四个方向上度量
- outbound-rtp 本地流出的 RTP 流
- inbound-rtp 本地流入的 RTP 流
- remote-inbound-rtp 远端流入的 RTP 流
- remote-outbound-rtp 远端流出的 RTP 流
- RTCReceivedRtpStreamStats for inbound-rtp
packetsReceived: 收到的 RTP 包packetsLost: 丢失的包jitter抖动packetsDiscarded丢弃的包packetsRepaired修复的包burstPacketsLost在丢失突发期间丢失的RTP数据包的累积数量burstPacketsDiscarded在丢弃突发期间丢失的RTP数据包的丢弃数量burstLossCount丢失的RTP数据包的累积突发数burstDiscardCount丢弃的RTP数据包的累积突发数burstLossRate突发期间丢失的RTP数据包占突发中预期的RTP数据包总数的比例。burstDiscardRate突发期间丢弃的RTP数据包占突发中预期的RTP数据包总数的比例。gapLossRate在间隙期间丢失的RTP数据包的百分比。gapDiscardRate在间隙期间丢弃的RTP数据包的百分比。framesDropped仅存在于视频中。 解码之前丢失或丢弃的总帧数,因为该帧错过了此接收器轨道的显示截止日期。 该测量从创建接收方开始,并且是[RFC7004] 附录 A(g)中定义的累积度量。partialFramesLost仅存在于视频中。 丢失的部分帧的累积数量。 该测量从创建接收方开始,并且是[RFC7004]附录A(j) 中定义的累积度量。 当帧发送到解码器时,此度量会增加。 如果在解码之前通过重传或FEC接收并恢复了部分帧,则会增加frameReceived计数器。fullFramesLost仅存在于视频中。 丢失完整帧的累计数量。 该测量从创建接收方开始,并且是[RFC7004] 附录A(i) 中定义的累积度量。
- RTCInboundRtpStreamStats for inbound-rtp
receiverIdremoteIdframesDecodedkeyFramesDecodedframeWidthframeHeightframeBitDepthframesPerSecondqpSumtotalDecodeTimetotalInterFrameDelaytotalSquaredInterFrameDelayvoiceActivityFlaglastPacketReceivedTimestampaverageRtcpIntervalheaderBytesReceivedfecPacketsReceivedfecPacketsDiscardedbytesReceivedpacketsFailedDecryptionpacketsDuplicatedperDscpPacketsReceivednackCountfirCountpliCountsliCounttotalProcessingDelayestimatedPlayoutTimestampjitterBufferDelayjitterBufferEmittedCounttotalSamplesReceivedtotalSamplesDecodedsamplesDecodedWithSilksamplesDecodedWithCeltconcealedSamplessilentConcealedSamplesconcealmentEventsinsertedSamplesForDecelerationremovedSamplesForAccelerationaudioLeveltotalAudioEnergytotalSamplesDurationframesReceiveddecoderImplementation
- RTCSentRtpStreamStats for outbound-rtp
packetsSent发送的包bytesSent发送的字节
- RTCOutboundRtpStreamStats for outbound-rtp
rtxSsrcmediaSourceIdsenderIdremoteIdridlastPacketSentTimestampheaderBytesSentpacketsDiscardedOnSendbytesDiscardedOnSendfecPacketsSentretransmittedPacketsSentretransmittedBytesSenttargetBitratetotalEncodedBytesTargetframeWidthframeHeightframeBitDepthframesPerSecondframesSenthugeFramesSentframesEncodedkeyFramesEncodedframesDiscardedOnSendqpSumtotalSamplesSentsamplesEncodedWithSilksamplesEncodedWithCeltvoiceActivityFlagtotalEncodeTimetotalPacketSendDelayaverageRtcpIntervalqualityLimitationReasonqualityLimitationDurationsqualityLimitationResolutionChangesperDscpPacketsSentnackCountfirCountpliCountsliCountencoderImplementation