Skip to content

Commit

Permalink
WIP client-overridable encoding settings
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyquagsire23 committed Oct 9, 2024
1 parent 406f9d5 commit 252ba9b
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 11 deletions.
10 changes: 10 additions & 0 deletions alvr/client_core/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ pub struct AlvrClientCapabilities {
encoder_high_profile: bool,
encoder_10_bits: bool,
encoder_av1: bool,
use_10bit: bool,
use_full_range: bool,
encoding_gamma: f32,
enable_hdr: bool,
enable_color_correction: bool,
}

#[repr(u8)]
Expand Down Expand Up @@ -283,6 +288,11 @@ pub unsafe extern "C" fn alvr_initialize(capabilities: AlvrClientCapabilities) {
encoder_high_profile: capabilities.encoder_high_profile,
encoder_10_bits: capabilities.encoder_10_bits,
encoder_av1: capabilities.encoder_av1,
use_10bit: capabilities.use_10bit,
use_full_range: capabilities.use_full_range,
encoding_gamma: capabilities.encoding_gamma,
enable_hdr: capabilities.enable_hdr,
enable_color_correction: capabilities.enable_color_correction,
};
*CLIENT_CORE_CONTEXT.lock() = Some(ClientCoreContext::new(capabilities));
}
Expand Down
5 changes: 5 additions & 0 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ fn connection_pipeline(
encoder_10_bits: capabilities.encoder_10_bits,
encoder_av1: capabilities.encoder_av1,
multimodal_protocol: true,
use_10bit: capabilities.use_10bit,
use_full_range: capabilities.use_full_range,
encoding_gamma: capabilities.encoding_gamma,
enable_hdr: capabilities.enable_hdr,
enable_color_correction: capabilities.enable_color_correction,
})
.to_con()?,
),
Expand Down
5 changes: 5 additions & 0 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ pub struct ClientCapabilities {
pub encoder_high_profile: bool,
pub encoder_10_bits: bool,
pub encoder_av1: bool,
pub use_10bit: bool,
pub use_full_range: bool,
pub encoding_gamma: f32,
pub enable_hdr: bool,
pub enable_color_correction: bool,
}

pub struct ClientCoreContext {
Expand Down
12 changes: 12 additions & 0 deletions alvr/packets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct VideoStreamingCapabilities {
pub encoder_10_bits: bool,
pub encoder_av1: bool,
pub multimodal_protocol: bool,
pub use_10bit: bool,
pub use_full_range: bool,
pub encoding_gamma: f32,
pub enable_hdr: bool,
pub enable_color_correction: bool,
}

// Nasty workaround to make the packet extensible, pushing the limits of protocol compatibility
Expand Down Expand Up @@ -95,6 +100,13 @@ pub fn decode_video_streaming_capabilities(
encoder_10_bits: caps_json["encoder_10_bits"].as_bool().unwrap_or(true),
encoder_av1: caps_json["encoder_av1"].as_bool().unwrap_or(true),
multimodal_protocol: caps_json["multimodal_protocol"].as_bool().unwrap_or(false),
use_10bit: caps_json["use_10bit"].as_bool().unwrap_or(false),
use_full_range: caps_json["use_full_range"].as_bool().unwrap_or(true),
encoding_gamma: caps_json["encoding_gamma"].as_f64().unwrap_or(1.0) as f32,
enable_hdr: caps_json["enable_hdr"].as_bool().unwrap_or(false),
enable_color_correction: caps_json["enable_color_correction"]
.as_bool()
.unwrap_or(true),
})
}

Expand Down
52 changes: 45 additions & 7 deletions alvr/server_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,47 @@ fn connection_pipeline(
settings.video.encoder_config.h264_profile
};

let enable_10_bits_encoding = if settings.video.encoder_config.use_10bit {
let enable = streaming_caps.encoder_10_bits;
let mut enable_10_bits_encoding = if settings.video.encoder_config.server_overrides_use_10bit {
settings.video.encoder_config.use_10bit
} else {
streaming_caps.use_10bit
};

if !enable {
warn!("10 bits encoding is not supported by the client.");
}
if enable_10_bits_encoding && !streaming_caps.encoder_10_bits {
warn!("10 bits encoding is not supported by the client.");
enable_10_bits_encoding = false
}

enable
let use_full_range = if settings
.video
.encoder_config
.server_overrides_use_full_range
{
settings.video.encoder_config.use_full_range
} else {
false
streaming_caps.use_full_range
};

let enable_hdr = if settings.video.encoder_config.server_overrides_enable_hdr {
settings.video.encoder_config.enable_hdr
} else {
streaming_caps.enable_hdr
};

let encoding_gamma = if settings
.video
.encoder_config
.server_overrides_encoding_gamma
{
settings.video.encoder_config.encoding_gamma
} else {
streaming_caps.encoding_gamma
};

let enable_color_correction = if settings.video.server_overrides_color_correction {
settings.video.color_correction.enabled()
} else {
streaming_caps.enable_color_correction
};

let codec = if settings.video.preferred_codec == CodecType::AV1 {
Expand Down Expand Up @@ -651,8 +682,15 @@ fn connection_pipeline(
new_openvr_config.enable_foveated_encoding = enable_foveated_encoding;
new_openvr_config.h264_profile = encoder_profile as _;
new_openvr_config.use_10bit_encoder = enable_10_bits_encoding;
new_openvr_config.use_full_range_encoding = use_full_range;
new_openvr_config.enable_hdr = enable_hdr;
new_openvr_config.encoding_gamma = encoding_gamma;
new_openvr_config.codec = codec as _;

if enable_color_correction {
new_openvr_config.enable_color_correction = enable_color_correction;
}

if session_manager_lock.session().openvr_config != new_openvr_config {
session_manager_lock.session_mut().openvr_config = new_openvr_config;

Expand Down
48 changes: 44 additions & 4 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,33 +224,61 @@ CABAC produces better compression but it's significantly slower and may lead to
pub entropy_coding: EntropyCoding,

#[schema(strings(
display_name = "10 bit encoding",
help = "Sets the encoder to use 10 bits per channel instead of 8. Does not work on Linux with Nvidia"
display_name = "10-bit encoding",
help = "Sets the encoder to use 10 bits per channel instead of 8, if the client has no preference. Does not work on Linux with Nvidia"
))]
#[schema(flag = "steamvr-restart")]
pub use_10bit: bool,

#[schema(strings(
display_name = "Override headset's preference for 10-bit encoding",
help = "Override the headset client's preference for 10-bit encoding."
))]
#[schema(flag = "steamvr-restart")]
pub server_overrides_use_10bit: bool,

#[schema(strings(
display_name = "Full range color",
help = "Sets the encoder to encode full range RGB (0-255) instead of limited/video range RGB (16-235)"
help = "Sets the encoder to encode full range RGB (0-255) instead of limited/video range RGB (16-235), if the client has no preference"
))]
#[schema(flag = "steamvr-restart")]
pub use_full_range: bool,

#[schema(strings(
display_name = "Override headset's preference for full range color",
help = "The server will override the headset client's preference for full range color."
))]
#[schema(flag = "steamvr-restart")]
pub server_overrides_use_full_range: bool,

#[schema(strings(
display_name = "Encoding Gamma",
help = "To prioritize darker pixels at the expense of potentially additional banding in midtones, set to 2.2. To allow the encoder to decide priority on its own, set to 1.0."
))]
#[schema(flag = "steamvr-restart")]
pub encoding_gamma: f32,

#[schema(strings(
display_name = "Override headset's preference for encoding gamma",
help = "The server will override the headset client's preference for encoding gamma."
))]
#[schema(flag = "steamvr-restart")]
pub server_overrides_encoding_gamma: bool,

#[schema(strings(
display_name = "Enable HDR",
help = "Composite VR layers to an RGBA float16 framebuffer, and do sRGB/YUV conversions in shader code."
help = "If the client has no preference, enables compositing VR layers to an RGBA float16 framebuffer, and doing sRGB/YUV conversions in shader code."
))]
#[schema(flag = "steamvr-restart")]
pub enable_hdr: bool,

#[schema(strings(
display_name = "Override headset's preference for HDR",
help = "The server will override the headset client's preference for HDR."
))]
#[schema(flag = "steamvr-restart")]
pub server_overrides_enable_hdr: bool,

#[schema(strings(
display_name = "Force HDR sRGB Correction",
help = "Forces sRGB correction on all composited SteamVR layers. Useful if an HDR-injected game is too dark."
Expand Down Expand Up @@ -520,6 +548,13 @@ pub struct VideoConfig {
#[schema(flag = "steamvr-restart")]
pub color_correction: Switch<ColorCorrectionConfig>,

#[schema(strings(
display_name = "Override headset's preference for Color Correction",
help = "The server will override the headset client's preference for Color Correction."
))]
#[schema(flag = "steamvr-restart")]
pub server_overrides_color_correction: bool,

#[schema(
strings(
display_name = "Maximum buffering",
Expand Down Expand Up @@ -1332,9 +1367,13 @@ pub fn session_settings_default() -> SettingsDefault {
variant: EntropyCodingDefaultVariant::Cavlc,
},
use_10bit: false,
server_overrides_use_10bit: false,
use_full_range: true,
server_overrides_use_full_range: false,
encoding_gamma: 1.0,
server_overrides_encoding_gamma: false,
enable_hdr: false,
server_overrides_enable_hdr: false,
force_hdr_srgb_correction: false,
clamp_hdr_extended_range: false,
nvenc: NvencConfigDefault {
Expand Down Expand Up @@ -1452,6 +1491,7 @@ pub fn session_settings_default() -> SettingsDefault {
sharpening: 0.5,
},
},
server_overrides_color_correction: false,
},
audio: AudioConfigDefault {
game_audio: SwitchDefault {
Expand Down

0 comments on commit 252ba9b

Please sign in to comment.