Fix HEVC mode if the encoder changes

This commit is contained in:
Cameron Gutman
2023-04-16 15:15:19 -05:00
parent 006a6984c3
commit d33bd00bb4
5 changed files with 21 additions and 15 deletions

View File

@@ -622,13 +622,13 @@ namespace nvhttp {
tree.put("root.HttpsPort", map_port(PORT_HTTPS));
tree.put("root.ExternalPort", map_port(PORT_HTTP));
tree.put("root.mac", platf::get_mac_address(local_endpoint.address().to_string()));
tree.put("root.MaxLumaPixelsHEVC", config::video.hevc_mode > 1 ? "1869449984" : "0");
tree.put("root.MaxLumaPixelsHEVC", video::active_hevc_mode > 1 ? "1869449984" : "0");
tree.put("root.LocalIP", local_endpoint.address().to_string());
if (config::video.hevc_mode == 3) {
if (video::active_hevc_mode == 3) {
tree.put("root.ServerCodecModeSupport", "3843");
}
else if (config::video.hevc_mode == 2) {
else if (video::active_hevc_mode == 2) {
tree.put("root.ServerCodecModeSupport", "259");
}
else {
@@ -713,7 +713,7 @@ namespace nvhttp {
for (auto &proc : proc::proc.get_apps()) {
pt::ptree app;
app.put("IsHdrSupported"s, config::video.hevc_mode == 3 ? 1 : 0);
app.put("IsHdrSupported"s, video::active_hevc_mode == 3 ? 1 : 0);
app.put("AppTitle"s, proc.name);
app.put("ID", proc.id);

View File

@@ -25,6 +25,7 @@ vaSyncBuffer(
#include "src/main.h"
#include "src/platform/common.h"
#include "src/utility.h"
#include "src/video.h"
using namespace std::literals;
@@ -626,11 +627,11 @@ namespace va {
return false;
}
if (config::video.hevc_mode > 1 && !query(display.get(), profile_e::HEVCMain)) {
if (video::active_hevc_mode > 1 && !query(display.get(), profile_e::HEVCMain)) {
return false;
}
if (config::video.hevc_mode > 2 && !query(display.get(), profile_e::HEVCMain10)) {
if (video::active_hevc_mode > 2 && !query(display.get(), profile_e::HEVCMain10)) {
return false;
}

View File

@@ -19,6 +19,7 @@ extern "C" {
#include "rtsp.h"
#include "stream.h"
#include "sync.h"
#include "video.h"
#include <unordered_map>
@@ -489,7 +490,7 @@ namespace rtsp_stream {
option.content = const_cast<char *>(seqn_str.c_str());
std::stringstream ss;
if (config::video.hevc_mode != 1) {
if (video::active_hevc_mode != 1) {
ss << "sprop-parameter-sets=AAAAAU"sv << std::endl;
}
@@ -690,7 +691,7 @@ namespace rtsp_stream {
}
}
if (config.monitor.videoFormat != 0 && config::video.hevc_mode == 1) {
if (config.monitor.videoFormat != 0 && video::active_hevc_mode == 1) {
BOOST_LOG(warning) << "HEVC is disabled, yet the client requested HEVC"sv;
respond(sock, &option, 400, "BAD REQUEST", req->sequenceNumber, {});

View File

@@ -724,6 +724,7 @@ namespace video {
};
static encoder_t *chosen_encoder;
int active_hevc_mode;
void
reset_display(std::shared_ptr<platf::display_t> &disp, AVHWDeviceType type, const std::string &display_name, const config_t &config) {
@@ -1860,8 +1861,8 @@ namespace video {
BOOST_LOG(info) << "Encoder ["sv << encoder.name << "] failed"sv;
});
auto force_hevc = config::video.hevc_mode >= 2;
auto test_hevc = force_hevc || (config::video.hevc_mode == 0 && !(encoder.flags & H264_ONLY));
auto force_hevc = active_hevc_mode >= 2;
auto test_hevc = force_hevc || (active_hevc_mode == 0 && !(encoder.flags & H264_ONLY));
encoder.h264.capabilities.set();
encoder.hevc.capabilities.set();
@@ -1984,6 +1985,7 @@ namespace video {
// Restart encoder selection
auto previous_encoder = chosen_encoder;
chosen_encoder = nullptr;
active_hevc_mode = config::video.hevc_mode;
if (!config::video.encoder.empty()) {
// If there is a specific encoder specified, use it if it passes validation
@@ -1998,9 +2000,9 @@ namespace video {
}
// If we can't satisfy both the encoder and HDR requirement, prefer the encoder over HDR support
if (config::video.hevc_mode == 3 && !encoder->hevc[encoder_t::DYNAMIC_RANGE]) {
if (active_hevc_mode == 3 && !encoder->hevc[encoder_t::DYNAMIC_RANGE]) {
BOOST_LOG(warning) << "Encoder ["sv << config::video.encoder << "] does not support HDR on this system"sv;
config::video.hevc_mode = 0;
active_hevc_mode = 0;
}
chosen_encoder = encoder;
@@ -2018,7 +2020,7 @@ namespace video {
BOOST_LOG(info) << "// Testing for available encoders, this may generate errors. You can safely ignore those errors. //"sv;
// If we haven't found an encoder yet, but we want one with HDR support, search for that now.
if (chosen_encoder == nullptr && config::video.hevc_mode == 3) {
if (chosen_encoder == nullptr && active_hevc_mode == 3) {
KITTY_WHILE_LOOP(auto pos = std::begin(encoder_list), pos != std::end(encoder_list), {
auto encoder = *pos;
@@ -2094,8 +2096,8 @@ namespace video {
BOOST_LOG(info) << "Found encoder "sv << encoder.name << ": ["sv << encoder.h264.name << ']';
}
if (config::video.hevc_mode == 0) {
config::video.hevc_mode = encoder.hevc[encoder_t::PASSED] ? (encoder.hevc[encoder_t::DYNAMIC_RANGE] ? 3 : 2) : 1;
if (active_hevc_mode == 0) {
active_hevc_mode = encoder.hevc[encoder_t::PASSED] ? (encoder.hevc[encoder_t::DYNAMIC_RANGE] ? 3 : 2) : 1;
}
return 0;

View File

@@ -90,6 +90,8 @@ namespace video {
extern color_t colors[6];
extern int active_hevc_mode;
void
capture(
safe::mail_t mail,