Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebRTC: How to calculate user bandwidth/network latency of RTC Peer Connection

So, I'm working on an App that utilises WebRTC to provide video/audio communication between peers.

I'd like to provide some feedback to users in regard to their network connection/bandwidth/latency etc in order to suggest possible solutions if bandwidth etc is terrible.

WebRTC has a getStats() API which provides a number of key pieces of information. When a Peer Connection is active, getStats() gives me the following object...

{
    "googLibjingleSession_5531731670954573009":{
        "id":"googLibjingleSession_5531731670954573009",
        "timestamp":"2016-02-02T11:14:43.467Z",
        "type":"googLibjingleSession",
        "googInitiator":"true"
    },
    "googTrack_SCEHhCOl":{
        "id":"googTrack_SCEHhCOl",
        "timestamp":"2016-02-02T11:14:43.467Z",
        "type":"googTrack",
        "googTrackId":"SCEHhCOl"
    },
    "ssrc_360347109_recv":{
        "id":"ssrc_360347109_recv",
        "timestamp":"2016-02-02T11:14:43.467Z",
        "type":"ssrc",
        "googDecodingCTN":"757",
        "packetsLost":"0",
        "googSecondaryDecodedRate":"0",
        "googDecodingPLC":"3",
        "packetsReceived":"373",
        "googExpandRate":"0.00579834",
        "googJitterReceived":"0",
        "googDecodingCNG":"0",
        "ssrc":"360347109",
        "googPreferredJitterBufferMs":"20",
        "googSpeechExpandRate":"0.00140381",
        "googTrackId":"SCEHhCOl",
        "transportId":"Channel-audio-1",
        "googDecodingPLCCNG":"10",
        "googCodecName":"opus",
        "googDecodingNormal":"744",
        "audioOutputLevel":"6271",
        "googAccelerateRate":"0",
        "bytesReceived":"21796",
        "googCurrentDelayMs":"64",
        "googDecodingCTSG":"0",
        "googCaptureStartNtpTimeMs":"-1",
        "googPreemptiveExpandRate":"0.00292969",
        "googJitterBufferMs":"42"
    }
}

It's with this information that I hope to calculate the users...

a) Bandwidth (Ideally Audio and Video separately but straight up bandwidth would suffice)

b) Network Latency

Thanks in advance...

NB: I have already seen this wrapper but I'd like to be able to do this myself really (with a little bit of your help of course :D) as the example code for this wrapper uses a "bytesSent" property which I don't seem to get back from getStats()?

I am also aware of the WebRTC test available on GitHub, but again, I should be able to achieve what I want without relying on third party "plugins" etc.

like image 319
An0nC0d3r Avatar asked Oct 19 '22 16:10

An0nC0d3r


1 Answers

As far as I can remember, the properties for these RTCStatReports vary a lot. For example, the bytesSent property you mentioned is not always available, you might have to do:

// chrome
if (res.googCodecName == 'VP8' && res.bytesSent) {
  // res.bytesSent - bytes sent so far (video)
}

// firefox
if (res.mediaType == 'video' && res.bytesSent) ...

Have a look at the source for the wrapper you posted to learn more. You can also have a look at my fork (if the wrapper does no longer work, that was the case when I last took a look).

like image 64
wpp Avatar answered Oct 21 '22 11:10

wpp