srs icon indicating copy to clipboard operation
srs copied to clipboard

WebRTC: Support bandwidth limit by b=AS in SDP

Open Drengel1990 opened this issue 2 years ago • 4 comments

https://webrtchacks.com/limit-webrtc-bandwidth-sdp I try to use b=AS:500 and send to the server, but it returns without this parameter

Drengel1990 avatar Jul 02 '23 12:07 Drengel1990

SRS no support yet.

Describe in RFC3556

Do you know how to enable it in browsers?

xiaozhihong avatar Jul 13 '23 12:07 xiaozhihong

self.setMediaBitrates = (sdp) => {
        return self.setMediaBitrate(self.setMediaBitrate(sdp, "video", 2000), "audio", 50);
    };

    self.setMediaBitrate = (sdp, media, bitrate) => {
        let lines = sdp.split("\n");
        let lineIndex = -1;
        for (let i = 0; i < lines.length; i++) {
            if (lines[i].startsWith(`m=${media}`)) {
                lineIndex = i;
                break;
            }
        }
        if (lineIndex === -1) {
            console.debug("Could not find the m line for", media);
            return sdp;
        }
        console.debug("Found the m line for", media, "at line", lineIndex);
        lineIndex++;
        while(lines[lineIndex].startsWith("i=") || lines[lineIndex].startsWith("c=")) {
            lineIndex++;
        }
        if (lines[lineIndex].startsWith("b")) {
            console.debug("Replaced b line at line", lineIndex);
            lines[lineIndex] = "b=AS:"+bitrate;
            return lines.join("\n");
        }
        console.debug("Adding new b line before line", lineIndex);
        let newLines = lines.slice(0, lineIndex);
        newLines.push("b=AS:"+bitrate);
        newLines = newLines.concat(lines.slice(lineIndex, lines.length));
        return newLines.join("\n");
    }

let offer = await self.pc.createOffer(); offer.sdp = self.setMediaBitrates(offer.sdp);

In play method

Drengel1990 avatar Jul 22 '23 12:07 Drengel1990

Is it correct to say that b=AS: applies only to the sender side?

For instance, if the publishing client sets b=AS:500, and the server responds with b=AS:800 does it mean the client will send at a bitrate of 500 kbps?

Similarly, if the playing client sets b=AS:500 and the server responds with b=AS:800, does this imply that the server will send the stream at a maximum of 800 kbps? However, in the latter case, the server (SRS) might have the ability to change the bitrate of the source stream.

xiaozhihong avatar Jul 25 '23 01:07 xiaozhihong

I think it's reasonable to support this feature, by including more research on usage and workflow.

winlinvip avatar Apr 06 '24 23:04 winlinvip