diff --git a/src/input.cpp b/src/input.cpp index dcbe993c3..15b55859c 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -535,9 +535,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_REL_MOUSE_MOVE_PACKET packet) { + void print(const NV_REL_MOUSE_MOVE_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin relative mouse move packet--"sv << std::endl << "deltaX ["sv << util::endian::big(packet->deltaX) << ']' << std::endl @@ -549,9 +549,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_ABS_MOUSE_MOVE_PACKET packet) { + void print(const NV_ABS_MOUSE_MOVE_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin absolute mouse move packet--"sv << std::endl << "x ["sv << util::endian::big(packet->x) << ']' << std::endl @@ -565,9 +565,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_MOUSE_BUTTON_PACKET packet) { + void print(const NV_MOUSE_BUTTON_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin mouse button packet--"sv << std::endl << "action ["sv << util::hex(packet->header.magic).to_string_view() << ']' << std::endl @@ -579,9 +579,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_SCROLL_PACKET packet) { + void print(const NV_SCROLL_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin mouse scroll packet--"sv << std::endl << "scrollAmt1 ["sv << util::endian::big(packet->scrollAmt1) << ']' << std::endl @@ -592,9 +592,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PSS_HSCROLL_PACKET packet) { + void print(const SS_HSCROLL_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin mouse hscroll packet--"sv << std::endl << "scrollAmount ["sv << util::endian::big(packet->scrollAmount) << ']' << std::endl @@ -605,9 +605,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_KEYBOARD_PACKET packet) { + void print(const NV_KEYBOARD_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin keyboard packet--"sv << std::endl << "keyAction ["sv << util::hex(packet->header.magic).to_string_view() << ']' << std::endl @@ -621,9 +621,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_UNICODE_PACKET packet) { + void print(const NV_UNICODE_PACKET *packet) { std::string text(packet->text, util::endian::big(packet->header.size) - sizeof(packet->header.magic)); logging::debug("--begin unicode packet--\ntext [{}]\n--end unicode packet--", text); } @@ -631,9 +631,9 @@ namespace input { /** * @brief Write a debug log representation of the input packet. * - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void print(PNV_MULTI_CONTROLLER_PACKET packet) { + void print(const NV_MULTI_CONTROLLER_PACKET *packet) { // Moonlight spams controller packet even when not necessary logging::verbose([&packet](std::ostream &out) { out << "--begin controller packet--"sv << std::endl @@ -692,9 +692,9 @@ namespace input { /** * @brief Prints a controller arrival packet. - * @param packet The controller arrival packet. + * @param packet Read-only controller arrival packet. */ - void print(PSS_CONTROLLER_ARRIVAL_PACKET packet) { + void print(const SS_CONTROLLER_ARRIVAL_PACKET *packet) { logging::debug([&packet](std::ostream &out) { out << "--begin controller arrival packet--"sv << std::endl << "controllerNumber ["sv << (uint32_t) packet->controllerNumber << ']' << std::endl @@ -740,9 +740,9 @@ namespace input { /** * @brief Prints a controller battery packet. - * @param packet The controller battery packet. + * @param packet Read-only controller battery packet. */ - void print(PSS_CONTROLLER_BATTERY_PACKET packet) { + void print(const SS_CONTROLLER_BATTERY_PACKET *packet) { logging::verbose([&packet](std::ostream &out) { out << "--begin controller battery packet--"sv << std::endl << "controllerNumber ["sv << util::hex(packet->controllerNumber).to_string_view() << ']' << std::endl @@ -953,9 +953,9 @@ namespace input { * @brief Forward a client input packet directly to the platform backend. * * @param input Platform input backend that receives the event. - * @param packet Protocol packet being processed. + * @param packet Read-only protocol packet being processed. */ - void passthrough(std::shared_ptr &input, PNV_ABS_MOUSE_MOVE_PACKET packet) { + void passthrough(std::shared_ptr &input, const NV_ABS_MOUSE_MOVE_PACKET *packet) { auto &host = input->host; if (!host.settings.input.mouse) { return; @@ -1060,11 +1060,11 @@ namespace input { /** * @brief Apply configured keybinding remaps to a platform keycode. * - * @param host Input service providing immutable keybinding settings. + * @param host Read-only input service providing immutable keybinding settings. * @param keycode Platform keycode being translated or emitted. * @return Remapped keycode when configured, otherwise the original keycode. */ - short map_keycode(service_t::impl_t &host, short keycode) { + short map_keycode(const service_t::impl_t &host, short keycode) { if (auto it = host.settings.input.keybindings.find(keycode); it != std::end(host.settings.input.keybindings)) { return it->second; } @@ -1413,12 +1413,12 @@ namespace input { /** * @brief Allocate a virtual gamepad for a client-relative controller slot. * - * @param input Stream input state. + * @param input Shared handle whose stream input state receives the gamepad allocation. * @param client_index Client-relative controller index. * @param arrival Client-reported controller metadata. * @return Assigned global gamepad slot, or -1 when allocation fails. */ - int alloc_gamepad(std::shared_ptr &input, int client_index, const platf::gamepad_arrival_t &arrival) { + int alloc_gamepad(const std::shared_ptr &input, int client_index, const platf::gamepad_arrival_t &arrival) { auto &host = input->host; if (client_index < 0 || client_index >= input->gamepads.size()) { logging::warning("ControllerNumber out of range [{}]", client_index); @@ -1447,10 +1447,10 @@ namespace input { /** * @brief Called to pass a controller arrival message to the platform backend. - * @param input The input context pointer. - * @param packet The controller arrival packet. + * @param input Shared handle retaining the mutable client input state. + * @param packet Read-only controller arrival packet. */ - void passthrough(std::shared_ptr &input, PSS_CONTROLLER_ARRIVAL_PACKET packet) { + void passthrough(const std::shared_ptr &input, const SS_CONTROLLER_ARRIVAL_PACKET *packet) { if (auto &host = input->host; !host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; } @@ -1597,10 +1597,10 @@ namespace input { /** * @brief Called to pass a controller touch message to the platform backend. - * @param input The input context pointer. + * @param input Shared handle retaining the mutable stream input context. * @param packet The controller touch packet. */ - void passthrough(std::shared_ptr &input, PSS_CONTROLLER_TOUCH_PACKET packet) { + void passthrough(const std::shared_ptr &input, PSS_CONTROLLER_TOUCH_PACKET packet) { auto &host = input->host; if (!host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; @@ -1631,10 +1631,10 @@ namespace input { /** * @brief Called to pass a controller motion message to the platform backend. - * @param input The input context pointer. + * @param input Shared handle retaining the mutable stream input context. * @param packet The controller motion packet. */ - void passthrough(std::shared_ptr &input, PSS_CONTROLLER_MOTION_PACKET packet) { + void passthrough(const std::shared_ptr &input, PSS_CONTROLLER_MOTION_PACKET packet) { auto &host = input->host; if (!host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; @@ -1664,10 +1664,10 @@ namespace input { /** * @brief Called to pass a controller battery message to the platform backend. - * @param input The input context pointer. - * @param packet The controller battery packet. + * @param input Shared handle retaining the mutable stream input context. + * @param packet Read-only controller battery packet. */ - void passthrough(std::shared_ptr &input, PSS_CONTROLLER_BATTERY_PACKET packet) { + void passthrough(const std::shared_ptr &input, const SS_CONTROLLER_BATTERY_PACKET *packet) { auto &host = input->host; if (!host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; @@ -1696,10 +1696,10 @@ namespace input { /** * @brief Forward a client input packet directly to the platform backend. * - * @param input Platform input backend that receives the event. - * @param packet Protocol packet being processed. + * @param input Shared handle retaining the mutable client input state. + * @param packet Read-only protocol packet being processed. */ - void passthrough(std::shared_ptr &input, PNV_MULTI_CONTROLLER_PACKET packet) { + void passthrough(const std::shared_ptr &input, const NV_MULTI_CONTROLLER_PACKET *packet) { auto &host = input->host; if (!host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; @@ -2326,10 +2326,10 @@ namespace input { /** * @brief Called on the control stream thread to queue an input message. - * @param input The input context pointer. - * @param input_data The input message. + * @param input Shared handle retaining the input context while its message is queued. + * @param input_data Input message whose storage is transferred to the queue. */ - void passthrough(std::shared_ptr &input, std::vector &&input_data) { + void passthrough(const std::shared_ptr &input, std::vector &&input_data) { if (NV_INPUT_HEADER header {}; !validate_input_packet(input_data, &header)) { if (input_data.size() >= sizeof(header)) { logging::warning([&header, &input_data](std::ostream &out) { diff --git a/src/input.h b/src/input.h index 0b52f00a5..65e3a3853 100644 --- a/src/input.h +++ b/src/input.h @@ -115,8 +115,10 @@ namespace input { /** * @brief Queue a raw input message for platform passthrough. + * @param input Shared handle retaining the input context while its message is queued. + * @param input_data Input message whose storage is transferred to the queue. */ - void passthrough(std::shared_ptr &input, std::vector &&input_data); + void passthrough(const std::shared_ptr &input, std::vector &&input_data); #ifdef SUNSHINE_TESTS namespace testing { diff --git a/src/logging.h b/src/logging.h index 5d11e7c26..03fe5f328 100644 --- a/src/logging.h +++ b/src/logging.h @@ -129,6 +129,8 @@ namespace logging { /** * @brief Format and log a message when an output accepts its severity. + * + * The formatted text is written in full, including any embedded null bytes. * @tparam Args Types of the formatting arguments. * @param level Message severity. * @param format Compile-time checked format string. @@ -138,7 +140,8 @@ namespace logging { requires(sizeof...(Args) > 0) void log(level_e level, std::format_string format, Args &&...args) { log(level, [&format, &args...](std::ostream &output) { - output << std::format(format, std::forward(args)...); + const auto message = std::format(format, std::forward(args)...); + output.write(message.data(), static_cast(message.size())); }); } diff --git a/src/nvhttp.cpp b/src/nvhttp.cpp index 36684708e..8499e9e62 100644 --- a/src/nvhttp.cpp +++ b/src/nvhttp.cpp @@ -142,7 +142,7 @@ namespace nvhttp { context.use_private_key_file(private_key_file, boost::asio::ssl::context::pem); } - std::function verify; ///< Callback that validates a client's TLS certificate after handshake. + std::function verify; ///< Callback that reads and validates a client's TLS certificate after handshake. std::function, std::shared_ptr)> on_verify_failed; ///< Handler used to return the pairing challenge when client verification fails. protected: @@ -1695,7 +1695,7 @@ namespace nvhttp { http_server_t http_server; // Verify certificates after establishing connection - https_server.verify = [this](SSL *ssl) { + https_server.verify = [this](const SSL *ssl) { crypto::x509_t x509 { #if OPENSSL_VERSION_MAJOR >= 3 SSL_get1_peer_certificate(ssl) diff --git a/src/platform/common.h b/src/platform/common.h index e1bcd95c3..bfd53a91d 100644 --- a/src/platform/common.h +++ b/src/platform/common.h @@ -965,14 +965,18 @@ namespace platf { * @param elevated Whether the command should run with elevated privileges. * @param interactive Whether the command should run in an interactive session. * @param cmd Command line to execute or inspect. - * @param working_dir Working directory for the child process. + * @param working_dir Read-only working directory for the child process. * @param env Environment variables for the child process. * @param file Optional stdio file handle connected to the child process. * @param ec Error code returned by the asynchronous operation. - * @param group Process group used when launching the command. + * @param group Process group used when launching the command; Windows reads its native handle, while POSIX may initialize the group. * @return Child process handle for the launched command. */ - boost::process::v1::child run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const boost::process::v1::environment &env, FILE *file, std::error_code &ec, boost::process::v1::group *group); +#ifdef _WIN32 + boost::process::v1::child run_command(bool elevated, bool interactive, const std::string &cmd, const boost::filesystem::path &working_dir, const boost::process::v1::environment &env, FILE *file, std::error_code &ec, const boost::process::v1::group *group); +#else + boost::process::v1::child run_command(bool elevated, bool interactive, const std::string &cmd, const boost::filesystem::path &working_dir, const boost::process::v1::environment &env, FILE *file, std::error_code &ec, boost::process::v1::group *group); +#endif /** * @brief Enumerates supported thread priority options. @@ -1103,10 +1107,10 @@ namespace platf { /** * @brief Send the serialized response over the active socket. * - * @param send_info Socket addresses, buffers, and sizes for the send operation. + * @param send_info Read-only socket addresses, buffers, and sizes for the send operation. * @return True when the packet is submitted to the socket. */ - bool send(send_info_t &send_info); + bool send(const send_info_t &send_info); /** * @brief Identifies traffic classes used for socket QoS tagging. @@ -1119,14 +1123,14 @@ namespace platf { /** * @brief Enable QoS on the given socket for traffic to the specified destination. * @param native_socket The native socket handle. - * @param address The destination address for traffic sent on this socket. + * @param address Read-only destination address for traffic sent on this socket. * @param port The destination port for traffic sent on this socket. * @param data_type The type of traffic sent on this socket. * @param dscp_tagging Specifies whether to enable DSCP tagging on outgoing traffic. * * @return Cleanup handle that restores or releases QoS state when destroyed. */ - std::unique_ptr enable_socket_qos(uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging); + std::unique_ptr enable_socket_qos(uintptr_t native_socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging); /** * @brief Own platform resources for one application lifetime. @@ -1212,13 +1216,13 @@ namespace platf { /** * @brief Create scoped socket priority settings. * @param socket Native socket. - * @param address Destination address. + * @param address Read-only destination address. * @param port Destination port. * @param type Traffic class. * @param dscp_tagging Enable DSCP tagging. * @return Settings lifetime owner. */ - std::unique_ptr enable_socket_qos(uintptr_t socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e type, bool dscp_tagging); + std::unique_ptr enable_socket_qos(uintptr_t socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e type, bool dscp_tagging); private: /** diff --git a/src/platform/linux/audio.cpp b/src/platform/linux/audio.cpp index a92a2ea4e..c0a7af0d2 100644 --- a/src/platform/linux/audio.cpp +++ b/src/platform/linux/audio.cpp @@ -295,7 +295,7 @@ namespace platf { /** * @brief Translate PulseAudio context state changes into server events. * - * @param ctx Native context object used by the operation or callback. + * @param ctx Native callback context forwarded to the read-only state handler. * @param userdata Caller-provided pointer passed through the callback. */ void ctx_state_cb(ctx_t::pointer ctx, void *userdata) { @@ -349,7 +349,7 @@ namespace platf { } index; ///< PulseAudio module indexes for Sunshine-created null sinks. std::unique_ptr> events; ///< Event queue receiving PulseAudio context state changes. - std::unique_ptr> events_cb; ///< Callback that translates PulseAudio context updates into events. + std::unique_ptr> events_cb; ///< Callback that reads PulseAudio context state and emits events. std::jthread worker; ///< Thread running the PulseAudio mainloop. @@ -363,7 +363,7 @@ 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) { + events_cb = std::make_unique>([this](const pa_context *ctx) { switch (pa_context_get_state(ctx)) { case PA_CONTEXT_READY: events->raise(ready); @@ -484,7 +484,7 @@ namespace platf { // Count of all virtual sinks that are created by us int nullcount = 0; - cb_t f = [this, &alarm, &nullcount](ctx_t::pointer ctx, const pa_sink_info *sink_info, int eol) { + cb_t f = [this, &alarm, &nullcount](const pa_context *ctx, const pa_sink_info *sink_info, int eol) { if (!sink_info) { if (!eol) { logging::error("Couldn't get pulseaudio sink info: {}", pa_strerror(pa_context_errno(ctx))); @@ -574,7 +574,7 @@ namespace platf { std::string sink_name; auto alarm = safe::make_alarm(); - cb_simple_t server_f = [&alarm, &sink_name](ctx_t::pointer ctx, const pa_server_info *server_info) { + cb_simple_t server_f = [&alarm, &sink_name](const pa_context *ctx, const pa_server_info *server_info) { if (!server_info) { logging::error("Couldn't get pulseaudio server info: {}", pa_strerror(pa_context_errno(ctx))); alarm->ring(-1); @@ -606,7 +606,7 @@ namespace platf { return monitor_name; } - cb_t sink_f = [&sink_name, &alarm, &monitor_name](ctx_t::pointer ctx, const pa_sink_info *sink_info, int eol) { + cb_t sink_f = [&sink_name, &alarm, &monitor_name](const pa_context *ctx, const pa_sink_info *sink_info, int eol) { if (!sink_info) { if (!eol) { logging::error("Couldn't get pulseaudio sink info for [{}]: {}", sink_name, pa_strerror(pa_context_errno(ctx))); diff --git a/src/platform/linux/kmsgrab.cpp b/src/platform/linux/kmsgrab.cpp index 773f158f3..6c8d9c8ce 100644 --- a/src/platform/linux/kmsgrab.cpp +++ b/src/platform/linux/kmsgrab.cpp @@ -1274,7 +1274,7 @@ namespace platf { logging::info("Found monitor for DRM screencasting"sv); // We need to find the correct /dev/dri/card{nr} to correlate the crtc_id with the monitor descriptor - auto pos = std::find_if(std::begin(state.card_descriptors), std::end(state.card_descriptors), [&](card_descriptor_t &cd) { + auto pos = std::find_if(std::begin(state.card_descriptors), std::end(state.card_descriptors), [&](const card_descriptor_t &cd) { return cd.path == filestring; }); diff --git a/src/platform/linux/misc.cpp b/src/platform/linux/misc.cpp index 9ef8ff66b..adad355c1 100644 --- a/src/platform/linux/misc.cpp +++ b/src/platform/linux/misc.cpp @@ -487,7 +487,20 @@ namespace platf { return "00:00:00:00:00:00"s; } - bp::child run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) { + /** + * @brief Launch a child process with the supplied environment and working directory. + * + * @param elevated Elevated launch request; unused on POSIX. + * @param interactive Interactive launch request; unused on POSIX. + * @param cmd Command to launch. + * @param working_dir Read-only working directory for the child process. + * @param env Environment for the child process. + * @param file Output stream for stdout and stderr, or nullptr to discard output. + * @param ec Receives any process launch error. + * @param group Optional process group whose native handle may be initialized during POSIX process launch. + * @return The child process object, with launch failures reported through ec. + */ + bp::child run_command(bool elevated, bool interactive, const std::string &cmd, const boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) { // clang-format off if (!group) { if (!file) { @@ -972,9 +985,9 @@ namespace platf { } /** - * @brief Send the serialized response over the active socket. + * @brief Send the serialized response described by read-only socket and payload metadata. */ - bool send(send_info_t &send_info) { + bool send(const send_info_t &send_info) { auto sockfd = (int) send_info.native_socket; struct msghdr msg = {}; @@ -1205,9 +1218,9 @@ namespace platf { }; /** - * @brief Enables QoS on the given socket for traffic to the specified destination. + * @brief Enables QoS on the given socket for traffic to the read-only destination address. */ - std::unique_ptr runtime_t::enable_socket_qos(uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { + std::unique_ptr runtime_t::enable_socket_qos(uintptr_t native_socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { int sockfd = (int) native_socket; std::vector> reset_options; diff --git a/src/platform/linux/vaapi.cpp b/src/platform/linux/vaapi.cpp index 8fceb9c42..6ae64fdd6 100644 --- a/src/platform/linux/vaapi.cpp +++ b/src/platform/linux/vaapi.cpp @@ -273,10 +273,10 @@ namespace va { /** * @brief Determines the matching VA profile for the codec configuration. - * @param ctx The FFmpeg codec context. + * @param ctx Read-only FFmpeg codec context. * @return The matching VA profile or `VAProfileNone` on failure. */ - VAProfile get_va_profile(AVCodecContext *ctx) { + VAProfile get_va_profile(const AVCodecContext *ctx) { if (ctx->codec_id == AV_CODEC_ID_H264) { // There's no VAAPI profile for H.264 4:4:4 return VAProfileH264High; diff --git a/src/platform/macos/misc.mm b/src/platform/macos/misc.mm index 4b8724b7f..9a0c7ac36 100644 --- a/src/platform/macos/misc.mm +++ b/src/platform/macos/misc.mm @@ -441,7 +441,20 @@ namespace platf { return "00:00:00:00:00:00"s; } - bp::child run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) { + /** + * @brief Launch a child process with the supplied environment and working directory. + * + * @param elevated Elevated launch request; unused on POSIX. + * @param interactive Interactive launch request; unused on POSIX. + * @param cmd Command to launch. + * @param working_dir Read-only working directory for the child process. + * @param env Environment for the child process. + * @param file Output stream for stdout and stderr, or nullptr to discard output. + * @param ec Receives any process launch error. + * @param group Optional process group whose native handle may be initialized during POSIX process launch. + * @return The child process object, with launch failures reported through ec. + */ + bp::child run_command(bool elevated, bool interactive, const std::string &cmd, const boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) { // clang-format off if (!group) { if (!file) { @@ -671,7 +684,7 @@ namespace platf { return false; } - bool send(send_info_t &send_info) { + bool send(const send_info_t &send_info) { auto sockfd = (int) send_info.native_socket; struct msghdr msg = {}; @@ -816,9 +829,9 @@ namespace platf { }; /** - * @brief Enables QoS on the given socket for traffic to the specified destination. + * @brief Enables QoS on the given socket for traffic to the read-only destination address. */ - std::unique_ptr enable_socket_qos(uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { + std::unique_ptr enable_socket_qos(uintptr_t native_socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { int sockfd = (int) native_socket; std::vector> reset_options; @@ -1027,7 +1040,7 @@ namespace platf { platf::enable_mouse_keys(); } - std::unique_ptr runtime_t::enable_socket_qos(uintptr_t socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e type, bool dscp_tagging) { + std::unique_ptr runtime_t::enable_socket_qos(uintptr_t socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e type, bool dscp_tagging) { return platf::enable_socket_qos(socket, address, port, type, dscp_tagging); } } // namespace platf diff --git a/src/platform/virtualhid_input.cpp b/src/platform/virtualhid_input.cpp index 314b355a7..11384712c 100644 --- a/src/platform/virtualhid_input.cpp +++ b/src/platform/virtualhid_input.cpp @@ -662,7 +662,7 @@ namespace platf::virtualhid { } std::vector supported_gamepads( - lvh::Runtime *runtime, + const lvh::Runtime *runtime, const bool fallback_vigem_available, const bool virtualhid_licensed, const bool require_license diff --git a/src/platform/virtualhid_input.h b/src/platform/virtualhid_input.h index 978ad961b..220a2570a 100644 --- a/src/platform/virtualhid_input.h +++ b/src/platform/virtualhid_input.h @@ -119,14 +119,14 @@ namespace platf::virtualhid { /** * @brief Return gamepad choices and runtime availability. * - * @param runtime Runtime to probe. + * @param runtime Read-only runtime whose backend capabilities determine availability. * @param fallback_vigem_available Whether Windows ViGEm fallback can create gamepads. * @param virtualhid_licensed Whether the broker has a valid license. * @param require_license Whether this platform requires a broker license for gamepads. * @return Supported gamepad choices. */ std::vector supported_gamepads( - lvh::Runtime *runtime, + const lvh::Runtime *runtime, bool fallback_vigem_available = false, bool virtualhid_licensed = true, bool require_license = false diff --git a/src/platform/windows/display_vram.cpp b/src/platform/windows/display_vram.cpp index ccfebf96f..9a4de33a1 100644 --- a/src/platform/windows/display_vram.cpp +++ b/src/platform/windows/display_vram.cpp @@ -437,10 +437,10 @@ namespace platf::dxgi { /** * @brief Convert a captured D3D image into encoder input textures. * - * @param img_base D3D image supplied by the capture backend. + * @param img_base Read-only D3D image supplied by the capture backend. * @return Conversion status. */ - int convert(platf::img_t &img_base) { + int convert(const platf::img_t &img_base) { // Garbage collect mapped capture images whose weak references have expired for (auto it = img_ctx_map.begin(); it != img_ctx_map.end();) { if (it->second.img_weak.expired()) { @@ -450,7 +450,7 @@ namespace platf::dxgi { } } - if (auto &img = (img_d3d_t &) img_base; !img.blank) { + if (const auto &img = static_cast(img_base); !img.blank) { auto &img_ctx = img_ctx_map[img.id]; // Open the shared capture texture with our ID3D11Device @@ -1283,10 +1283,10 @@ namespace platf::dxgi { * @param device D3D, audio, or platform device used by the operation. * @param cursor Cursor image or visibility state to composite. * @param cursor_img Cursor img. - * @param shape_info Shape info. + * @param shape_info Read-only pointer shape dimensions used to create the cursor texture. * @return True when the cursor image is uploaded to the D3D texture. */ - bool set_cursor_texture(device_t::pointer device, gpu_cursor_t &cursor, util::buffer_t &&cursor_img, DXGI_OUTDUPL_POINTER_SHAPE_INFO &shape_info) { + bool set_cursor_texture(device_t::pointer device, gpu_cursor_t &cursor, util::buffer_t &&cursor_img, const DXGI_OUTDUPL_POINTER_SHAPE_INFO &shape_info) { // This cursor image may not be used if (cursor_img.size() == 0) { cursor.input_res.reset(); diff --git a/src/platform/windows/misc.cpp b/src/platform/windows/misc.cpp index 81db8672e..e37be838b 100644 --- a/src/platform/windows/misc.cpp +++ b/src/platform/windows/misc.cpp @@ -578,10 +578,10 @@ namespace platf { * @param process_launched A boolean indicating if the launch was successful. * @param cmd The command that was used to launch the process. * @param ec A reference to an `std::error_code` object that will store any error that occurred during the launch. - * @param process_info A reference to a `PROCESS_INFORMATION` structure that contains information about the new process. + * @param process_info Read-only native process details containing the handles and ID of the new process. * @return A `bp::child` object representing the new process, or an empty `bp::child` object if the launch failed. */ - bp::child create_boost_child_from_results(bool process_launched, const std::string &cmd, std::error_code &ec, PROCESS_INFORMATION &process_info) { + bp::child create_boost_child_from_results(bool process_launched, const std::string &cmd, std::error_code &ec, const PROCESS_INFORMATION &process_info) { // Use RAII to ensure the process is closed when we're done with it, even if there was an error. auto close_process_handles = util::fail_guard([process_launched, process_info]() { if (process_launched) { @@ -1034,14 +1034,14 @@ namespace platf { * @param elevated Specify whether to elevate the process. * @param interactive Specify whether this will run in a window or hidden. * @param cmd The command to run. - * @param working_dir The working directory for the new process. + * @param working_dir Read-only working directory for the new process. * @param env The environment variables to use for the new process. * @param file A file object to redirect the child process's output to (may be `nullptr`). * @param ec An error code, set to indicate any errors that occur during the launch process. - * @param group A pointer to a `bp::group` object to which the new process should belong (may be `nullptr`). + * @param group Read-only process group whose native handle receives the child (may be `nullptr`). * @return A `bp::child` object representing the new process, or an empty `bp::child` object if the launch fails. */ - bp::child run_command(bool elevated, bool interactive, const std::string &cmd, boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, bp::group *group) { + bp::child run_command(bool elevated, bool interactive, const std::string &cmd, const boost::filesystem::path &working_dir, const bp::environment &env, FILE *file, std::error_code &ec, const bp::group *group) { std::wstring start_dir = utf_utils::from_utf8(working_dir.string()); HANDLE job = group ? group->native_handle() : nullptr; STARTUPINFOEXW startup_info = create_startup_info(file, job ? &job : nullptr, ec); @@ -1610,7 +1610,7 @@ namespace platf { return WSASendMsg((SOCKET) send_info.native_socket, &msg, 0, &bytes_sent, nullptr, nullptr) != SOCKET_ERROR; } - bool send(send_info_t &send_info) { + bool send(const send_info_t &send_info) { WSAMSG msg; // Convert the target address into a SOCKADDR @@ -1691,7 +1691,7 @@ namespace platf { /** * @brief Enables QoS on the given socket for traffic to the specified destination. */ - std::unique_ptr runtime_t::enable_socket_qos(uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { + std::unique_ptr runtime_t::enable_socket_qos(uintptr_t native_socket, const boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type, bool dscp_tagging) { SOCKADDR_IN saddr_v4; SOCKADDR_IN6 saddr_v6; PSOCKADDR dest_addr; diff --git a/src/rtsp.cpp b/src/rtsp.cpp index db6ba8dca..fd2161502 100644 --- a/src/rtsp.cpp +++ b/src/rtsp.cpp @@ -244,11 +244,11 @@ namespace rtsp_stream { /** * @brief Read and decrypt the encrypted RTSP payload. - * @param socket The socket the message was received on. + * @param socket Shared handle retaining the mutable socket that received the message. * @param ec The error code of the read operation. * @param bytes The number of bytes read. */ - static void handle_read_encrypted_message(std::shared_ptr &socket, const boost::system::error_code &ec, std::size_t bytes) { + static void handle_read_encrypted_message(const std::shared_ptr &socket, const boost::system::error_code &ec, std::size_t bytes) { logging::debug("handle_read_encrypted(): Handle read of size: {} bytes", bytes); auto sock_close = util::fail_guard([&socket]() { @@ -492,16 +492,16 @@ namespace rtsp_stream { class rtsp_server_t { public: const config::settings_t &settings; ///< Startup transport and encryption policy. - stream::service_t &streams; ///< Session allocation owner. - video::service_t &videos; ///< Encoder capability owner. + const stream::service_t &streams; ///< Stable service handle used to allocate mutable session state. + const video::service_t &videos; ///< Read-only encoder capability owner. /** * @brief Bind the host services used by RTSP handlers. * @param settings Startup transport and encryption policy. - * @param streams Stream allocation owner. - * @param videos Encoder capability owner. + * @param streams Stable service handle used to allocate mutable session state. + * @param videos Read-only encoder capability owner. */ - rtsp_server_t(const config::settings_t &settings, stream::service_t &streams, video::service_t &videos): + rtsp_server_t(const config::settings_t &settings, const stream::service_t &streams, const video::service_t &videos): settings {settings}, streams {streams}, videos {videos} { @@ -792,19 +792,19 @@ namespace rtsp_stream { /** * @brief Bind services before listener callbacks can run. * @param settings Startup transport and encryption policy. - * @param streams Session allocation owner. + * @param streams Stable service handle used to allocate mutable session state. * @param inputs Host input cleanup owner. - * @param videos Encoder capability owner. + * @param videos Read-only encoder capability owner. * @param host_mail Application shutdown mailbox. */ - impl_t(const config::settings_t &settings, stream::service_t &streams, input::service_t &inputs, video::service_t &videos, safe::mail_t host_mail): + impl_t(const config::settings_t &settings, const stream::service_t &streams, input::service_t &inputs, const video::service_t &videos, safe::mail_t host_mail): server {settings, streams, videos}, inputs {inputs}, host_mail {std::move(host_mail)} { } }; - service_t::service_t(const config::settings_t &settings, stream::service_t &streams, input::service_t &inputs, video::service_t &videos, safe::mail_t host_mail): + service_t::service_t(const config::settings_t &settings, const stream::service_t &streams, input::service_t &inputs, const video::service_t &videos, safe::mail_t host_mail): impl {std::make_shared(settings, streams, inputs, videos, std::move(host_mail))} { } @@ -987,12 +987,12 @@ namespace rtsp_stream { /** * @brief Handle RTSP DESCRIBE requests. * - * @param server RTSP server instance. + * @param server Read-only RTSP server dependencies used to advertise capabilities. * @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(const rtsp_server_t *server, tcp::socket &sock, launch_session_t &session, msg_t &&req) { const auto capabilities = server->videos.capabilities(); OPTION_ITEM option {}; diff --git a/src/rtsp.h b/src/rtsp.h index f70119313..d2c6cff05 100644 --- a/src/rtsp.h +++ b/src/rtsp.h @@ -71,12 +71,12 @@ namespace rtsp_stream { /** * @brief Bind the session owners without opening the listening socket. * @param settings Startup transport and encryption policy. - * @param streams Host stream and broadcast owner. + * @param streams Stable service handle used to allocate mutable session state. * @param inputs Host input owner for client cleanup. - * @param videos Encoder capabilities used in RTSP negotiation. + * @param videos Read-only encoder capabilities used in RTSP negotiation. * @param host_mail Host mailbox for listener shutdown. */ - service_t(const config::settings_t &settings, stream::service_t &streams, input::service_t &inputs, video::service_t &videos, safe::mail_t host_mail); + service_t(const config::settings_t &settings, const stream::service_t &streams, input::service_t &inputs, const video::service_t &videos, safe::mail_t host_mail); /** * @brief Stop and release listener state after the server loop has exited. */ diff --git a/src/stream.cpp b/src/stream.cpp index 986e3eff6..f5e08590b 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -2434,11 +2434,11 @@ namespace stream { /** * @brief Allocate stopped session state and retain its explicit host dependencies. * @param owner Host service state retained until all session resources release. - * @param config Negotiated transport and encoder settings. + * @param config Read-only negotiated transport and encoder settings copied into the session. * @param launch_session Client identity, encryption keys, and connection callback. * @return Newly allocated session; workers and platform input start separately. */ - std::shared_ptr alloc(std::shared_ptr owner, config_t &config, rtsp_stream::launch_session_t &launch_session) { + std::shared_ptr alloc(std::shared_ptr owner, const config_t &config, rtsp_stream::launch_session_t &launch_session) { auto session = std::make_shared(); session->owner = std::move(owner); session->on_stream_connected = launch_session.on_stream_connected; @@ -2515,7 +2515,7 @@ namespace stream { } } // namespace session - std::shared_ptr service_t::alloc(config_t &config, rtsp_stream::launch_session_t &launch_session) { + std::shared_ptr service_t::alloc(const config_t &config, rtsp_stream::launch_session_t &launch_session) const { return session::alloc(impl, config, launch_session); } } // namespace stream diff --git a/src/stream.h b/src/stream.h index 91b0cfd5f..8f0e53392 100644 --- a/src/stream.h +++ b/src/stream.h @@ -126,13 +126,13 @@ namespace stream { service_t(const service_t &) = delete; service_t &operator=(const service_t &) = delete; /** - * @brief Allocate and initialize platform input state for a stream. + * @brief Allocate stream state through the retained host context without changing the service handle. * - * @param config Configuration values to apply. + * @param config Read-only configuration values copied into the session. * @param launch_session Launch session. * @return Allocated object or identifier, or an error value on failure. */ - std::shared_ptr alloc(config_t &config, rtsp_stream::launch_session_t &launch_session); + std::shared_ptr alloc(const config_t &config, rtsp_stream::launch_session_t &launch_session) const; private: struct impl_t; ///< Private broadcast owner and dependencies. diff --git a/src/video.cpp b/src/video.cpp index 438687148..2d2f4136a 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1908,12 +1908,12 @@ namespace video { * * @param frame_nr Monotonic frame index assigned by the video pipeline. * @param session Active FFmpeg encoder session. - * @param packets Output queue that receives encoded packets. + * @param packets Shared handle to the output queue that receives encoded packets. * @param channel_data Platform or protocol state attached to each packet. * @param frame_timestamp Capture timestamp associated with the encoded frame. * @return 0 when packets are queued; nonzero when encoding or packetization fails. */ - int encode_avcodec(int64_t frame_nr, avcodec_encode_session_t &session, safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { + int encode_avcodec(int64_t frame_nr, avcodec_encode_session_t &session, const safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { auto &frame = session.device->frame; frame->pts = frame_nr; @@ -1994,12 +1994,12 @@ namespace video { * * @param frame_nr Monotonic frame index assigned by the video pipeline. * @param session Active NVENC encoder session. - * @param packets Output queue that receives the encoded packet. + * @param packets Shared handle to the output queue that receives the encoded packet. * @param channel_data Platform or protocol state attached to the packet. * @param frame_timestamp Capture timestamp associated with the encoded frame. * @return 0 when packets are queued; nonzero when NVENC encoding fails. */ - int encode_nvenc(int64_t frame_nr, nvenc_encode_session_t &session, safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { + int encode_nvenc(int64_t frame_nr, nvenc_encode_session_t &session, const safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { auto encoded_frame = session.encode_frame(frame_nr); if (encoded_frame.data.empty()) { logging::error("NvENC returned empty packet"); @@ -2024,12 +2024,12 @@ namespace video { * * @param frame_nr Frame nr. * @param session Active streaming or pairing session for the request. - * @param packets Packets queued or emitted by the stream. + * @param packets Shared handle to the queue that receives encoded packets. * @param channel_data Channel data. * @param frame_timestamp Frame timestamp. * @return 0 when the frame is encoded and queued; nonzero on encoder failure. */ - int encode(int64_t frame_nr, encode_session_t &session, safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { + int encode(int64_t frame_nr, encode_session_t &session, const safe::mail_raw_t::queue_t &packets, void *channel_data, std::optional frame_timestamp) { if (auto avcodec_session = dynamic_cast(&session)) { return encode_avcodec(frame_nr, *avcodec_session, packets, channel_data, frame_timestamp); } else if (auto nvenc_session = dynamic_cast(&session)) { diff --git a/tests/unit/test_logging_api.cpp b/tests/unit/test_logging_api.cpp index 4ed8a3378..884500612 100644 --- a/tests/unit/test_logging_api.cpp +++ b/tests/unit/test_logging_api.cpp @@ -425,6 +425,25 @@ TEST(LoggingApiTest, StandardFormatOverloadUsesTypedFormatting) { EXPECT_EQ(messages.front().message.text, "002a 1.25 custom"); } +/** + * @brief Formatted text preserves embedded null bytes and empty messages. + */ +TEST(LoggingApiTest, StandardFormatOverloadPreservesCompleteText) { + using namespace std::string_literals; + auto sink = std::make_shared(); + auto owner = logging::add_sink(sink, 0, false); + const auto text = "before\0after"s; + const auto expected = "[before\0after]"s; + + logging::info("[{}]", text); + logging::info("{}", std::string_view {}); + + const auto messages = sink->snapshot(); + ASSERT_EQ(messages.size(), 2U); + EXPECT_EQ(messages[0].message.text, expected); + EXPECT_TRUE(messages[1].message.text.empty()); +} + /** * @brief A throwing builder discards partial text without disabling subsequent records. */ diff --git a/tests/unit/test_windows_platform_ownership.cpp b/tests/unit/test_windows_platform_ownership.cpp index bdc0dc848..8288f93b1 100644 --- a/tests/unit/test_windows_platform_ownership.cpp +++ b/tests/unit/test_windows_platform_ownership.cpp @@ -188,7 +188,7 @@ TEST(WindowsNetworkingOwnerTest, LastFlowClosesClientBeforeLibraryUnload) { TEST(WindowsServiceOwnerTest, StopReportsDeadlineBeforeSignalingOnlyItsOwner) { std::vector events; SERVICE_STATUS snapshot {}; - service::state_t first {{[&snapshot, &events](SERVICE_STATUS_HANDLE handle, LPSERVICE_STATUS state) { + service::state_t first {{[&snapshot, &events](SERVICE_STATUS_HANDLE handle, const SERVICE_STATUS *state) { snapshot = *state; events.emplace_back("status"); return TRUE;