To improve network throughput and avoid network congestion, the Agora RTSA SDK provides recommendations on adjusting the transmission bitrates in real time according to the network conditions.
on_dec_bitrate
callback to recommend that the app decreases the bitrate by the given value. on_inc_bitrate
callback to recommend that the app increases the bitrate by the given value. static constexpr int VIDEO_TARGET_BPS_MAX = 1 << 23; // 8Mbps
static constexpr int VIDEO_TARGET_BPS_MIN = 1 << 16; // 64Kbps
static constexpr int CheckTargetBps (int bps)
{
// Make sure the target bps is valid
if (bps > VIDEO_TARGET_BPS_MAX) {
bps = VIDEO_TARGET_BPS_MAX;
} else if (bps < VIDEO_TARGET_BPS_MAX) {
bps = VIDEO_TARGET_BPS_MIN;
}
return bps;
}
static void OnDecBitrate (const char *channel, uint32_t bps)
{
auto video_encoder = GetVideoEncoder (channel);
const auto target_bps = CheckTargetBps (video_encoder.GetTargetBps () - bps);
video_encoder.SetTargetBps (target_bps);
}
static void OnIncBitrate (const char *channel, uint32_t bps)
{
auto video_encoder = GetVideoEncoder (channel);
const auto target_bps = CheckTargetBps (video_encoder.GetTargetBps () + bps);
video_encoder.SetTargetBps (target_bps);
}
static const agora_rtc_event_handler_t listener = {
.on_dec_bitrate = OnDecBitrate,
.on_inc_bitrate = OnIncBitrate,
// ...
};