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

feat: ✨ Reduce session file length #2480

Merged
merged 1 commit into from
Nov 3, 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions alvr/client_core/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
warn, DeviceMotion, Fov, OptLazy, Pose,
};
use alvr_packets::{ButtonEntry, ButtonValue, FaceData, ViewParams};
use alvr_session::{CodecType, FoveatedEncodingConfig, MediacodecDataType};
use alvr_session::{CodecType, FoveatedEncodingConfig, MediacodecPropType, MediacodecProperty};
use std::{
cell::RefCell,
ffi::{c_char, c_void, CStr, CString},
Expand Down Expand Up @@ -59,7 +59,7 @@
pub enum AlvrEvent {
HudMessageUpdated,
StreamingStarted {
view_width: u32,

Check warning on line 62 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

fields `view_width`, `view_height`, `refresh_rate_hint`, `encoding_gamma`, `enable_foveated_encoding`, and `enable_hdr` are never read

warning: fields `view_width`, `view_height`, `refresh_rate_hint`, `encoding_gamma`, `enable_foveated_encoding`, and `enable_hdr` are never read --> alvr/client_core/src/c_api.rs:62:9 | 61 | StreamingStarted { | ---------------- fields in this variant 62 | view_width: u32, | ^^^^^^^^^^ 63 | view_height: u32, | ^^^^^^^^^^^ 64 | refresh_rate_hint: f32, | ^^^^^^^^^^^^^^^^^ 65 | encoding_gamma: f32, | ^^^^^^^^^^^^^^ 66 | enable_foveated_encoding: bool, | ^^^^^^^^^^^^^^^^^^^^^^^^ 67 | enable_hdr: bool, | ^^^^^^^^^^ | = note: `#[warn(dead_code)]` on by default
view_height: u32,
refresh_rate_hint: f32,
encoding_gamma: f32,
Expand All @@ -68,14 +68,14 @@
},
StreamingStopped,
Haptics {
device_id: u64,

Check warning on line 71 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

fields `device_id`, `duration_s`, `frequency`, and `amplitude` are never read

warning: fields `device_id`, `duration_s`, `frequency`, and `amplitude` are never read --> alvr/client_core/src/c_api.rs:71:9 | 70 | Haptics { | ------- fields in this variant 71 | device_id: u64, | ^^^^^^^^^ 72 | duration_s: f32, | ^^^^^^^^^^ 73 | frequency: f32, | ^^^^^^^^^ 74 | amplitude: f32, | ^^^^^^^^^
duration_s: f32,
frequency: f32,
amplitude: f32,
},
/// Note: All subsequent DecoderConfig events should be ignored until reconnection
DecoderConfig {
codec: AlvrCodec,

Check warning on line 78 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

field `codec` is never read

warning: field `codec` is never read --> alvr/client_core/src/c_api.rs:78:9 | 77 | DecoderConfig { | ------------- field in this variant 78 | codec: AlvrCodec, | ^^^^^
},
}

Expand Down Expand Up @@ -828,7 +828,7 @@

#[repr(u8)]
pub enum AlvrMediacodecPropType {
Float,

Check warning on line 831 in alvr/client_core/src/c_api.rs

View workflow job for this annotation

GitHub Actions / clippy

variants `Float`, `Int32`, `Int64`, and `String` are never constructed

warning: variants `Float`, `Int32`, `Int64`, and `String` are never constructed --> alvr/client_core/src/c_api.rs:831:5 | 830 | pub enum AlvrMediacodecPropType { | ---------------------- variants in this enum 831 | Float, | ^^^^^ 832 | Int32, | ^^^^^ 833 | Int64, | ^^^^^ 834 | String, | ^^^^^^
Int32,
Int64,
String,
Expand Down Expand Up @@ -880,25 +880,29 @@
.iter()
.map(|option| unsafe {
let key = CStr::from_ptr(option.key).to_str().unwrap();
let value = match option.ty {
AlvrMediacodecPropType::Float => {
MediacodecDataType::Float(option.value.float_)
}
AlvrMediacodecPropType::Int32 => {
MediacodecDataType::Int32(option.value.int32)
}
AlvrMediacodecPropType::Int64 => {
MediacodecDataType::Int64(option.value.int64)
}
AlvrMediacodecPropType::String => MediacodecDataType::String(
CStr::from_ptr(option.value.string)
let prop = match option.ty {
AlvrMediacodecPropType::Float => MediacodecProperty {
ty: MediacodecPropType::Float,
value: option.value.float_.to_string(),
},
AlvrMediacodecPropType::Int32 => MediacodecProperty {
ty: MediacodecPropType::Int32,
value: option.value.int32.to_string(),
},
AlvrMediacodecPropType::Int64 => MediacodecProperty {
ty: MediacodecPropType::Int64,
value: option.value.int64.to_string(),
},
AlvrMediacodecPropType::String => MediacodecProperty {
ty: MediacodecPropType::String,
value: CStr::from_ptr(option.value.string)
.to_str()
.unwrap()
.to_owned(),
),
},
};

(key.to_string(), value)
(key.to_owned(), prop)
})
.collect()
} else {
Expand Down
32 changes: 24 additions & 8 deletions alvr/client_core/src/video_decoder/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use alvr_common::{
anyhow::{anyhow, bail, Context, Result},
error, info,
parking_lot::{Condvar, Mutex},
warn, RelaxedAtomic,
warn, RelaxedAtomic, ToAny,
};
use alvr_session::{CodecType, MediacodecDataType};
use alvr_session::{CodecType, MediacodecPropType};
use ndk::{
hardware_buffer::HardwareBufferUsage,
media::{
Expand Down Expand Up @@ -254,12 +254,28 @@ fn decoder_lifecycle(
format.set_i32("height", 1024);
format.set_buffer("csd-0", &csd_0);

for (key, value) in &config.options {
match value {
MediacodecDataType::Float(value) => format.set_f32(key, *value),
MediacodecDataType::Int32(value) => format.set_i32(key, *value),
MediacodecDataType::Int64(value) => format.set_i64(key, *value),
MediacodecDataType::String(value) => format.set_str(key, value),
for (key, prop) in &config.options {
let maybe_error = match prop.ty {
MediacodecPropType::Float => prop
.value
.parse()
.map(|value| format.set_f32(key, value))
.to_any(),
MediacodecPropType::Int32 => prop
.value
.parse()
.map(|value| format.set_i32(key, value))
.to_any(),
MediacodecPropType::Int64 => prop
.value
.parse()
.map(|value| format.set_i64(key, value))
.to_any(),
MediacodecPropType::String => Ok(format.set_str(key, &prop.value)),
};

if let Err(e) = maybe_error {
error!("Failed to set property {key} to {}: {e}", prop.value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions alvr/client_core/src/video_decoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod android;

use alvr_common::anyhow::Result;
use alvr_session::{CodecType, MediacodecDataType};
use alvr_session::{CodecType, MediacodecProperty};
use std::time::Duration;

#[derive(Clone, Default, PartialEq)]
Expand All @@ -11,7 +11,7 @@ pub struct VideoDecoderConfig {
pub force_software_decoder: bool,
pub max_buffering_frames: f32,
pub buffering_history_weight: f32,
pub options: Vec<(String, MediacodecDataType)>,
pub options: Vec<(String, MediacodecProperty)>,
pub config_buffer: Vec<u8>,
}

Expand Down
4 changes: 2 additions & 2 deletions alvr/client_openxr/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use alvr_common::{
use alvr_packets::{FaceData, StreamConfig, ViewParams};
use alvr_session::{
BodyTrackingSourcesConfig, ClientsideFoveationConfig, ClientsideFoveationMode, CodecType,
FaceTrackingSourcesConfig, FoveatedEncodingConfig, MediacodecDataType,
FaceTrackingSourcesConfig, FoveatedEncodingConfig, MediacodecProperty,
};
use openxr as xr;
use std::{
Expand All @@ -44,7 +44,7 @@ pub struct ParsedStreamConfig {
pub force_software_decoder: bool,
pub max_buffering_frames: f32,
pub buffering_history_weight: f32,
pub decoder_options: Vec<(String, MediacodecDataType)>,
pub decoder_options: Vec<(String, MediacodecProperty)>,
}

impl ParsedStreamConfig {
Expand Down
21 changes: 14 additions & 7 deletions alvr/server_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
tracking::{self, TrackingManager},
ConnectionContext, ServerCoreEvent, ViewsConfig, SESSION_MANAGER,
};
use alvr_audio::AudioDevice;

Check warning on line 10 in alvr/server_core/src/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `alvr_audio::AudioDevice`

warning: unused import: `alvr_audio::AudioDevice` --> alvr/server_core/src/connection.rs:10:5 | 10 | use alvr_audio::AudioDevice; | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
use alvr_common::{
con_bail, dbg_connection, debug, error,
glam::{Quat, UVec2, Vec2, Vec3},
Expand Down Expand Up @@ -664,8 +664,8 @@
game_audio_sample_rate,
enable_foveated_encoding,
use_multimodal_protocol: streaming_caps.multimodal_protocol,
encoding_gamma: encoding_gamma,

Check warning on line 667 in alvr/server_core/src/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant field names in struct initialization

warning: redundant field names in struct initialization --> alvr/server_core/src/connection.rs:667:13 | 667 | encoding_gamma: encoding_gamma, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `encoding_gamma` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names = note: `#[warn(clippy::redundant_field_names)]` on by default
enable_hdr: enable_hdr,

Check warning on line 668 in alvr/server_core/src/connection.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant field names in struct initialization

warning: redundant field names in struct initialization --> alvr/server_core/src/connection.rs:668:13 | 668 | enable_hdr: enable_hdr, | ^^^^^^^^^^^^^^^^^^^^^^ help: replace it with: `enable_hdr` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
},
)
.to_con()?;
Expand Down Expand Up @@ -804,12 +804,14 @@

#[cfg(windows)]
if let Ok(id) = alvr_audio::get_windows_device_id(&device) {
let prop = alvr_session::OpenvrProperty {
key: alvr_session::OpenvrPropKey::AudioDefaultPlaybackDeviceIdString,
value: id,
};
ctx.events_sender
.send(ServerCoreEvent::SetOpenvrProperty {
device_id: *alvr_common::HEAD_ID,
prop: alvr_session::OpenvrProperty::AudioDefaultPlaybackDeviceId(
id,
),
prop,
})
.ok();
} else {
Expand All @@ -833,12 +835,14 @@
if let Ok(id) = AudioDevice::new_output(None)
.and_then(|d| alvr_audio::get_windows_device_id(&d))
{
let prop = alvr_session::OpenvrProperty {
key: alvr_session::OpenvrPropKey::AudioDefaultPlaybackDeviceIdString,
value: id,
};
ctx.events_sender
.send(ServerCoreEvent::SetOpenvrProperty {
device_id: *alvr_common::HEAD_ID,
prop: alvr_session::OpenvrProperty::AudioDefaultPlaybackDeviceId(
id,
),
prop,
})
.ok();
}
Expand All @@ -861,7 +865,10 @@
ctx.events_sender
.send(ServerCoreEvent::SetOpenvrProperty {
device_id: *alvr_common::HEAD_ID,
prop: alvr_session::OpenvrProperty::AudioDefaultRecordingDeviceId(id),
prop: alvr_session::OpenvrProperty {
key: alvr_session::OpenvrPropKey::AudioDefaultRecordingDeviceIdString,
value: id,
},
})
.ok();
}
Expand Down
2 changes: 2 additions & 0 deletions alvr/server_openvr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ alvr_server_core.workspace = true
alvr_server_io.workspace = true
alvr_session.workspace = true

serde_json = "1"

[build-dependencies]
alvr_filesystem = { path = "../filesystem" }
bindgen = "0.70"
Expand Down
6 changes: 3 additions & 3 deletions alvr/server_openvr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ extern "C" fn driver_ready_idle(set_default_chap: bool) {
};

match event {
ServerCoreEvent::SetOpenvrProperty { device_id, prop } => unsafe {
SetOpenvrProperty(device_id, props::to_ffi_openvr_prop(prop))
},
ServerCoreEvent::SetOpenvrProperty { device_id, prop } => {
props::set_openvr_prop(device_id, prop)
}
ServerCoreEvent::ClientConnected => {
unsafe {
InitializeStreaming();
Expand Down
Loading
Loading