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

Add option to encode using baseline/constrained baseline. #1932

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions alvr/server/cpp/alvr_server/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void Settings::Load() {
picojson::value v;
std::string err = picojson::parse(v, json);
if (!err.empty()) {
Error("Error on parsing json: %hs\n", err.c_str());
Error("Error on parsing session config (%s): %hs\n", g_sessionPath, err.c_str());
return;
}

Expand Down Expand Up @@ -105,10 +105,15 @@ void Settings::Load() {
m_enableControllers = config.get("controllers_enabled").get<bool>();
m_controllerIsTracker = config.get("controller_is_tracker").get<bool>();

auto sessionSettings = v.get("session_settings");
auto sessionVideo = sessionSettings.get("video");

m_h264UseBaselineProfile = sessionVideo.get("h264_use_baseline_profile").get<bool>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you write this code like this, SteamVR will not restart when this setting has been changed. Please check how the other settings are passed to SteamVR and do something similar.


Info("Render Target: %d %d\n", m_renderWidth, m_renderHeight);
Info("Refresh Rate: %d\n", m_refreshRate);
m_loaded = true;
} catch (std::exception &e) {
Error("Exception on parsing json: %hs\n", e.what());
Error("Exception on parsing session config (%s): %hs\n", g_sessionPath, e.what());
}
}
1 change: 1 addition & 0 deletions alvr/server/cpp/alvr_server/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class Settings {
float m_sharpening;

int m_codec;
bool m_h264UseBaselineProfile;
bool m_use10bitEncoder;
bool m_enableVbaq;
bool m_usePreproc;
Expand Down
3 changes: 3 additions & 0 deletions alvr/server/cpp/platform/linux/EncodePipelineNvEnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ alvr::EncodePipelineNvEnc::EncodePipelineNvEnc(Renderer *render,
break;
}

if (settings.m_h264UseBaselineProfile)
av_opt_set(encoder_ctx->priv_data, "profile", "baseline", 0);

char preset[] = "p0";
// replace 0 with preset number
preset[1] += settings.m_nvencQualityPreset;
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/linux/EncodePipelineSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ alvr::EncodePipelineSW::EncodePipelineSW(Renderer *render, uint32_t width, uint3
const auto& settings = Settings::Instance();

x264_param_default_preset(&param, "ultrafast", "zerolatency");
x264_param_apply_profile(&param, "high");
x264_param_apply_profile(&param, settings.m_h264UseBaselineProfile ? "baseline" : "high");

param.pf_log = x264_log;
param.i_log_level = X264_LOG_INFO;
Expand Down
2 changes: 1 addition & 1 deletion alvr/server/cpp/platform/linux/EncodePipelineVAAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ alvr::EncodePipelineVAAPI::EncodePipelineVAAPI(Renderer *render, VkContext &vk_c
switch (codec_id)
{
case ALVR_CODEC_H264:
encoder_ctx->profile = FF_PROFILE_H264_MAIN;
encoder_ctx->profile = settings.m_h264UseBaselineProfile ? FF_PROFILE_H264_CONSTRAINED_BASELINE : FF_PROFILE_H264_MAIN;

switch (settings.m_entropyCoding) {
case ALVR_CABAC:
Expand Down
8 changes: 6 additions & 2 deletions alvr/server/cpp/platform/win32/VideoEncoderAMF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ amf::AMFComponentPtr VideoEncoderAMF::MakeEncoder(
if (codec == ALVR_CODEC_H264)
{
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_USAGE, AMF_VIDEO_ENCODER_USAGE_ULTRA_LOW_LATENCY);
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_PROFILE, AMF_VIDEO_ENCODER_PROFILE_HIGH);
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_PROFILE_LEVEL, 42);
if (Settings::Instance().m_h264UseBaselineProfile) {
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_PROFILE, AMF_VIDEO_ENCODER_PROFILE_CONSTRAINED_BASELINE);
} else {
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_PROFILE, AMF_VIDEO_ENCODER_PROFILE_HIGH);
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_PROFILE_LEVEL, 42);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move profile level outside the condition. This is common for both profiles.

}
switch (Settings::Instance().m_rateControlMode) {
case ALVR_CBR:
amfEncoder->SetProperty(AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD, AMF_VIDEO_ENCODER_RATE_CONTROL_METHOD_CBR);
Expand Down
4 changes: 2 additions & 2 deletions alvr/server/cpp/platform/win32/VideoEncoderSW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void VideoEncoderSW::Initialize() {
av_dict_set(&opt, "preset", "ultrafast", 0);
av_dict_set(&opt, "tune", "zerolatency", 0);

m_codecContext->profile = FF_PROFILE_H264_HIGH;
m_codecContext->profile = settings.m_h264UseBaselineProfile ? FF_PROFILE_H264_CONSTRAINED_BASELINE : FF_PROFILE_H264_HIGH;
switch (settings.m_entropyCoding) {
case ALVR_CABAC:
av_dict_set(&opt, "coder", "ac", 0);
Expand Down Expand Up @@ -245,4 +245,4 @@ AVCodecID VideoEncoderSW::ToFFMPEGCodec(ALVR_CODEC codec) {
}
}

#endif // ALVR_GPL
#endif // ALVR_GPL
8 changes: 8 additions & 0 deletions alvr/session/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ pub struct VideoConfig {
#[schema(flag = "steamvr-restart")]
pub preferred_codec: CodecType,

#[schema(strings(
display_name = "Use h264 baseline profile",
help = "Whenever possible, attempts to force the 'baseline profile' or the 'constrained baseline profile' to increase compatibility with varying mobile devices. Only has an effect for h264 and may not have an effect for some configurations."
))]
#[schema(flag = "steamvr-restart")]
pub h264_use_baseline_profile: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put the setting inside EncoderConfig.


#[schema(flag = "steamvr-restart")]
pub encoder_config: EncoderConfig,

Expand Down Expand Up @@ -1159,6 +1166,7 @@ pub fn session_settings_default() -> SettingsDefault {
preferred_codec: CodecTypeDefault {
variant: CodecTypeDefaultVariant::H264,
},
h264_use_baseline_profile: false,
encoder_config: EncoderConfigDefault {
gui_collapsed: true,
rate_control_mode: RateControlModeDefault {
Expand Down
4 changes: 2 additions & 2 deletions alvr/vulkan_layer/layer/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void Settings::Load()
std::string err = picojson::parse(v, json);
if (!err.empty())
{
Error("Error on parsing json: %hs\n", err.c_str());
Error("Error on parsing session config (%s): %hs\n", g_sessionPath, err.c_str());
return;
}

Expand All @@ -56,6 +56,6 @@ void Settings::Load()
}
catch (std::exception &e)
{
Error("Exception on parsing json: %hs\n", e.what());
Error("Exception on parsing session config (%s): %hs\n", g_sessionPath, e.what());
}
}
Loading