Skip to content

Commit c5a96af

Browse files
authored
fix: 🐛 Fix wrong default resolution for stream; add max res bounds (#3071)
* fix: 🐛 Fix weong default resolution for stream; add max res bounds * Address comment
1 parent 522d4de commit c5a96af

File tree

9 files changed

+77
-32
lines changed

9 files changed

+77
-32
lines changed

Cargo.lock

Lines changed: 22 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["alvr/*"]
44

55
[workspace.package]
6-
version = "21.0.0-dev10"
6+
version = "21.0.0-dev11"
77
edition = "2024"
88
rust-version = "1.88"
99
authors = ["alvr-org"]

alvr/client_core/src/c_api.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ static DECODER_CONFIG_BUFFER: Mutex<Vec<u8>> = Mutex::new(vec![]);
4242
pub struct AlvrClientCapabilities {
4343
default_view_width: u32,
4444
default_view_height: u32,
45+
max_view_width: u32,
46+
max_view_height: u32,
4547
refresh_rates: *const f32,
4648
refresh_rates_count: u64,
4749
foveated_encoding: bool,
@@ -201,6 +203,8 @@ pub extern "C" fn alvr_initialize(capabilities: AlvrClientCapabilities) {
201203
capabilities.default_view_height,
202204
);
203205

206+
let max_view_resolution = UVec2::new(capabilities.max_view_width, capabilities.max_view_height);
207+
204208
let refresh_rates = unsafe {
205209
slice::from_raw_parts(
206210
capabilities.refresh_rates,
@@ -211,6 +215,7 @@ pub extern "C" fn alvr_initialize(capabilities: AlvrClientCapabilities) {
211215

212216
let capabilities = ClientCapabilities {
213217
default_view_resolution,
218+
max_view_resolution,
214219
refresh_rates,
215220
foveated_encoding: capabilities.foveated_encoding,
216221
encoder_high_profile: capabilities.encoder_high_profile,

alvr/client_core/src/connection.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ fn connection_pipeline(
169169
streaming_capabilities: Some(
170170
VideoStreamingCapabilities {
171171
default_view_resolution: capabilities.default_view_resolution,
172+
max_view_resolution: capabilities.max_view_resolution,
172173
refresh_rates: capabilities.refresh_rates,
173174
microphone_sample_rate,
174175
foveated_encoding: capabilities.foveated_encoding,

alvr/client_core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum ClientCoreEvent {
6060
#[derive(Clone)]
6161
pub struct ClientCapabilities {
6262
pub default_view_resolution: UVec2,
63+
pub max_view_resolution: UVec2,
6364
pub refresh_rates: Vec<f32>,
6465
pub foveated_encoding: bool,
6566
pub encoder_high_profile: bool,

alvr/client_mock/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ fn client_thread(
191191
) {
192192
let capabilities = ClientCapabilities {
193193
default_view_resolution: UVec2::new(1920, 1832),
194+
max_view_resolution: UVec2::new(1920, 1832),
194195
refresh_rates: vec![60.0, 72.0, 80.0, 90.0, 120.0],
195196
foveated_encoding: false,
196197
encoder_high_profile: false,

alvr/client_openxr/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ pub fn entry_point() {
247247
let default_view_resolution = UVec2::new(
248248
views_config[0].recommended_image_rect_width,
249249
views_config[0].recommended_image_rect_height,
250-
) * 2;
250+
);
251+
252+
let max_view_resolution = UVec2::new(
253+
views_config[0].max_image_rect_width,
254+
views_config[0].max_image_rect_height,
255+
);
251256

252257
let refresh_rates = if exts.fb_display_refresh_rate {
253258
xr_session.enumerate_display_refresh_rates().unwrap()
@@ -263,6 +268,7 @@ pub fn entry_point() {
263268

264269
let capabilities = ClientCapabilities {
265270
default_view_resolution,
271+
max_view_resolution,
266272
refresh_rates,
267273
foveated_encoding: platform != Platform::Unknown,
268274
encoder_high_profile: platform != Platform::Unknown,
@@ -290,7 +296,7 @@ pub fn entry_point() {
290296
Rc::clone(&graphics_context),
291297
Arc::clone(&interaction_context),
292298
platform,
293-
default_view_resolution,
299+
UVec2::min(default_view_resolution * 2, max_view_resolution),
294300
&last_lobby_message,
295301
);
296302

alvr/packets/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub struct VideoStreamingCapabilitiesExt {
3030
#[derive(Serialize, Deserialize, Clone)]
3131
pub struct VideoStreamingCapabilities {
3232
pub default_view_resolution: UVec2,
33+
pub max_view_resolution: UVec2,
3334
pub refresh_rates: Vec<f32>,
3435
pub microphone_sample_rate: u32,
3536
pub foveated_encoding: bool,

alvr/server_core/src/connection.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,42 @@ fn connection_pipeline(
599599
UVec2::new(align32(res.x), align32(res.y))
600600
}
601601

602-
let stream_view_resolution = get_view_res(
602+
let mut transcoding_view_resolution = get_view_res(
603603
initial_settings.video.transcoding_view_resolution.clone(),
604604
streaming_caps.default_view_resolution,
605605
);
606+
if transcoding_view_resolution.x > streaming_caps.max_view_resolution.x
607+
|| transcoding_view_resolution.y > streaming_caps.max_view_resolution.y
608+
{
609+
warn!(
610+
"Chosen resolution {}x{} exceeds client maximum supported resolution of {}x{}. \
611+
Using maximum supported resolution at same aspect ratio.",
612+
transcoding_view_resolution.x,
613+
transcoding_view_resolution.y,
614+
streaming_caps.max_view_resolution.x,
615+
streaming_caps.max_view_resolution.y,
616+
);
617+
618+
let transcoding_ratio =
619+
transcoding_view_resolution.x as f32 / transcoding_view_resolution.y as f32;
620+
621+
if transcoding_ratio
622+
> streaming_caps.max_view_resolution.x as f32
623+
/ streaming_caps.max_view_resolution.y as f32
624+
{
625+
transcoding_view_resolution = UVec2::new(
626+
align32(streaming_caps.max_view_resolution.x as f32),
627+
align32(streaming_caps.max_view_resolution.x as f32 / transcoding_ratio),
628+
);
629+
} else {
630+
transcoding_view_resolution = UVec2::new(
631+
align32(streaming_caps.max_view_resolution.y as f32 * transcoding_ratio),
632+
align32(streaming_caps.max_view_resolution.y as f32),
633+
);
634+
}
635+
}
606636

607-
let target_view_resolution = get_view_res(
637+
let emulated_headset_view_resolution = get_view_res(
608638
initial_settings
609639
.video
610640
.emulated_headset_view_resolution
@@ -740,7 +770,7 @@ fn connection_pipeline(
740770
let stream_config_packet = StreamConfigPacket::new(
741771
session_manager_lock.session(),
742772
NegotiatedStreamingConfig {
743-
view_resolution: stream_view_resolution,
773+
view_resolution: transcoding_view_resolution,
744774
refresh_rate_hint: fps,
745775
game_audio_sample_rate,
746776
enable_foveated_encoding,
@@ -758,10 +788,10 @@ fn connection_pipeline(
758788
proto_socket.split(STREAMING_RECV_TIMEOUT).to_con()?;
759789

760790
let mut new_openvr_config = contruct_openvr_config(session_manager_lock.session());
761-
new_openvr_config.eye_resolution_width = stream_view_resolution.x;
762-
new_openvr_config.eye_resolution_height = stream_view_resolution.y;
763-
new_openvr_config.target_eye_resolution_width = target_view_resolution.x;
764-
new_openvr_config.target_eye_resolution_height = target_view_resolution.y;
791+
new_openvr_config.eye_resolution_width = transcoding_view_resolution.x;
792+
new_openvr_config.eye_resolution_height = transcoding_view_resolution.y;
793+
new_openvr_config.target_eye_resolution_width = emulated_headset_view_resolution.x;
794+
new_openvr_config.target_eye_resolution_height = emulated_headset_view_resolution.y;
765795
new_openvr_config.refresh_rate = fps as _;
766796
new_openvr_config.enable_foveated_encoding = enable_foveated_encoding;
767797
new_openvr_config.h264_profile = encoder_profile as _;

0 commit comments

Comments
 (0)