From 2d8041e52815172e9705e0effc4a00cbca725a36 Mon Sep 17 00:00:00 2001 From: Riccardo Zaglia Date: Thu, 28 Jul 2022 12:59:59 +0200 Subject: [PATCH] Add adaptive bitrate enable and video bitrate dynamic settings --- alvr/server/cpp/alvr_server/alvr_server.cpp | 12 ++++++++++-- alvr/server/cpp/alvr_server/bindings.h | 4 +++- alvr/server/src/connection.rs | 21 ++++++++++++++++++--- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/alvr/server/cpp/alvr_server/alvr_server.cpp b/alvr/server/cpp/alvr_server/alvr_server.cpp index 3a0543d50a..00be44ccfb 100644 --- a/alvr/server/cpp/alvr_server/alvr_server.cpp +++ b/alvr/server/cpp/alvr_server/alvr_server.cpp @@ -317,8 +317,16 @@ void SetButton(unsigned long long path, AlvrButtonValue value) { } } -void SetAdaptiveBitrateMax(unsigned long long bitrate_max) { +void SetBitrateParameters(unsigned long long bitrate_mbs, + bool adaptive_bitrate_enabled, + unsigned long long bitrate_max) { if (g_driver_provider.hmd && g_driver_provider.hmd->m_Listener) { - g_driver_provider.hmd->m_Listener->m_Statistics->m_adaptiveBitrateMaximum = bitrate_max; + if (adaptive_bitrate_enabled) { + g_driver_provider.hmd->m_Listener->m_Statistics->m_enableAdaptiveBitrate = true; + g_driver_provider.hmd->m_Listener->m_Statistics->m_adaptiveBitrateMaximum = bitrate_max; + } else { + g_driver_provider.hmd->m_Listener->m_Statistics->m_enableAdaptiveBitrate = false; + g_driver_provider.hmd->m_Listener->m_Statistics->m_bitrate = bitrate_mbs; + } } } \ No newline at end of file diff --git a/alvr/server/cpp/alvr_server/bindings.h b/alvr/server/cpp/alvr_server/bindings.h index 1317766b22..13b1b9f429 100644 --- a/alvr/server/cpp/alvr_server/bindings.h +++ b/alvr/server/cpp/alvr_server/bindings.h @@ -145,4 +145,6 @@ extern "C" void SetViewsConfig(ViewsConfigData config); extern "C" void SetBattery(unsigned long long topLevelPath, float gauge_value, bool is_plugged); extern "C" void SetButton(unsigned long long path, AlvrButtonValue value); -extern "C" void SetAdaptiveBitrateMax(unsigned long long bitrate_max); \ No newline at end of file +extern "C" void SetBitrateParameters(unsigned long long bitrate_mbs, + bool adaptive_bitrate_enabled, + unsigned long long bitrate_max); \ No newline at end of file diff --git a/alvr/server/src/connection.rs b/alvr/server/src/connection.rs index e9e3474018..fee018dd3f 100644 --- a/alvr/server/src/connection.rs +++ b/alvr/server/src/connection.rs @@ -901,12 +901,27 @@ async fn connection_pipeline() -> StrResult { time::sleep(NETWORK_KEEPALIVE_INTERVAL).await; // copy some settings periodically into c++ + let data_manager = SERVER_DATA_MANAGER.read(); + let settings = data_manager.settings(); - if let Switch::Enabled(config) = + let mut bitrate_maximum = 0; + let adaptive_bitrate_enabled = if let Switch::Enabled(config) = &SERVER_DATA_MANAGER.read().settings().video.adaptive_bitrate { - unsafe { crate::SetAdaptiveBitrateMax(config.bitrate_maximum) }; - } + bitrate_maximum = config.bitrate_maximum; + + true + } else { + false + }; + + unsafe { + crate::SetBitrateParameters( + settings.video.encode_bitrate_mbs, + adaptive_bitrate_enabled, + bitrate_maximum, + ) + }; } } };