Skip to content

Commit

Permalink
Add adaptive bitrate enable and video bitrate dynamic settings
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp committed Sep 14, 2022
1 parent b051aea commit 2d8041e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
12 changes: 10 additions & 2 deletions alvr/server/cpp/alvr_server/alvr_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
4 changes: 3 additions & 1 deletion alvr/server/cpp/alvr_server/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
extern "C" void SetBitrateParameters(unsigned long long bitrate_mbs,
bool adaptive_bitrate_enabled,
unsigned long long bitrate_max);
21 changes: 18 additions & 3 deletions alvr/server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
};
}
}
};
Expand Down

0 comments on commit 2d8041e

Please sign in to comment.