Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Drengel1990 opened this issue Jul 2, 2023 · 4 comments
Open

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

Drengel1990 opened this issue Jul 2, 2023 · 4 comments
Assignees
Labels
EnglishNative This issue is conveyed exclusively in English. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.

Comments

@Drengel1990
Copy link

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
Copy link
Collaborator

SRS no support yet.

Describe in RFC3556

Do you know how to enable it in browsers?

@Drengel1990
Copy link
Author

Drengel1990 commented Jul 22, 2023

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
Copy link
Collaborator

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 winlinvip added the EnglishNative This issue is conveyed exclusively in English. label Jul 28, 2023
@winlinvip winlinvip changed the title Limit WebRTC banwidth WebRTC: Support bandwidth limit by b=AS in SDP Apr 6, 2024
@winlinvip winlinvip self-assigned this Apr 6, 2024
@winlinvip winlinvip added the WebRTC WebRTC, RTC2RTMP or RTMP2RTC. label Apr 6, 2024
@winlinvip
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
EnglishNative This issue is conveyed exclusively in English. WebRTC WebRTC, RTC2RTMP or RTMP2RTC.
Projects
None yet
Development

No branches or pull requests

3 participants