From e2a56b3d1731d2cc423e616fbb04bb14413b7f5a Mon Sep 17 00:00:00 2001 From: Dave Lane <42013603+ReenigneArcher@users.noreply.github.com> Date: Mon, 12 Oct 2026 22:03:58 -0400 Subject: [PATCH] refactor: resolve Sonar cpp:S1117 findings (#5908) --- src/config.cpp | 120 ++++++++++++------------ src/confighttp.cpp | 16 ++-- src/crypto.cpp | 12 +-- src/crypto.h | 18 ++-- src/entry_handler.cpp | 4 +- src/input.cpp | 8 +- src/logging.cpp | 4 +- src/nvhttp.cpp | 10 +- src/platform/common.h | 10 +- src/platform/linux/audio.cpp | 18 ++-- src/platform/linux/cuda.cpp | 104 ++++++++++---------- src/platform/linux/graphics.h | 8 +- src/platform/linux/kmsgrab.cpp | 70 +++++++++----- src/platform/linux/pipewire.cpp | 32 ++++--- src/platform/linux/portalgrab.cpp | 2 +- src/platform/linux/vaapi.cpp | 62 ++++++------ src/platform/linux/wlgrab.cpp | 20 ++-- src/platform/linux/x11grab.cpp | 52 ++++++---- src/platform/macos/nv12_zero_device.cpp | 16 ++-- src/platform/macos/nv12_zero_device.h | 10 +- src/platform/windows/audio.cpp | 6 +- src/platform/windows/display.h | 40 ++++---- src/platform/windows/display_base.cpp | 25 +++-- src/platform/windows/display_ram.cpp | 18 ++-- src/platform/windows/display_vram.cpp | 88 ++++++++--------- src/platform/windows/display_wgc.cpp | 16 ++-- src/platform/windows/input.cpp | 10 +- src/platform/windows/misc.cpp | 20 ++-- src/process.cpp | 6 +- src/process.h | 4 +- src/rtsp.cpp | 42 ++++----- src/stream.cpp | 10 +- src/video.cpp | 44 ++++----- src/video.h | 30 +++--- 34 files changed, 507 insertions(+), 448 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 3f6e3782d..0b1f18c93 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1079,15 +1079,15 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void string_f(std::unordered_map &vars, const std::string &name, std::string &input) { + void string_f(std::unordered_map &vars, const std::string &name, std::string &destination) { auto it = vars.find(name); if (it == std::end(vars)) { return; } - input = std::move(it->second); + destination = std::move(it->second); vars.erase(it); } @@ -1097,15 +1097,15 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param f Converter applied to the raw configuration string. */ template - void generic_f(std::unordered_map &vars, const std::string &name, T &input, F &&f) { + void generic_f(std::unordered_map &vars, const std::string &name, T &destination, F &&f) { std::string tmp; string_f(vars, name, tmp); if (!tmp.empty()) { - input = f(tmp); + destination = f(tmp); } } @@ -1114,16 +1114,16 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param allowed_vals Accepted string values for this setting. */ - void string_restricted_f(std::unordered_map &vars, const std::string &name, std::string &input, const std::vector &allowed_vals) { + void string_restricted_f(std::unordered_map &vars, const std::string &name, std::string &destination, const std::vector &allowed_vals) { std::string temp; string_f(vars, name, temp); for (auto &allowed_val : allowed_vals) { if (temp == allowed_val) { - input = std::move(temp); + destination = std::move(temp); return; } } @@ -1162,9 +1162,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void path_f(std::unordered_map &vars, const std::string &name, fs::path &input) { + void path_f(std::unordered_map &vars, const std::string &name, fs::path &destination) { // appdata needs to be retrieved once only static auto appdata = platf::appdata(); @@ -1172,14 +1172,14 @@ namespace config { string_f(vars, name, temp); if (!temp.empty()) { - input = temp; + destination = temp; } - if (input.is_relative()) { - input = appdata / input; + if (destination.is_relative()) { + destination = appdata / destination; } - auto dir = input; + auto dir = destination; dir.remove_filename(); // Ensure the directories exists @@ -1193,14 +1193,14 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void path_f(std::unordered_map &vars, const std::string &name, std::string &input) { - fs::path temp = input; + void path_f(std::unordered_map &vars, const std::string &name, std::string &destination) { + fs::path temp = destination; path_f(vars, name, temp); - input = temp.string(); + destination = temp.string(); } /** @@ -1225,16 +1225,16 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void int_f(std::unordered_map &vars, const std::string &name, int &input) { + void int_f(std::unordered_map &vars, const std::string &name, int &destination) { auto it = vars.find(name); if (it == std::end(vars)) { return; } - input = parse_config_integer(it->second); + destination = parse_config_integer(it->second); vars.erase(it); } @@ -1243,16 +1243,16 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void int_f(std::unordered_map &vars, const std::string &name, std::optional &input) { + void int_f(std::unordered_map &vars, const std::string &name, std::optional &destination) { auto it = vars.find(name); if (it == std::end(vars)) { return; } - input = parse_config_integer(it->second); + destination = parse_config_integer(it->second); vars.erase(it); } @@ -1261,15 +1261,15 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param f Converter applied to the raw configuration string. */ template - void int_f(std::unordered_map &vars, const std::string &name, int &input, F &&f) { + void int_f(std::unordered_map &vars, const std::string &name, int &destination, F &&f) { std::string tmp; string_f(vars, name, tmp); if (!tmp.empty()) { - input = f(tmp); + destination = f(tmp); } } @@ -1278,15 +1278,15 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param f Converter applied to the raw configuration string. */ template - void int_f(std::unordered_map &vars, const std::string &name, std::optional &input, F &&f) { + void int_f(std::unordered_map &vars, const std::string &name, std::optional &destination, F &&f) { std::string tmp; string_f(vars, name, tmp); if (!tmp.empty()) { - input = f(tmp); + destination = f(tmp); } } @@ -1295,17 +1295,17 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param range Inclusive range accepted for the parsed value. */ - void int_between_f(std::unordered_map &vars, const std::string &name, int &input, const std::pair &range) { - int temp = input; + void int_between_f(std::unordered_map &vars, const std::string &name, int &destination, const std::pair &range) { + int temp = destination; int_f(vars, name, temp); TUPLE_2D_REF(lower, upper, range); if (temp >= lower && temp <= upper) { - input = temp; + destination = temp; } } @@ -1333,9 +1333,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void bool_f(std::unordered_map &vars, const std::string &name, bool &input) { + void bool_f(std::unordered_map &vars, const std::string &name, bool &destination) { std::string tmp; string_f(vars, name, tmp); @@ -1343,7 +1343,7 @@ namespace config { return; } - input = to_bool(tmp); + destination = to_bool(tmp); } /** @@ -1351,9 +1351,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void double_f(std::unordered_map &vars, const std::string &name, double &input) { + void double_f(std::unordered_map &vars, const std::string &name, double &destination) { std::string tmp; string_f(vars, name, tmp); @@ -1368,7 +1368,7 @@ namespace config { return; } - input = val; + destination = val; } /** @@ -1376,17 +1376,17 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. * @param range Inclusive range accepted for the parsed value. */ - void double_between_f(std::unordered_map &vars, const std::string &name, double &input, const std::pair &range) { - double temp = input; + void double_between_f(std::unordered_map &vars, const std::string &name, double &destination, const std::pair &range) { + double temp = destination; double_f(vars, name, temp); TUPLE_2D_REF(lower, upper, range); if (temp >= lower && temp <= upper) { - input = temp; + destination = temp; } } @@ -1395,9 +1395,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void list_string_f(std::unordered_map &vars, const std::string &name, std::vector &input) { + void list_string_f(std::unordered_map &vars, const std::string &name, std::vector &destination) { std::string string; string_f(vars, name, string); @@ -1405,7 +1405,7 @@ namespace config { return; } - input.clear(); + destination.clear(); auto begin = std::cbegin(string); if (*begin == '[') { @@ -1424,7 +1424,7 @@ namespace config { } else if (*pos == ']') { break; } else if (*pos == ',') { - input.emplace_back(begin, pos); + destination.emplace_back(begin, pos); pos = begin = std::find_if_not(pos + 1, std::cend(string), whitespace); } else { ++pos; @@ -1432,7 +1432,7 @@ namespace config { } if (pos != begin) { - input.emplace_back(begin, pos); + destination.emplace_back(begin, pos); } } @@ -1441,9 +1441,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void list_prep_cmd_f(std::unordered_map &vars, const std::string &name, std::vector &input) { + void list_prep_cmd_f(std::unordered_map &vars, const std::string &name, std::vector &destination) { std::string string; string_f(vars, name, string); @@ -1465,7 +1465,7 @@ namespace config { auto undo_cmd = prep_cmd.get_optional("undo"s); auto elevated = prep_cmd.get_optional("elevated"s); - input.emplace_back(do_cmd.value_or(""), undo_cmd.value_or(""), elevated.value_or(false)); + destination.emplace_back(do_cmd.value_or(""), undo_cmd.value_or(""), elevated.value_or(false)); } } @@ -1474,9 +1474,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void list_int_f(std::unordered_map &vars, const std::string &name, std::vector &input) { + void list_int_f(std::unordered_map &vars, const std::string &name, std::vector &destination) { std::vector list; list_string_f(vars, name, list); @@ -1488,7 +1488,7 @@ namespace config { // The framerate list must be cleared before adding values from the file configuration. // If the list is not cleared, then the specified parameters do not affect the behavior of the sunshine server. // That is, if you set only 30 fps in the configuration file, it will not work because by default, during initialization the list includes 10, 30, 60, 90 and 120 fps. - input.clear(); + destination.clear(); for (auto &el : list) { std::string_view val = el; @@ -1505,7 +1505,7 @@ namespace config { } else { tmp = (int) util::from_view(val); } - input.emplace_back(tmp); + destination.emplace_back(tmp); } } @@ -1514,9 +1514,9 @@ namespace config { * * @param vars Parsed configuration entries; consumed keys are erased. * @param name Configuration key to consume. - * @param input Destination field updated when the setting exists and parses successfully. + * @param destination Destination field updated when the setting exists and parses successfully. */ - void map_int_int_f(std::unordered_map &vars, const std::string &name, std::unordered_map &input) { + void map_int_int_f(std::unordered_map &vars, const std::string &name, std::unordered_map &destination) { std::vector list; list_int_f(vars, name, list); @@ -1531,7 +1531,7 @@ namespace config { auto key = list[x++]; auto val = list[x++]; - input.emplace(key, val); + destination.emplace(key, val); } } diff --git a/src/confighttp.cpp b/src/confighttp.cpp index 1e2403ae5..aac428c60 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -912,13 +912,13 @@ namespace confighttp { std::string file = file_handler::read_file(config::stream.file_apps.c_str()); nlohmann::json file_tree = nlohmann::json::parse(file); if (const auto &apps = file_tree["apps"]; index < 0 || index >= static_cast(apps.size())) { - std::string error; + std::string error_message; if (const int max_index = static_cast(apps.size()) - 1; max_index < 0) { - error = "No applications found"; + error_message = "No applications found"; } else { - error = std::format("'index' {} out of range, max index is {}", index, max_index); + error_message = std::format("'index' {} out of range, max index is {}", index, max_index); } - bad_request(response, request, error); + bad_request(response, request, error_message); return false; } return true; @@ -1783,10 +1783,10 @@ namespace confighttp { if (!errors.empty()) { // join the errors array - std::string error = std::accumulate(errors.begin(), errors.end(), std::string(), [](const std::string &a, const std::string &b) { + std::string error_message = std::accumulate(errors.begin(), errors.end(), std::string(), [](const std::string &a, const std::string &b) { return a.empty() ? b : a + ", " + b; }); - bad_request(response, request, error); + bad_request(response, request, error_message); return; } @@ -2523,10 +2523,10 @@ namespace confighttp { const auto display_addr = net::get_bind_address_url_host(); - auto accept_and_run = [&](auto *server) { + auto accept_and_run = [&](auto *https_server) { try { platf::set_thread_name("confighttp::tcp"); - server->start([&display_addr](const unsigned short port) { + https_server->start([&display_addr](const unsigned short port) { BOOST_LOG(info) << "Configuration UI available at [https://"sv << display_addr << ":" << port << "]"; }); } catch (boost::system::system_error &err) { diff --git a/src/crypto.cpp b/src/crypto.cpp index ca8d4de40..6b7dfee7f 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -310,16 +310,16 @@ namespace crypto { return update_outlen + final_outlen; } - ecb_t::ecb_t(const aes_t &key, bool padding): - cipher_t {EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_new(), key, padding} { + ecb_t::ecb_t(const aes_t &key_material, bool use_padding): + cipher_t {EVP_CIPHER_CTX_new(), EVP_CIPHER_CTX_new(), key_material, use_padding} { } - cbc_t::cbc_t(const aes_t &key, bool padding): - cipher_t {nullptr, nullptr, key, padding} { + cbc_t::cbc_t(const aes_t &key_material, bool use_padding): + cipher_t {nullptr, nullptr, key_material, use_padding} { } - gcm_t::gcm_t(const crypto::aes_t &key, bool padding): - cipher_t {nullptr, nullptr, key, padding} { + gcm_t::gcm_t(const crypto::aes_t &key_material, bool use_padding): + cipher_t {nullptr, nullptr, key_material, use_padding} { } } // namespace cipher diff --git a/src/crypto.h b/src/crypto.h index 1a1c00f04..624e4dfc5 100644 --- a/src/crypto.h +++ b/src/crypto.h @@ -251,10 +251,10 @@ namespace crypto { /** * @brief Construct an AES-ECB cipher helper with key material. * - * @param key AES key material used to initialize the cipher. - * @param padding Whether the cipher should use block padding. + * @param key_material AES key material used to initialize the cipher. + * @param use_padding Whether the cipher should use block padding. */ - ecb_t(const aes_t &key, bool padding = true); + ecb_t(const aes_t &key_material, bool use_padding = true); /** * @brief Encrypt plaintext into the supplied ciphertext buffer. @@ -294,10 +294,10 @@ namespace crypto { /** * @brief Construct an AES-GCM cipher helper with key material and IV state. * - * @param key AES key material used to initialize the cipher. - * @param padding Whether the cipher should use block padding. + * @param key_material AES key material used to initialize the cipher. + * @param use_padding Whether the cipher should use block padding. */ - gcm_t(const crypto::aes_t &key, bool padding = true); + gcm_t(const crypto::aes_t &key_material, bool use_padding = true); /** * @brief Encrypts the plaintext using AES GCM mode. @@ -350,10 +350,10 @@ namespace crypto { /** * @brief Construct an AES-CBC cipher helper with key material and IV state. * - * @param key AES key material used to initialize the cipher. - * @param padding Whether the cipher should use block padding. + * @param key_material AES key material used to initialize the cipher. + * @param use_padding Whether the cipher should use block padding. */ - cbc_t(const crypto::aes_t &key, bool padding = true); + cbc_t(const crypto::aes_t &key_material, bool use_padding = true); /** * @brief Encrypts the plaintext using AES CBC mode. diff --git a/src/entry_handler.cpp b/src/entry_handler.cpp index c2249af0a..b8924b5e7 100644 --- a/src/entry_handler.cpp +++ b/src/entry_handler.cpp @@ -271,8 +271,8 @@ namespace service_ctrl { } uint16_t port_nbo = htons(net::map_port(confighttp::PORT_HTTPS)); - for (DWORD i = 0; i < tcp_table->dwNumEntries; i++) { - auto &entry = tcp_table->table[i]; + for (DWORD entry_index = 0; entry_index < tcp_table->dwNumEntries; entry_index++) { + auto &entry = tcp_table->table[entry_index]; // Look for our port in the listening state if (entry.dwLocalPort == port_nbo && entry.dwState == MIB_TCP_STATE_LISTEN) { diff --git a/src/input.cpp b/src/input.cpp index 65123f37d..4653a9b43 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -212,12 +212,12 @@ namespace input { /** * @brief Release all platform resources associated with a virtual gamepad. * - * @param platf_input Platf input. + * @param platform_input Platf input. * @param id Identifier for the controller, session, display, or resource. */ - void free_gamepad(platf::input_t &platf_input, int id) { - platf::gamepad_update(platf_input, id, platf::gamepad_state_t {}); - platf::free_gamepad(platf_input, id); + void free_gamepad(platf::input_t &platform_input, int id) { + platf::gamepad_update(platform_input, id, platf::gamepad_state_t {}); + platf::free_gamepad(platform_input, id); free_id(gamepadMask, id); } diff --git a/src/logging.cpp b/src/logging.cpp index 39a3f0071..da6b17d6b 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -66,9 +66,9 @@ namespace logging { */ void formatter(const boost::log::record_view &view, boost::log::formatting_ostream &os) { constexpr const char *message = "Message"; - constexpr const char *severity = "Severity"; + constexpr const char *severity_attribute = "Severity"; - auto log_level = view.attribute_values()[severity].extract().get(); + auto log_level = view.attribute_values()[severity_attribute].extract().get(); std::string_view log_type; switch (log_level) { diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 196a30868..33400f7f0 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -122,8 +122,8 @@ namespace nvhttp { if (!ec) { boost::asio::ip::tcp::no_delay option(true); - SimpleWeb::error_code ec; - session->connection->socket->lowest_layer().set_option(option, ec); + SimpleWeb::error_code option_error; + session->connection->socket->lowest_layer().set_option(option, option_error); session->connection->set_timeout(config.timeout_request); session->connection->socket->async_handshake(boost::asio::ssl::stream_base::server, [this, session](const SimpleWeb::error_code &ec) { @@ -1726,11 +1726,11 @@ namespace nvhttp { http_server.config.address = net::get_bind_address(address_family); http_server.config.port = port_http; - auto accept_and_run = [&](auto *http_server) { + auto accept_and_run = [&](auto *web_server) { try { - std::string name = "nvhttp::" + std::to_string(http_server->config.port); + std::string name = "nvhttp::" + std::to_string(web_server->config.port); platf::set_thread_name(name); - http_server->start(); + web_server->start(); } catch (boost::system::system_error &err) { // It's possible the exception gets thrown after calling http_server->stop() from a different thread if (shutdown_event->peek()) { diff --git a/src/platform/common.h b/src/platform/common.h index 14cd13a24..b349c924b 100644 --- a/src/platform/common.h +++ b/src/platform/common.h @@ -611,13 +611,13 @@ namespace platf { /** * @brief Set the frame to be encoded. - * @note Implementations must take ownership of 'frame'. + * @note Implementations must take ownership of 'new_frame'. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx FFmpeg hardware frames context associated with the frame. * @return Status from updating frame. */ - virtual int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) { + virtual int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) { BOOST_LOG(error) << "Illegal call to hwdevice_t::set_frame(). Did you forget to override it?"; return -1; }; @@ -675,7 +675,7 @@ namespace platf { reinit, ///< Need to reinitialize timeout, ///< Timeout interrupted, ///< Capture was interrupted - error ///< Error + capture_error ///< Capture failed. }; /** @@ -712,7 +712,7 @@ namespace platf { * Calls to this callback and push_captured_image_cb must be synchronized as well. * @param cursor A pointer to the flag that indicates whether the cursor should be captured as well. * @retval capture_e::ok When stopping - * @retval capture_e::error On error + * @retval capture_e::capture_error On error * @retval capture_e::reinit When need of reinitialization */ virtual capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) = 0; diff --git a/src/platform/linux/audio.cpp b/src/platform/linux/audio.cpp index f7439eb61..92d4126c9 100644 --- a/src/platform/linux/audio.cpp +++ b/src/platform/linux/audio.cpp @@ -83,7 +83,7 @@ namespace platf { if (pa_simple_read(mic.get(), buf, sample_size * sizeof(float), &status)) { BOOST_LOG(error) << "pa_simple_read() failed: "sv << pa_strerror(status); - return capture_e::error; + return capture_e::capture_error; } return capture_e::ok; @@ -355,8 +355,8 @@ namespace platf { loop.reset(pa_mainloop_new()); ctx.reset(pa_context_new(pa_mainloop_get_api(loop.get()), "sunshine")); - events_cb = std::make_unique>([this](ctx_t::pointer ctx) { - switch (pa_context_get_state(ctx)) { + events_cb = std::make_unique>([this](ctx_t::pointer callback_ctx) { + switch (pa_context_get_state(callback_ctx)) { case PA_CONTEXT_READY: events->raise(ready); break; @@ -476,10 +476,10 @@ namespace platf { // Count of all virtual sinks that are created by us int nullcount = 0; - cb_t f = [&](ctx_t::pointer ctx, const pa_sink_info *sink_info, int eol) { + cb_t f = [&](ctx_t::pointer callback_ctx, const pa_sink_info *sink_info, int eol) { if (!sink_info) { if (!eol) { - BOOST_LOG(error) << "Couldn't get pulseaudio sink info: "sv << pa_strerror(pa_context_errno(ctx)); + BOOST_LOG(error) << "Couldn't get pulseaudio sink info: "sv << pa_strerror(pa_context_errno(callback_ctx)); alarm->ring(-1); } @@ -568,9 +568,9 @@ namespace platf { std::string sink_name; auto alarm = safe::make_alarm(); - cb_simple_t server_f = [&](ctx_t::pointer ctx, const pa_server_info *server_info) { + cb_simple_t server_f = [&](ctx_t::pointer callback_ctx, const pa_server_info *server_info) { if (!server_info) { - BOOST_LOG(error) << "Couldn't get pulseaudio server info: "sv << pa_strerror(pa_context_errno(ctx)); + BOOST_LOG(error) << "Couldn't get pulseaudio server info: "sv << pa_strerror(pa_context_errno(callback_ctx)); alarm->ring(-1); } @@ -600,11 +600,11 @@ namespace platf { return monitor_name; } - cb_t sink_f = [&](ctx_t::pointer ctx, const pa_sink_info *sink_info, int eol) { + cb_t sink_f = [&](ctx_t::pointer callback_ctx, const pa_sink_info *sink_info, int eol) { if (!sink_info) { if (!eol) { BOOST_LOG(error) << "Couldn't get pulseaudio sink info for ["sv << sink_name - << "]: "sv << pa_strerror(pa_context_errno(ctx)); + << "]: "sv << pa_strerror(pa_context_errno(callback_ctx)); alarm->ring(-1); } diff --git a/src/platform/linux/cuda.cpp b/src/platform/linux/cuda.cpp index a87e98798..10f38bbed 100644 --- a/src/platform/linux/cuda.cpp +++ b/src/platform/linux/cuda.cpp @@ -181,13 +181,13 @@ namespace cuda { /** * @brief Attach frame resources used by the next conversion or encode operation. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx FFmpeg hardware frames context associated with the frame. * @return Status from updating frame. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override { - this->hwframe.reset(frame); - this->frame = frame; + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) override { + this->hwframe.reset(new_frame); + this->frame = new_frame; auto hwframe_ctx = (AVHWFramesContext *) hw_frames_ctx->data; @@ -196,8 +196,8 @@ namespace cuda { return -1; } - if (!frame->buf[0]) { - if (av_hwframe_get_buffer(hw_frames_ctx, frame, 0)) { + if (!new_frame->buf[0]) { + if (av_hwframe_get_buffer(hw_frames_ctx, new_frame, 0)) { BOOST_LOG(error) << "Couldn't get hwframe for NVENC"sv; return -1; } @@ -214,14 +214,14 @@ namespace cuda { cuda_ctx->stream = stream.get(); - auto sws_opt = sws_t::make(width, height, frame->width, frame->height, width * 4); + auto sws_opt = sws_t::make(width, height, new_frame->width, new_frame->height, width * 4); if (!sws_opt) { return -1; } sws = std::move(*sws_opt); - linear_interpolation = width != frame->width || height != frame->height; + linear_interpolation = width != new_frame->width || height != new_frame->height; return 0; } @@ -306,12 +306,12 @@ namespace cuda { /** * @brief Attach frame resources used by the next conversion or encode operation. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx FFmpeg hardware frames context associated with the frame. * @return Status from updating frame. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override { - if (cuda_t::set_frame(frame, hw_frames_ctx)) { + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) override { + if (cuda_t::set_frame(new_frame, hw_frames_ctx)) { return -1; } @@ -412,11 +412,11 @@ namespace cuda { * @brief Initialize the GL->CUDA encoding device. * @param in_width Width of captured frames. * @param in_height Height of captured frames. - * @param offset_x Offset of content in captured frame. - * @param offset_y Offset of content in captured frame. + * @param in_offset_x Offset of content in captured frame. + * @param in_offset_y Offset of content in captured frame. * @return 0 on success or -1 on failure. */ - int init(int in_width, int in_height, int offset_x, int offset_y) { + int init(int in_width, int in_height, int in_offset_x, int in_offset_y) { // This must be non-zero to tell the video core that it's a hardware encoding device. data = (void *) 0x1; @@ -451,21 +451,21 @@ namespace cuda { sequence = 0; - this->offset_x = offset_x; - this->offset_y = offset_y; + this->offset_x = in_offset_x; + this->offset_y = in_offset_y; return 0; } /** * @brief Initialize color conversion into target CUDA frame. - * @param frame Destination CUDA frame to write into. + * @param new_frame Destination CUDA frame to write into. * @param hw_frames_ctx_buf FFmpeg hardware frame context. * @return 0 on success or -1 on failure. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx_buf) override { - this->hwframe.reset(frame); - this->frame = frame; + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx_buf) override { + this->hwframe.reset(new_frame); + this->frame = new_frame; auto hw_frames_ctx = (AVHWFramesContext *) hw_frames_ctx_buf->data; @@ -474,8 +474,8 @@ namespace cuda { return -1; } - if (!frame->buf[0]) { - if (av_hwframe_get_buffer(hw_frames_ctx_buf, frame, 0)) { + if (!new_frame->buf[0]) { + if (av_hwframe_get_buffer(hw_frames_ctx_buf, new_frame, 0)) { BOOST_LOG(error) << "Couldn't get hwframe for NVENC_GL"sv; return -1; } @@ -484,7 +484,7 @@ namespace cuda { sw_format = hw_frames_ctx->sw_format; is_yuv444 = (sw_format == AV_PIX_FMT_YUV444P || sw_format == AV_PIX_FMT_YUV444P16LE); - auto sws_opt = egl::sws_t::make(width, height, frame->width, frame->height, sw_format, is_yuv444); + auto sws_opt = egl::sws_t::make(width, height, new_frame->width, new_frame->height, sw_format, is_yuv444); if (!sws_opt) { return -1; } @@ -492,13 +492,13 @@ namespace cuda { this->sws = std::move(*sws_opt); if (is_yuv444) { - auto yuv444_opt = egl::create_yuv444_target(frame->width, frame->height, sw_format); + auto yuv444_opt = egl::create_yuv444_target(new_frame->width, new_frame->height, sw_format); if (!yuv444_opt) { return -1; } this->yuv444 = std::move(*yuv444_opt); } else { - auto nv12_opt = egl::create_nv12_target(frame->width, frame->height, sw_format); + auto nv12_opt = egl::create_nv12_target(new_frame->width, new_frame->height, sw_format); if (!nv12_opt) { return -1; } @@ -701,7 +701,7 @@ namespace cuda { return b ? NVFBC_TRUE : NVFBC_FALSE; } - static void *handle {nullptr}; + static void *library_handle {nullptr}; ///< Loaded NvFBC library retained while its function table is in use. /** * @brief Load NvFBC and create the CUDA capture helper. @@ -715,9 +715,9 @@ namespace cuda { return 0; } - if (!handle) { - handle = dyn::handle({"libnvidia-fbc.so.1", "libnvidia-fbc.so"}); - if (!handle) { + if (!library_handle) { + library_handle = dyn::handle({"libnvidia-fbc.so.1", "libnvidia-fbc.so"}); + if (!library_handle) { return -1; } } @@ -726,9 +726,9 @@ namespace cuda { {(dyn::apiproc *) &createInstance, "NvFBCCreateInstance"}, }; - if (dyn::load(handle, funcs)) { - dlclose(handle); - handle = nullptr; + if (dyn::load(library_handle, funcs)) { + dlclose(library_handle); + library_handle = nullptr; return -1; } @@ -737,8 +737,8 @@ namespace cuda { if (status) { BOOST_LOG(error) << "Unable to create NvFBC instance"sv; - dlclose(handle); - handle = nullptr; + dlclose(library_handle); + library_handle = nullptr; return -1; } @@ -754,16 +754,16 @@ namespace cuda { /** * @brief Create an NvFBC session context for a native capture handle. * - * @param handle Native library or object handle used by the operation. + * @param session_handle Native library or object handle used by the operation. */ - ctx_t(NVFBC_SESSION_HANDLE handle) { + ctx_t(NVFBC_SESSION_HANDLE session_handle) { NVFBC_BIND_CONTEXT_PARAMS params {NVFBC_BIND_CONTEXT_PARAMS_VER}; - if (func.nvFBCBindContext(handle, ¶ms)) { - BOOST_LOG(error) << "Couldn't bind NvFBC context to current thread: " << func.nvFBCGetLastErrorStr(handle); + if (func.nvFBCBindContext(session_handle, ¶ms)) { + BOOST_LOG(error) << "Couldn't bind NvFBC context to current thread: " << func.nvFBCGetLastErrorStr(session_handle); } - this->handle = handle; + this->handle = session_handle; } ~ctx_t() { @@ -1049,7 +1049,7 @@ namespace cuda { auto status = snapshot(pull_free_image_cb, img_out, 150ms, *cursor); switch (status) { case platf::capture_e::reinit: - case platf::capture_e::error: + case platf::capture_e::capture_error: case platf::capture_e::interrupted: return status; case platf::capture_e::timeout: @@ -1080,7 +1080,7 @@ namespace cuda { */ platf::capture_e reinit(bool cursor) { if (handle.stop()) { - return platf::capture_e::error; + return platf::capture_e::capture_error; } cursor_visible = cursor; @@ -1095,19 +1095,19 @@ namespace cuda { } if (handle.capture(capture_params)) { - return platf::capture_e::error; + return platf::capture_e::capture_error; } // If trying to capture directly, test if it actually does. if (capture_params.bAllowDirectCapture) { CUdeviceptr device_ptr; - NVFBC_FRAME_GRAB_INFO info; + NVFBC_FRAME_GRAB_INFO grab_info; NVFBC_TOCUDA_GRAB_FRAME_PARAMS grab { NVFBC_TOCUDA_GRAB_FRAME_PARAMS_VER, NVFBC_TOCUDA_GRAB_FLAGS_NOWAIT, &device_ptr, - &info, + &grab_info, 0, }; @@ -1120,17 +1120,17 @@ namespace cuda { BOOST_LOG(error) << "Couldn't capture nvFramebuffer: "sv << handle.last_error(); - return platf::capture_e::error; + return platf::capture_e::capture_error; } - if (info.bDirectCapture) { + if (grab_info.bDirectCapture) { break; } BOOST_LOG(debug) << "Direct capture failed attempt ["sv << x << ']'; } - if (!info.bDirectCapture) { + if (!grab_info.bDirectCapture) { BOOST_LOG(debug) << "Direct capture failed, trying the extra copy method"sv; // Direct capture failed capture_params.bPushModel = nv_bool(false); @@ -1138,7 +1138,7 @@ namespace cuda { capture_params.bAllowDirectCapture = nv_bool(false); if (handle.stop() || handle.capture(capture_params)) { - return platf::capture_e::error; + return platf::capture_e::capture_error; } } } @@ -1164,13 +1164,13 @@ namespace cuda { } CUdeviceptr device_ptr; - NVFBC_FRAME_GRAB_INFO info; + NVFBC_FRAME_GRAB_INFO grab_info; NVFBC_TOCUDA_GRAB_FRAME_PARAMS grab { NVFBC_TOCUDA_GRAB_FRAME_PARAMS_VER, NVFBC_TOCUDA_GRAB_FLAGS_NOWAIT, &device_ptr, - &info, + &grab_info, (std::uint32_t) timeout.count(), }; @@ -1180,7 +1180,7 @@ namespace cuda { } BOOST_LOG(error) << "Couldn't capture nvFramebuffer: "sv << handle.last_error(); - return platf::capture_e::error; + return platf::capture_e::capture_error; } if (!pull_free_image_cb(img_out)) { @@ -1189,7 +1189,7 @@ namespace cuda { auto img = (img_t *) img_out.get(); if (img->tex.copy((std::uint8_t *) device_ptr, img->height, img->row_pitch)) { - return platf::capture_e::error; + return platf::capture_e::capture_error; } return platf::capture_e::ok; diff --git a/src/platform/linux/graphics.h b/src/platform/linux/graphics.h index 16afd8364..2e8c28b1e 100644 --- a/src/platform/linux/graphics.h +++ b/src/platform/linux/graphics.h @@ -616,11 +616,11 @@ namespace egl { * @brief Reset the object to its initial empty state. */ void reset() { - for (auto x = 0; x < 4; ++x) { - if (sd.fds[x] >= 0) { - close(sd.fds[x]); + for (auto fd_index = 0; fd_index < 4; ++fd_index) { + if (sd.fds[fd_index] >= 0) { + close(sd.fds[fd_index]); - sd.fds[x] = -1; + sd.fds[fd_index] = -1; } } } diff --git a/src/platform/linux/kmsgrab.cpp b/src/platform/linux/kmsgrab.cpp index 29168579a..7c89f31ab 100644 --- a/src/platform/linux/kmsgrab.cpp +++ b/src/platform/linux/kmsgrab.cpp @@ -510,13 +510,13 @@ namespace platf { this->plane.reset(); for (; plane_p != end; ++plane_p) { - plane_t plane = drmModeGetPlane(fd, *plane_p); - if (!plane) { + plane_t next_plane = drmModeGetPlane(fd, *plane_p); + if (!next_plane) { BOOST_LOG(error) << "Couldn't get drm plane ["sv << (end - plane_p) << "]: "sv << strerror(errno); continue; } - this->plane = util::make_shared(plane.release()); + this->plane = util::make_shared(next_plane.release()); break; } } @@ -1265,9 +1265,9 @@ namespace platf { this->env_logical_width = ::platf::kms::env_logical_width; this->env_logical_height = ::platf::kms::env_logical_height; - auto monitor = pos->crtc_to_monitor.find(plane->crtc_id); - if (monitor != std::end(pos->crtc_to_monitor)) { - auto &viewport = monitor->second.viewport; + auto monitor_pos = pos->crtc_to_monitor.find(plane->crtc_id); + if (monitor_pos != std::end(pos->crtc_to_monitor)) { + auto &viewport = monitor_pos->second.viewport; width = viewport.width; height = viewport.height; @@ -1678,7 +1678,7 @@ namespace platf { if (!fb->handles[0]) { BOOST_LOG(error) << "Couldn't get handle for DRM Framebuffer ["sv << plane->fb_id << "]: Probably not permitted"sv; - return capture_e::error; + return capture_e::capture_error; } for (int y = 0; y < 4; ++y) { @@ -1695,7 +1695,7 @@ namespace platf { file[y] = card.handleFD(fb->handles[y]); if (file[y].el < 0) { BOOST_LOG(error) << "Couldn't get primary file descriptor for Framebuffer ["sv << fb->fb_id << "]: "sv << strerror(errno); - return capture_e::error; + return capture_e::capture_error; } sd->fds[y] = file[y].el; @@ -1796,7 +1796,17 @@ namespace platf { return 0; } + /** + * @brief Capture KMS frames until capture stops or the display needs reinitialization. + * + * @param push_captured_image_cb Callback receiving a captured image or a capture timeout. + * @param pull_free_image_cb Callback providing an available image buffer. + * @param cursor Whether the cursor should be included in the captured image. + * @return Final capture status reported to the streaming pipeline. + */ capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); sleep_overshoot_logger.reset(); @@ -1807,18 +1817,18 @@ namespace platf { std::shared_ptr img_out; auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor); switch (status) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: return status; - case platf::capture_e::timeout: + case timeout: if (!push_captured_image_cb(std::move(img_out), false)) { - return platf::capture_e::ok; + return ok; } break; - case platf::capture_e::ok: + case ok: if (!push_captured_image_cb(std::move(img_out), true)) { - return platf::capture_e::ok; + return ok; } break; default: @@ -1827,7 +1837,7 @@ namespace platf { } } - return capture_e::ok; + return ok; } /** @@ -1928,7 +1938,7 @@ namespace platf { auto rgb_opt = egl::import_source(display.get(), sd); if (!rgb_opt) { - return capture_e::error; + return capture_e::capture_error; } auto &rgb = *rgb_opt; @@ -2062,7 +2072,17 @@ namespace platf { return 0; } + /** + * @brief Capture KMS frames until capture stops or the display needs reinitialization. + * + * @param push_captured_image_cb Callback receiving a captured image or a capture timeout. + * @param pull_free_image_cb Callback providing an available image buffer. + * @param cursor Whether the cursor should be included in the captured image. + * @return Final capture status reported to the streaming pipeline. + */ capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); sleep_overshoot_logger.reset(); @@ -2073,18 +2093,18 @@ namespace platf { std::shared_ptr img_out; auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor); switch (status) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: return status; - case platf::capture_e::timeout: + case timeout: if (!push_captured_image_cb(std::move(img_out), false)) { - return platf::capture_e::ok; + return ok; } break; - case platf::capture_e::ok: + case ok: if (!push_captured_image_cb(std::move(img_out), true)) { - return platf::capture_e::ok; + return ok; } break; default: @@ -2093,7 +2113,7 @@ namespace platf { } } - return capture_e::ok; + return ok; } /** diff --git a/src/platform/linux/pipewire.cpp b/src/platform/linux/pipewire.cpp index 6ce9d3e21..3836a002b 100644 --- a/src/platform/linux/pipewire.cpp +++ b/src/platform/linux/pipewire.cpp @@ -1217,12 +1217,22 @@ namespace pipewire { return false; // Return to default stream dead handling. } + /** + * @brief Capture PipeWire frames until capture stops or the stream needs reinitialization. + * + * @param push_captured_image_cb Callback receiving a captured image or a capture timeout. + * @param pull_free_image_cb Callback providing an available image buffer. + * @param cursor Whether the cursor should be included in the captured image. + * @return Final capture status reported to the streaming pipeline. + */ platf::capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); if (pipewire.ensure_stream(mem_type, width, height, target_framerate, dmabuf_infos.data(), n_dmabuf_infos, display_is_nvidia) < 0) { BOOST_LOG(error) << "[pipewire] Failed to ensure pipewire stream. capture() failed with error."; - return platf::capture_e::error; + return capture_error; } sleep_overshoot_logger.reset(); @@ -1238,7 +1248,7 @@ namespace pipewire { } // Re-init the capture if the stream is dead for any other reason BOOST_LOG(warning) << "[pipewire] PipeWire stream disconnected. Forcing session reset."sv; - return platf::capture_e::reinit; + return reinit; } // Use unpaced event driven capture when possible @@ -1248,27 +1258,27 @@ namespace pipewire { std::shared_ptr img_out; switch (const auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor)) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: pipewire.frame_cv().notify_all(); return status; - case platf::capture_e::timeout: + case timeout: if (!pull_free_image_cb(img_out)) { // Detect if shutdown is pending BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> shutdown pending -> interrupt nudge"; pipewire.frame_cv().notify_all(); - return platf::capture_e::interrupted; + return interrupted; } if (!push_captured_image_cb(std::move(img_out), false)) { BOOST_LOG(debug) << "[pipewire] PipeWire: timeout -> !push_captured_image_cb -> ok"; - return platf::capture_e::ok; + return ok; } break; - case platf::capture_e::ok: + case ok: if (!push_captured_image_cb(std::move(img_out), true)) { BOOST_LOG(debug) << "[pipewire] PipeWire: ok -> !push_captured_image_cb -> ok"; - return platf::capture_e::ok; + return ok; } break; default: @@ -1277,7 +1287,7 @@ namespace pipewire { } } - return platf::capture_e::ok; + return ok; } /** diff --git a/src/platform/linux/portalgrab.cpp b/src/platform/linux/portalgrab.cpp index b530ae6d4..d6ae2a750 100644 --- a/src/platform/linux/portalgrab.cpp +++ b/src/platform/linux/portalgrab.cpp @@ -1063,7 +1063,7 @@ namespace portal { if (dbus.is_session_closed()) { BOOST_LOG(warning) << "[portalgrab] PipeWire stream stopped by closed portal session."sv; pipewire.frame_cv().notify_all(); - out_status = platf::capture_e::error; + out_status = platf::capture_e::capture_error; return true; // Stop capture with error (due to out_status) } // Disable maxframerate negotiation if the stream died without having ever started (e.g. GNOME mutter does not support it) diff --git a/src/platform/linux/vaapi.cpp b/src/platform/linux/vaapi.cpp index c0df4aa8b..6cf70068e 100644 --- a/src/platform/linux/vaapi.cpp +++ b/src/platform/linux/vaapi.cpp @@ -263,17 +263,17 @@ namespace va { /** * @brief Determines the matching VA profile for the codec configuration. - * @param ctx The FFmpeg codec context. + * @param codec_ctx The FFmpeg codec context. * @return The matching VA profile or `VAProfileNone` on failure. */ - VAProfile get_va_profile(AVCodecContext *ctx) { - if (ctx->codec_id == AV_CODEC_ID_H264) { + VAProfile get_va_profile(AVCodecContext *codec_ctx) { + if (codec_ctx->codec_id == AV_CODEC_ID_H264) { // There's no VAAPI profile for H.264 4:4:4 return VAProfileH264High; - } else if (ctx->codec_id == AV_CODEC_ID_HEVC) { - switch (ctx->profile) { + } else if (codec_ctx->codec_id == AV_CODEC_ID_HEVC) { + switch (codec_ctx->profile) { case AV_PROFILE_HEVC_REXT: - switch (av_pix_fmt_desc_get(ctx->sw_pix_fmt)->comp[0].depth) { + switch (av_pix_fmt_desc_get(codec_ctx->sw_pix_fmt)->comp[0].depth) { case 10: return VAProfileHEVCMain444_10; case 8: @@ -285,8 +285,8 @@ namespace va { case AV_PROFILE_HEVC_MAIN: return VAProfileHEVCMain; } - } else if (ctx->codec_id == AV_CODEC_ID_AV1) { - switch (ctx->profile) { + } else if (codec_ctx->codec_id == AV_CODEC_ID_AV1) { + switch (codec_ctx->profile) { case AV_PROFILE_AV1_HIGH: return VAProfileAV1Profile1; case AV_PROFILE_AV1_MAIN: @@ -294,18 +294,18 @@ namespace va { } } - BOOST_LOG(error) << "Unknown encoder profile: "sv << ctx->profile; + BOOST_LOG(error) << "Unknown encoder profile: "sv << codec_ctx->profile; return VAProfileNone; } /** * @brief Initialize codec options. * - * @param ctx Native context object used by the operation or callback. + * @param codec_ctx Native context object used by the operation or callback. * @param options Request options or socket options to apply. */ - void init_codec_options(AVCodecContext *ctx, AVDictionary **options) override { - auto va_profile = get_va_profile(ctx); + void init_codec_options(AVCodecContext *codec_ctx, AVDictionary **options) override { + auto va_profile = get_va_profile(codec_ctx); if (va_profile == VAProfileNone || !is_va_profile_supported(va_profile)) { // Don't bother doing anything if the profile isn't supported return; @@ -351,8 +351,8 @@ namespace va { break; } if (target_quality > 0) { - ctx->compression_level = target_quality; - BOOST_LOG(info) << "[VAAPI] Quality level set to "sv << ctx->compression_level << " (fastest level: "sv << quality_attr.value << ")"sv; + codec_ctx->compression_level = target_quality; + BOOST_LOG(info) << "[VAAPI] Quality level set to "sv << codec_ctx->compression_level << " (fastest level: "sv << quality_attr.value << ")"sv; } VAConfigAttrib rc_attr = {.type = VAConfigAttribRateControl}; @@ -368,9 +368,9 @@ namespace va { // Assume only a single slice is supported slice_attr.value = 1; } - if (ctx->slices > slice_attr.value) { + if (codec_ctx->slices > slice_attr.value) { BOOST_LOG(info) << "Limiting slice count to encoder maximum: "sv << slice_attr.value; - ctx->slices = slice_attr.value; + codec_ctx->slices = slice_attr.value; } // Use VBR with a single frame VBV when the user forces it and for known good cases: @@ -394,7 +394,7 @@ namespace va { auto rc_val = config::video.vaapi.vaapi_rc.value_or(0); // Detect whitelisted configurations - if ((vendor && std::string_view(vendor).contains("Intel") == true) || ctx->codec_id == AV_CODEC_ID_AV1) { + if ((vendor && std::string_view(vendor).contains("Intel") == true) || codec_ctx->codec_id == AV_CODEC_ID_AV1) { auto_whitelist = true; rc_whitelist = " (whitelist override)"; } @@ -416,7 +416,7 @@ namespace va { } if (config::video.vaapi.strict_rc_buffer || auto_whitelist) { - ctx->rc_buffer_size = ctx->bit_rate * ctx->framerate.den / ctx->framerate.num; + codec_ctx->rc_buffer_size = codec_ctx->bit_rate * codec_ctx->framerate.den / codec_ctx->framerate.num; rc_vbv = "with single frame VBV size"; } @@ -435,23 +435,23 @@ namespace va { /** * @brief Attach frame resources used by the next conversion or encode operation. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx_buf Hardware frames context buffer. * @return Status from updating frame. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx_buf) override { - this->hwframe.reset(frame); - this->frame = frame; + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx_buf) override { + this->hwframe.reset(new_frame); + this->frame = new_frame; - if (!frame->buf[0]) { - if (av_hwframe_get_buffer(hw_frames_ctx_buf, frame, 0)) { + if (!new_frame->buf[0]) { + if (av_hwframe_get_buffer(hw_frames_ctx_buf, new_frame, 0)) { BOOST_LOG(error) << "Couldn't get hwframe for VAAPI"sv; return -1; } } va::DRMPRIMESurfaceDescriptor prime; - va::VASurfaceID surface = (std::uintptr_t) frame->data[3]; + va::VASurfaceID surface = (std::uintptr_t) new_frame->data[3]; auto hw_frames_ctx = (AVHWFramesContext *) hw_frames_ctx_buf->data; auto status = vaExportSurfaceHandle( @@ -505,7 +505,7 @@ namespace va { return -1; } - auto sws_opt = egl::sws_t::make(width, height, frame->width, frame->height, hw_frames_ctx->sw_format, false); + auto sws_opt = egl::sws_t::make(width, height, new_frame->width, new_frame->height, hw_frames_ctx->sw_format, false); if (!sws_opt) { return -1; } @@ -603,19 +603,19 @@ namespace va { * @param in_width In width. * @param in_height In height. * @param render_device Render device. - * @param offset_x Offset x. - * @param offset_y Offset y. + * @param in_offset_x Offset x. + * @param in_offset_y Offset y. * @return 0 on success; nonzero or negative platform status on failure. */ - int init(int in_width, int in_height, file_t &&render_device, int offset_x, int offset_y) { + int init(int in_width, int in_height, file_t &&render_device, int in_offset_x, int in_offset_y) { if (va_t::init(in_width, in_height, std::move(render_device))) { return -1; } sequence = 0; - this->offset_x = offset_x; - this->offset_y = offset_y; + this->offset_x = in_offset_x; + this->offset_y = in_offset_y; return 0; } diff --git a/src/platform/linux/wlgrab.cpp b/src/platform/linux/wlgrab.cpp index c5cd887c7..e2ad5c430 100644 --- a/src/platform/linux/wlgrab.cpp +++ b/src/platform/linux/wlgrab.cpp @@ -223,7 +223,7 @@ namespace wl { * @brief Populate a fallback image when real capture data is unavailable. * * @param img Image or frame object to read from or populate. - * @return Capture status reported to the streaming pipeline. + * @return Final capture status when callbacks stop capture or the display needs reinitialization. */ int dummy_img(platf::img_t *img) override { return 0; @@ -319,6 +319,8 @@ namespace wl { * @return Capture status reported to the streaming pipeline. */ platf::capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); sleep_overshoot_logger.reset(); @@ -329,14 +331,14 @@ namespace wl { std::shared_ptr img_out; auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor); switch (status) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: return status; - case platf::capture_e::timeout: - case platf::capture_e::ok: - if (!push_captured_image_cb(std::move(img_out), status == platf::capture_e::ok)) { - return platf::capture_e::ok; + case timeout: + case ok: + if (!push_captured_image_cb(std::move(img_out), status == ok)) { + return ok; } break; default: @@ -345,7 +347,7 @@ namespace wl { } } - return platf::capture_e::ok; + return ok; } /** diff --git a/src/platform/linux/x11grab.cpp b/src/platform/linux/x11grab.cpp index c9c98f571..f29384781 100644 --- a/src/platform/linux/x11grab.cpp +++ b/src/platform/linux/x11grab.cpp @@ -559,7 +559,17 @@ namespace platf { x11::GetWindowAttributes(xdisplay.get(), xwindow, &xattr); // Update xattr's } + /** + * @brief Capture X11 frames until capture stops or the display needs reinitialization. + * + * @param push_captured_image_cb Callback receiving a captured image or a capture timeout. + * @param pull_free_image_cb Callback providing an available image buffer. + * @param cursor Whether the cursor should be included in the captured image. + * @return Final capture status reported to the streaming pipeline. + */ capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); sleep_overshoot_logger.reset(); @@ -570,18 +580,18 @@ namespace platf { std::shared_ptr img_out; auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor); switch (status) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: return status; - case platf::capture_e::timeout: + case timeout: if (!push_captured_image_cb(std::move(img_out), false)) { - return platf::capture_e::ok; + return ok; } break; - case platf::capture_e::ok: + case ok: if (!push_captured_image_cb(std::move(img_out), true)) { - return platf::capture_e::ok; + return ok; } break; default: @@ -590,7 +600,7 @@ namespace platf { } } - return capture_e::ok; + return ok; } /** @@ -724,7 +734,17 @@ namespace platf { while (!task_pool.cancel(refresh_task_id)); } + /** + * @brief Capture X11 shared-memory frames until capture stops or reinitialization is needed. + * + * @param push_captured_image_cb Callback receiving a captured image or a capture timeout. + * @param pull_free_image_cb Callback providing an available image buffer. + * @param cursor Whether the cursor should be included in the captured image. + * @return Final capture status reported to the streaming pipeline. + */ capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override { + using enum platf::capture_e; + auto next_frame = std::chrono::steady_clock::now(); sleep_overshoot_logger.reset(); @@ -735,18 +755,18 @@ namespace platf { std::shared_ptr img_out; auto status = snapshot(pull_free_image_cb, img_out, 1000ms, *cursor); switch (status) { - case platf::capture_e::reinit: - case platf::capture_e::error: - case platf::capture_e::interrupted: + case reinit: + case capture_error: + case interrupted: return status; - case platf::capture_e::timeout: + case timeout: if (!push_captured_image_cb(std::move(img_out), false)) { - return platf::capture_e::ok; + return ok; } break; - case platf::capture_e::ok: + case ok: if (!push_captured_image_cb(std::move(img_out), true)) { - return platf::capture_e::ok; + return ok; } break; default: @@ -755,7 +775,7 @@ namespace platf { } } - return capture_e::ok; + return ok; } /** diff --git a/src/platform/macos/nv12_zero_device.cpp b/src/platform/macos/nv12_zero_device.cpp index dc1be63f3..055fa5944 100644 --- a/src/platform/macos/nv12_zero_device.cpp +++ b/src/platform/macos/nv12_zero_device.cpp @@ -54,21 +54,21 @@ namespace platf { return 0; } - int nv12_zero_device::set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) { - this->frame = frame; + int nv12_zero_device::set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) { + this->frame = new_frame; - av_frame.reset(frame); + av_frame.reset(new_frame); - resolution_fn(this->display, frame->width, frame->height); + resolution_fn(this->display, new_frame->width, new_frame->height); return 0; } - int nv12_zero_device::init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn) { - pixel_format_fn(display, pix_fmt == pix_fmt_e::nv12 ? kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange : kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange); + int nv12_zero_device::init(void *capture_display, pix_fmt_e pix_fmt, resolution_fn_t set_resolution, const pixel_format_fn_t &pixel_format_fn) { + pixel_format_fn(capture_display, pix_fmt == pix_fmt_e::nv12 ? kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange : kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange); - this->display = display; - this->resolution_fn = std::move(resolution_fn); + this->display = capture_display; + this->resolution_fn = std::move(set_resolution); // we never use this pointer, but its existence is checked/used // by the platform independent code diff --git a/src/platform/macos/nv12_zero_device.h b/src/platform/macos/nv12_zero_device.h index 7b6d68faa..7857f74d8 100644 --- a/src/platform/macos/nv12_zero_device.h +++ b/src/platform/macos/nv12_zero_device.h @@ -41,13 +41,13 @@ namespace platf { /** * @brief Initialize zero-copy NV12 encoding for an AVFoundation display. * - * @param display Display object or identifier associated with the operation. + * @param capture_display Display object or identifier associated with the operation. * @param pix_fmt Sunshine pixel format to convert or allocate for. - * @param resolution_fn Callback used to resize the AVFoundation capture output. + * @param set_resolution Callback used to resize the AVFoundation capture output. * @param pixel_format_fn Pixel format. * @return 0 on success; nonzero or negative platform status on failure. */ - int init(void *display, pix_fmt_e pix_fmt, resolution_fn_t resolution_fn, const pixel_format_fn_t &pixel_format_fn); + int init(void *capture_display, pix_fmt_e pix_fmt, resolution_fn_t set_resolution, const pixel_format_fn_t &pixel_format_fn); /** * @brief Forward a captured AVFoundation frame to FFmpeg without copying. @@ -59,11 +59,11 @@ namespace platf { /** * @brief Attach frame resources used by the next conversion or encode operation. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx FFmpeg hardware frames context associated with the frame. * @return Status from updating frame. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override; + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) override; private: util::safe_ptr av_frame; diff --git a/src/platform/windows/audio.cpp b/src/platform/windows/audio.cpp index d12f983a8..7a3e0c9ac 100644 --- a/src/platform/windows/audio.cpp +++ b/src/platform/windows/audio.cpp @@ -780,7 +780,7 @@ namespace platf::audio { return capture_e::timeout; default: BOOST_LOG(error) << "Couldn't wait for audio event: [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } std::uint32_t packet_size {}; @@ -804,7 +804,7 @@ namespace platf::audio { return capture_e::reinit; default: BOOST_LOG(error) << "Couldn't capture audio [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } if (buffer_flags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY) { @@ -834,7 +834,7 @@ namespace platf::audio { } if (FAILED(status)) { - return capture_e::error; + return capture_e::capture_error; } return capture_e::ok; diff --git a/src/platform/windows/display.h b/src/platform/windows/display.h index 55675b5f5..26f9f2ecb 100644 --- a/src/platform/windows/display.h +++ b/src/platform/windows/display.h @@ -235,34 +235,34 @@ namespace platf::dxgi { /** * @brief Update the cursor position and display geometry used for rendering. * - * @param topleft_x Cursor left edge in desktop coordinates. - * @param topleft_y Cursor top edge in desktop coordinates. - * @param display_width Captured display width in pixels. - * @param display_height Captured display height in pixels. - * @param display_rotation DXGI rotation applied to the captured display. - * @param visible Whether the cursor should be visible in the frame. + * @param new_topleft_x Cursor left edge in desktop coordinates. + * @param new_topleft_y Cursor top edge in desktop coordinates. + * @param new_display_width Captured display width in pixels. + * @param new_display_height Captured display height in pixels. + * @param new_display_rotation DXGI rotation applied to the captured display. + * @param new_visible Whether the cursor should be visible in the frame. */ - void set_pos(LONG topleft_x, LONG topleft_y, LONG display_width, LONG display_height, DXGI_MODE_ROTATION display_rotation, bool visible) { - this->topleft_x = topleft_x; - this->topleft_y = topleft_y; - this->display_width = display_width; - this->display_height = display_height; - this->display_rotation = display_rotation; - this->visible = visible; + void set_pos(LONG new_topleft_x, LONG new_topleft_y, LONG new_display_width, LONG new_display_height, DXGI_MODE_ROTATION new_display_rotation, bool new_visible) { + this->topleft_x = new_topleft_x; + this->topleft_y = new_topleft_y; + this->display_width = new_display_width; + this->display_height = new_display_height; + this->display_rotation = new_display_rotation; + this->visible = new_visible; update_viewport(); } /** * @brief Replace the cursor texture and update its render viewport. * - * @param texture_width Cursor texture width in pixels. - * @param texture_height Cursor texture height in pixels. - * @param texture D3D11 cursor texture to render. + * @param new_texture_width Cursor texture width in pixels. + * @param new_texture_height Cursor texture height in pixels. + * @param new_texture D3D11 cursor texture to render. */ - void set_texture(LONG texture_width, LONG texture_height, texture2d_t &&texture) { - this->texture = std::move(texture); - this->texture_width = texture_width; - this->texture_height = texture_height; + void set_texture(LONG new_texture_width, LONG new_texture_height, texture2d_t &&new_texture) { + this->texture = std::move(new_texture); + this->texture_width = new_texture_width; + this->texture_height = new_texture_height; update_viewport(); } diff --git a/src/platform/windows/display_base.cpp b/src/platform/windows/display_base.cpp index bef3b3ff0..733112cc7 100644 --- a/src/platform/windows/display_base.cpp +++ b/src/platform/windows/display_base.cpp @@ -174,7 +174,7 @@ namespace platf::dxgi { return capture_e::reinit; default: BOOST_LOG(error) << "Couldn't acquire next frame [0x"sv << util::hex(status).to_string_view(); - return capture_e::error; + return capture_e::capture_error; } } @@ -186,27 +186,34 @@ namespace platf::dxgi { return capture_status; } + /** + * @brief Release the acquired desktop duplication frame and classify the DXGI result. + * + * @return Success, a required display reinitialization, or a capture error. + */ capture_e duplication_t::release_frame() { + using enum platf::capture_e; + if (!has_frame) { - return capture_e::ok; + return ok; } auto status = dup->ReleaseFrame(); has_frame = false; switch (status) { case S_OK: - return capture_e::ok; + return ok; case DXGI_ERROR_INVALID_CALL: BOOST_LOG(warning) << "Duplication frame already released"; - return capture_e::ok; + return ok; case DXGI_ERROR_ACCESS_LOST: - return capture_e::reinit; + return reinit; default: BOOST_LOG(error) << "Error while releasing duplication frame [0x"sv << util::hex(status).to_string_view(); - return capture_e::error; + return capture_error; } } @@ -332,7 +339,7 @@ namespace platf::dxgi { switch (status) { case platf::capture_e::reinit: - case platf::capture_e::error: + case platf::capture_e::capture_error: case platf::capture_e::interrupted: return status; case platf::capture_e::timeout: @@ -639,7 +646,7 @@ namespace platf::dxgi { HMODULE gdi32 = GetModuleHandleA("GDI32"); if (gdi32) { - auto check_hags = [&](const LUID &adapter) -> bool { + auto check_hags = [&](const LUID &adapter_luid) -> bool { auto d3dkmt_open_adapter = (PD3DKMTOpenAdapterFromLuid) GetProcAddress(gdi32, "D3DKMTOpenAdapterFromLuid"); auto d3dkmt_query_adapter_info = (PD3DKMTQueryAdapterInfo) GetProcAddress(gdi32, "D3DKMTQueryAdapterInfo"); auto d3dkmt_close_adapter = (PD3DKMTCloseAdapter) GetProcAddress(gdi32, "D3DKMTCloseAdapter"); @@ -648,7 +655,7 @@ namespace platf::dxgi { return false; } - D3DKMT_OPENADAPTERFROMLUID d3dkmt_adapter = {.AdapterLuid = adapter}; + D3DKMT_OPENADAPTERFROMLUID d3dkmt_adapter = {.AdapterLuid = adapter_luid}; if (FAILED(d3dkmt_open_adapter(&d3dkmt_adapter))) { BOOST_LOG(error) << "D3DKMTOpenAdapterFromLuid() failed while trying to determine GPU HAGS status"; return false; diff --git a/src/platform/windows/display_ram.cpp b/src/platform/windows/display_ram.cpp index 9a4553bff..947346806 100644 --- a/src/platform/windows/display_ram.cpp +++ b/src/platform/windows/display_ram.cpp @@ -241,7 +241,7 @@ namespace platf::dxgi { if (FAILED(status)) { BOOST_LOG(error) << "Failed to get new pointer shape [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } } @@ -258,7 +258,7 @@ namespace platf::dxgi { if (FAILED(status)) { BOOST_LOG(error) << "Couldn't query interface [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } D3D11_TEXTURE2D_DESC desc; @@ -279,11 +279,11 @@ namespace platf::dxgi { t.Format = capture_format; t.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - auto status = device->CreateTexture2D(&t, nullptr, &texture); + auto texture_status = device->CreateTexture2D(&t, nullptr, &texture); - if (FAILED(status)) { - BOOST_LOG(error) << "Failed to create staging texture [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + if (FAILED(texture_status)) { + BOOST_LOG(error) << "Failed to create staging texture [0x"sv << util::hex(texture_status).to_string_view() << ']'; + return capture_e::capture_error; } } @@ -316,7 +316,7 @@ namespace platf::dxgi { BOOST_LOG(debug) << "Capture format is still unknown. Encoding a blank image"sv; if (dummy_img(img)) { - return capture_e::error; + return capture_e::capture_error; } } else { // Map the staging texture for CPU access (making it inaccessible for the GPU) @@ -324,14 +324,14 @@ namespace platf::dxgi { if (FAILED(status)) { BOOST_LOG(error) << "Failed to map texture [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } // Now that we know the capture format, we can finish creating the image if (complete_img(img, false)) { device_ctx->Unmap(texture.get(), 0); img_info.pData = nullptr; - return capture_e::error; + return capture_e::capture_error; } std::copy_n((std::uint8_t *) img_info.pData, height * img_info.RowPitch, (std::uint8_t *) img->data); diff --git a/src/platform/windows/display_vram.cpp b/src/platform/windows/display_vram.cpp index d4b7141e2..4ce41ca14 100644 --- a/src/platform/windows/display_vram.cpp +++ b/src/platform/windows/display_vram.cpp @@ -788,9 +788,9 @@ namespace platf::dxgi { rtv_desc.Format = rt_format; rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - auto status = device->CreateRenderTargetView(output_texture.get(), &rtv_desc, &rt); - if (FAILED(status)) { - BOOST_LOG(error) << "Failed to create render target view: " << util::log_hex(status); + auto view_status = device->CreateRenderTargetView(output_texture.get(), &rtv_desc, &rt); + if (FAILED(view_status)) { + BOOST_LOG(error) << "Failed to create render target view: " << util::log_hex(view_status); return false; } @@ -827,12 +827,12 @@ namespace platf::dxgi { /** * @brief Initialize shared D3D conversion resources for the encoder. * - * @param display Display object or identifier associated with the operation. + * @param capture_display Display object or identifier associated with the operation. * @param adapter_p Adapter p. * @param pix_fmt Sunshine pixel format to convert or allocate for. * @return 0 on success; nonzero or negative platform status on failure. */ - int init(std::shared_ptr display, adapter_t::pointer adapter_p, pix_fmt_e pix_fmt) { + int init(std::shared_ptr capture_display, adapter_t::pointer adapter_p, pix_fmt_e pix_fmt) { switch (pix_fmt) { using enum pix_fmt_e; case nv12: @@ -914,11 +914,11 @@ namespace platf::dxgi { device_ctx->VSSetConstantBuffers(3, 1, &color_matrix); device_ctx->PSSetConstantBuffers(0, 1, &color_matrix); - this->display = std::dynamic_pointer_cast(display); + this->display = std::dynamic_pointer_cast(capture_display); if (!this->display) { return -1; } - display = nullptr; + capture_display = nullptr; blend_disable = make_blend(device.get(), false, false); if (!blend_disable) { @@ -1186,17 +1186,17 @@ namespace platf::dxgi { /** * @brief Attach frame resources used by the next conversion or encode operation. * - * @param frame Video or graphics frame being processed. + * @param new_frame Video or graphics frame being processed. * @param hw_frames_ctx FFmpeg hardware frames context associated with the frame. * @return Status from updating frame. */ - int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx) override { - this->hwframe.reset(frame); - this->frame = frame; + int set_frame(AVFrame *new_frame, AVBufferRef *hw_frames_ctx) override { + this->hwframe.reset(new_frame); + this->frame = new_frame; // Populate this frame with a hardware buffer if one isn't there already - if (!frame->buf[0]) { - auto err = av_hwframe_get_buffer(hw_frames_ctx, frame, 0); + if (!new_frame->buf[0]) { + auto err = av_hwframe_get_buffer(hw_frames_ctx, new_frame, 0); if (err) { std::array err_str {0}; BOOST_LOG(error) << "Failed to get hwframe buffer: "sv << av_make_error_string(err_str.data(), AV_ERROR_MAX_STRING_SIZE, err); @@ -1206,12 +1206,12 @@ namespace platf::dxgi { // If this is a frame from a derived context, we'll need to map it to D3D11 ID3D11Texture2D *frame_texture; - if (frame->format != AV_PIX_FMT_D3D11) { + if (new_frame->format != AV_PIX_FMT_D3D11) { frame_t d3d11_frame {av_frame_alloc()}; d3d11_frame->format = AV_PIX_FMT_D3D11; - auto err = av_hwframe_map(d3d11_frame.get(), frame, AV_HWFRAME_MAP_WRITE | AV_HWFRAME_MAP_OVERWRITE); + auto err = av_hwframe_map(d3d11_frame.get(), new_frame, AV_HWFRAME_MAP_WRITE | AV_HWFRAME_MAP_OVERWRITE); if (err) { std::array err_str {0}; BOOST_LOG(error) << "Failed to map D3D11 frame: "sv << av_make_error_string(err_str.data(), AV_ERROR_MAX_STRING_SIZE, err); @@ -1222,10 +1222,10 @@ namespace platf::dxgi { frame_texture = (ID3D11Texture2D *) d3d11_frame->data[0]; } else { // Otherwise, we can just use the texture inside the original frame - frame_texture = (ID3D11Texture2D *) frame->data[0]; + frame_texture = (ID3D11Texture2D *) new_frame->data[0]; } - return base.init_output(frame_texture, frame->width, frame->height); + return base.init_output(frame_texture, new_frame->width, new_frame->height); } private: @@ -1275,19 +1275,19 @@ namespace platf::dxgi { * @brief Initialize the platform encoder for the client stream configuration. * * @param client_config Client stream configuration negotiated for this session. - * @param colorspace Colorimetry information used for conversion or encoding. + * @param encoder_colorspace Colorimetry information used for conversion or encoding. * @return True when the NVENC encoder initializes for the client configuration. */ - bool init_encoder(const ::video::config_t &client_config, const ::video::sunshine_colorspace_t &colorspace) override { + bool init_encoder(const ::video::config_t &client_config, const ::video::sunshine_colorspace_t &encoder_colorspace) override { if (!nvenc_d3d) { return false; } - if (!nvenc_d3d->create_encoder(config::video.nv, client_config, colorspace, buffer_format)) { + if (!nvenc_d3d->create_encoder(config::video.nv, client_config, encoder_colorspace, buffer_format)) { return false; } - base.apply_colorspace(colorspace); + base.apply_colorspace(encoder_colorspace); return base.init_output(nvenc_d3d->get_input_texture(), client_config.width, client_config.height) == 0; } @@ -1396,14 +1396,14 @@ namespace platf::dxgi { if (FAILED(status)) { BOOST_LOG(error) << "Failed to get new pointer shape [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } auto alpha_cursor_img = make_cursor_alpha_image(img_data, shape_info); auto xor_cursor_img = make_cursor_xor_image(img_data, shape_info); if (!set_cursor_texture(device.get(), cursor_alpha, std::move(alpha_cursor_img), shape_info) || !set_cursor_texture(device.get(), cursor_xor, std::move(xor_cursor_img), shape_info)) { - return capture_e::error; + return capture_e::capture_error; } } @@ -1421,7 +1421,7 @@ namespace platf::dxgi { status = res->QueryInterface(IID_ID3D11Texture2D, (void **) &src); if (FAILED(status)) { BOOST_LOG(error) << "Couldn't query interface [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } D3D11_TEXTURE2D_DESC desc; @@ -1577,7 +1577,7 @@ namespace platf::dxgi { auto p_surface = std::get_if(&last_frame_variant); if (!p_surface) { BOOST_LOG(error) << "Logical error at " << __FILE__ << ":" << __LINE__; - return capture_e::error; + return capture_e::capture_error; } std::shared_ptr img; @@ -1587,7 +1587,7 @@ namespace platf::dxgi { auto [d3d_img, lock] = get_locked_d3d_img(img); if (!d3d_img) { - return capture_e::error; + return capture_e::capture_error; } device_ctx->CopyResource(d3d_img->capture_texture.get(), p_surface->get()); @@ -1605,18 +1605,18 @@ namespace platf::dxgi { auto p_img = std::get_if>(&last_frame_variant); if (!p_img) { BOOST_LOG(error) << "Logical error at " << __FILE__ << ":" << __LINE__; - return capture_e::error; + return capture_e::capture_error; } auto [d3d_img, lock] = get_locked_d3d_img(*p_img); if (!d3d_img) { - return capture_e::error; + return capture_e::capture_error; } p_img = nullptr; last_frame_variant = texture2d_t {}; auto &surface = std::get(last_frame_variant); if (!create_surface(surface)) { - return capture_e::error; + return capture_e::capture_error; } device_ctx->CopyResource(surface.get(), d3d_img->capture_texture.get()); @@ -1634,7 +1634,7 @@ namespace platf::dxgi { auto [d3d_img, lock] = get_locked_d3d_img(img); if (!d3d_img) { - return capture_e::error; + return capture_e::capture_error; } device_ctx->CopyResource(d3d_img->capture_texture.get(), src.get()); @@ -1649,7 +1649,7 @@ namespace platf::dxgi { last_frame_variant = texture2d_t {}; p_surface = std::get_if(&last_frame_variant); if (!create_surface(*p_surface)) { - return capture_e::error; + return capture_e::capture_error; } } device_ctx->CopyResource(p_surface->get(), src.get()); @@ -1695,7 +1695,7 @@ namespace platf::dxgi { auto p_img = std::get_if>(&last_frame_variant); if (!p_img) { BOOST_LOG(error) << "Logical error at " << __FILE__ << ":" << __LINE__; - return capture_e::error; + return capture_e::capture_error; } img_out = *p_img; break; @@ -1706,11 +1706,11 @@ namespace platf::dxgi { auto p_surface = std::get_if(&last_frame_variant); if (!p_surface) { BOOST_LOG(error) << "Logical error at " << __FILE__ << ":" << __LINE__; - return capture_e::error; + return capture_e::capture_error; } if (!blend_mouse_cursor_flag) { BOOST_LOG(error) << "Logical error at " << __FILE__ << ":" << __LINE__; - return capture_e::error; + return capture_e::capture_error; } if (!pull_free_image_cb(img_out)) { @@ -1719,7 +1719,7 @@ namespace platf::dxgi { auto [d3d_img, lock] = get_locked_d3d_img(img_out); if (!d3d_img) { - return capture_e::error; + return capture_e::capture_error; } device_ctx->CopyResource(d3d_img->capture_texture.get(), p_surface->get()); @@ -1740,7 +1740,7 @@ namespace platf::dxgi { auto [d3d_img, lock] = get_locked_d3d_img(img_out, true); if (!d3d_img) { - return capture_e::error; + return capture_e::capture_error; } if (reclear_dummy) { @@ -1894,10 +1894,10 @@ namespace platf::dxgi { device_ctx->CopyResource(d3d_img->capture_texture.get(), src.get()); } else { BOOST_LOG(error) << "Failed to lock capture texture"; - return capture_e::error; + return capture_e::capture_error; } } else { - return capture_e::error; + return capture_e::capture_error; } img_out = img; if (img_out) { @@ -2134,19 +2134,19 @@ namespace platf::dxgi { } std::unique_ptr display_vram_t::make_avcodec_encode_device(pix_fmt_e pix_fmt) { - auto device = std::make_unique(); - if (device->init(shared_from_this(), adapter.get(), pix_fmt) != 0) { + auto encode_device = std::make_unique(); + if (encode_device->init(shared_from_this(), adapter.get(), pix_fmt) != 0) { return nullptr; } - return device; + return encode_device; } std::unique_ptr display_vram_t::make_nvenc_encode_device(pix_fmt_e pix_fmt) { - auto device = std::make_unique(); - if (!device->init_device(shared_from_this(), adapter.get(), pix_fmt)) { + auto encode_device = std::make_unique(); + if (!encode_device->init_device(shared_from_this(), adapter.get(), pix_fmt)) { return nullptr; } - return device; + return encode_device; } /** diff --git a/src/platform/windows/display_wgc.cpp b/src/platform/windows/display_wgc.cpp index b85dbd232..e2d850932 100644 --- a/src/platform/windows/display_wgc.cpp +++ b/src/platform/windows/display_wgc.cpp @@ -212,7 +212,7 @@ namespace platf::dxgi { if (GetLastError() == ERROR_TIMEOUT) { return capture_e::timeout; } else { - return capture_e::error; + return capture_e::capture_error; } } if (produced_frame) { @@ -226,7 +226,7 @@ namespace platf::dxgi { auto capture_access = consumed_frame.Surface().as(); if (capture_access == nullptr) { - return capture_e::error; + return capture_e::capture_error; } capture_access->GetInterface(IID_ID3D11Texture2D, (void **) out); out_time = consumed_frame.SystemRelativeTime().count(); // raw ticks from query performance counter @@ -293,11 +293,11 @@ namespace platf::dxgi { t.Format = capture_format; t.CPUAccessFlags = D3D11_CPU_ACCESS_READ; - auto status = device->CreateTexture2D(&t, nullptr, &texture); + auto texture_status = device->CreateTexture2D(&t, nullptr, &texture); - if (FAILED(status)) { - BOOST_LOG(error) << "Failed to create staging texture [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + if (FAILED(texture_status)) { + BOOST_LOG(error) << "Failed to create staging texture [0x"sv << util::hex(texture_status).to_string_view() << ']'; + return capture_e::capture_error; } } @@ -326,14 +326,14 @@ namespace platf::dxgi { if (FAILED(status = device_ctx->Map(texture.get(), 0, D3D11_MAP_READ, 0, &img_info))) { BOOST_LOG(error) << "Failed to map texture [0x"sv << util::hex(status).to_string_view() << ']'; - return capture_e::error; + return capture_e::capture_error; } // Now that we know the capture format, we can finish creating the image if (complete_img(img, false)) { device_ctx->Unmap(texture.get(), 0); img_info.pData = nullptr; - return capture_e::error; + return capture_e::capture_error; } std::copy_n((std::uint8_t *) img_info.pData, height * img_info.RowPitch, (std::uint8_t *) img->data); diff --git a/src/platform/windows/input.cpp b/src/platform/windows/input.cpp index 08f10e690..96387d25c 100644 --- a/src/platform/windows/input.cpp +++ b/src/platform/windows/input.cpp @@ -255,13 +255,13 @@ namespace platf { int init() { // Probe ViGEm during startup to see if we can successfully attach gamepads. This will allow us to // immediately display the error message in the web UI even before the user tries to stream. - client_t client {vigem_alloc()}; - VIGEM_ERROR status = vigem_connect(client.get()); + client_t probe_client {vigem_alloc()}; + VIGEM_ERROR status = vigem_connect(probe_client.get()); if (!VIGEM_SUCCESS(status)) { BOOST_LOG(warning) << "ViGEmBus is not installed or running, so its limited Xbox 360 and DualShock 4 gamepad support is unavailable"sv; return -1; } else { - vigem_disconnect(client.get()); + vigem_disconnect(probe_client.get()); } gamepads.resize(MAX_GAMEPADS); @@ -392,8 +392,8 @@ namespace platf { // Disconnect from ViGEm if we just removed the last gamepad bool disconnect = true; - for (auto &gamepad : gamepads) { - if (gamepad.gp && vigem_target_is_attached(gamepad.gp.get())) { + for (auto &attached_gamepad : gamepads) { + if (attached_gamepad.gp && vigem_target_is_attached(attached_gamepad.gp.get())) { disconnect = false; break; } diff --git a/src/platform/windows/misc.cpp b/src/platform/windows/misc.cpp index c619138d4..b31b13bd5 100644 --- a/src/platform/windows/misc.cpp +++ b/src/platform/windows/misc.cpp @@ -206,19 +206,19 @@ namespace platf { * @return Adapter-address list populated by GetAdaptersAddresses. */ adapteraddrs_t get_adapteraddrs() { - adapteraddrs_t info {nullptr}; + adapteraddrs_t adapter_addresses {nullptr}; ULONG size = 0; - while (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, info.get(), &size) == ERROR_BUFFER_OVERFLOW) { - info.reset((PIP_ADAPTER_ADDRESSES) malloc(size)); + while (GetAdaptersAddresses(AF_UNSPEC, 0, nullptr, adapter_addresses.get(), &size) == ERROR_BUFFER_OVERFLOW) { + adapter_addresses.reset((PIP_ADAPTER_ADDRESSES) malloc(size)); } - return info; + return adapter_addresses; } std::string get_mac_address(const std::string_view &address) { - adapteraddrs_t info = get_adapteraddrs(); - for (auto adapter_pos = info.get(); adapter_pos != nullptr; adapter_pos = adapter_pos->Next) { + adapteraddrs_t adapter_addresses = get_adapteraddrs(); + for (auto adapter_pos = adapter_addresses.get(); adapter_pos != nullptr; adapter_pos = adapter_pos->Next) { for (auto addr_pos = adapter_pos->FirstUnicastAddress; addr_pos != nullptr; addr_pos = addr_pos->Next) { if (adapter_pos->PhysicalAddressLength != 0 && address == from_sockaddr(addr_pos->Address.lpSockaddr)) { std::stringstream mac_addr; @@ -1234,8 +1234,8 @@ namespace platf { // https://docs.microsoft.com/en-us/windows-hardware/drivers/network/oid-wdi-set-connection-quality // https://docs.microsoft.com/en-us/previous-versions/windows/hardware/wireless/native-802-11-media-streaming BOOL value = TRUE; - auto error = fn_WlanSetInterface(wlan_handle, &wlan_interface_list->InterfaceInfo[i].InterfaceGuid, wlan_intf_opcode_media_streaming_mode, sizeof(value), &value, nullptr); - if (error == ERROR_SUCCESS) { + auto wlan_status = fn_WlanSetInterface(wlan_handle, &wlan_interface_list->InterfaceInfo[i].InterfaceGuid, wlan_intf_opcode_media_streaming_mode, sizeof(value), &value, nullptr); + if (wlan_status == ERROR_SUCCESS) { BOOST_LOG(info) << "WLAN interface "sv << i << " is now in low latency mode"sv; } } @@ -1372,8 +1372,8 @@ namespace platf { BOOST_LOG(debug) << "Sent WM_CLOSE to PID: "sv << wnd_process_id; enum_ctx->requested_exit = true; } else { - auto error = GetLastError(); - BOOST_LOG(warning) << "Failed to send WM_CLOSE to PID ["sv << wnd_process_id << "]: " << error; + auto close_error = GetLastError(); + BOOST_LOG(warning) << "Failed to send WM_CLOSE to PID ["sv << wnd_process_id << "]: " << close_error; } } diff --git a/src/process.cpp b/src/process.cpp index a17dbaa8a..3c5e7ae46 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -64,7 +64,7 @@ namespace proc { return std::make_unique(); } - void terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout) { + void terminate_process_group(boost::process::v1::child &child_process, boost::process::v1::group &group, std::chrono::seconds exit_timeout) { if (group.valid() && platf::process_group_running((std::uintptr_t) group.native_handle())) { if (exit_timeout.count() > 0) { // Request processes in the group to exit gracefully @@ -96,9 +96,9 @@ namespace proc { group.detach(); } - if (proc.valid()) { + if (child_process.valid()) { // avoid zombie process - proc.detach(); + child_process.detach(); } } diff --git a/src/process.h b/src/process.h index e02e6d895..132178be7 100644 --- a/src/process.h +++ b/src/process.h @@ -236,11 +236,11 @@ namespace proc { /** * @brief Terminates all child processes in a process group. - * @param proc The child process itself. + * @param child_process The child process itself. * @param group The group of all children in the process tree. * @param exit_timeout The timeout to wait for the process group to gracefully exit. */ - void terminate_process_group(boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout); + void terminate_process_group(boost::process::v1::child &child_process, boost::process::v1::group &group, std::chrono::seconds exit_timeout); extern proc_t proc; } // namespace proc diff --git a/src/rtsp.cpp b/src/rtsp.cpp index 554d6d3fa..5b4dfd22f 100644 --- a/src/rtsp.cpp +++ b/src/rtsp.cpp @@ -410,11 +410,11 @@ namespace rtsp_stream { if (ec) { BOOST_LOG(error) << "RTSP: handle_read_plaintext(): Couldn't read from tcp socket: "sv << ec.message(); - boost::system::error_code ec; - socket->sock.close(ec); + boost::system::error_code close_error; + socket->sock.close(close_error); - if (ec) { - BOOST_LOG(error) << "RTSP: handle_read_plaintext(): Couldn't close tcp socket: "sv << ec.message(); + if (close_error) { + BOOST_LOG(error) << "RTSP: handle_read_plaintext(): Couldn't close tcp socket: "sv << close_error.message(); } return; @@ -566,8 +566,8 @@ namespace rtsp_stream { BOOST_LOG(debug) << "No pending session for incoming RTSP connection"sv; // If there is no session pending, close the connection immediately - boost::system::error_code ec; - socket->sock.close(ec); + boost::system::error_code close_error; + socket->sock.close(close_error); } // Queue another asynchronous accept for the next incoming connection @@ -891,12 +891,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP OPTIONS requests. * - * @param server RTSP server instance handling the request. + * @param rtsp_server RTSP server instance handling the request. * @param sock Socket used to read or write the protocol message. * @param session Active streaming or pairing session for the request. * @param req Parsed RTSP request being handled. */ - void cmd_option(rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { + void cmd_option(rtsp_server_t *rtsp_server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { OPTION_ITEM option {}; // I know these string literals will not be modified @@ -911,12 +911,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP DESCRIBE requests. * - * @param server RTSP server instance. + * @param rtsp_server RTSP server instance. * @param sock Client socket. * @param session Launch session. * @param req RTSP request message. */ - void cmd_describe(rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { + void cmd_describe(rtsp_server_t *rtsp_server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { OPTION_ITEM option {}; // I know these string literals will not be modified @@ -1002,12 +1002,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP SETUP requests and prepare transport state. * - * @param server RTSP server instance handling the request. + * @param rtsp_server RTSP server instance handling the request. * @param sock Socket used to read or write the protocol message. * @param session Active streaming or pairing session for the request. * @param req Parsed RTSP request being handled. */ - void cmd_setup(rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { + void cmd_setup(rtsp_server_t *rtsp_server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { std::array options {}; auto &seqn = options[0]; @@ -1069,12 +1069,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP ANNOUNCE requests from the client. * - * @param server RTSP server instance handling the request. + * @param rtsp_server RTSP server instance handling the request. * @param sock Socket used to read or write the protocol message. * @param session Active streaming or pairing session for the request. * @param req Parsed RTSP request being handled. */ - void cmd_announce(rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { + void cmd_announce(rtsp_server_t *rtsp_server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { OPTION_ITEM option {}; // I know these string literals will not be modified @@ -1218,9 +1218,9 @@ namespace rtsp_stream { // in the RTSP message matches a local interface's IP address. Fortunately, Moonlight always sends // 0.0.0.0 when it wants low quality, so it is easy to check without enumerating interfaces. if (config.audio.channels == 2) { - for (auto option = req->options; option != nullptr; option = option->next) { - if ("Host"sv == option->option) { - std::string_view content {option->content}; + for (auto request_option = req->options; request_option != nullptr; request_option = request_option->next) { + if ("Host"sv == request_option->option) { + std::string_view content {request_option->content}; BOOST_LOG(debug) << "Found Host: "sv << content; config.audio.flags[audio::config_t::HIGH_QUALITY] = (content.find("0.0.0.0"sv) == std::string::npos); } @@ -1303,12 +1303,12 @@ namespace rtsp_stream { } auto stream_session = stream::session::alloc(config, session); - server->insert(stream_session); + rtsp_server->insert(stream_session); if (stream::session::start(*stream_session, sock.remote_endpoint().address().to_string())) { BOOST_LOG(error) << "Failed to start a streaming session"sv; - server->remove(stream_session); + rtsp_server->remove(stream_session); respond(sock, session, &option, 500, "Internal Server Error", req->sequenceNumber, {}); return; } @@ -1319,12 +1319,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP PLAY requests and start streaming. * - * @param server RTSP server instance handling the request. + * @param rtsp_server RTSP server instance handling the request. * @param sock Socket used to read or write the protocol message. * @param session Active streaming or pairing session for the request. * @param req Parsed RTSP request being handled. */ - void cmd_play(rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { + void cmd_play(rtsp_server_t *rtsp_server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { OPTION_ITEM option {}; // I know these string literals will not be modified diff --git a/src/stream.cpp b/src/stream.cpp index 10061560e..0a65a5c19 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1692,9 +1692,9 @@ namespace stream { auto blockIndex = 0; std::for_each(fec_blocks_begin, fec_blocks_end, [&](std::string_view ¤t_payload) { - auto packets = (current_payload.size() + (blocksize - 1)) / blocksize; + auto payload_packets = (current_payload.size() + (blocksize - 1)) / blocksize; - for (int x = 0; x < packets; ++x) { + for (int x = 0; x < payload_packets; ++x) { auto *inspect = (video_packet_raw_t *) ¤t_payload[x * blocksize]; inspect->packet.frameIndex = (uint32_t) packet->frame_index(); @@ -1708,7 +1708,7 @@ namespace stream { if (x == 0) { inspect->packet.flags |= FLAG_SOF; } - if (x == packets - 1) { + if (x == payload_packets - 1) { inspect->packet.flags |= FLAG_EOF; } } @@ -1944,7 +1944,7 @@ namespace stream { fec_packet.rtp.sequenceNumber = util::endian::big(sequenceNumber + x + 1); fec_packet.fecHeader.fecShardIndex = x; - auto send_info = platf::send_info_t { + auto fec_send_info = platf::send_info_t { (const char *) &fec_packet, sizeof(fec_packet), (const char *) shards_p[RTPA_DATA_SHARDS + x], @@ -1954,7 +1954,7 @@ namespace stream { session->audio.peer.port(), session->localAddress, }; - platf::send(send_info); + platf::send(fec_send_info); BOOST_LOG(verbose) << "Audio FEC ["sv << (sequenceNumber & ~(RTPA_DATA_SHARDS - 1)) << ' ' << x << "] :: send..."sv; } } diff --git a/src/video.cpp b/src/video.cpp index 0a8c0c8f6..87e827d02 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -286,10 +286,10 @@ namespace video { // If frame is not a software frame, it means we still need to transfer from main memory // to vram memory if (frame->hw_frames_ctx) { - auto status = av_hwframe_transfer_data(frame, sw_frame.get(), 0); - if (status < 0) { + auto transfer_status = av_hwframe_transfer_data(frame, sw_frame.get(), 0); + if (transfer_status < 0) { std::array string; - BOOST_LOG(error) << "Failed to transfer image data to hardware frame: "sv << av_make_error_string(string.data(), AV_ERROR_MAX_STRING_SIZE, status); + BOOST_LOG(error) << "Failed to transfer image data to hardware frame: "sv << av_make_error_string(string.data(), AV_ERROR_MAX_STRING_SIZE, transfer_status); return -1; } } @@ -1736,7 +1736,7 @@ namespace video { auto status = disp->capture(push_captured_image_callback, pull_free_image_callback, &display_cursor); - if (artificial_reinit && status != platf::capture_e::error) { + if (artificial_reinit && status != platf::capture_e::capture_error) { status = platf::capture_e::reinit; artificial_reinit = false; @@ -1803,7 +1803,7 @@ namespace video { reinit_event.reset(); continue; } - case platf::capture_e::error: + case platf::capture_e::capture_error: case platf::capture_e::ok: case platf::capture_e::timeout: case platf::capture_e::interrupted: @@ -2718,19 +2718,19 @@ namespace video { } if (!disp) { - return encode_e::error; + return encode_e::capture_error; } auto img = disp->alloc_img(); if (!img || disp->dummy_img(img.get())) { - return encode_e::error; + return encode_e::capture_error; } std::vector synced_sessions; for (auto &ctx : synced_session_ctxs) { auto synced_session = make_synced_session(disp.get(), encoder, *img, *ctx); if (!synced_session) { - return encode_e::error; + return encode_e::capture_error; } synced_sessions.emplace_back(std::move(*synced_session)); @@ -2738,7 +2738,7 @@ namespace video { auto ec = platf::capture_e::ok; while (encode_session_ctx_queue.running()) { - auto push_captured_image_callback = [&](std::shared_ptr &&img, bool frame_captured) -> bool { + auto push_captured_image_callback = [&](std::shared_ptr &&captured_image, bool frame_captured) -> bool { while (encode_session_ctx_queue.peek()) { auto encode_session_ctx = encode_session_ctx_queue.pop(); if (!encode_session_ctx) { @@ -2747,9 +2747,9 @@ namespace video { synced_session_ctxs.emplace_back(std::make_unique(std::move(*encode_session_ctx))); - auto encode_session = make_synced_session(disp.get(), encoder, *img, *synced_session_ctxs.back()); + auto encode_session = make_synced_session(disp.get(), encoder, *captured_image, *synced_session_ctxs.back()); if (!encode_session) { - ec = platf::capture_e::error; + ec = platf::capture_e::capture_error; return false; } @@ -2779,7 +2779,7 @@ namespace video { ctx->idr_events->pop(); } - if (frame_captured && pos->session->convert(*img)) { + if (frame_captured && pos->session->convert(*captured_image)) { BOOST_LOG(error) << "Could not convert image"sv; ctx->shutdown_event->raise(true); @@ -2787,8 +2787,8 @@ namespace video { } std::optional frame_timestamp; - if (img) { - frame_timestamp = img->frame_timestamp; + if (captured_image) { + frame_timestamp = captured_image->frame_timestamp; } if (encode(ctx->frame_nr++, *pos->session, ctx->packets, ctx->channel_data, frame_timestamp)) { @@ -2820,7 +2820,7 @@ namespace video { auto status = disp->capture(push_captured_image_callback, pull_free_image_callback, &display_cursor); switch (status) { case platf::capture_e::reinit: - case platf::capture_e::error: + case platf::capture_e::capture_error: case platf::capture_e::ok: case platf::capture_e::timeout: case platf::capture_e::interrupted: @@ -2843,14 +2843,14 @@ namespace video { auto lg = util::fail_guard([&]() { ctx.stop(); - for (auto &ctx : synced_session_ctxs) { - ctx->shutdown_event->raise(true); - ctx->join_event->raise(true); + for (auto &session_ctx : synced_session_ctxs) { + session_ctx->shutdown_event->raise(true); + session_ctx->join_event->raise(true); } - for (auto &ctx : ctx.unsafe()) { - ctx.shutdown_event->raise(true); - ctx.join_event->raise(true); + for (auto &pending_ctx : ctx.unsafe()) { + pending_ctx.shutdown_event->raise(true); + pending_ctx.join_event->raise(true); } }); @@ -2911,7 +2911,7 @@ namespace video { // Wait for the display to be ready std::shared_ptr display; { - auto lg = ref->display_wp.lock(); + auto display_lock = ref->display_wp.lock(); if (ref->display_wp->expired()) { continue; } diff --git a/src/video.h b/src/video.h index 412b40c27..006fb9f0b 100644 --- a/src/video.h +++ b/src/video.h @@ -263,24 +263,24 @@ namespace video { /** * @brief Construct NVENC platform format mappings. * - * @param dev_type Platform memory type. - * @param pix_fmt_8bit Platform 8-bit pixel format. - * @param pix_fmt_10bit Platform 10-bit pixel format. - * @param pix_fmt_yuv444_8bit Platform 8-bit YUV444 pixel format. - * @param pix_fmt_yuv444_10bit Platform 10-bit YUV444 pixel format. + * @param device_type Platform memory type. + * @param format_8bit Platform 8-bit pixel format. + * @param format_10bit Platform 10-bit pixel format. + * @param format_yuv444_8bit Platform 8-bit YUV444 pixel format. + * @param format_yuv444_10bit Platform 10-bit YUV444 pixel format. */ encoder_platform_formats_nvenc( - const platf::mem_type_e &dev_type, - const platf::pix_fmt_e &pix_fmt_8bit, - const platf::pix_fmt_e &pix_fmt_10bit, - const platf::pix_fmt_e &pix_fmt_yuv444_8bit, - const platf::pix_fmt_e &pix_fmt_yuv444_10bit + const platf::mem_type_e &device_type, + const platf::pix_fmt_e &format_8bit, + const platf::pix_fmt_e &format_10bit, + const platf::pix_fmt_e &format_yuv444_8bit, + const platf::pix_fmt_e &format_yuv444_10bit ) { - encoder_platform_formats_t::dev_type = dev_type; - encoder_platform_formats_t::pix_fmt_8bit = pix_fmt_8bit; - encoder_platform_formats_t::pix_fmt_10bit = pix_fmt_10bit; - encoder_platform_formats_t::pix_fmt_yuv444_8bit = pix_fmt_yuv444_8bit; - encoder_platform_formats_t::pix_fmt_yuv444_10bit = pix_fmt_yuv444_10bit; + encoder_platform_formats_t::dev_type = device_type; + encoder_platform_formats_t::pix_fmt_8bit = format_8bit; + encoder_platform_formats_t::pix_fmt_10bit = format_10bit; + encoder_platform_formats_t::pix_fmt_yuv444_8bit = format_yuv444_8bit; + encoder_platform_formats_t::pix_fmt_yuv444_10bit = format_yuv444_10bit; } };