自适应比特率与拥塞控制
学习 WebRTC 如何使用拥塞控制算法和 simulcast 实时调整媒体质量,让通话在不断变化的网络环境中保持流畅。
自适应比特率与拥塞控制 是 CoddyKit 上的免费 Real-Time Streaming Systems (WebRTC + Live Data) 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Real-Time Streaming Systems (WebRTC + Live Data) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Real-Time Streaming Systems (WebRTC + Live Data) 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Networks Are Never Stable
Real-time media runs over networks that fluctuate constantly: Wi-Fi dips, cellular handoffs, shared bandwidth. A fixed bitrate will either waste capacity or overwhelm a weak link.
Adaptive bitrate lets the sender match its output to current conditions.
Signals of Congestion
WebRTC infers congestion from feedback:
- Packet loss reported via RTCP.
- Increasing delay (jitter and one-way delay growth).
- Receiver estimates of available bandwidth.
Google Congestion Control
The core algorithm in WebRTC is GCC (Google Congestion Control). It combines a loss-based controller and a delay-based controller to estimate the safe sending rate.
Delay-Based Estimation
The delay-based part watches how packet arrival times drift. If packets start queuing up, that growing delay signals congestion before loss even happens, so the sender can back off early.
Loss-Based Estimation
The loss-based controller reacts to RTCP loss reports. Above a threshold it lowers the rate; with little loss it slowly probes upward to reclaim bandwidth.
Trading Resolution for Frame Rate
When bandwidth drops, the encoder must shed bits. It can lower resolution (softer image) or frame rate (choppier motion). WebRTC chooses based on content: video calls favor smoothness, screen shares favor sharpness.
Simulcast to the Rescue
With simulcast, a sender encodes the same video at several qualities at once. The SFU forwards the layer each receiver can handle, so one weak viewer does not degrade everyone.
const sender = pc.addTransceiver(track, {
sendEncodings: [
{ rid: 'low', scaleResolutionDownBy: 4 },
{ rid: 'mid', scaleResolutionDownBy: 2 },
{ rid: 'high', scaleResolutionDownBy: 1 }
]
});Reading Bandwidth from Stats
You can observe the estimate via getStats(), watching available outgoing bitrate and current send rate to drive UI warnings.
const stats = await pc.getStats();
stats.forEach(r => {
if (r.type === 'outbound-rtp') {
console.log('bitrate', r.targetBitrate);
}
});Setting Bitrate Caps
You can bound the encoder so it never exceeds a ceiling, useful for cost control or guaranteeing other traffic gets bandwidth.
const params = sender.getParameters();
params.encodings[0].maxBitrate = 500000;
await sender.setParameters(params);FEC and Retransmission
To survive loss without dropping quality, WebRTC uses FEC (forward error correction) and selective retransmission (NACK/RTX). These add overhead but protect against lossy links.
Tuning for Your Use Case
- Conferencing: prioritize low latency and smoothness.
- Broadcast: allow a larger buffer for stability.
- Screen share: protect resolution over frame rate.
Quick Check
Test your understanding of adaptive bitrate.
Recap
WebRTC adapts bitrate using GCC's delay- and loss-based estimates, trades resolution for frame rate as needed, and uses simulcast plus FEC/retransmission to keep calls smooth across unstable networks.
用 AI 导师学习 Real-Time Streaming Systems (WebRTC + Live Data) — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 12
- 课程
- 48
常见问题解答
「自适应比特率与拥塞控制」课时是免费的吗?
是的 — 「自适应比特率与拥塞控制」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Real-Time Streaming Systems (WebRTC + Live Data) 课程的其余内容,请升级到 CoddyKit PRO。 Real-Time Streaming Systems (WebRTC + Live Data) 课程共包含 4 节课。
「自适应比特率与拥塞控制」这节课中我会学到什么?
学习 WebRTC 如何使用拥塞控制算法和 simulcast 实时调整媒体质量,让通话在不断变化的网络环境中保持流畅。 你通过在浏览器中直接运行的动手代码来练习 Real-Time Streaming Systems (WebRTC + Live Data),全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Real-Time Streaming Systems (WebRTC + Live Data) 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Real-Time Streaming Systems (WebRTC + Live Data) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「自适应比特率与拥塞控制」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Real-Time Streaming Systems (WebRTC + Live Data) 课中编写并运行代码吗?
能。每节 Real-Time Streaming Systems (WebRTC + Live Data) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- WebRTC 安全最佳实践
- 优化媒体质量
- 带宽管理技术
- 自适应比特率与拥塞控制