What is the current bandwidth or quality of an audio MediaStream in a browser? (WebRTC)

Viewed 3005

I'm currently building a WebRTC application and want to gather some statistics in order to rate my solution. One metric I'm interested in is the current bandwidth of the received audio (and video) stream. I was able to find the currently used codec at chrome://webrtc-internals/ (OPUS), but I wasn't able to find numbers about the current quality/bandwidth of the stream (e.g. 128kbit/s).

I already searched the RTCPeerConnection Object for such numbers, but haven't found some. XXX.RTCconnection.getRemoteStreams()[0].getAudioTracks()[0].getConstraints() only returns

{ 
  deviceId: {}, 
  echoCancellation: {}, 
  facingMode: {}, 
  frameRate: {}, 
  height: {}, 
  mediaSource: "camera", 
  mozAutoGainControl: {}, 
  mozNoiseSuppression: {}, 
  viewportHeight: {}, 
  viewportOffsetX: {}, 
  ...
}

that only contains information about a video stream (funnily I requested an audio stream) and no bandwidth details. There are no other streams for the arrays in the example above. Do you know where I need to look for the current quality/bandwidth of a MediaStream?

2 Answers

If you set the SDP to be stereo and increase the maxaveragebitrate:

let answer = await peer.conn.createAnswer(offerOptions);
answer.sdp = answer.sdp.replace('useinbandfec=1', 'useinbandfec=1; stereo=1; maxaveragebitrate=510000');
await peer.conn.setLocalDescription(answer);

Then I get a potential maximum bitrate of 520kb/s for stereo, which is 260kps per channel. Actual bitrate depends on the speed of your network and strength of your signal though :)

Related