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

fix(server): 🐛 Fix IDR resend logic #2403

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion alvr/server_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn contruct_openvr_config(session: &SessionConfig) -> OpenvrConfig {
OpenvrConfig {
tracking_ref_only: settings.headset.tracking_ref_only,
enable_vive_tracker_proxy: settings.headset.enable_vive_tracker_proxy,
aggressive_keyframe_resend: settings.connection.aggressive_keyframe_resend,
minimum_idr_interval_ms: settings.connection.minimum_idr_interval_ms,
adapter_index: settings.video.adapter_index,
codec: settings.video.preferred_codec as _,
h264_profile: settings.video.encoder_config.h264_profile as u32,
Expand Down
25 changes: 3 additions & 22 deletions alvr/server_openvr/cpp/alvr_server/IDRScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,11 @@ IDRScheduler::IDRScheduler() { }

IDRScheduler::~IDRScheduler() { }

void IDRScheduler::OnPacketLoss() {
std::unique_lock lock(m_mutex);

if (m_scheduled) {
// Waiting next insertion.
return;
}
if (GetTimestampUs() - m_insertIDRTime > m_minIDRFrameInterval) {
// Insert immediately
m_insertIDRTime = GetTimestampUs();
m_scheduled = true;
} else {
// Schedule next insertion.
m_insertIDRTime += m_minIDRFrameInterval;
m_scheduled = true;
}
}
void IDRScheduler::OnPacketLoss() { InsertIDR(); }

void IDRScheduler::OnStreamStart() {
if (Settings::Instance().IsLoaded() && Settings::Instance().m_aggressiveKeyframeResend) {
m_minIDRFrameInterval = MIN_IDR_FRAME_INTERVAL_AGGRESSIVE;
} else {
m_minIDRFrameInterval = MIN_IDR_FRAME_INTERVAL;
}
m_minIDRFrameInterval = Settings::Instance().m_minimumIdrIntervalMs * 1000;
m_scheduled = false;
InsertIDR();
}

Expand Down
2 changes: 0 additions & 2 deletions alvr/server_openvr/cpp/alvr_server/IDRScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class IDRScheduler {

private:
static const int MIN_IDR_FRAME_INTERVAL = 100 * 1000; // 100-milliseconds
static const int MIN_IDR_FRAME_INTERVAL_AGGRESSIVE
= 5 * 1000; // 5-milliseconds (less than screen refresh interval)
uint64_t m_insertIDRTime = 0;
bool m_scheduled = false;
std::mutex m_mutex;
Expand Down
2 changes: 1 addition & 1 deletion alvr/server_openvr/cpp/alvr_server/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void Settings::Load() {
m_nvencEnableWeightedPrediction
= config.get("nvenc_enable_weighted_prediction").get<bool>();

m_aggressiveKeyframeResend = config.get("aggressive_keyframe_resend").get<bool>();
m_minimumIdrIntervalMs = config.get("minimum_idr_interval_ms").get<int64_t>();

m_enableViveTrackerProxy = config.get("enable_vive_tracker_proxy").get<bool>();
m_TrackingRefOnly = config.get("tracking_ref_only").get<bool>();
Expand Down
2 changes: 1 addition & 1 deletion alvr/server_openvr/cpp/alvr_server/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Settings {
int64_t m_nvencRcAverageBitrate;
bool m_nvencEnableWeightedPrediction;

bool m_aggressiveKeyframeResend;
uint64_t m_minimumIdrIntervalMs;

bool m_enableViveTrackerProxy = false;
bool m_TrackingRefOnly = false;
Expand Down
2 changes: 1 addition & 1 deletion alvr/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct OpenvrConfig {
pub target_eye_resolution_height: u32,
pub tracking_ref_only: bool,
pub enable_vive_tracker_proxy: bool,
pub aggressive_keyframe_resend: bool,
pub minimum_idr_interval_ms: u64,
pub adapter_index: u32,
pub codec: u8,
pub h264_profile: u32,
Expand Down
9 changes: 4 additions & 5 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,11 +1090,10 @@ This could happen on TCP. A IDR frame is requested in this case."#
#[schema(suffix = " frames")]
pub statistics_history_size: usize,

#[schema(strings(
help = "Reduce minimum delay between IDR keyframes from 100ms to 5ms. Use on networks with high packet loss."
))]
#[schema(strings(display_name = "Minimum IDR interval"))]
#[schema(flag = "steamvr-restart")]
pub aggressive_keyframe_resend: bool,
#[schema(gui(slider(min = 5, max = 1000, step = 5)), suffix = "ms")]
pub minimum_idr_interval_ms: u64,

pub dscp: Option<DscpTos>,
}
Expand Down Expand Up @@ -1689,7 +1688,7 @@ pub fn session_settings_default() -> SettingsDefault {
client_recv_buffer_bytes: socket_buffer,
max_queued_server_video_frames: 1024,
avoid_video_glitching: false,
aggressive_keyframe_resend: false,
minimum_idr_interval_ms: 100,
on_connect_script: "".into(),
on_disconnect_script: "".into(),
packet_size: 1400,
Expand Down
Loading