Skip to content

Commit

Permalink
Update SteamVR framerate on statistics thread, support Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed May 30, 2023
1 parent 5e95fca commit 9d47919
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
25 changes: 17 additions & 8 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bitrate::BitrateManager,
buttons::BUTTON_PATH_FROM_ID,
face_tracking::FaceTrackingSink,
haptics,
haptics, openvr_props,
sockets::WelcomeSocket,
statistics::StatisticsManager,
tracking::{self, TrackingManager},
Expand All @@ -24,7 +24,10 @@ use alvr_packets::{
ButtonValue, ClientConnectionResult, ClientControlPacket, ClientListAction, ClientStatistics,
ServerControlPacket, StreamConfigPacket, Tracking, AUDIO, HAPTICS, STATISTICS, TRACKING, VIDEO,
};
use alvr_session::{CodecType, ControllersEmulationMode, FrameSize, OpenvrConfig};
use alvr_session::{
CodecType, ControllersEmulationMode, FrameSize, OpenvrConfig, OpenvrPropValue,
OpenvrPropertyKey,
};
use alvr_sockets::{
spawn_cancelable, ControlSocketReceiver, ControlSocketSender, PeerType, ProtoControlSocket,
StreamSocketBuilder, KEEPALIVE_INTERVAL,
Expand Down Expand Up @@ -626,8 +629,8 @@ async fn connection_pipeline(
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
alvr_session::OpenvrPropValue::String(id),
OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
OpenvrPropValue::String(id),
),
)
}
Expand All @@ -650,8 +653,8 @@ async fn connection_pipeline(
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
alvr_session::OpenvrPropValue::String(id),
OpenvrPropertyKey::AudioDefaultPlaybackDeviceId,
OpenvrPropValue::String(id),
),
)
}
Expand All @@ -675,8 +678,8 @@ async fn connection_pipeline(
crate::SetOpenvrProperty(
*alvr_common::HEAD_ID,
crate::openvr_props::to_ffi_openvr_prop(
alvr_session::OpenvrPropertyKey::AudioDefaultRecordingDeviceId,
alvr_session::OpenvrPropValue::String(id),
OpenvrPropertyKey::AudioDefaultRecordingDeviceId,
OpenvrPropValue::String(id),
),
)
}
Expand Down Expand Up @@ -914,6 +917,12 @@ async fn connection_pipeline(
network_latency,
decoder_latency,
);

openvr_props::set_prop(
*HEAD_ID,
OpenvrPropertyKey::DisplayFrequency,
OpenvrPropValue::Float(1.0 / stats.frame_interval_average().as_secs_f32()),
);
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions alvr/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ use alvr_common::{
once_cell::sync::{Lazy, OnceCell},
parking_lot::{Mutex, RwLock},
prelude::*,
RelaxedAtomic, HEAD_ID,
RelaxedAtomic,
};
use alvr_events::EventType;
use alvr_filesystem::{self as afs, Layout};
use alvr_packets::{
ClientListAction, DecoderInitializationConfig, Haptics, ServerControlPacket, VideoPacketHeader,
};
use alvr_server_io::ServerDataManager;
use alvr_session::{CodecType, OpenvrPropValue, OpenvrPropertyKey};
use alvr_session::CodecType;
use bitrate::BitrateManager;
use statistics::StatisticsManager;
use std::{
Expand Down Expand Up @@ -484,12 +484,6 @@ pub unsafe extern "C" fn HmdDriverFactory(

extern "C" fn wait_for_vsync() {
if let Some(stats) = &mut *STATISTICS_MANAGER.lock() {
openvr_props::set_prop(
*HEAD_ID,
OpenvrPropertyKey::DisplayFrequency,
OpenvrPropValue::Float(1.0 / stats.get_frame_interval().as_secs_f32()),
);

thread::sleep(stats.duration_until_next_vsync());
}
}
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/src/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ impl StatisticsManager {
.saturating_sub(self.total_pipeline_latency_average.get_average())
}

pub fn get_frame_interval(&self) -> Duration {
pub fn frame_interval_average(&self) -> Duration {
self.predicted_frame_interval_average.get_average()
}

Expand Down

0 comments on commit 9d47919

Please sign in to comment.