From 6e1566386e3b2a4892123562969b0455c60a8edc Mon Sep 17 00:00:00 2001 From: lainon Date: Thu, 21 Jul 2022 13:09:10 +0200 Subject: [PATCH] project: Apply more C++ paradigms to the code - Use auto in places where code clarity is improved or identical. - Replace trivial constructors and destructors with default. - Use true random for random generation. - Use std::string_view where it is valid to do so. - Apply const where it is valid to do so. - Use references where it is valid to do so. - Manually optimize memory usage with std::move and std::copy. - Opt for memory efficient containers where the size is known ahead of time. Signed-off-by: lainon --- source/encoders/encoder-ffmpeg.cpp | 10 +++--- source/encoders/encoder-ffmpeg.hpp | 4 +-- source/encoders/handlers/dnxhd_handler.cpp | 2 +- .../encoders/handlers/nvenc_h264_handler.cpp | 4 +-- .../encoders/handlers/nvenc_hevc_handler.cpp | 6 ++-- source/encoders/handlers/nvenc_shared.cpp | 28 ++++++++-------- source/ffmpeg/avframe-queue.cpp | 2 +- source/ffmpeg/hwapi/base.hpp | 2 +- source/ffmpeg/hwapi/d3d11.cpp | 8 ++--- source/ffmpeg/hwapi/d3d11.hpp | 2 +- source/ffmpeg/swscale.cpp | 2 +- source/ffmpeg/tools.cpp | 33 +++++++++---------- source/ffmpeg/tools.hpp | 15 +++++---- source/filters/filter-autoframing.cpp | 16 ++++----- source/filters/filter-displacement.cpp | 2 +- source/filters/filter-dynamic-mask.cpp | 2 +- source/filters/filter-transform.cpp | 8 ++--- source/gfx/blur/gfx-blur-box-linear.cpp | 3 +- source/gfx/blur/gfx-blur-box.cpp | 2 +- source/gfx/blur/gfx-blur-dual-filtering.cpp | 2 +- source/gfx/blur/gfx-blur-gaussian-linear.cpp | 3 +- source/gfx/blur/gfx-blur-gaussian.cpp | 6 ++-- source/gfx/gfx-debug.cpp | 2 +- source/gfx/lut/gfx-lut-consumer.cpp | 2 +- source/gfx/lut/gfx-lut-producer.cpp | 2 +- source/gfx/shader/gfx-shader-param-basic.cpp | 9 ++--- source/gfx/shader/gfx-shader-param-basic.hpp | 2 +- .../gfx/shader/gfx-shader-param-texture.cpp | 23 +++++++------ .../gfx/shader/gfx-shader-param-texture.hpp | 2 +- source/gfx/shader/gfx-shader-param.cpp | 6 ++-- source/gfx/shader/gfx-shader-param.hpp | 2 +- source/gfx/shader/gfx-shader.cpp | 6 ++-- source/gfx/shader/gfx-shader.hpp | 4 +-- source/nvidia/ar/nvidia-ar-facedetection.cpp | 2 +- source/nvidia/cuda/nvidia-cuda-context.hpp | 2 +- source/nvidia/cuda/nvidia-cuda-gs-texture.cpp | 7 ++-- source/nvidia/cv/nvidia-cv.hpp | 2 +- .../nvidia/vfx/nvidia-vfx-superresolution.cpp | 2 +- source/obs/gs/gs-effect-parameter.cpp | 12 +++---- source/obs/gs/gs-effect-pass.cpp | 18 +++++----- source/obs/gs/gs-effect-pass.hpp | 12 +++---- source/obs/gs/gs-effect-technique.cpp | 8 ++--- source/obs/gs/gs-effect-technique.hpp | 4 +-- source/obs/gs/gs-effect.cpp | 26 +++++++-------- source/obs/gs/gs-effect.hpp | 18 +++++----- source/obs/gs/gs-mipmapper.cpp | 4 +-- source/obs/gs/gs-rendertarget.cpp | 2 +- source/obs/gs/gs-rendertarget.hpp | 2 +- source/obs/gs/gs-vertexbuffer.cpp | 2 +- source/obs/gs/gs-vertexbuffer.hpp | 2 +- source/obs/obs-encoder-factory.hpp | 2 +- source/obs/obs-signal-handler.hpp | 6 ++-- source/obs/obs-source-factory.hpp | 2 +- source/sources/source-mirror.cpp | 2 +- source/ui/ui-about.cpp | 3 +- source/util/util-curl.cpp | 18 +++++----- source/util/util-curl.hpp | 2 +- source/util/util-event.hpp | 4 +-- source/util/util-library.cpp | 8 ++--- source/util/util-threadpool.cpp | 2 +- source/util/utility.cpp | 6 ++-- source/util/utility.hpp | 4 +-- 62 files changed, 200 insertions(+), 206 deletions(-) diff --git a/source/encoders/encoder-ffmpeg.cpp b/source/encoders/encoder-ffmpeg.cpp index 465fcdc7..c952a06c 100644 --- a/source/encoders/encoder-ffmpeg.cpp +++ b/source/encoders/encoder-ffmpeg.cpp @@ -824,7 +824,7 @@ const AVCodecContext* ffmpeg_instance::get_avcodeccontext() return _context; } -void ffmpeg_instance::parse_ffmpeg_commandline(std::string text) +void ffmpeg_instance::parse_ffmpeg_commandline(std::string_view text) { // Steps to properly parse a command line: // 1. Split by space and package by quotes. @@ -915,7 +915,7 @@ void ffmpeg_instance::parse_ffmpeg_commandline(std::string text) // have also dealt with escaping for the most part. We want to parse // an FFmpeg commandline option set here, so the first character in // the string must be a '-'. - for (std::string& opt : opts) { + for (const auto& opt : opts) { // Skip empty options. if (opt.size() == 0) continue; @@ -1133,7 +1133,7 @@ obs_properties_t* ffmpeg_factory::get_properties2(instance_t* data) if (_handler && _handler->has_threading_support(this)) { auto p = obs_properties_add_int_slider(grp, ST_KEY_FFMPEG_THREADS, D_TRANSLATE(ST_I18N_FFMPEG_THREADS), 0, - static_cast(std::thread::hardware_concurrency() * 2), 1); + static_cast(std::thread::hardware_concurrency()) * 2, 1); } }; @@ -1220,9 +1220,9 @@ std::shared_ptr ffmpeg_manager::get_handler(std::string codec) #endif } -bool ffmpeg_manager::has_handler(std::string codec) +bool ffmpeg_manager::has_handler(std::string_view codec) { - return (_handlers.find(codec) != _handlers.end()); + return (_handlers.find(codec.data()) != _handlers.end()); } std::shared_ptr _ffmepg_encoder_factory_instance = nullptr; diff --git a/source/encoders/encoder-ffmpeg.hpp b/source/encoders/encoder-ffmpeg.hpp index ae25553b..33182df1 100644 --- a/source/encoders/encoder-ffmpeg.hpp +++ b/source/encoders/encoder-ffmpeg.hpp @@ -123,7 +123,7 @@ namespace streamfx::encoder::ffmpeg { const AVCodecContext* get_avcodeccontext(); - void parse_ffmpeg_commandline(std::string text); + void parse_ffmpeg_commandline(std::string_view text); }; class ffmpeg_factory : public obs::encoder_factory { @@ -172,7 +172,7 @@ namespace streamfx::encoder::ffmpeg { std::shared_ptr get_handler(std::string codec); - bool has_handler(std::string codec); + bool has_handler(std::string_view codec); public: // Singleton static void initialize(); diff --git a/source/encoders/handlers/dnxhd_handler.cpp b/source/encoders/handlers/dnxhd_handler.cpp index b7d55088..f8c8fd3b 100644 --- a/source/encoders/handlers/dnxhd_handler.cpp +++ b/source/encoders/handlers/dnxhd_handler.cpp @@ -27,7 +27,7 @@ void dnxhd_handler::override_colorformat(AVPixelFormat& target_format, obs_data_ std::pair{"dnxhr_444", AV_PIX_FMT_YUV444P10LE}}; const char* selected_profile = obs_data_get_string(settings, S_CODEC_DNXHR_PROFILE); - for (auto kv : profile_to_format_map) { + for (const auto& kv : profile_to_format_map) { if (strcmp(kv.first, selected_profile) == 0) { target_format = kv.second; return; diff --git a/source/encoders/handlers/nvenc_h264_handler.cpp b/source/encoders/handlers/nvenc_h264_handler.cpp index d395c418..a4ddac33 100644 --- a/source/encoders/handlers/nvenc_h264_handler.cpp +++ b/source/encoders/handlers/nvenc_h264_handler.cpp @@ -94,10 +94,10 @@ void nvenc_h264_handler::update(obs_data_t* settings, const AVCodec* codec, AVCo nvenc::update(settings, codec, context); if (!context->internal) { - if (auto v = obs_data_get_string(settings, ST_KEY_PROFILE); v && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_PROFILE); v && (v[0] != '\0')) { av_opt_set(context->priv_data, "profile", v, AV_OPT_SEARCH_CHILDREN); } - if (auto v = obs_data_get_string(settings, ST_KEY_LEVEL); v && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_LEVEL); v && (v[0] != '\0')) { av_opt_set(context->priv_data, "level", v, AV_OPT_SEARCH_CHILDREN); } } diff --git a/source/encoders/handlers/nvenc_hevc_handler.cpp b/source/encoders/handlers/nvenc_hevc_handler.cpp index 7c8915cd..570f8f26 100644 --- a/source/encoders/handlers/nvenc_hevc_handler.cpp +++ b/source/encoders/handlers/nvenc_hevc_handler.cpp @@ -92,13 +92,13 @@ void nvenc_hevc_handler::update(obs_data_t* settings, const AVCodec* codec, AVCo nvenc::update(settings, codec, context); if (!context->internal) { - if (auto v = obs_data_get_string(settings, ST_KEY_PROFILE); v && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_PROFILE); v && (v[0] != '\0')) { av_opt_set(context->priv_data, "profile", v, AV_OPT_SEARCH_CHILDREN); } - if (auto v = obs_data_get_string(settings, ST_KEY_TIER); v && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_TIER); v && (v[0] != '\0')) { av_opt_set(context->priv_data, "tier", v, AV_OPT_SEARCH_CHILDREN); } - if (auto v = obs_data_get_string(settings, ST_KEY_LEVEL); v && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_LEVEL); v && (v[0] != '\0')) { av_opt_set(context->priv_data, "level", v, AV_OPT_SEARCH_CHILDREN); } } diff --git a/source/encoders/handlers/nvenc_shared.cpp b/source/encoders/handlers/nvenc_shared.cpp index 2f6de97b..a12445b4 100644 --- a/source/encoders/handlers/nvenc_shared.cpp +++ b/source/encoders/handlers/nvenc_shared.cpp @@ -202,12 +202,12 @@ void nvenc::get_defaults(obs_data_t* settings, const AVCodec*, AVCodecContext*) static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept { // Decode the name into useful flags. - auto value = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE); - bool have_bitrate = false; - bool have_bitrate_range = false; - bool have_quality = false; - bool have_qp_limits = false; - bool have_qp = false; + const char* value = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE); + bool have_bitrate = false; + bool have_bitrate_range = false; + bool have_quality = false; + bool have_qp_limits = false; + bool have_qp = false; if (value == std::string_view("cbr")) { have_bitrate = true; } else if (value == std::string_view("vbr")) { @@ -513,14 +513,14 @@ void nvenc::get_runtime_properties(obs_properties_t* props, const AVCodec*, AVCo void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context) { - if (auto v = obs_data_get_string(settings, ST_KEY_PRESET); - !context->internal && (v != nullptr) && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_PRESET); + !context->internal && (v != nullptr) && (v[0] != '\0')) { av_opt_set(context->priv_data, "preset", v, AV_OPT_SEARCH_CHILDREN); } { // Rate Control - auto v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE); - if (!context->internal && (v != nullptr) && (strlen(v) > 0)) { + const char* v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MODE); + if (!context->internal && (v != nullptr) && (v[0] != '\0')) { av_opt_set(context->priv_data, "rc", v, AV_OPT_SEARCH_CHILDREN); } @@ -572,8 +572,8 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c if (!context->internal) { if (streamfx::ffmpeg::tools::avoption_exists(context->priv_data, "multipass")) { // Multi-Pass - if (auto v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MULTIPASS); - (v != nullptr) && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_RATECONTROL_MULTIPASS); + (v != nullptr) && (v[0] != '\0')) { av_opt_set(context->priv_data, "multipass", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "2pass", 0, AV_OPT_SEARCH_CHILDREN); } @@ -717,8 +717,8 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c av_opt_set_int(context->priv_data, "weighted_pred", wp, AV_OPT_SEARCH_CHILDREN); } - if (auto v = obs_data_get_string(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE); - (v != nullptr) && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_OTHER_BFRAMEREFERENCEMODE); + (v != nullptr) && (v[0] != '\0')) { av_opt_set(context->priv_data, "b_ref_mode", v, AV_OPT_SEARCH_CHILDREN); } diff --git a/source/ffmpeg/avframe-queue.cpp b/source/ffmpeg/avframe-queue.cpp index 059e0666..5066a3d9 100644 --- a/source/ffmpeg/avframe-queue.cpp +++ b/source/ffmpeg/avframe-queue.cpp @@ -42,7 +42,7 @@ std::shared_ptr avframe_queue::create_frame() return frame; } -avframe_queue::avframe_queue() {} +avframe_queue::avframe_queue() = default; avframe_queue::~avframe_queue() { diff --git a/source/ffmpeg/hwapi/base.hpp b/source/ffmpeg/hwapi/base.hpp index b49f603f..20ade021 100644 --- a/source/ffmpeg/hwapi/base.hpp +++ b/source/ffmpeg/hwapi/base.hpp @@ -63,7 +63,7 @@ namespace streamfx::ffmpeg::hwapi { virtual std::list enumerate_adapters() = 0; - virtual std::shared_ptr create(hwapi::device target) = 0; + virtual std::shared_ptr create(const hwapi::device& target) = 0; virtual std::shared_ptr create_from_obs() = 0; }; diff --git a/source/ffmpeg/hwapi/d3d11.cpp b/source/ffmpeg/hwapi/d3d11.cpp index 425aec43..d215ff52 100644 --- a/source/ffmpeg/hwapi/d3d11.cpp +++ b/source/ffmpeg/hwapi/d3d11.cpp @@ -102,7 +102,7 @@ std::list d3d11::enumerate_adapters() return std::move(adapters); } -std::shared_ptr d3d11::create(device target) +std::shared_ptr d3d11::create(const device& target) { std::shared_ptr inst; ATL::CComPtr device; @@ -156,10 +156,8 @@ struct D3D11AVFrame { }; d3d11_instance::d3d11_instance(ATL::CComPtr device, ATL::CComPtr context) -{ - _device = device; - _context = context; -} + : _device(device), _context(context) +{} d3d11_instance::~d3d11_instance() {} diff --git a/source/ffmpeg/hwapi/d3d11.hpp b/source/ffmpeg/hwapi/d3d11.hpp index 369a65ff..9a4d136d 100644 --- a/source/ffmpeg/hwapi/d3d11.hpp +++ b/source/ffmpeg/hwapi/d3d11.hpp @@ -57,7 +57,7 @@ namespace streamfx::ffmpeg::hwapi { virtual std::list enumerate_adapters() override; - virtual std::shared_ptr create(hwapi::device target) override; + virtual std::shared_ptr create(const hwapi::device& target) override; virtual std::shared_ptr create_from_obs() override; }; diff --git a/source/ffmpeg/swscale.cpp b/source/ffmpeg/swscale.cpp index 0ab25a0b..73ded2aa 100644 --- a/source/ffmpeg/swscale.cpp +++ b/source/ffmpeg/swscale.cpp @@ -24,7 +24,7 @@ using namespace streamfx::ffmpeg; -swscale::swscale() {} +swscale::swscale() = default; swscale::~swscale() { diff --git a/source/ffmpeg/tools.cpp b/source/ffmpeg/tools.cpp index 4e454177..fc65be42 100644 --- a/source/ffmpeg/tools.cpp +++ b/source/ffmpeg/tools.cpp @@ -357,66 +357,65 @@ const char* tools::get_thread_type_name(int thread_type) } } -void tools::print_av_option_bool(AVCodecContext* ctx_codec, const char* option, std::string text, bool inverse) +void tools::print_av_option_bool(AVCodecContext* ctx_codec, const char* option, std::string_view text, bool inverse) { print_av_option_bool(ctx_codec, ctx_codec, option, text, inverse); } -void tools::print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, +void tools::print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string_view text, bool inverse) { int64_t v = 0; if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { - DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str(), + DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text, streamfx::ffmpeg::tools::get_error_description(err)); } else { - DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(), - (inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled", + DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text, (inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled", av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); } } -void tools::print_av_option_int(AVCodecContext* ctx_codec, const char* option, std::string text, std::string suffix) +void tools::print_av_option_int(AVCodecContext* ctx_codec, const char* option, std::string_view text, + std::string_view suffix) { print_av_option_int(ctx_codec, ctx_codec, option, text, suffix); } -void tools::print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, - std::string suffix) +void tools::print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string_view text, + std::string_view suffix) { int64_t v = 0; bool is_default = av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0; if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { if (is_default) { - DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str()); + DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text); } else { - DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str(), + DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text, streamfx::ffmpeg::tools::get_error_description(err)); } } else { - DLOG_INFO("[%s] %s: %" PRId64 " %s%s", ctx_codec->codec->name, text.c_str(), v, suffix.c_str(), - is_default ? " " : ""); + DLOG_INFO("[%s] %s: %" PRId64 " %s%s", ctx_codec->codec->name, text, v, suffix, is_default ? " " : ""); } } -void tools::print_av_option_string(AVCodecContext* ctx_codec, const char* option, std::string text, +void tools::print_av_option_string(AVCodecContext* ctx_codec, const char* option, std::string_view text, std::function decoder) { print_av_option_string(ctx_codec, ctx_codec, option, text, decoder); } -void tools::print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, - std::function decoder) +void tools::print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, const char* option, + std::string_view text, std::function decoder) { int64_t v = 0; if (int err = av_opt_get_int(ctx_option, option, AV_OPT_SEARCH_CHILDREN, &v); err != 0) { - DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str(), + DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text, streamfx::ffmpeg::tools::get_error_description(err)); } else { std::string name = ""; if (decoder) name = decoder(v); - DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text.c_str(), name.c_str(), + DLOG_INFO("[%s] %s: %s%s", ctx_codec->codec->name, text, name.c_str(), av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); } } diff --git a/source/ffmpeg/tools.hpp b/source/ffmpeg/tools.hpp index 584dc7a1..edc1465e 100644 --- a/source/ffmpeg/tools.hpp +++ b/source/ffmpeg/tools.hpp @@ -63,17 +63,18 @@ namespace streamfx::ffmpeg::tools { const char* get_thread_type_name(int thread_type); - void print_av_option_bool(AVCodecContext* context, const char* option, std::string text, bool inverse = false); - void print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, + void print_av_option_bool(AVCodecContext* context, const char* option, std::string_view text, bool inverse = false); + void print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string_view text, bool inverse = false); - void print_av_option_int(AVCodecContext* context, const char* option, std::string text, std::string suffix); - void print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, - std::string suffix); + void print_av_option_int(AVCodecContext* context, const char* option, std::string_view text, + std::string_view suffix); + void print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string_view text, + std::string_view suffix); - void print_av_option_string(AVCodecContext* context, const char* option, std::string text, + void print_av_option_string(AVCodecContext* context, const char* option, std::string_view text, std::function decoder); - void print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string text, + void print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, const char* option, std::string_view text, std::function decoder); void print_av_option_string2(AVCodecContext* context, std::string_view option, std::string_view text, diff --git a/source/filters/filter-autoframing.cpp b/source/filters/filter-autoframing.cpp index 5150c454..e7cde0d6 100644 --- a/source/filters/filter-autoframing.cpp +++ b/source/filters/filter-autoframing.cpp @@ -246,7 +246,7 @@ void autoframing_instance::update(obs_data_t* data) // Tracking _track_mode = static_cast(obs_data_get_int(data, ST_KEY_TRACKING_MODE)); { - if (auto text = obs_data_get_string(data, ST_KEY_TRACKING_FREQUENCY); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_TRACKING_FREQUENCY); text != nullptr) { float value = 0.; if (sscanf(text, "%f", &value) == 1) { if (const char* seconds = strchr(text, 's'); seconds == nullptr) { @@ -284,7 +284,7 @@ void autoframing_instance::update(obs_data_t* data) _frame_size_y = {_frame_stability_kalman, 1.0f, ST_KALMAN_EEC, _frame_size_y.get()}; } { // Padding - if (auto text = obs_data_get_string(data, ST_KEY_FRAMING_PADDING ".X"); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_FRAMING_PADDING ".X"); text != nullptr) { float value = 0.; if (sscanf(text, "%f", &value) == 1) { if (const char* percent = strchr(text, '%'); percent != nullptr) { @@ -297,7 +297,7 @@ void autoframing_instance::update(obs_data_t* data) } _frame_padding.x = value; } - if (auto text = obs_data_get_string(data, ST_KEY_FRAMING_PADDING ".Y"); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_FRAMING_PADDING ".Y"); text != nullptr) { float value = 0.; if (sscanf(text, "%f", &value) == 1) { if (const char* percent = strchr(text, '%'); percent != nullptr) { @@ -312,7 +312,7 @@ void autoframing_instance::update(obs_data_t* data) } } { // Offset - if (auto text = obs_data_get_string(data, ST_KEY_FRAMING_OFFSET ".X"); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_FRAMING_OFFSET ".X"); text != nullptr) { float value = 0.; if (sscanf(text, "%f", &value) == 1) { if (const char* percent = strchr(text, '%'); percent != nullptr) { @@ -325,7 +325,7 @@ void autoframing_instance::update(obs_data_t* data) } _frame_offset.x = value; } - if (auto text = obs_data_get_string(data, ST_KEY_FRAMING_OFFSET ".Y"); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_FRAMING_OFFSET ".Y"); text != nullptr) { float value = 0.; if (sscanf(text, "%f", &value) == 1) { if (const char* percent = strchr(text, '%'); percent != nullptr) { @@ -341,7 +341,7 @@ void autoframing_instance::update(obs_data_t* data) } { // Aspect Ratio _frame_aspect_ratio = static_cast(_size.first) / static_cast(_size.second); - if (auto text = obs_data_get_string(data, ST_KEY_FRAMING_ASPECTRATIO); text != nullptr) { + if (const char* text = obs_data_get_string(data, ST_KEY_FRAMING_ASPECTRATIO); text != nullptr) { if (const char* percent = strchr(text, ':'); percent != nullptr) { float left = 0.; float right = 0.; @@ -479,7 +479,7 @@ void autoframing_instance::video_render(gs_effect_t* effect) auto op = _input->render(width, height); // Set correct projection matrix. - gs_ortho(0, width, 0, height, 0, 1); + gs_ortho(0, static_cast(width), 0, static_cast(height), 0, 1); // Clear the buffer gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &blank, 0, 0); @@ -982,7 +982,7 @@ void streamfx::filter::autoframing::autoframing_instance::nvar_facedetection_pro // Try and find a match in the current list of tracked elements. std::shared_ptr match; float match_dst = max_dst; - for (auto el : _tracked_elements) { + for (const auto& el : _tracked_elements) { // Skip "fresh" elements. if (el->age < 0.00001) { continue; diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index 64a28f86..a89fe79d 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -95,7 +95,7 @@ void displacement_instance::update(obs_data_t* settings) _scale[0] = _scale[1] = static_cast(obs_data_get_double(settings, ST_KEY_SCALE)); _scale_type = static_cast(obs_data_get_double(settings, ST_KEY_SCALE_TYPE) / 100.0); - std::string new_file = obs_data_get_string(settings, ST_KEY_FILE); + const char* new_file = obs_data_get_string(settings, ST_KEY_FILE); if (new_file != _texture_file) { try { _texture = std::make_shared(new_file); diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 7bad5bfb..df674e1a 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -112,7 +112,7 @@ void dynamic_mask_instance::migrate(obs_data_t* data, uint64_t version) {} void dynamic_mask_instance::update(obs_data_t* settings) { // Update source. - if (auto v = obs_data_get_string(settings, ST_KEY_INPUT); (v != nullptr) && (strlen(v) > 0)) { + if (const char* v = obs_data_get_string(settings, ST_KEY_INPUT); (v != nullptr) && (v[0] != '\0')) { if (!acquire(v)) DLOG_ERROR("Failed to acquire Input source '%s'.", v); } else { diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index d06f655b..e8b3be4a 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -705,7 +705,7 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) {ST_KEY_POSITION_Y, "Y"}, {ST_KEY_POSITION_Z, "Z"}, }; - for (auto opt : opts) { + for (const auto& opt : opts) { auto p = obs_properties_add_float(grp, opt.first.c_str(), D_TRANSLATE(opt.second.c_str()), std::numeric_limits::lowest(), std::numeric_limits::max(), 0.01); @@ -721,7 +721,7 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) {ST_KEY_ROTATION_Y, D_TRANSLATE(ST_I18N_ROTATION ".Y")}, {ST_KEY_ROTATION_Z, D_TRANSLATE(ST_I18N_ROTATION ".Z")}, }; - for (auto opt : opts) { + for (const auto& opt : opts) { auto p = obs_properties_add_float_slider(grp, opt.first.c_str(), D_TRANSLATE(opt.second.c_str()), -180.0, 180.0, 0.01); obs_property_float_set_suffix(p, "° Deg"); @@ -736,7 +736,7 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) {ST_KEY_SCALE_X, "X"}, {ST_KEY_SCALE_Y, "Y"}, }; - for (auto opt : opts) { + for (const auto& opt : opts) { auto p = obs_properties_add_float_slider(grp, opt.first.c_str(), opt.second.c_str(), -1000, 1000, 0.01); obs_property_float_set_suffix(p, "%"); } @@ -750,7 +750,7 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) {ST_KEY_SHEAR_X, "X"}, {ST_KEY_SHEAR_Y, "Y"}, }; - for (auto opt : opts) { + for (const auto& opt : opts) { auto p = obs_properties_add_float_slider(grp, opt.first.c_str(), opt.second.c_str(), -200.0, 200.0, 0.01); obs_property_float_set_suffix(p, "%"); diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index c6ef7d92..a9c762ff 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -66,7 +66,6 @@ bool streamfx::gfx::blur::box_linear_factory::is_type_supported(::streamfx::gfx: { switch (type) { case ::streamfx::gfx::blur::type::Area: - return true; case ::streamfx::gfx::blur::type::Directional: return true; default: @@ -199,7 +198,7 @@ streamfx::gfx::blur::box_linear::~box_linear() {} void streamfx::gfx::blur::box_linear::set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) { - _input_texture = texture; + _input_texture = std::move(texture); } ::streamfx::gfx::blur::type streamfx::gfx::blur::box_linear::get_type() diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index 40dd554e..9a223604 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -208,7 +208,7 @@ streamfx::gfx::blur::box::~box() {} void streamfx::gfx::blur::box::set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) { - _input_texture = texture; + _input_texture = std::move(texture); } ::streamfx::gfx::blur::type streamfx::gfx::blur::box::get_type() diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index d56d26ca..6cddb3ec 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -202,7 +202,7 @@ streamfx::gfx::blur::dual_filtering::~dual_filtering() {} void streamfx::gfx::blur::dual_filtering::set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) { - _input_texture = texture; + _input_texture = std::move(texture); } ::streamfx::gfx::blur::type streamfx::gfx::blur::dual_filtering::get_type() diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index fe266cfd..0ca35ffc 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -115,7 +115,6 @@ bool streamfx::gfx::blur::gaussian_linear_factory::is_type_supported(::streamfx: { switch (v) { case ::streamfx::gfx::blur::type::Area: - return true; case ::streamfx::gfx::blur::type::Directional: return true; default: @@ -251,7 +250,7 @@ streamfx::gfx::blur::gaussian_linear::~gaussian_linear() {} void streamfx::gfx::blur::gaussian_linear::set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) { - _input_texture = texture; + _input_texture = std::move(texture); } ::streamfx::gfx::blur::type streamfx::gfx::blur::gaussian_linear::get_type() diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index e705c4f1..b295166e 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -41,8 +41,8 @@ streamfx::gfx::blur::gaussian_data::gaussian_data() { using namespace streamfx::util; - std::vector kernel_dbl(ST_KERNEL_SIZE); - std::vector kernel(ST_KERNEL_SIZE); + std::array kernel_dbl; + std::vector kernel(ST_KERNEL_SIZE); { auto gctx = streamfx::obs::gs::context(); @@ -277,7 +277,7 @@ streamfx::gfx::blur::gaussian::~gaussian() {} void streamfx::gfx::blur::gaussian::set_input(std::shared_ptr<::streamfx::obs::gs::texture> texture) { - _input_texture = texture; + _input_texture = std::move(texture); } ::streamfx::gfx::blur::type streamfx::gfx::blur::gaussian::get_type() diff --git a/source/gfx/gfx-debug.cpp b/source/gfx/gfx-debug.cpp index ca23a54b..5ce77d3a 100644 --- a/source/gfx/gfx-debug.cpp +++ b/source/gfx/gfx-debug.cpp @@ -139,7 +139,7 @@ void streamfx::gfx::debug::draw_arrow(float x, float y, float x2, float y2, floa float len = sqrt(dx * dx + dy * dy); if (abs(w) <= 1) { - w = len / 3.; + w = len / 3.f; } matrix4 rotator; diff --git a/source/gfx/lut/gfx-lut-consumer.cpp b/source/gfx/lut/gfx-lut-consumer.cpp index 56a1f74d..54f8d685 100644 --- a/source/gfx/lut/gfx-lut-consumer.cpp +++ b/source/gfx/lut/gfx-lut-consumer.cpp @@ -29,7 +29,7 @@ streamfx::gfx::lut::consumer::consumer() throw std::runtime_error("Unable to get LUT consumer effect."); } -streamfx::gfx::lut::consumer::~consumer() {} +streamfx::gfx::lut::consumer::~consumer() = default; std::shared_ptr streamfx::gfx::lut::consumer::prepare(streamfx::gfx::lut::color_depth depth, diff --git a/source/gfx/lut/gfx-lut-producer.cpp b/source/gfx/lut/gfx-lut-producer.cpp index 0e8ddbd5..99bf7ec8 100644 --- a/source/gfx/lut/gfx-lut-producer.cpp +++ b/source/gfx/lut/gfx-lut-producer.cpp @@ -47,7 +47,7 @@ streamfx::gfx::lut::producer::producer() throw std::runtime_error("Unable to get LUT producer effect."); } -streamfx::gfx::lut::producer::~producer() {} +streamfx::gfx::lut::producer::~producer() = default; std::shared_ptr streamfx::gfx::lut::producer::produce(streamfx::gfx::lut::color_depth depth) { diff --git a/source/gfx/shader/gfx-shader-param-basic.cpp b/source/gfx/shader/gfx-shader-param-basic.cpp index df03c46e..2b0e42af 100644 --- a/source/gfx/shader/gfx-shader-param-basic.cpp +++ b/source/gfx/shader/gfx-shader-param-basic.cpp @@ -31,7 +31,8 @@ static const std::string_view _annotation_scale = "scale"; static const std::string_view _annotation_enum_entry = "enum_%zu"; static const std::string_view _annotation_enum_entry_name = "enum_%zu_name"; -inline bool get_annotation_string(streamfx::obs::gs::effect_parameter param, std::string anno_name, std::string& out) +inline bool get_annotation_string(streamfx::obs::gs::effect_parameter param, std::string_view anno_name, + std::string& out) { if (!param) return false; @@ -46,7 +47,7 @@ inline bool get_annotation_string(streamfx::obs::gs::effect_parameter param, std return false; } -inline bool get_annotation_float(streamfx::obs::gs::effect_parameter param, std::string anno_name, float_t& out) +inline bool get_annotation_float(streamfx::obs::gs::effect_parameter param, std::string_view anno_name, float_t& out) { if (!param) { return false; @@ -60,7 +61,7 @@ inline bool get_annotation_float(streamfx::obs::gs::effect_parameter param, std: return false; } -streamfx::gfx::shader::basic_field_type streamfx::gfx::shader::get_field_type_from_string(std::string v) +streamfx::gfx::shader::basic_field_type streamfx::gfx::shader::get_field_type_from_string(std::string_view v) { std::map matches = { {"input", basic_field_type::Input}, @@ -69,7 +70,7 @@ streamfx::gfx::shader::basic_field_type streamfx::gfx::shader::get_field_type_fr {"enumeration", basic_field_type::Enum}, }; - auto fnd = matches.find(v); + auto fnd = matches.find(v.data()); if (fnd != matches.end()) return fnd->second; diff --git a/source/gfx/shader/gfx-shader-param-basic.hpp b/source/gfx/shader/gfx-shader-param-basic.hpp index 982282f4..0a8e0ee6 100644 --- a/source/gfx/shader/gfx-shader-param-basic.hpp +++ b/source/gfx/shader/gfx-shader-param-basic.hpp @@ -29,7 +29,7 @@ namespace streamfx::gfx { Enum, }; - basic_field_type get_field_type_from_string(std::string v); + basic_field_type get_field_type_from_string(std::string_view v); struct basic_data { union { diff --git a/source/gfx/shader/gfx-shader-param-texture.cpp b/source/gfx/shader/gfx-shader-param-texture.cpp index e52b169d..d0bd8b85 100644 --- a/source/gfx/shader/gfx-shader-param-texture.cpp +++ b/source/gfx/shader/gfx-shader-param-texture.cpp @@ -52,7 +52,7 @@ static constexpr std::string_view _annotation_default = "default"; static constexpr std::string_view _annotation_enum_entry = "enum_%zu"; static constexpr std::string_view _annotation_enum_entry_name = "enum_%zu_name"; -streamfx::gfx::shader::texture_field_type streamfx::gfx::shader::get_texture_field_type_from_string(std::string v) +streamfx::gfx::shader::texture_field_type streamfx::gfx::shader::get_texture_field_type_from_string(std::string_view v) { std::map matches = { {"input", texture_field_type::Input}, @@ -60,7 +60,7 @@ streamfx::gfx::shader::texture_field_type streamfx::gfx::shader::get_texture_fie {"enumeration", texture_field_type::Enum}, }; - auto fnd = matches.find(v); + auto fnd = matches.find(v.data()); if (fnd != matches.end()) return fnd->second; @@ -82,15 +82,15 @@ streamfx::gfx::shader::texture_parameter::texture_parameter(streamfx::gfx::shade _keys.reserve(3); { // Type snprintf(string_buffer, sizeof(string_buffer), "%s%s", get_key().data(), ST_KEY_TYPE); - _keys.push_back(std::string(string_buffer)); + _keys.emplace_back(string_buffer); } { // File snprintf(string_buffer, sizeof(string_buffer), "%s%s", get_key().data(), ST_KEY_FILE); - _keys.push_back(std::string(string_buffer)); + _keys.emplace_back(string_buffer); } { // Source snprintf(string_buffer, sizeof(string_buffer), "%s%s", get_key().data(), ST_KEY_SOURCE); - _keys.push_back(std::string(string_buffer)); + _keys.emplace_back(string_buffer); } } @@ -233,9 +233,8 @@ void streamfx::gfx::shader::texture_parameter::properties(obs_properties_t* prop } } -std::filesystem::path make_absolute_to(std::filesystem::path origin, std::filesystem::path destination) +std::filesystem::path make_absolute_to(const std::filesystem::path& origin, const std::filesystem::path& destination) { - auto destination_dir = std::filesystem::absolute(destination.remove_filename()); return std::filesystem::absolute(destination / origin); } @@ -263,7 +262,7 @@ void streamfx::gfx::shader::texture_parameter::update(obs_data_t* settings) _dirty_ts = std::chrono::high_resolution_clock::now() - std::chrono::milliseconds(1); } } else if (_type == texture_type::Source) { - auto source_name = obs_data_get_string(settings, _keys[2].c_str()); + const char* source_name = obs_data_get_string(settings, _keys[2].c_str()); if (_source_name != source_name) { _source_name = source_name; @@ -321,14 +320,14 @@ void streamfx::gfx::shader::texture_parameter::assign() // Propagate all of this into the storage. _source_rendertarget = rt; - _source_visible = visible; - _source_active = active; + _source_visible = std::move(visible); + _source_active = std::move(active); _source_child = child; - _source = source; + _source = std::move(source); } _dirty = false; - } catch (const std::exception& ex) { + } catch (const std::exception&) { _dirty_ts = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(5000); } catch (...) { _dirty_ts = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(5000); diff --git a/source/gfx/shader/gfx-shader-param-texture.hpp b/source/gfx/shader/gfx-shader-param-texture.hpp index 7491efb1..7a886aa9 100644 --- a/source/gfx/shader/gfx-shader-param-texture.hpp +++ b/source/gfx/shader/gfx-shader-param-texture.hpp @@ -19,7 +19,7 @@ namespace streamfx::gfx { Enum, }; - texture_field_type get_texture_field_type_from_string(std::string v); + texture_field_type get_texture_field_type_from_string(std::string_view v); enum class texture_type { File, diff --git a/source/gfx/shader/gfx-shader-param.cpp b/source/gfx/shader/gfx-shader-param.cpp index ef4fcb5b..620b99e7 100644 --- a/source/gfx/shader/gfx-shader-param.cpp +++ b/source/gfx/shader/gfx-shader-param.cpp @@ -84,7 +84,7 @@ std::size_t streamfx::gfx::shader::get_length_from_effect_type(streamfx::obs::gs } } -streamfx::gfx::shader::parameter_type streamfx::gfx::shader::get_type_from_string(std::string v) +streamfx::gfx::shader::parameter_type streamfx::gfx::shader::get_type_from_string(std::string_view v) { if ((v == "bool") || (v == "boolean")) { return parameter_type::Boolean; @@ -139,7 +139,7 @@ streamfx::gfx::shader::parameter::parameter(streamfx::gfx::shader::shader* // Read Name if (auto anno = _param.get_annotation(ST_ANNO_NAME); anno) { if (std::string v = anno.get_default_string(); v.length() > 0) { - _name = v; + _name = std::move(v); } else { throw std::out_of_range("'" ST_ANNO_NAME "' annotation has zero length."); } @@ -148,7 +148,7 @@ streamfx::gfx::shader::parameter::parameter(streamfx::gfx::shader::shader* // Read Description if (auto anno = _param.get_annotation(ST_ANNO_DESCRIPTION); anno) { if (std::string v = anno.get_default_string(); v.length() > 0) { - _description = v; + _description = std::move(v); } else { throw std::out_of_range("'" ST_ANNO_DESCRIPTION "' annotation has zero length."); } diff --git a/source/gfx/shader/gfx-shader-param.hpp b/source/gfx/shader/gfx-shader-param.hpp index 7bc47850..5561aefc 100644 --- a/source/gfx/shader/gfx-shader-param.hpp +++ b/source/gfx/shader/gfx-shader-param.hpp @@ -45,7 +45,7 @@ namespace streamfx::gfx { std::size_t get_length_from_effect_type(streamfx::obs::gs::effect_parameter::type type); - parameter_type get_type_from_string(std::string v); + parameter_type get_type_from_string(std::string_view v); class parameter { // Parent Shader diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index eb079149..75c3ae3f 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -62,7 +62,7 @@ streamfx::gfx::shader::shader::shader(obs_source_t* self, shader_mode mode) } } -streamfx::gfx::shader::shader::~shader() {} +streamfx::gfx::shader::shader::~shader() = default; bool streamfx::gfx::shader::shader::is_shader_different(const std::filesystem::path& file) try { @@ -88,7 +88,7 @@ try { return false; } -bool streamfx::gfx::shader::shader::is_technique_different(const std::string& tech) +bool streamfx::gfx::shader::shader::is_technique_different(std::string_view tech) { // Is the technique different? if (tech != _shader_tech) @@ -97,7 +97,7 @@ bool streamfx::gfx::shader::shader::is_technique_different(const std::string& te return false; } -bool streamfx::gfx::shader::shader::load_shader(const std::filesystem::path& file, const std::string& tech, +bool streamfx::gfx::shader::shader::load_shader(const std::filesystem::path& file, std::string_view tech, bool& shader_dirty, bool& param_dirty) try { if (!std::filesystem::exists(file)) diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index 5b55643f..b90d1e62 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -84,9 +84,9 @@ namespace streamfx::gfx { bool is_shader_different(const std::filesystem::path& file); - bool is_technique_different(const std::string& tech); + bool is_technique_different(std::string_view tech); - bool load_shader(const std::filesystem::path& file, const std::string& tech, bool& shader_dirty, + bool load_shader(const std::filesystem::path& file, std::string_view tech, bool& shader_dirty, bool& param_dirty); static void defaults(obs_data_t* data); diff --git a/source/nvidia/ar/nvidia-ar-facedetection.cpp b/source/nvidia/ar/nvidia-ar-facedetection.cpp index b5822dbf..a27ca897 100644 --- a/source/nvidia/ar/nvidia-ar-facedetection.cpp +++ b/source/nvidia/ar/nvidia-ar-facedetection.cpp @@ -92,7 +92,7 @@ void ar::facedetection::set_tracking_limit(size_t v) // Update bounding boxes structure. _bboxes.rects = _rects.data(); - _bboxes.maximum = v; + _bboxes.maximum = static_cast(v); _bboxes.current = 0; // Update feature. diff --git a/source/nvidia/cuda/nvidia-cuda-context.hpp b/source/nvidia/cuda/nvidia-cuda-context.hpp index cfe1f59b..e231488f 100644 --- a/source/nvidia/cuda/nvidia-cuda-context.hpp +++ b/source/nvidia/cuda/nvidia-cuda-context.hpp @@ -60,7 +60,7 @@ namespace streamfx::nvidia::cuda { { _ctx->pop(); } - inline context_stack(std::shared_ptr<::streamfx::nvidia::cuda::context> ctx) : _ctx(ctx) + inline context_stack(std::shared_ptr<::streamfx::nvidia::cuda::context> ctx) : _ctx(std::move(ctx)) { _ctx->push(); } diff --git a/source/nvidia/cuda/nvidia-cuda-gs-texture.cpp b/source/nvidia/cuda/nvidia-cuda-gs-texture.cpp index 3fc8536c..e3dac4b7 100644 --- a/source/nvidia/cuda/nvidia-cuda-gs-texture.cpp +++ b/source/nvidia/cuda/nvidia-cuda-gs-texture.cpp @@ -62,14 +62,11 @@ streamfx::nvidia::cuda::gstexture::gstexture(std::shared_ptrget_type()) { case streamfx::obs::gs::texture::type::Cube: + case streamfx::obs::gs::texture::type::Volume: case streamfx::obs::gs::texture::type::Normal: { resource = static_cast(gs_texture_get_obj(_texture->get_object())); break; } - case streamfx::obs::gs::texture::type::Volume: { - resource = static_cast(gs_texture_get_obj(_texture->get_object())); - break; - } } if (!resource) { @@ -101,7 +98,7 @@ streamfx::nvidia::cuda::array_t throw std::runtime_error("nvidia::cuda::gstexture: Mapping failed."); } - _stream = stream; + _stream = std::move(stream); _is_mapped = true; switch (_cuda->cuGraphicsSubResourceGetMappedArray(&_pointer, _resource, 0, 0)) { diff --git a/source/nvidia/cv/nvidia-cv.hpp b/source/nvidia/cv/nvidia-cv.hpp index 84f6c995..51689418 100644 --- a/source/nvidia/cv/nvidia-cv.hpp +++ b/source/nvidia/cv/nvidia-cv.hpp @@ -293,7 +293,7 @@ namespace streamfx::nvidia::cv { public: exception(const char* what, result code) : std::runtime_error(what), _code(code) {} - exception(const std::string& what, result code) : std::runtime_error(what), _code(code) {} + exception(std::string_view what, result code) : std::runtime_error(what.data()), _code(code) {} ~exception(){}; inline result code() diff --git a/source/nvidia/vfx/nvidia-vfx-superresolution.cpp b/source/nvidia/vfx/nvidia-vfx-superresolution.cpp index dc487d9f..c2023123 100644 --- a/source/nvidia/vfx/nvidia-vfx-superresolution.cpp +++ b/source/nvidia/vfx/nvidia-vfx-superresolution.cpp @@ -134,7 +134,7 @@ void streamfx::nvidia::vfx::superresolution::set_scale(float scale) scale = std::clamp(scale, 1., 4.); // Match to nearest scale. - double factor = find_closest_scale_factor(scale); + float factor = static_cast(find_closest_scale_factor(scale)); // If anything was changed, flag the effect as dirty. if (!::streamfx::util::math::is_close(_scale, factor, 0.01f)) diff --git a/source/obs/gs/gs-effect-parameter.cpp b/source/obs/gs/gs-effect-parameter.cpp index 8556d93a..49155f75 100644 --- a/source/obs/gs/gs-effect-parameter.cpp +++ b/source/obs/gs/gs-effect-parameter.cpp @@ -48,22 +48,22 @@ streamfx::obs::gs::effect_parameter::effect_parameter(gs_eparam_t* param) streamfx::obs::gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr parent) : effect_parameter(param) { - _effect_parent = parent; + _effect_parent = std::move(parent); } streamfx::obs::gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr parent) : effect_parameter(param) { - _pass_parent = parent; + _pass_parent = std::move(parent); } streamfx::obs::gs::effect_parameter::effect_parameter(gs_eparam_t* param, std::shared_ptr parent) : effect_parameter(param) { - _param_parent = parent; + _param_parent = std::move(parent); } -streamfx::obs::gs::effect_parameter::~effect_parameter() {} +streamfx::obs::gs::effect_parameter::~effect_parameter() = default; streamfx::obs::gs::effect_parameter::effect_parameter(const effect_parameter& rhs) { @@ -694,7 +694,7 @@ void streamfx::obs::gs::effect_parameter::get_string(std::string& v) v = std::string(reinterpret_cast(ptr), reinterpret_cast(ptr) + ptr_len - 1); bfree(ptr); } else { - v = ""; + v.clear(); } } @@ -708,6 +708,6 @@ void streamfx::obs::gs::effect_parameter::get_default_string(std::string& v) v = std::string(reinterpret_cast(ptr), reinterpret_cast(ptr) + ptr_len - 1); bfree(ptr); } else { - v = ""; + v.clear(); } } diff --git a/source/obs/gs/gs-effect-pass.cpp b/source/obs/gs/gs-effect-pass.cpp index 46f44ef8..4d81ab82 100644 --- a/source/obs/gs/gs-effect-pass.cpp +++ b/source/obs/gs/gs-effect-pass.cpp @@ -36,7 +36,7 @@ streamfx::obs::gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptrvertshader_params.array + idx)->eparam, *this); } -streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_vertex_parameter(std::string name) +streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_vertex_parameter(std::string_view name) { for (std::size_t idx = 0; idx < count_vertex_parameters(); idx++) { auto ptr = get()->vertshader_params.array + idx; - if (strcmp(ptr->eparam->name, name.c_str()) == 0) + if (strcmp(ptr->eparam->name, name.data()) == 0) return streamfx::obs::gs::effect_parameter(ptr->eparam, *this); } return nullptr; } -bool streamfx::obs::gs::effect_pass::has_vertex_parameter(std::string name) +bool streamfx::obs::gs::effect_pass::has_vertex_parameter(std::string_view name) { return (get_vertex_parameter(name) != nullptr); } -bool streamfx::obs::gs::effect_pass::has_vertex_parameter(std::string name, +bool streamfx::obs::gs::effect_pass::has_vertex_parameter(std::string_view name, streamfx::obs::gs::effect_parameter::type type) { if (auto el = get_vertex_parameter(name); el != nullptr) { @@ -95,22 +95,22 @@ streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_pixel_pa return streamfx::obs::gs::effect_parameter((get()->pixelshader_params.array + idx)->eparam, *this); } -streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_pixel_parameter(std::string name) +streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_pixel_parameter(std::string_view name) { for (std::size_t idx = 0; idx < count_pixel_parameters(); idx++) { auto ptr = get()->pixelshader_params.array + idx; - if (strcmp(ptr->eparam->name, name.c_str()) == 0) + if (strcmp(ptr->eparam->name, name.data()) == 0) return streamfx::obs::gs::effect_parameter(ptr->eparam, *this); } return nullptr; } -bool streamfx::obs::gs::effect_pass::has_pixel_parameter(std::string name) +bool streamfx::obs::gs::effect_pass::has_pixel_parameter(std::string_view name) { return (get_pixel_parameter(name) != nullptr); } -bool streamfx::obs::gs::effect_pass::has_pixel_parameter(std::string name, +bool streamfx::obs::gs::effect_pass::has_pixel_parameter(std::string_view name, streamfx::obs::gs::effect_parameter::type type) { if (auto el = get_pixel_parameter(name); el != nullptr) { diff --git a/source/obs/gs/gs-effect-pass.hpp b/source/obs/gs/gs-effect-pass.hpp index 8d69a4df..62e5bac8 100644 --- a/source/obs/gs/gs-effect-pass.hpp +++ b/source/obs/gs/gs-effect-pass.hpp @@ -37,14 +37,14 @@ namespace streamfx::obs::gs { std::size_t count_vertex_parameters(); streamfx::obs::gs::effect_parameter get_vertex_parameter(std::size_t idx); - streamfx::obs::gs::effect_parameter get_vertex_parameter(std::string name); - bool has_vertex_parameter(std::string name); - bool has_vertex_parameter(std::string name, streamfx::obs::gs::effect_parameter::type type); + streamfx::obs::gs::effect_parameter get_vertex_parameter(std::string_view name); + bool has_vertex_parameter(std::string_view name); + bool has_vertex_parameter(std::string_view name, streamfx::obs::gs::effect_parameter::type type); std::size_t count_pixel_parameters(); streamfx::obs::gs::effect_parameter get_pixel_parameter(std::size_t idx); - streamfx::obs::gs::effect_parameter get_pixel_parameter(std::string name); - bool has_pixel_parameter(std::string name); - bool has_pixel_parameter(std::string name, streamfx::obs::gs::effect_parameter::type type); + streamfx::obs::gs::effect_parameter get_pixel_parameter(std::string_view name); + bool has_pixel_parameter(std::string_view name); + bool has_pixel_parameter(std::string_view name, streamfx::obs::gs::effect_parameter::type type); }; } // namespace streamfx::obs::gs diff --git a/source/obs/gs/gs-effect-technique.cpp b/source/obs/gs/gs-effect-technique.cpp index 8304e127..bd085511 100644 --- a/source/obs/gs/gs-effect-technique.cpp +++ b/source/obs/gs/gs-effect-technique.cpp @@ -38,7 +38,7 @@ streamfx::obs::gs::effect_technique::effect_technique(gs_technique_t* technique, reset(technique, [](void*) {}); } -streamfx::obs::gs::effect_technique::~effect_technique() {} +streamfx::obs::gs::effect_technique::~effect_technique() = default; std::string streamfx::obs::gs::effect_technique::name() { @@ -61,18 +61,18 @@ streamfx::obs::gs::effect_pass streamfx::obs::gs::effect_technique::get_pass(std return streamfx::obs::gs::effect_pass(get()->passes.array + idx, *this); } -streamfx::obs::gs::effect_pass streamfx::obs::gs::effect_technique::get_pass(std::string name) +streamfx::obs::gs::effect_pass streamfx::obs::gs::effect_technique::get_pass(std::string_view name) { for (std::size_t idx = 0; idx < get()->passes.num; idx++) { auto ptr = get()->passes.array + idx; - if (strcmp(ptr->name, name.c_str()) == 0) + if (strcmp(ptr->name, name.data()) == 0) return streamfx::obs::gs::effect_pass(ptr, *this); } return nullptr; } -bool streamfx::obs::gs::effect_technique::has_pass(std::string name) +bool streamfx::obs::gs::effect_technique::has_pass(std::string_view name) { if (get_pass(name) != nullptr) return true; diff --git a/source/obs/gs/gs-effect-technique.hpp b/source/obs/gs/gs-effect-technique.hpp index fafee067..791a0108 100644 --- a/source/obs/gs/gs-effect-technique.hpp +++ b/source/obs/gs/gs-effect-technique.hpp @@ -33,7 +33,7 @@ namespace streamfx::obs::gs { std::size_t count_passes(); streamfx::obs::gs::effect_pass get_pass(std::size_t idx); - streamfx::obs::gs::effect_pass get_pass(std::string name); - bool has_pass(std::string name); + streamfx::obs::gs::effect_pass get_pass(std::string_view name); + bool has_pass(std::string_view name); }; } // namespace streamfx::obs::gs diff --git a/source/obs/gs/gs-effect.cpp b/source/obs/gs/gs-effect.cpp index d7d7d568..8c8d81ae 100644 --- a/source/obs/gs/gs-effect.cpp +++ b/source/obs/gs/gs-effect.cpp @@ -27,11 +27,11 @@ #define MAX_EFFECT_SIZE 32 * 1024 * 1024 // 32 MiB, big enough for everything. -static std::string load_file_as_code(std::filesystem::path shader_file, bool is_top_level = true) +static std::string load_file_as_code(const std::filesystem::path& shader_file, bool is_top_level = true) { - std::stringstream shader_stream; - std::filesystem::path shader_path = std::filesystem::absolute(shader_file); - std::filesystem::path shader_root = std::filesystem::path(shader_path).remove_filename(); + std::stringstream shader_stream; + const std::filesystem::path& shader_path = std::filesystem::absolute(shader_file); + const std::filesystem::path& shader_root = std::filesystem::path(shader_path).remove_filename(); // Ensure it meets size limits. uintmax_t size = std::filesystem::file_size(shader_path); @@ -96,12 +96,12 @@ static std::string load_file_as_code(std::filesystem::path shader_file, bool is_ return shader_stream.str(); } -streamfx::obs::gs::effect::effect(const std::string& code, const std::string& name) +streamfx::obs::gs::effect::effect(std::string_view code, std::string_view name) { auto gctx = streamfx::obs::gs::context(); char* error_buffer = nullptr; - gs_effect_t* effect = gs_effect_create(code.c_str(), name.c_str(), &error_buffer); + gs_effect_t* effect = gs_effect_create(code.data(), name.data(), &error_buffer); if (!effect) { throw error_buffer ? std::runtime_error(error_buffer) @@ -136,11 +136,11 @@ streamfx::obs::gs::effect_technique streamfx::obs::gs::effect::get_technique(std return streamfx::obs::gs::effect_technique(get()->techniques.array + idx, *this); } -streamfx::obs::gs::effect_technique streamfx::obs::gs::effect::get_technique(const std::string& name) +streamfx::obs::gs::effect_technique streamfx::obs::gs::effect::get_technique(std::string_view name) { for (std::size_t idx = 0; idx < count_techniques(); idx++) { auto ptr = get()->techniques.array + idx; - if (strcmp(ptr->name, name.c_str()) == 0) { + if (strcmp(ptr->name, name.data()) == 0) { return streamfx::obs::gs::effect_technique(ptr, *this); } } @@ -148,7 +148,7 @@ streamfx::obs::gs::effect_technique streamfx::obs::gs::effect::get_technique(con return nullptr; } -bool streamfx::obs::gs::effect::has_technique(const std::string& name) +bool streamfx::obs::gs::effect::has_technique(std::string_view name) { if (get_technique(name)) return true; @@ -169,11 +169,11 @@ streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect::get_parameter(std return streamfx::obs::gs::effect_parameter(get()->params.array + idx, *this); } -streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect::get_parameter(const std::string& name) +streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect::get_parameter(std::string_view name) { for (std::size_t idx = 0; idx < count_parameters(); idx++) { auto ptr = get()->params.array + idx; - if (strcmp(ptr->name, name.c_str()) == 0) { + if (strcmp(ptr->name, name.data()) == 0) { return streamfx::obs::gs::effect_parameter(ptr, *this); } } @@ -181,14 +181,14 @@ streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect::get_parameter(con return nullptr; } -bool streamfx::obs::gs::effect::has_parameter(const std::string& name) +bool streamfx::obs::gs::effect::has_parameter(std::string_view name) { if (get_parameter(name)) return true; return false; } -bool streamfx::obs::gs::effect::has_parameter(const std::string& name, effect_parameter::type type) +bool streamfx::obs::gs::effect::has_parameter(std::string_view name, effect_parameter::type type) { auto eprm = get_parameter(name); if (eprm) diff --git a/source/obs/gs/gs-effect.hpp b/source/obs/gs/gs-effect.hpp index 6b00e52e..4d065443 100644 --- a/source/obs/gs/gs-effect.hpp +++ b/source/obs/gs/gs-effect.hpp @@ -27,21 +27,21 @@ namespace streamfx::obs::gs { class effect : public std::shared_ptr { public: - effect(){}; - effect(const std::string& code, const std::string& name); + effect() = default; + effect(std::string_view code, std::string_view name); effect(std::filesystem::path file); ~effect(); std::size_t count_techniques(); streamfx::obs::gs::effect_technique get_technique(std::size_t idx); - streamfx::obs::gs::effect_technique get_technique(const std::string& name); - bool has_technique(const std::string& name); + streamfx::obs::gs::effect_technique get_technique(std::string_view name); + bool has_technique(std::string_view name); std::size_t count_parameters(); streamfx::obs::gs::effect_parameter get_parameter(std::size_t idx); - streamfx::obs::gs::effect_parameter get_parameter(const std::string& name); - bool has_parameter(const std::string& name); - bool has_parameter(const std::string& name, effect_parameter::type type); + streamfx::obs::gs::effect_parameter get_parameter(std::string_view name); + bool has_parameter(std::string_view name); + bool has_parameter(std::string_view name, effect_parameter::type type); public /* Legacy Support */: inline gs_effect_t* get_object() @@ -49,12 +49,12 @@ namespace streamfx::obs::gs { return get(); } - static streamfx::obs::gs::effect create(const std::string& code, const std::string& name) + static streamfx::obs::gs::effect create(std::string_view code, std::string_view name) { return streamfx::obs::gs::effect(code, name); }; - static streamfx::obs::gs::effect create(const std::string& file) + static streamfx::obs::gs::effect create(std::string_view file) { return streamfx::obs::gs::effect(std::filesystem::path(file)); }; diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index f5880475..8e9d3095 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -327,11 +327,11 @@ void streamfx::obs::gs::mipmapper::rebuild(std::shared_ptrget_texture(), mip, cwidth, cheight); + d3d_copy_subregion(d3dinfo, _rt->get_texture(), static_cast(mip), cwidth, cheight); } #endif if (gs_get_device_type() == GS_DEVICE_OPENGL) { - opengl_copy_subregion(oglinfo, _rt->get_texture(), mip, cwidth, cheight); + opengl_copy_subregion(oglinfo, _rt->get_texture(), static_cast(mip), cwidth, cheight); } } diff --git a/source/obs/gs/gs-rendertarget.cpp b/source/obs/gs/gs-rendertarget.cpp index c0a65f99..46e330de 100644 --- a/source/obs/gs/gs-rendertarget.cpp +++ b/source/obs/gs/gs-rendertarget.cpp @@ -97,7 +97,7 @@ streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertar parent->_is_being_rendered = true; } -streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget_op&& r) +streamfx::obs::gs::rendertarget_op::rendertarget_op(streamfx::obs::gs::rendertarget_op&& r) noexcept { this->parent = r.parent; r.parent = nullptr; diff --git a/source/obs/gs/gs-rendertarget.hpp b/source/obs/gs/gs-rendertarget.hpp index 0b864fb1..d736cdd4 100644 --- a/source/obs/gs/gs-rendertarget.hpp +++ b/source/obs/gs/gs-rendertarget.hpp @@ -65,7 +65,7 @@ namespace streamfx::obs::gs { rendertarget_op(streamfx::obs::gs::rendertarget* rt, uint32_t width, uint32_t height); // Move Constructor - rendertarget_op(streamfx::obs::gs::rendertarget_op&&); + rendertarget_op(streamfx::obs::gs::rendertarget_op&&) noexcept; // Copy Constructor rendertarget_op(const streamfx::obs::gs::rendertarget_op&) = delete; diff --git a/source/obs/gs/gs-vertexbuffer.cpp b/source/obs/gs/gs-vertexbuffer.cpp index 1ede2ced..8ba49ad7 100644 --- a/source/obs/gs/gs-vertexbuffer.cpp +++ b/source/obs/gs/gs-vertexbuffer.cpp @@ -203,7 +203,7 @@ streamfx::obs::gs::vertex_buffer::vertex_buffer(vertex_buffer const&& other) noe _obs_data = other._obs_data; } -void streamfx::obs::gs::vertex_buffer::operator=(vertex_buffer const&& other) +void streamfx::obs::gs::vertex_buffer::operator=(vertex_buffer const&& other) noexcept { // Move Assignment finalize(); diff --git a/source/obs/gs/gs-vertexbuffer.hpp b/source/obs/gs/gs-vertexbuffer.hpp index 3bb61cd6..0d218bdd 100644 --- a/source/obs/gs/gs-vertexbuffer.hpp +++ b/source/obs/gs/gs-vertexbuffer.hpp @@ -111,7 +111,7 @@ namespace streamfx::obs::gs { * * \param other */ - void operator=(vertex_buffer const&& other); + void operator=(vertex_buffer const&& other) noexcept; void resize(uint32_t new_size); diff --git a/source/obs/obs-encoder-factory.hpp b/source/obs/obs-encoder-factory.hpp index 66d58687..b70e6500 100644 --- a/source/obs/obs-encoder-factory.hpp +++ b/source/obs/obs-encoder-factory.hpp @@ -118,7 +118,7 @@ namespace streamfx::obs { _info.get_extra_data = _get_extra_data; _info.get_sei_data = _get_sei_data; } - virtual ~encoder_factory() {} + virtual ~encoder_factory() = default; void finish_setup() { diff --git a/source/obs/obs-signal-handler.hpp b/source/obs/obs-signal-handler.hpp index 47f466ef..a691b509 100644 --- a/source/obs/obs-signal-handler.hpp +++ b/source/obs/obs-signal-handler.hpp @@ -35,8 +35,8 @@ namespace streamfx::obs { template class signal_handler : public signal_handler_base { public: - signal_handler(std::string signal, T keepalive) {} - virtual ~signal_handler() {} + signal_handler(std::string_view signal, T keepalive) {} + virtual ~signal_handler() = default; }; template<> @@ -51,7 +51,7 @@ namespace streamfx::obs { } public: - signal_handler(std::string signal, std::shared_ptr keepalive) : _keepalive(keepalive) + signal_handler(std::string_view signal, std::shared_ptr keepalive) : _keepalive(keepalive) { _signal = signal; signal_handler_t* sh = obs_source_get_signal_handler(_keepalive.get()); diff --git a/source/obs/obs-source-factory.hpp b/source/obs/obs-source-factory.hpp index ad64229d..e5c2bf2b 100644 --- a/source/obs/obs-source-factory.hpp +++ b/source/obs/obs-source-factory.hpp @@ -45,7 +45,7 @@ namespace streamfx::obs { _info.save = _save; _info.filter_remove = _filter_remove; } - virtual ~source_factory() {} + virtual ~source_factory() = default; protected: void finish_setup() diff --git a/source/sources/source-mirror.cpp b/source/sources/source-mirror.cpp index 7c70649f..7035f2a1 100644 --- a/source/sources/source-mirror.cpp +++ b/source/sources/source-mirror.cpp @@ -195,7 +195,7 @@ try { // Everything went well, store. _source_child = std::make_shared<::streamfx::obs::source_active_child>(_self, source); - _source = source; + _source = std::move(source); _source_size.first = obs_source_get_width(_source); _source_size.second = obs_source_get_height(_source); diff --git a/source/ui/ui-about.cpp b/source/ui/ui-about.cpp index 74f6c303..7f0b9ab0 100644 --- a/source/ui/ui-about.cpp +++ b/source/ui/ui-about.cpp @@ -70,7 +70,8 @@ streamfx::ui::about::about() : QDialog(reinterpret_cast(obs_frontend_g content->setSizePolicy(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Maximum); // Create a uniform - std::mt19937_64 generator; + std::random_device rd; + std::mt19937_64 generator(rd()); std::uniform_int_distribution rnd; // Load entries from 'thanks.json' diff --git a/source/util/util-curl.cpp b/source/util/util-curl.cpp index d72965e9..75db704d 100644 --- a/source/util/util-curl.cpp +++ b/source/util/util-curl.cpp @@ -124,9 +124,9 @@ void streamfx::util::curl::clear_headers() _headers.clear(); } -void streamfx::util::curl::clear_header(std::string header) +void streamfx::util::curl::clear_header(std::string_view header) { - _headers.erase(header); + _headers.erase(header.data()); } void streamfx::util::curl::set_header(std::string header, std::string value) @@ -134,7 +134,7 @@ void streamfx::util::curl::set_header(std::string header, std::string value) _headers.insert_or_assign(header, value); } -size_t perform_get_kv_size(std::string a, std::string b) +size_t perform_get_kv_size(std::string_view a, std::string_view b) { return a.size() + 2 + b.size() + 1; }; @@ -148,7 +148,7 @@ CURLcode streamfx::util::curl::perform() // Calculate full buffer size. { size_t buffer_size = 0; - for (auto kv : _headers) { + for (const auto& kv : _headers) { buffer_size += perform_get_kv_size(kv.first, kv.second); } buffer.resize(buffer_size * 2); @@ -156,7 +156,7 @@ CURLcode streamfx::util::curl::perform() // Create HTTP Headers. { size_t buffer_offset = 0; - for (auto kv : _headers) { + for (const auto& kv : _headers) { size_t size = perform_get_kv_size(kv.first, kv.second); snprintf(&buffer.at(buffer_offset), size, "%s: %s", kv.first.c_str(), kv.second.c_str()); @@ -186,7 +186,7 @@ void streamfx::util::curl::reset() CURLcode streamfx::util::curl::set_read_callback(curl_io_callback_t cb) { - _read_callback = cb; + _read_callback = std::move(cb); if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_READDATA, this); res != CURLE_OK) return res; return curl_easy_setopt(_curl, CURLOPT_READFUNCTION, &read_helper); @@ -194,7 +194,7 @@ CURLcode streamfx::util::curl::set_read_callback(curl_io_callback_t cb) CURLcode streamfx::util::curl::set_write_callback(curl_io_callback_t cb) { - _write_callback = cb; + _write_callback = std::move(cb); if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this); res != CURLE_OK) return res; return curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, &write_helper); @@ -202,7 +202,7 @@ CURLcode streamfx::util::curl::set_write_callback(curl_io_callback_t cb) CURLcode streamfx::util::curl::set_xferinfo_callback(curl_xferinfo_callback_t cb) { - _xferinfo_callback = cb; + _xferinfo_callback = std::move(cb); if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_XFERINFODATA, this); res != CURLE_OK) return res; return curl_easy_setopt(_curl, CURLOPT_XFERINFOFUNCTION, &xferinfo_callback); @@ -210,7 +210,7 @@ CURLcode streamfx::util::curl::set_xferinfo_callback(curl_xferinfo_callback_t cb CURLcode streamfx::util::curl::set_debug_callback(curl_debug_callback_t cb) { - _debug_callback = cb; + _debug_callback = std::move(cb); if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_DEBUGDATA, this); res != CURLE_OK) return res; return curl_easy_setopt(_curl, CURLOPT_DEBUGFUNCTION, &debug_helper); diff --git a/source/util/util-curl.hpp b/source/util/util-curl.hpp index 54ab4a37..12ffaaa1 100644 --- a/source/util/util-curl.hpp +++ b/source/util/util-curl.hpp @@ -110,7 +110,7 @@ namespace streamfx::util { void clear_headers(); - void clear_header(std::string header); + void clear_header(std::string_view header); void set_header(std::string header, std::string value); diff --git a/source/util/util-event.hpp b/source/util/util-event.hpp index a0dd01b8..7e8a5847 100644 --- a/source/util/util-event.hpp +++ b/source/util/util-event.hpp @@ -44,7 +44,7 @@ namespace streamfx::util { event(const event<_args...>&) = delete; /* Move Constructor */ - event(event<_args...>&& other) : event() + event(event<_args...>&& other) noexcept : event() { std::lock_guard lg(_lock); std::lock_guard lgo(other._lock); @@ -60,7 +60,7 @@ namespace streamfx::util { event<_args...>& operator=(const event<_args...>&) = delete; /* Move Operator */ - event<_args...>& operator=(event<_args...>&& other) + event<_args...>& operator=(event<_args...>&& other) noexcept { std::lock_guard lg(_lock); std::lock_guard lgo(other._lock); diff --git a/source/util/util-library.cpp b/source/util/util-library.cpp index b6ba2d0a..5c266cfb 100644 --- a/source/util/util-library.cpp +++ b/source/util/util-library.cpp @@ -45,10 +45,10 @@ streamfx::util::library::library(std::filesystem::path file) : _library(nullptr) _library = reinterpret_cast(LoadLibraryExW(wfile.c_str(), nullptr, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS)); } if (!_library) { - DWORD error = GetLastError(); + std::string ex = "Failed to load library."; + DWORD error = GetLastError(); if (error != ERROR_PROC_NOT_FOUND) { - PSTR message = NULL; - std::string ex = "Failed to load library."; + PSTR message = NULL; FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), (LPSTR)&message, 0, NULL); if (message) { @@ -57,7 +57,7 @@ streamfx::util::library::library(std::filesystem::path file) : _library(nullptr) throw std::runtime_error(ex); } } - throw std::runtime_error("Failed to load library."); + throw std::runtime_error(ex); } #elif defined(ST_UNIX) _library = dlopen(file.u8string().c_str(), RTLD_LAZY); diff --git a/source/util/util-threadpool.cpp b/source/util/util-threadpool.cpp index 72cb5352..ceb8537f 100644 --- a/source/util/util-threadpool.cpp +++ b/source/util/util-threadpool.cpp @@ -145,7 +145,7 @@ void streamfx::util::threadpool::work() _worker_idx.fetch_sub(1); } -streamfx::util::threadpool::task::task() {} +streamfx::util::threadpool::task::task() = default; streamfx::util::threadpool::task::task(threadpool_callback_t fn, threadpool_data_t dt) : _mutex(), _is_complete(), _is_dead(false), _callback(fn), _data(dt) diff --git a/source/util/utility.cpp b/source/util/utility.cpp index 0e57a36a..4d00247b 100644 --- a/source/util/utility.cpp +++ b/source/util/utility.cpp @@ -103,12 +103,12 @@ void streamfx::util::vec4a::operator delete[](void* p) streamfx::util::free_aligned(p); } -std::pair streamfx::util::size_from_string(std::string text, bool allowSquare) +std::pair streamfx::util::size_from_string(std::string_view text, bool allowSquare) { int64_t width, height; - const char* begin = text.c_str(); - const char* end = text.c_str() + text.size() + 1; + const auto* begin = text.data(); + const auto* end = text.data() + text.size() + 1; char* here = const_cast(end); long long res = strtoll(begin, &here, 0); diff --git a/source/util/utility.hpp b/source/util/utility.hpp index 9ed49f7a..84a9a8c6 100644 --- a/source/util/utility.hpp +++ b/source/util/utility.hpp @@ -103,7 +103,7 @@ namespace streamfx::util { static void operator delete[](void* p); }; - std::pair size_from_string(std::string text, bool allowSquare = true); + std::pair size_from_string(std::string_view text, bool allowSquare = true); namespace math { template @@ -243,7 +243,7 @@ namespace streamfx::util { : _q_process_noise_covariance(pnc), _r_measurement_noise_covariance(mnc), _x_value_of_interest(value), _p_estimation_error_covariance(eec), _k_kalman_gain(0.0) {} - ~kalman1D() {} + ~kalman1D() = default; T filter(T measurement) {