sampleRate = 48000 //采样率
period = 2 //周期:秒
playSample = 据实统计 //1个周期内,给扬声器播放声音的样本数
卡顿率百分比 = [1 - playSample*1.0f / (sampleRate * period) ] * 100
fps = 20 //帧率
period = 5 //周期:秒
renderFrames = 渲染帧数 //1个周期内,发起视频渲染的帧数
卡顿率百分比 = [1 - renderFrames*1.0f / (fps * period) ] * 100 //在一个浮动范围更好
//这里可能忽略了渲染的平滑程度,只考虑丢帧,平滑渲染需要软件自己做好
从stats里面获取totalSamplesReceived和framesReceived计算
{
"type": "track",
"id": "RTCMediaStreamTrack_receiver_3",
"timestamp": 1622995437355000,
"trackIdentifier": "824ad06d-6253-407f-9bf8-cd90ee438133",
"remoteSource": true,
"ended": false,
"detached": false,
"kind": "audio",
"jitterBufferDelay": 5596.8,
"jitterBufferEmittedCount": 148800,
"audioLevel": 0.00006103701895199438,
"totalAudioEnergy": 1.085988404462192e-8,
"totalSamplesReceived": 151040,
"totalSamplesDuration": 3.179999999999976,
"concealedSamples": 800,
"silentConcealedSamples": 280,
"concealmentEvents": 1,
"insertedSamplesForDeceleration": 1489,
"removedSamplesForAcceleration": 0,
"jitterBufferFlushes": 0,
"delayedPacketOutageSamples": 0,
"relativePacketArrivalDelay": 1.63,
"interruptionCount": 0,
"totalInterruptionDuration": 0
},
{
"type": "track",
"id": "RTCMediaStreamTrack_receiver_4",
"timestamp": 1622995437355000,
"trackIdentifier": "07a99ef3-314c-4629-b326-1022e6fa7058",
"remoteSource": true,
"ended": false,
"detached": false,
"kind": "video",
"jitterBufferDelay": 2.206,
"jitterBufferEmittedCount": 60,
"frameWidth": 640,
"frameHeight": 480,
"framesReceived": 61,
"framesDecoded": 61,
"framesDropped": 0,
"freezeCount": 0,
"pauseCount": 0,
"totalFreezesDuration": 0,
"totalPausesDuration": 0,
"totalFramesDuration": 2.977,
"sumOfSquaredFramesDuration": 0.151969
}