ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
24.7k stars 5.28k forks source link

WebRTC: Support bandwidth limit by b=AS in SDP #3612

Open Drengel1990 opened 12 months ago

Drengel1990 commented 12 months ago

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

xiaozhihong commented 11 months ago

SRS no support yet.

Describe in RFC3556

Do you know how to enable it in browsers?

Drengel1990 commented 11 months ago
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

xiaozhihong commented 11 months ago

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.

winlinvip commented 2 months ago

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