Skip to content

Commit

Permalink
Fix VAAPI with dynamic bitrate (#1863)
Browse files Browse the repository at this point in the history
* Revert "EncodePipelineVAAPI: Force VBR with adaptive bitrate (#1768)"

This reverts commit c1821aa.

* EncodePipelineVAAPI: Fix setting quality preset

quality == 1 means "default" preset which is balanced + preencode + vbaq.
  • Loading branch information
nowrep authored Oct 13, 2023
1 parent b17d99e commit 1825ae1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 21 deletions.
6 changes: 0 additions & 6 deletions alvr/server/cpp/alvr_server/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ void Settings::Load() {
m_enableControllers = config.get("controllers_enabled").get<bool>();
m_controllerIsTracker = config.get("controller_is_tracker").get<bool>();

m_constantBitrate = v.get("session_settings")
.get("video")
.get("bitrate")
.get("mode")
.get("variant").get<std::string>() == "ConstantMbps";

Info("Render Target: %d %d\n", m_renderWidth, m_renderHeight);
Info("Refresh Rate: %d\n", m_refreshRate);
m_loaded = true;
Expand Down
2 changes: 0 additions & 2 deletions alvr/server/cpp/alvr_server/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,4 @@ class Settings {

bool m_enableControllers;
int m_controllerIsTracker = false;

bool m_constantBitrate;
};
15 changes: 2 additions & 13 deletions alvr/server/cpp/platform/linux/EncodePipelineVAAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "ALVR-common/packet_types.h"
#include "ffmpeg_helper.h"
#include "alvr_server/Settings.h"
#include "alvr_server/Logger.h"
#include <chrono>

extern "C" {
Expand Down Expand Up @@ -181,12 +180,7 @@ alvr::EncodePipelineVAAPI::EncodePipelineVAAPI(Renderer *render, VkContext &vk_c
break;
case ALVR_CBR:
default:
if (settings.m_constantBitrate) {
av_opt_set(encoder_ctx->priv_data, "rc_mode", "CBR", 0);
} else {
Info("Forcing VBR rate control with adaptive bitrate");
av_opt_set(encoder_ctx->priv_data, "rc_mode", "VBR", 0);
}
av_opt_set(encoder_ctx->priv_data, "rc_mode", "CBR", 0);
break;
}

Expand All @@ -207,7 +201,6 @@ alvr::EncodePipelineVAAPI::EncodePipelineVAAPI(Renderer *render, VkContext &vk_c
SetParams(params);

vlVaQualityBits quality = {};
quality.valid_setting = 1;
quality.vbaq_mode = Settings::Instance().m_enableVbaq; //No noticable performance difference and should improve subjective quality by allocating more bits to smooth areas
switch (settings.m_amdEncoderQualityPreset)
{
Expand Down Expand Up @@ -349,11 +342,7 @@ void alvr::EncodePipelineVAAPI::SetParams(FfiDynamicEncoderParams params)
}
encoder_ctx->bit_rate = params.bitrate_bps;
encoder_ctx->framerate = AVRational{int(params.framerate * 1000), 1000};
if (settings.m_constantBitrate) {
encoder_ctx->rc_buffer_size = encoder_ctx->bit_rate / params.framerate;
} else {
encoder_ctx->rc_buffer_size = (encoder_ctx->bit_rate / params.framerate) * 5.0;
}
encoder_ctx->rc_buffer_size = encoder_ctx->bit_rate / params.framerate;
encoder_ctx->rc_max_rate = encoder_ctx->bit_rate;
encoder_ctx->rc_initial_buffer_occupancy = encoder_ctx->rc_buffer_size;

Expand Down

0 comments on commit 1825ae1

Please sign in to comment.