I would like to set the max bitrate that my WebRTC client can support. I only have access to the client (receive video frames) not to the host (sending video). How do I go about signaling that my client can only support a low bitrate (512kbps for example).
So far I have tried to modify the SDP offer adding the b=AS
field to try to set the max bitrate. Here is the code I have:
const rtcPeer = new RTCPeerConnection()
...
rtcPeer.createOffer().then((offer) => {
offer.sdp = `b=AS:512\r\n`; // <-- trying to set max bitrate to 512 kbps here
rtcPeer.setLocalDescription(offer)
...
}
The full SDP that this creates looks like this:
v=0
o=- 2186277925215273999 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0
a=extmap-allow-mixed
a=msid-semantic: WMS
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=ice-ufrag:7 MK
a=ice-pwd:removed
a=ice-options:trickle
a=fingerprint:sha-256 05:37:61:F1:48:8B:0B:9D:77:84:2C:74:5E:E3:25:7B:86:D2:E2:CF:E1:5E:A2:F6:14:C2:F5:9C:03:38:3D:ED
a=setup:actpass
a=mid:0
a=sctp-port:5000
a=max-message-size:262144
b=AS:512
Note, my SDP offer doesn't have a m:video
or m:audio
because its just a data channel that frames are sent over (I have no control over this; the host). I am not sure if not having m:video
will make it so I cant sent the max bitrate? More details on this here:
Appreciate any help you guys can provide!
CodePudding user response:
If your goal is to control data channel bandwidth, forget about recipes related to RTP bandwidth control because they are for audio and video only. There is no such "magic" option in a browser (at least for today), but you can implement data channel bandwidth control in your JavaScript application by yourself.
First, keep transmitted messages size lower than the lowest value of the max-message-size
parameter. Even though some modern browsers allow a message size of up to 1Gb (and more), my advice is not to exceed 128Kb. If the message size is larger than allowed, you can split it into chunks on the sender side and reassemble it on the receiver side.
Second, look after the buffer size of the data channel on the sender side RTCDataChannel.bufferedamount
. It is easy to overflow the buffer at the low network bandwidth and intensive write to the data channel, so the data channel will go into the closed state.
CodePudding user response:
I don't believe b=AS
will influence the SCTP congestion control. I am going to look deeper in libwebrtc, but it is a RTP specific value.
How much control do you have on the client? Is it just a browser? Is it mobile? Is it a process running on Linux/Windows?
With SCTP you have a a_rwnd
which communicates how much buffer space you have as a receiver. You could artificially limit this to cause the sender congestion controller to get the behavior you want?