Skip to content

Commit 67c1860

Browse files
fix: prevent AMF bitrate getting reset to 30mbps when going over max (#3138)
supported
1 parent 090883e commit 67c1860

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

alvr/server_openvr/cpp/platform/win32/VideoEncoderAMF.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,18 @@ void VideoEncoderAMF::Transmit(
709709

710710
auto params = GetDynamicEncoderParams();
711711
if (params.updated) {
712-
amf_int64 bitRateIn = params.bitrate_bps / params.framerate * m_refreshRate; // in bits
712+
amf_int64 bitRateIn = params.bitrate_bps / params.framerate * m_refreshRate; // in bps
713+
714+
const amf_int64 maxRate = 1'000'000'000;
715+
if (bitRateIn > maxRate) {
716+
// Don't warn if we're within 1% (10 mbps) of the max bitrate because that case gets
717+
// triggered by rounding errors with the max supported rate
718+
if (bitRateIn > maxRate + maxRate / 100) {
719+
Warn("Set bitrate over max supported by AMF, clamping to 1000mbps");
720+
}
721+
bitRateIn = maxRate;
722+
}
723+
713724
if (m_codec == ALVR_CODEC_H264) {
714725
m_amfComponents.back()->SetProperty(AMF_VIDEO_ENCODER_TARGET_BITRATE, bitRateIn);
715726
m_amfComponents.back()->SetProperty(AMF_VIDEO_ENCODER_PEAK_BITRATE, bitRateIn);

0 commit comments

Comments
 (0)