From d33bd00bb460c442a652b91efd8e3530941fd736 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 16 Apr 2023 15:15:19 -0500 Subject: [PATCH] Fix HEVC mode if the encoder changes --- src/nvhttp.cpp | 8 ++++---- src/platform/linux/vaapi.cpp | 5 +++-- src/rtsp.cpp | 5 +++-- src/video.cpp | 16 +++++++++------- src/video.h | 2 ++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index d2cdd6a8..f2e65f20 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -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); diff --git a/src/platform/linux/vaapi.cpp b/src/platform/linux/vaapi.cpp index 12281ac4..8f3c3705 100644 --- a/src/platform/linux/vaapi.cpp +++ b/src/platform/linux/vaapi.cpp @@ -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; } diff --git a/src/rtsp.cpp b/src/rtsp.cpp index 98606be9..653afde5 100644 --- a/src/rtsp.cpp +++ b/src/rtsp.cpp @@ -19,6 +19,7 @@ extern "C" { #include "rtsp.h" #include "stream.h" #include "sync.h" +#include "video.h" #include @@ -489,7 +490,7 @@ namespace rtsp_stream { option.content = const_cast(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, {}); diff --git a/src/video.cpp b/src/video.cpp index 1304d776..41ddab7e 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -724,6 +724,7 @@ namespace video { }; static encoder_t *chosen_encoder; + int active_hevc_mode; void reset_display(std::shared_ptr &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; diff --git a/src/video.h b/src/video.h index c02c317e..d3eb1a95 100644 --- a/src/video.h +++ b/src/video.h @@ -90,6 +90,8 @@ namespace video { extern color_t colors[6]; + extern int active_hevc_mode; + void capture( safe::mail_t mail,