From d332007ae058531e9cdbb3446213a052e5755c8c Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 12 Jul 2020 18:41:50 +0200 Subject: [PATCH] project: Code cleanup and reapply formatting Changes applied: * Moved utility files to /util/. * Removed unused #includes. * Removed unused ::ffmpeg::tools function. * Removed unused variables. * Fixed missing parentheses in the version macro. * Fixed missing override on virtual function overrides and removed unnecessary virtual keyword from them. * Disabled additional warning for ATL headers on MSVC only. * Replaced direct printf parameters with their macro equivalent. * Replaced C-style casts with C++-style casts. * Applied clang-format again after an earlier change to the CMake file broke the integration for it. --- CMakeLists.txt | 14 ++--- cmake/version.hpp.in | 2 +- source/common.hpp | 7 ++- source/configuration.cpp | 7 ++- source/encoders/codecs/hevc.cpp | 1 - source/encoders/encoder-ffmpeg.cpp | 47 ++++++++-------- source/encoders/handlers/debug_handler.cpp | 11 ++-- source/encoders/handlers/handler.hpp | 3 +- .../encoders/handlers/nvenc_h264_handler.cpp | 1 - .../encoders/handlers/nvenc_hevc_handler.cpp | 1 - source/encoders/handlers/nvenc_shared.cpp | 1 - source/encoders/handlers/nvenc_shared.hpp | 1 - .../encoders/handlers/prores_aw_handler.cpp | 1 - source/ffmpeg/hwapi/d3d11.cpp | 6 +- source/ffmpeg/hwapi/d3d11.hpp | 15 ++--- source/ffmpeg/swscale.cpp | 6 +- source/ffmpeg/tools.cpp | 55 +++---------------- source/ffmpeg/tools.hpp | 2 - source/filters/filter-blur.cpp | 7 +-- source/filters/filter-color-grade.cpp | 1 - source/filters/filter-dynamic-mask.cpp | 2 +- source/filters/filter-nv-face-tracking.cpp | 22 ++++---- source/filters/filter-sdf-effects.cpp | 4 +- source/filters/filter-shader.cpp | 1 - source/filters/filter-transform.cpp | 20 ++++--- source/gfx/blur/gfx-blur-box-linear.cpp | 1 - source/gfx/blur/gfx-blur-box.cpp | 1 - source/gfx/blur/gfx-blur-dual-filtering.cpp | 5 +- source/gfx/blur/gfx-blur-gaussian-linear.cpp | 1 - source/gfx/blur/gfx-blur-gaussian.cpp | 1 - source/gfx/gfx-source-texture.cpp | 4 +- source/gfx/shader/gfx-shader-param-basic.cpp | 6 +- source/gfx/shader/gfx-shader-param-basic.hpp | 24 ++++---- source/nvidia/cuda/nvidia-cuda-context.cpp | 2 +- source/nvidia/cuda/nvidia-cuda-context.hpp | 4 +- source/nvidia/cuda/nvidia-cuda-gs-texture.hpp | 6 +- source/nvidia/cuda/nvidia-cuda-memory.hpp | 2 +- source/nvidia/cuda/nvidia-cuda-stream.hpp | 5 +- source/nvidia/cuda/nvidia-cuda.hpp | 2 +- source/obs/gs/gs-indexbuffer.cpp | 4 +- source/obs/gs/gs-mipmapper.cpp | 15 +++-- source/obs/gs/gs-sampler.cpp | 1 - source/obs/gs/gs-texture.cpp | 9 ++- source/obs/gs/gs-texture.hpp | 1 - source/obs/gs/gs-vertex.cpp | 1 - source/obs/gs/gs-vertexbuffer.cpp | 38 ++++++------- source/obs/gs/gs-vertexbuffer.hpp | 1 - source/obs/obs-signal-handler.hpp | 2 +- source/obs/obs-source.cpp | 2 +- source/obs/obs-source.hpp | 2 +- source/plugin.cpp | 4 +- source/sources/source-shader.cpp | 1 - source/transitions/transition-shader.cpp | 6 +- source/transitions/transition-shader.hpp | 2 - source/ui/ui-about-entry.cpp | 4 ++ source/{ => util}/util-event.hpp | 0 source/{ => util}/util-math.hpp | 0 source/{ => util}/util-memory.cpp | 0 source/{ => util}/util-profiler.cpp | 5 +- source/{ => util}/util-profiler.hpp | 0 source/{ => util}/util-threadpool.cpp | 10 ++-- source/{ => util}/util-threadpool.hpp | 0 source/{ => util}/utility.cpp | 0 source/{ => util}/utility.hpp | 0 64 files changed, 174 insertions(+), 236 deletions(-) rename source/{ => util}/util-event.hpp (100%) rename source/{ => util}/util-math.hpp (100%) rename source/{ => util}/util-memory.cpp (100%) rename source/{ => util}/util-profiler.cpp (96%) rename source/{ => util}/util-profiler.hpp (100%) rename source/{ => util}/util-threadpool.cpp (88%) rename source/{ => util}/util-threadpool.hpp (100%) rename source/{ => util}/utility.cpp (100%) rename source/{ => util}/utility.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4eefb4e..fe4bd365 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,13 +477,13 @@ list(APPEND PROJECT_PRIVATE_SOURCE "source/strings.hpp" "source/plugin.hpp" "source/plugin.cpp" - "source/utility.hpp" - "source/utility.cpp" - "source/util-event.hpp" - "source/util-profiler.cpp" - "source/util-profiler.hpp" - "source/util-threadpool.cpp" - "source/util-threadpool.hpp" + "source/util/utility.hpp" + "source/util/utility.cpp" + "source/util/util-event.hpp" + "source/util/util-profiler.cpp" + "source/util/util-profiler.hpp" + "source/util/util-threadpool.cpp" + "source/util/util-threadpool.hpp" # Graphics "source/gfx/gfx-source-texture.hpp" diff --git a/cmake/version.hpp.in b/cmake/version.hpp.in index c803e0df..d890fba7 100644 --- a/cmake/version.hpp.in +++ b/cmake/version.hpp.in @@ -21,7 +21,7 @@ #include #include -#define STREAMFX_MAKE_VERSION(major,minor,patch,tweak) ((uint64_t(major) & 0xFFFFull) << 48ull) | ((uint64_t(minor) & 0xFFFFull) << 32ull) | ((uint64_t(patch) & 0xFFFFull) << 16ull) | ((uint64_t(tweak) & 0xFFFFull)) +#define STREAMFX_MAKE_VERSION(major,minor,patch,tweak) (((uint64_t(major) & 0xFFFFull) << 48ull) | ((uint64_t(minor) & 0xFFFFull) << 32ull) | ((uint64_t(patch) & 0xFFFFull) << 16ull) | ((uint64_t(tweak) & 0xFFFFull))) #define STREAMFX_MASK_MAJOR 0xFFFF000000000000ull #define STREAMFX_MASK_COMPAT 0xFFFFFFFF00000000ull diff --git a/source/common.hpp b/source/common.hpp index 7434620a..b902c4d5 100644 --- a/source/common.hpp +++ b/source/common.hpp @@ -46,9 +46,10 @@ // Common Plugin includes #include "strings.hpp" #include "version.hpp" -#include "util-profiler.hpp" -#include "util-threadpool.hpp" -#include "utility.hpp" +#include "util/util-math.hpp" +#include "util/util-profiler.hpp" +#include "util/util-threadpool.hpp" +#include "util/utility.hpp" // Common OBS includes extern "C" { diff --git a/source/configuration.cpp b/source/configuration.cpp index 77a71263..7667c0d2 100644 --- a/source/configuration.cpp +++ b/source/configuration.cpp @@ -44,8 +44,8 @@ streamfx::configuration::~configuration() streamfx::configuration::configuration() : _data(), _config_path() { { // Retrieve global configuration path. - char* path = obs_module_config_path("config.json"); - _config_path = path; + char* path = obs_module_config_path("config.json"); + _config_path = path; bfree(path); } @@ -53,7 +53,8 @@ streamfx::configuration::configuration() : _data(), _config_path() if (!std::filesystem::exists(_config_path) || !std::filesystem::is_regular_file(_config_path)) { throw std::runtime_error("Configuration does not exist."); } else { - obs_data_t* data = obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data()); + obs_data_t* data = + obs_data_create_from_json_file_safe(_config_path.string().c_str(), path_backup_ext.data()); if (!data) { throw std::runtime_error("Failed to load configuration from disk."); } else { diff --git a/source/encoders/codecs/hevc.cpp b/source/encoders/codecs/hevc.cpp index 26336a6b..afb478fc 100644 --- a/source/encoders/codecs/hevc.cpp +++ b/source/encoders/codecs/hevc.cpp @@ -20,7 +20,6 @@ // SOFTWARE. #include "hevc.hpp" -#include "utility.hpp" using namespace streamfx::encoder::codec; diff --git a/source/encoders/encoder-ffmpeg.cpp b/source/encoders/encoder-ffmpeg.cpp index 915a3a04..eef6c96d 100644 --- a/source/encoders/encoder-ffmpeg.cpp +++ b/source/encoders/encoder-ffmpeg.cpp @@ -30,7 +30,6 @@ #include "handlers/prores_aw_handler.hpp" #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #pragma warning(push) @@ -97,7 +96,8 @@ ffmpeg_instance::ffmpeg_instance(obs_data_t* settings, obs_encoder_t* self, bool // Abort if user specified manual override. if ((static_cast(obs_data_get_int(settings, KEY_FFMPEG_COLORFORMAT)) != AV_PIX_FMT_NONE) || (obs_data_get_int(settings, KEY_FFMPEG_GPU) != -1) || (obs_encoder_scaling_enabled(_self))) { - throw std::runtime_error("Selected settings prevent the use of hardware encoding, falling back to software."); + throw std::runtime_error( + "Selected settings prevent the use of hardware encoding, falling back to software."); } #ifdef WIN32 @@ -262,32 +262,33 @@ bool ffmpeg_instance::update(obs_data_t* settings) DLOG_INFO("[%s] Initializing...", _codec->name); DLOG_INFO("[%s] FFmpeg:", _codec->name); DLOG_INFO("[%s] Custom Settings: %s", _codec->name, - obs_data_get_string(settings, KEY_FFMPEG_CUSTOMSETTINGS)); + obs_data_get_string(settings, KEY_FFMPEG_CUSTOMSETTINGS)); DLOG_INFO("[%s] Standard Compliance: %s", _codec->name, - ::ffmpeg::tools::get_std_compliance_name(_context->strict_std_compliance)); + ::ffmpeg::tools::get_std_compliance_name(_context->strict_std_compliance)); DLOG_INFO("[%s] Threading: %s (with %i threads)", _codec->name, - ::ffmpeg::tools::get_thread_type_name(_context->thread_type), _context->thread_count); + ::ffmpeg::tools::get_thread_type_name(_context->thread_type), _context->thread_count); DLOG_INFO("[%s] Video:", _codec->name); if (_hwinst) { - DLOG_INFO("[%s] Texture: %ldx%ld %s %s %s", _codec->name, _context->width, _context->height, - ::ffmpeg::tools::get_pixel_format_name(_context->sw_pix_fmt), - ::ffmpeg::tools::get_color_space_name(_context->colorspace), - av_color_range_name(_context->color_range)); + DLOG_INFO("[%s] Texture: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _context->width, _context->height, + ::ffmpeg::tools::get_pixel_format_name(_context->sw_pix_fmt), + ::ffmpeg::tools::get_color_space_name(_context->colorspace), + av_color_range_name(_context->color_range)); } else { - DLOG_INFO("[%s] Input: %ldx%ld %s %s %s", _codec->name, _scaler.get_source_width(), - _scaler.get_source_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()), - ::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()), - _scaler.is_source_full_range() ? "Full" : "Partial"); - DLOG_INFO("[%s] Output: %ldx%ld %s %s %s", _codec->name, _scaler.get_target_width(), - _scaler.get_target_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format()), - ::ffmpeg::tools::get_color_space_name(_scaler.get_target_colorspace()), - _scaler.is_target_full_range() ? "Full" : "Partial"); + DLOG_INFO("[%s] Input: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_source_width(), + _scaler.get_source_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_source_format()), + ::ffmpeg::tools::get_color_space_name(_scaler.get_source_colorspace()), + _scaler.is_source_full_range() ? "Full" : "Partial"); + DLOG_INFO("[%s] Output: %" PRId32 "x%" PRId32 " %s %s %s", _codec->name, _scaler.get_target_width(), + _scaler.get_target_height(), ::ffmpeg::tools::get_pixel_format_name(_scaler.get_target_format()), + ::ffmpeg::tools::get_color_space_name(_scaler.get_target_colorspace()), + _scaler.is_target_full_range() ? "Full" : "Partial"); if (!_hwinst) DLOG_INFO("[%s] On GPU Index: %lli", _codec->name, obs_data_get_int(settings, KEY_FFMPEG_GPU)); } - DLOG_INFO("[%s] Framerate: %ld/%ld (%f FPS)", _codec->name, _context->time_base.den, _context->time_base.num, - static_cast(_context->time_base.den) / static_cast(_context->time_base.num)); + DLOG_INFO("[%s] Framerate: %" PRId32 "/%" PRId32 " (%f FPS)", _codec->name, _context->time_base.den, + _context->time_base.num, + static_cast(_context->time_base.den) / static_cast(_context->time_base.num)); DLOG_INFO("[%s] Keyframes: ", _codec->name); if (_context->keyint_min != _context->gop_size) { @@ -360,7 +361,7 @@ bool ffmpeg_instance::encode_video(struct encoder_frame* frame, struct encoder_p _scaler.convert(reinterpret_cast(frame->data), reinterpret_cast(frame->linesize), 0, _context->height, vframe->data, vframe->linesize); if (res <= 0) { - DLOG_ERROR("Failed to convert frame: %s (%ld).", ::ffmpeg::tools::get_error_description(res), res); + DLOG_ERROR("Failed to convert frame: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), res); return false; } } @@ -700,7 +701,7 @@ bool ffmpeg_instance::encode_avframe(std::shared_ptr frame, encoder_pac sent_frame = true; break; default: - DLOG_ERROR("Failed to encode frame: %s (%ld).", ::ffmpeg::tools::get_error_description(res), res); + DLOG_ERROR("Failed to encode frame: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), res); return false; } } @@ -725,7 +726,7 @@ bool ffmpeg_instance::encode_avframe(std::shared_ptr frame, encoder_pac } break; default: - DLOG_ERROR("Failed to receive packet: %s (%ld).", ::ffmpeg::tools::get_error_description(res), res); + DLOG_ERROR("Failed to receive packet: %s (%" PRId32 ").", ::ffmpeg::tools::get_error_description(res), res); return false; } } @@ -873,7 +874,7 @@ void ffmpeg_instance::parse_ffmpeg_commandline(std::string text) int res = av_opt_set(_context, key.c_str(), value.c_str(), AV_OPT_SEARCH_CHILDREN); if (res < 0) { DLOG_WARNING("Option '%s' (key: '%s', value: '%s') encountered error: %s", opt.c_str(), key.c_str(), - value.c_str(), ::ffmpeg::tools::get_error_description(res)); + value.c_str(), ::ffmpeg::tools::get_error_description(res)); } } catch (const std::exception& ex) { DLOG_ERROR("Option '%s' encountered exception: %s", opt.c_str(), ex.what()); diff --git a/source/encoders/handlers/debug_handler.cpp b/source/encoders/handlers/debug_handler.cpp index 32ba34cd..1d871d3d 100644 --- a/source/encoders/handlers/debug_handler.cpp +++ b/source/encoders/handlers/debug_handler.cpp @@ -26,7 +26,6 @@ #include #include "handler.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #include @@ -47,7 +46,7 @@ template<> std::string to_string(int64_t value) { std::vector buf(32); - snprintf(buf.data(), buf.size(), "%lld", value); + snprintf(buf.data(), buf.size(), "%" PRId64, value); return std::string(buf.data(), buf.data() + buf.size()); } @@ -55,7 +54,7 @@ template<> std::string to_string(uint64_t value) { std::vector buf(32); - snprintf(buf.data(), buf.size(), "%llu", value); + snprintf(buf.data(), buf.size(), "%" PRIu64, value); return std::string(buf.data(), buf.data() + buf.size()); } @@ -119,8 +118,8 @@ void debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCo } else { auto unit_type = unit_types.find(opt->unit); if (unit_type == unit_types.end()) { - DLOG_INFO(" [%s] Flag '%s' and help text '%s' with value '%lld'.", opt->unit, opt->name, opt->help, - opt->default_val.i64); + DLOG_INFO(" [%s] Flag '%s' and help text '%s' with value '%" PRId64 "'.", opt->unit, opt->name, opt->help, + opt->default_val.i64); } else { std::string out; switch (unit_type->second) { @@ -148,7 +147,7 @@ void debug_handler::get_properties(obs_properties_t*, const AVCodec* codec, AVCo } DLOG_INFO(" [%s] Constant '%s' and help text '%s' with value '%s'.", opt->unit, opt->name, - opt->help, out.c_str()); + opt->help, out.c_str()); } } } else { diff --git a/source/encoders/handlers/handler.hpp b/source/encoders/handlers/handler.hpp index 3401d498..7c26dddc 100644 --- a/source/encoders/handlers/handler.hpp +++ b/source/encoders/handlers/handler.hpp @@ -60,7 +60,8 @@ namespace streamfx::encoder::ffmpeg { virtual void get_properties(obs_properties_t* props, const AVCodec* codec, AVCodecContext* context, bool hw_encode){}; - virtual void migrate(obs_data_t* settings, std::uint64_t version, const AVCodec* codec, AVCodecContext* context){}; + virtual void migrate(obs_data_t* settings, std::uint64_t version, const AVCodec* codec, + AVCodecContext* context){}; virtual void update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* context){}; diff --git a/source/encoders/handlers/nvenc_h264_handler.cpp b/source/encoders/handlers/nvenc_h264_handler.cpp index 65246481..698f3d23 100644 --- a/source/encoders/handlers/nvenc_h264_handler.cpp +++ b/source/encoders/handlers/nvenc_h264_handler.cpp @@ -26,7 +26,6 @@ #include "ffmpeg/tools.hpp" #include "nvenc_shared.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #ifdef _MSC_VER diff --git a/source/encoders/handlers/nvenc_hevc_handler.cpp b/source/encoders/handlers/nvenc_hevc_handler.cpp index ea6c7b56..3ed249e5 100644 --- a/source/encoders/handlers/nvenc_hevc_handler.cpp +++ b/source/encoders/handlers/nvenc_hevc_handler.cpp @@ -26,7 +26,6 @@ #include "ffmpeg/tools.hpp" #include "nvenc_shared.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #include diff --git a/source/encoders/handlers/nvenc_shared.cpp b/source/encoders/handlers/nvenc_shared.cpp index 6fa8a69d..0edf2fec 100644 --- a/source/encoders/handlers/nvenc_shared.cpp +++ b/source/encoders/handlers/nvenc_shared.cpp @@ -26,7 +26,6 @@ #include "../encoder-ffmpeg.hpp" #include "ffmpeg/tools.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #include diff --git a/source/encoders/handlers/nvenc_shared.hpp b/source/encoders/handlers/nvenc_shared.hpp index ba985b22..c38a472b 100644 --- a/source/encoders/handlers/nvenc_shared.hpp +++ b/source/encoders/handlers/nvenc_shared.hpp @@ -22,7 +22,6 @@ #pragma once #include #include "handler.hpp" -#include "utility.hpp" extern "C" { #ifdef _MSC_VER diff --git a/source/encoders/handlers/prores_aw_handler.cpp b/source/encoders/handlers/prores_aw_handler.cpp index cab85de0..dec282cb 100644 --- a/source/encoders/handlers/prores_aw_handler.cpp +++ b/source/encoders/handlers/prores_aw_handler.cpp @@ -24,7 +24,6 @@ #include "../codecs/prores.hpp" #include "ffmpeg/tools.hpp" #include "plugin.hpp" -#include "utility.hpp" extern "C" { #include diff --git a/source/ffmpeg/hwapi/d3d11.cpp b/source/ffmpeg/hwapi/d3d11.cpp index f48e519a..2bd28c77 100644 --- a/source/ffmpeg/hwapi/d3d11.cpp +++ b/source/ffmpeg/hwapi/d3d11.cpp @@ -25,7 +25,6 @@ #include #include #include "obs/gs/gs-helper.hpp" -#include "utility.hpp" extern "C" { #pragma warning(push) @@ -88,8 +87,9 @@ std::list d3d11::enumerate_adapters() dxgi_adapter->GetDesc1(&desc); std::vector buf(1024); - std::size_t len = snprintf(buf.data(), buf.size(), "%ls (VEN_%04x/DEV_%04x/SUB_%04x/REV_%04x)", - desc.Description, desc.VendorId, desc.DeviceId, desc.SubSysId, desc.Revision); + std::size_t len = + static_cast(snprintf(buf.data(), buf.size(), "%ls (VEN_%04x/DEV_%04x/SUB_%04x/REV_%04x)", + desc.Description, desc.VendorId, desc.DeviceId, desc.SubSysId, desc.Revision)); device dev; dev.name = std::string(buf.data(), buf.data() + len); diff --git a/source/ffmpeg/hwapi/d3d11.hpp b/source/ffmpeg/hwapi/d3d11.hpp index 19643370..446bd689 100644 --- a/source/ffmpeg/hwapi/d3d11.hpp +++ b/source/ffmpeg/hwapi/d3d11.hpp @@ -22,22 +22,17 @@ #pragma once #include "base.hpp" -extern "C++" { +#ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable : 4191) -#pragma warning(disable : 4242) -#pragma warning(disable : 4244) -#pragma warning(disable : 4365) -#pragma warning(disable : 4777) -#pragma warning(disable : 4986) -#pragma warning(disable : 5039) -#pragma warning(disable : 5204) +#pragma warning(disable : 4191 4242 4244 4365 4777 4986 5039 5204) +#endif #include #include #include #include +#ifdef _MSC_VER #pragma warning(pop) -} +#endif namespace ffmpeg::hwapi { class d3d11 : public ffmpeg::hwapi::base { diff --git a/source/ffmpeg/swscale.cpp b/source/ffmpeg/swscale.cpp index 7adc919b..cf800af1 100644 --- a/source/ffmpeg/swscale.cpp +++ b/source/ffmpeg/swscale.cpp @@ -171,8 +171,10 @@ bool swscale::initialize(int flags) throw std::invalid_argument("not all target parameters were set"); } - this->context = sws_getContext(source_size.first, source_size.second, source_format, target_size.first, - target_size.second, target_format, flags, nullptr, nullptr, nullptr); + this->context = + sws_getContext(static_cast(source_size.first), static_cast(source_size.second), source_format, + static_cast(target_size.first), static_cast(target_size.second), target_format, flags, + nullptr, nullptr, nullptr); if (!this->context) { return false; } diff --git a/source/ffmpeg/tools.cpp b/source/ffmpeg/tools.cpp index 512939b9..9a33a12f 100644 --- a/source/ffmpeg/tools.cpp +++ b/source/ffmpeg/tools.cpp @@ -25,7 +25,6 @@ #include #include #include "plugin.hpp" -#include "utility.hpp" extern "C" { #pragma warning(push) @@ -39,44 +38,6 @@ extern "C" { using namespace ffmpeg; -std::string tools::translate_encoder_capabilities(int capabilities) -{ - // Sorted by relative importance. - std::pair caps[] = { - {AV_CODEC_CAP_EXPERIMENTAL, "Experimental"}, - - // Quality - {AV_CODEC_CAP_LOSSLESS, "Lossless"}, - - // Features - {AV_CODEC_CAP_PARAM_CHANGE, "Dynamic Parameter Change"}, - {AV_CODEC_CAP_SUBFRAMES, "Sub-Frames"}, - {AV_CODEC_CAP_VARIABLE_FRAME_SIZE, "Variable Frame Size"}, - {AV_CODEC_CAP_SMALL_LAST_FRAME, "Small Final Frame"}, - - // Other - {AV_CODEC_CAP_TRUNCATED, "Truncated"}, - {AV_CODEC_CAP_CHANNEL_CONF, "AV_CODEC_CAP_CHANNEL_CONF"}, - {AV_CODEC_CAP_DRAW_HORIZ_BAND, "AV_CODEC_CAP_DRAW_HORIZ_BAND"}, - {AV_CODEC_CAP_AVOID_PROBING, "AV_CODEC_CAP_AVOID_PROBING"}, - }; - - std::stringstream sstr; - for (auto const kv : caps) { - if (capabilities & kv.first) { - capabilities &= ~kv.first; - sstr << kv.second; - if (capabilities != 0) { - sstr << ", "; - } else { - break; - } - } - } - - return sstr.str(); -} - const char* tools::get_pixel_format_name(AVPixelFormat v) { return av_get_pix_fmt_name(v); @@ -327,11 +288,11 @@ void tools::print_av_option_bool(AVCodecContext* ctx_codec, void* ctx_option, co 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(), - ffmpeg::tools::get_error_description(err)); + 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", - av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); + (inverse ? v != 0 : v == 0) ? "Disabled" : "Enabled", + av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); } } @@ -350,11 +311,11 @@ void tools::print_av_option_int(AVCodecContext* ctx_codec, void* ctx_option, con DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str()); } else { DLOG_INFO("[%s] %s: ", ctx_codec->codec->name, text.c_str(), - ffmpeg::tools::get_error_description(err)); + ffmpeg::tools::get_error_description(err)); } } else { - DLOG_INFO("[%s] %s: %lld %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.c_str(), v, suffix.c_str(), + is_default ? " " : ""); } } @@ -370,13 +331,13 @@ void tools::print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, 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(), - ffmpeg::tools::get_error_description(err)); + 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(), - av_opt_is_set_to_default_by_name(ctx_option, option, AV_OPT_SEARCH_CHILDREN) > 0 ? " " : ""); + 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 68036e50..e58bd19b 100644 --- a/source/ffmpeg/tools.hpp +++ b/source/ffmpeg/tools.hpp @@ -38,8 +38,6 @@ extern "C" { } namespace ffmpeg::tools { - std::string translate_encoder_capabilities(int capabilities); - const char* get_pixel_format_name(AVPixelFormat v); const char* get_color_space_name(AVColorSpace v); diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index 2851a5b6..c7fd111e 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -31,7 +31,6 @@ #include "gfx/blur/gfx-blur-gaussian.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/obs-source-tracker.hpp" -#include "util-math.hpp" // OBS #ifdef _MSC_VER @@ -333,7 +332,7 @@ void blur_instance::video_tick(float) _mask.image.path_old = _mask.image.path; } catch (...) { DLOG_ERROR(" Instance '%s' failed to load image '%s'.", obs_source_get_name(_self), - _mask.image.path.c_str()); + _mask.image.path.c_str()); } } } else if (_mask.type == mask_type::Source) { @@ -344,7 +343,7 @@ void blur_instance::video_tick(float) _mask.source.name_old = _mask.source.name; } catch (...) { DLOG_ERROR(" Instance '%s' failed to grab source '%s'.", obs_source_get_name(_self), - _mask.source.name.c_str()); + _mask.source.name.c_str()); } } } @@ -399,7 +398,7 @@ void blur_instance::video_render(gs_effect_t* effect) gs_stencil_op(GS_STENCIL_BOTH, GS_KEEP, GS_KEEP, GS_KEEP); // Orthographic Camera and clear RenderTarget. - gs_ortho(0, (float)baseW, 0, (float)baseH, -1., 1.); + gs_ortho(0, static_cast(baseW), 0, static_cast(baseH), -1., 1.); //gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &black, 0, 0); // Render diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 57cb11be..9a0f3513 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -21,7 +21,6 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "util-math.hpp" // OBS #ifdef _MSC_VER diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index 50dfa704..e9d53d53 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -233,7 +233,7 @@ void dynamic_mask_instance::video_render(gs_effect_t* in_effect) gs_enable_stencil_write(false); gs_stencil_function(GS_STENCIL_BOTH, GS_ALWAYS); gs_stencil_op(GS_STENCIL_BOTH, GS_KEEP, GS_KEEP, GS_KEEP); - gs_ortho(0, (float)width, 0, (float)height, -1., 1.); + gs_ortho(0, static_cast(width), 0, static_cast(height), -1., 1.); obs_source_process_filter_end(_self, default_effect, width, height); diff --git a/source/filters/filter-nv-face-tracking.cpp b/source/filters/filter-nv-face-tracking.cpp index abc9594d..ffe17962 100644 --- a/source/filters/filter-nv-face-tracking.cpp +++ b/source/filters/filter-nv-face-tracking.cpp @@ -24,7 +24,6 @@ #include "nvidia/cuda/nvidia-cuda-context-stack.hpp" #include "obs/gs/gs-helper.hpp" #include "obs/obs-tools.hpp" -#include "utility.hpp" #define ST "Filter.Nvidia.FaceTracking" #define ST_ROI "Filter.Nvidia.FaceTracking.ROI" @@ -74,12 +73,11 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_ #endif { // Create render target, vertex buffer, and CUDA stream. - auto gctx = gs::context{}; - _rt = std::make_shared(GS_RGBA, GS_ZS_NONE); - _geometry = std::make_shared(4, 1); - auto cctx = std::make_shared<::nvidia::cuda::context_stack>(_cuda, _cuda_ctx); - _cuda_stream = - std::make_shared<::nvidia::cuda::stream>(_cuda, ::nvidia::cuda::stream_flags::NON_BLOCKING, 0); + auto gctx = gs::context{}; + _rt = std::make_shared(GS_RGBA, GS_ZS_NONE); + _geometry = std::make_shared(uint32_t(4), uint8_t(1)); + auto cctx = std::make_shared<::nvidia::cuda::context_stack>(_cuda, _cuda_ctx); + _cuda_stream = std::make_shared<::nvidia::cuda::stream>(_cuda, ::nvidia::cuda::stream_flags::NON_BLOCKING, 0); } { // Asynchronously load Face Tracking. @@ -235,7 +233,7 @@ void face_tracking_instance::async_track(std::shared_ptr ptr) gs::debug_marker marker{gs::debug_color_allocate, "Reallocate GPU Buffer"}; #endif _ar_texture = - std::make_shared(_size.first, _size.second, GS_RGBA, 1, nullptr, gs::texture::flags::None); + std::make_shared(_size.first, _size.second, GS_RGBA, uint32_t(1), nullptr, gs::texture::flags::None); _ar_texture_cuda_fresh = false; } @@ -593,10 +591,10 @@ bool face_tracking_instance::button_profile(obs_properties_t* props, obs_propert }; for (auto& kv : profilers) { DLOG_INFO(" %-20s: %8lldµs %10lld %8lldµs %8lldµs %8lldµs", kv.first.c_str(), - std::chrono::duration_cast(kv.second->total_duration()).count(), - kv.second->count(), static_cast(kv.second->average_duration() / 1000.0), - std::chrono::duration_cast(kv.second->percentile(0.999)).count(), - std::chrono::duration_cast(kv.second->percentile(0.95)).count()); + std::chrono::duration_cast(kv.second->total_duration()).count(), + kv.second->count(), static_cast(kv.second->average_duration() / 1000.0), + std::chrono::duration_cast(kv.second->percentile(0.999)).count(), + std::chrono::duration_cast(kv.second->percentile(0.95)).count()); } return false; diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index 59ec8df1..250edaa6 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -106,7 +106,7 @@ sdf_effects_instance::sdf_effects_instance(obs_data_t* settings, obs_source_t* s kv.second = gs::effect::create(path); } catch (const std::exception& ex) { DLOG_ERROR(LOG_PREFIX "Failed to load _effect '%s' (located at '%s') with error(s): %s", kv.first, path, - ex.what()); + ex.what()); } bfree(path); } @@ -312,7 +312,7 @@ void sdf_effects_instance::video_render(gs_effect_t* effect) #endif auto op = _source_rt->render(baseW, baseH); - gs_ortho(0, (float)baseW, 0, (float)baseH, -1, 1); + gs_ortho(0, static_cast(baseW), 0, static_cast(baseH), -1, 1); gs_clear(GS_CLEAR_COLOR | GS_CLEAR_DEPTH, &color_transparent, 0, 0); if (obs_source_process_filter_begin(_self, GS_RGBA, OBS_ALLOW_DIRECT_RENDERING)) { diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 3396014a..8da4935a 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -21,7 +21,6 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "utility.hpp" #define ST "Filter.Shader" diff --git a/source/filters/filter-transform.cpp b/source/filters/filter-transform.cpp index 59f3313d..86fa71e0 100644 --- a/source/filters/filter-transform.cpp +++ b/source/filters/filter-transform.cpp @@ -22,7 +22,6 @@ #include #include #include "obs/gs/gs-helper.hpp" -#include "util-math.hpp" // OBS #ifdef _MSC_VER @@ -130,7 +129,7 @@ void transform_instance::update(obs_data_t* settings) { // Camera _camera_orthographic = obs_data_get_int(settings, ST_CAMERA) == 0; - _camera_fov = (float)obs_data_get_double(settings, ST_CAMERA_FIELDOFVIEW); + _camera_fov = static_cast(obs_data_get_double(settings, ST_CAMERA_FIELDOFVIEW)); // Source _position->x = static_cast(obs_data_get_double(settings, ST_POSITION_X) / 100.0); @@ -365,8 +364,9 @@ void transform_instance::video_render(gs_effect_t* effect) std::size_t mip_levels = std::max(util::math::get_power_of_two_exponent_ceil(cache_width), util::math::get_power_of_two_exponent_ceil(cache_height)); - _mipmap_texture = std::make_shared(cache_width, cache_height, GS_RGBA, mip_levels, nullptr, - gs::texture::flags::None); + _mipmap_texture = + std::make_shared(cache_width, cache_height, GS_RGBA, static_cast(mip_levels), + nullptr, gs::texture::flags::None); } _mipmapper.rebuild(_cache_texture, _mipmap_texture); @@ -457,7 +457,7 @@ const char* transform_factory::get_name() void transform_factory::get_defaults2(obs_data_t* settings) { - obs_data_set_default_int(settings, ST_CAMERA, (int64_t)CameraMode::Orthographic); + obs_data_set_default_int(settings, ST_CAMERA, static_cast(CameraMode::Orthographic)); obs_data_set_default_double(settings, ST_CAMERA_FIELDOFVIEW, 90.0); obs_data_set_default_double(settings, ST_POSITION_X, 0); obs_data_set_default_double(settings, ST_POSITION_Y, 0); @@ -465,7 +465,7 @@ void transform_factory::get_defaults2(obs_data_t* settings) obs_data_set_default_double(settings, ST_ROTATION_X, 0); obs_data_set_default_double(settings, ST_ROTATION_Y, 0); obs_data_set_default_double(settings, ST_ROTATION_Z, 0); - obs_data_set_default_int(settings, ST_ROTATION_ORDER, RotationOrder::ZXY); + obs_data_set_default_int(settings, ST_ROTATION_ORDER, static_cast(RotationOrder::ZXY)); obs_data_set_default_double(settings, ST_SCALE_X, 100); obs_data_set_default_double(settings, ST_SCALE_Y, 100); obs_data_set_default_double(settings, ST_SHEAR_X, 0); @@ -475,7 +475,7 @@ void transform_factory::get_defaults2(obs_data_t* settings) static bool modified_properties(obs_properties_t* pr, obs_property_t*, obs_data_t* d) noexcept try { - switch ((CameraMode)obs_data_get_int(d, ST_CAMERA)) { + switch (static_cast(obs_data_get_int(d, ST_CAMERA))) { case CameraMode::Orthographic: obs_property_set_visible(obs_properties_get(pr, ST_CAMERA_FIELDOFVIEW), false); obs_property_set_visible(obs_properties_get(pr, ST_POSITION_Z), false); @@ -507,8 +507,10 @@ obs_properties_t* transform_factory::get_properties2(transform_instance* data) auto p = obs_properties_add_list(grp, ST_CAMERA, D_TRANSLATE(ST_CAMERA), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_set_long_description(p, D_TRANSLATE(D_DESC(ST_CAMERA))); - obs_property_list_add_int(p, D_TRANSLATE(ST_CAMERA_ORTHOGRAPHIC), (int64_t)CameraMode::Orthographic); - obs_property_list_add_int(p, D_TRANSLATE(ST_CAMERA_PERSPECTIVE), (int64_t)CameraMode::Perspective); + obs_property_list_add_int(p, D_TRANSLATE(ST_CAMERA_ORTHOGRAPHIC), + static_cast(CameraMode::Orthographic)); + obs_property_list_add_int(p, D_TRANSLATE(ST_CAMERA_PERSPECTIVE), + static_cast(CameraMode::Perspective)); obs_property_set_modified_callback(p, modified_properties); } { // Field Of View diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index e2a9183a..5217dffa 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -21,7 +21,6 @@ #include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "util-math.hpp" #ifdef _MSC_VER #pragma warning(push) diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index 5a94372b..41ce8ff6 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -21,7 +21,6 @@ #include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "util-math.hpp" #ifdef _MSC_VER #pragma warning(push) diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index 86f3ab4f..bcc31768 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -19,7 +19,6 @@ #include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "util-math.hpp" #ifdef _MSC_VER #pragma warning(push) @@ -260,7 +259,7 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render() // Downsample for (std::size_t n = 1; n <= actual_iterations; n++) { #ifdef ENABLE_PROFILING - auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Down %lld", n); + auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Down %" PRIuMAX, n); #endif // Select Texture @@ -297,7 +296,7 @@ std::shared_ptr<::gs::texture> gfx::blur::dual_filtering::render() // Upsample for (std::size_t n = actual_iterations; n > 0; n--) { #ifdef ENABLE_PROFILING - auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Up %lld", n); + auto gdm = gs::debug_marker(gs::debug_color_azure_radiance, "Up %" PRIuMAX, n); #endif // Select Texture diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index 148b5669..2058caea 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -18,7 +18,6 @@ #include "gfx-blur-gaussian-linear.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "util-math.hpp" #ifdef _MSC_VER #pragma warning(push) diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index fd8dbd8e..aa4a65e7 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -19,7 +19,6 @@ #include #include "obs/gs/gs-helper.hpp" #include "plugin.hpp" -#include "util-math.hpp" #ifdef _MSC_VER #pragma warning(push) diff --git a/source/gfx/gfx-source-texture.cpp b/source/gfx/gfx-source-texture.cpp index 5a8e367d..78bd9080 100644 --- a/source/gfx/gfx-source-texture.cpp +++ b/source/gfx/gfx-source-texture.cpp @@ -123,10 +123,10 @@ std::shared_ptr gfx::source_texture::render(std::size_t width, std: auto cctr = gs::debug_marker(gs::debug_color_capture, "gfx::source_texture '%s'", obs_source_get_name(_child->get())); #endif - auto op = _rt->render((uint32_t)width, (uint32_t)height); + auto op = _rt->render(static_cast(width), static_cast(height)); vec4 black; vec4_zero(&black); - gs_ortho(0, (float_t)width, 0, (float_t)height, 0, 1); + gs_ortho(0, static_cast(width), 0, static_cast(height), 0, 1); gs_clear(GS_CLEAR_COLOR, &black, 0, 0); obs_source_video_render(_child->get()); } diff --git a/source/gfx/shader/gfx-shader-param-basic.cpp b/source/gfx/shader/gfx-shader-param-basic.cpp index 3d411e02..75147994 100644 --- a/source/gfx/shader/gfx-shader-param-basic.cpp +++ b/source/gfx/shader/gfx-shader-param-basic.cpp @@ -96,9 +96,9 @@ gfx::shader::basic_parameter::basic_parameter(gs::effect_parameter param, std::s _keys[0] = get_key(); } else { for (std::size_t idx = 0; idx < get_size(); idx++) { - snprintf(string_buffer, sizeof(string_buffer), "[%d]", static_cast(idx)); + snprintf(string_buffer, sizeof(string_buffer), "[%" PRId32 "]", static_cast(idx)); _names[idx] = std::string(string_buffer, string_buffer + strnlen(string_buffer, sizeof(string_buffer))); - snprintf(string_buffer, sizeof(string_buffer), "%s[%d]", get_key().data(), static_cast(idx)); + snprintf(string_buffer, sizeof(string_buffer), "%s[%" PRId32 "]", get_key().data(), static_cast(idx)); _keys[idx] = std::string(string_buffer, string_buffer + strnlen(string_buffer, sizeof(string_buffer))); } } @@ -203,7 +203,7 @@ void gfx::shader::bool_parameter::update(obs_data_t* settings) // TODO: Support for bool[] if (get_size() == 1) { - _data[0] = obs_data_get_int(settings, get_key().data()); + _data[0] = static_cast(obs_data_get_int(settings, get_key().data())); } } diff --git a/source/gfx/shader/gfx-shader-param-basic.hpp b/source/gfx/shader/gfx-shader-param-basic.hpp index 007dfc9d..0ea9ce12 100644 --- a/source/gfx/shader/gfx-shader-param-basic.hpp +++ b/source/gfx/shader/gfx-shader-param-basic.hpp @@ -101,13 +101,13 @@ namespace gfx { bool_parameter(gs::effect_parameter param, std::string prefix); virtual ~bool_parameter(); - virtual void defaults(obs_data_t* settings); + void defaults(obs_data_t* settings) override; - virtual void properties(obs_properties_t* props, obs_data_t* settings) override; + void properties(obs_properties_t* props, obs_data_t* settings) override; - virtual void update(obs_data_t* settings) override; + void update(obs_data_t* settings) override; - virtual void assign() override; + void assign() override; }; struct float_parameter : public basic_parameter { @@ -117,13 +117,13 @@ namespace gfx { float_parameter(gs::effect_parameter param, std::string prefix); virtual ~float_parameter(); - virtual void defaults(obs_data_t* settings); + void defaults(obs_data_t* settings) override; - virtual void properties(obs_properties_t* props, obs_data_t* settings) override; + void properties(obs_properties_t* props, obs_data_t* settings) override; - virtual void update(obs_data_t* settings) override; + void update(obs_data_t* settings) override; - virtual void assign() override; + void assign() override; }; struct int_parameter : public basic_parameter { @@ -133,13 +133,13 @@ namespace gfx { int_parameter(gs::effect_parameter param, std::string prefix); virtual ~int_parameter(); - virtual void defaults(obs_data_t* settings); + void defaults(obs_data_t* settings) override; - virtual void properties(obs_properties_t* props, obs_data_t* settings) override; + void properties(obs_properties_t* props, obs_data_t* settings) override; - virtual void update(obs_data_t* settings) override; + void update(obs_data_t* settings) override; - virtual void assign() override; + void assign() override; }; } // namespace shader diff --git a/source/nvidia/cuda/nvidia-cuda-context.cpp b/source/nvidia/cuda/nvidia-cuda-context.cpp index 6d1ebefe..e738c93c 100644 --- a/source/nvidia/cuda/nvidia-cuda-context.cpp +++ b/source/nvidia/cuda/nvidia-cuda-context.cpp @@ -23,7 +23,7 @@ #ifdef WIN32 #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable : 4191 4365 4777 5039 5204) +#pragma warning(disable : 4191 4242 4244 4365 4777 4986 5039 5204) #endif #include #ifdef _MSC_VER diff --git a/source/nvidia/cuda/nvidia-cuda-context.hpp b/source/nvidia/cuda/nvidia-cuda-context.hpp index ad79df10..1ae042df 100644 --- a/source/nvidia/cuda/nvidia-cuda-context.hpp +++ b/source/nvidia/cuda/nvidia-cuda-context.hpp @@ -24,10 +24,10 @@ namespace nvidia::cuda { class context { std::shared_ptr<::nvidia::cuda::cuda> _cuda; - ::nvidia::cuda::context_t _ctx; + ::nvidia::cuda::context_t _ctx; // Primary Device Context - bool _has_device; + bool _has_device; ::nvidia::cuda::device_t _device; private: diff --git a/source/nvidia/cuda/nvidia-cuda-gs-texture.hpp b/source/nvidia/cuda/nvidia-cuda-gs-texture.hpp index 59fb3d7f..26e8f90c 100644 --- a/source/nvidia/cuda/nvidia-cuda-gs-texture.hpp +++ b/source/nvidia/cuda/nvidia-cuda-gs-texture.hpp @@ -28,10 +28,10 @@ namespace nvidia::cuda { class gstexture { std::shared_ptr<::nvidia::cuda::cuda> _cuda; std::shared_ptr _texture; - graphics_resource_t _resource; + graphics_resource_t _resource; bool _is_mapped; - array_t _pointer; + array_t _pointer; std::shared_ptr _stream; public: @@ -39,6 +39,6 @@ namespace nvidia::cuda { ~gstexture(); array_t map(std::shared_ptr stream); - void unmap(); + void unmap(); }; } // namespace nvidia::cuda diff --git a/source/nvidia/cuda/nvidia-cuda-memory.hpp b/source/nvidia/cuda/nvidia-cuda-memory.hpp index 57441c1c..315aefba 100644 --- a/source/nvidia/cuda/nvidia-cuda-memory.hpp +++ b/source/nvidia/cuda/nvidia-cuda-memory.hpp @@ -25,7 +25,7 @@ namespace nvidia::cuda { class memory { std::shared_ptr<::nvidia::cuda::cuda> _cuda; - device_ptr_t _pointer; + device_ptr_t _pointer; std::size_t _size; public: diff --git a/source/nvidia/cuda/nvidia-cuda-stream.hpp b/source/nvidia/cuda/nvidia-cuda-stream.hpp index 12c56d88..29403276 100644 --- a/source/nvidia/cuda/nvidia-cuda-stream.hpp +++ b/source/nvidia/cuda/nvidia-cuda-stream.hpp @@ -24,12 +24,11 @@ namespace nvidia::cuda { class stream { std::shared_ptr<::nvidia::cuda::cuda> _cuda; - ::nvidia::cuda::stream_t _stream; + ::nvidia::cuda::stream_t _stream; public: stream(std::shared_ptr<::nvidia::cuda::cuda> cuda, - ::nvidia::cuda::stream_flags flags = ::nvidia::cuda::stream_flags::DEFAULT, - std::int32_t priority = 0); + ::nvidia::cuda::stream_flags flags = ::nvidia::cuda::stream_flags::DEFAULT, std::int32_t priority = 0); ~stream(); ::nvidia::cuda::stream_t get(); diff --git a/source/nvidia/cuda/nvidia-cuda.hpp b/source/nvidia/cuda/nvidia-cuda.hpp index ff3dbc21..53bb71a3 100644 --- a/source/nvidia/cuda/nvidia-cuda.hpp +++ b/source/nvidia/cuda/nvidia-cuda.hpp @@ -18,10 +18,10 @@ */ #pragma once +#include "common.hpp" #include #include #include -#include "utility.hpp" #ifdef WIN32 #pragma warning(push) diff --git a/source/obs/gs/gs-indexbuffer.cpp b/source/obs/gs/gs-indexbuffer.cpp index 5e4b2749..e559d04f 100644 --- a/source/obs/gs/gs-indexbuffer.cpp +++ b/source/obs/gs/gs-indexbuffer.cpp @@ -31,12 +31,12 @@ gs::index_buffer::index_buffer(std::uint32_t maximumVertices) gs::index_buffer::index_buffer() : index_buffer(MAXIMUM_VERTICES) {} -gs::index_buffer::index_buffer(index_buffer& other) : index_buffer((uint32_t)other.size()) +gs::index_buffer::index_buffer(index_buffer& other) : index_buffer(static_cast(other.size())) { std::copy(other.begin(), other.end(), this->end()); } -gs::index_buffer::index_buffer(std::vector& other) : index_buffer((uint32_t)other.size()) +gs::index_buffer::index_buffer(std::vector& other) : index_buffer(static_cast(other.size())) { std::copy(other.begin(), other.end(), this->end()); } diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index f11e8768..50a33668 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -25,7 +25,7 @@ #ifdef _WIN32 #ifdef _MSC_VER #pragma warning(push) -#pragma warning(disable : 4201 4365 5039) +#pragma warning(disable : 4191 4242 4244 4365 4777 4986 5039 5204) #endif #include #include @@ -118,7 +118,6 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr ID3D11Resource* d3d_source = nullptr; ID3D11Resource* d3d_target = nullptr; if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) { - D3D11_TEXTURE2D_DESC td; d3d_source = reinterpret_cast(gs_texture_get_obj(source->get_object())); d3d_target = reinterpret_cast(gs_texture_get_obj(target->get_object())); d3d_device = reinterpret_cast(gs_get_device_obj()); @@ -138,14 +137,14 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr { #ifdef ENABLE_PROFILING - auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %lld", 0); + auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %" PRId64 "", 0); #endif #ifdef _WIN32 if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) { { // Retrieve maximum mip map level. D3D11_TEXTURE2D_DESC td; - reinterpret_cast(d3d_target)->GetDesc(&td); + static_cast(d3d_target)->GetDesc(&td); max_mip_level = td.MipLevels; } @@ -165,13 +164,13 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr // Render each mip map level. for (size_t mip = 1; mip < max_mip_level; mip++) { #ifdef ENABLE_PROFILING - auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %lld", mip); + auto cctr = gs::debug_marker(gs::debug_color_azure_radiance, "Mip Level %" PRIuMAX, mip); #endif uint32_t cwidth = std::max(width >> mip, 1); uint32_t cheight = std::max(height >> mip, 1); - float_t iwidth = 1. / static_cast(cwidth); - float_t iheight = 1. / static_cast(cheight); + float_t iwidth = 1.f / static_cast(cwidth); + float_t iheight = 1.f / static_cast(cheight); // Set up rendering state. gs_load_vertexbuffer(_vb->update(false)); @@ -187,7 +186,7 @@ void gs::mipmapper::rebuild(std::shared_ptr source, std::shared_ptr gs_set_cull_mode(GS_NEITHER); try { auto op = _rt->render(width, height); - gs_set_viewport(0, 0, cwidth, cheight); + gs_set_viewport(0, 0, static_cast(cwidth), static_cast(cheight)); gs_ortho(0, 1, 0, 1, 0, 1); vec4 black = {1., 1., 1., 1}; diff --git a/source/obs/gs/gs-sampler.cpp b/source/obs/gs/gs-sampler.cpp index 8794f75d..061a8201 100644 --- a/source/obs/gs/gs-sampler.cpp +++ b/source/obs/gs/gs-sampler.cpp @@ -19,7 +19,6 @@ #include "gs-sampler.hpp" #include -#include "utility.hpp" gs::sampler::sampler() { diff --git a/source/obs/gs/gs-texture.cpp b/source/obs/gs/gs-texture.cpp index ea4a83f7..db495e34 100644 --- a/source/obs/gs/gs-texture.cpp +++ b/source/obs/gs/gs-texture.cpp @@ -22,7 +22,6 @@ #include #include #include "obs/gs/gs-helper.hpp" -#include "util-math.hpp" static std::uint32_t decode_flags(gs::texture::flags texture_flags) { @@ -74,9 +73,9 @@ gs::texture::texture(std::uint32_t width, std::uint32_t height, std::uint32_t de throw std::logic_error("mip_levels must be at least 1"); if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) { - bool isPOT = (util::math::is_equal(pow(2, (int64_t)floor(log(width) / log(2))), width) - && util::math::is_equal(pow(2, (int64_t)floor(log(height) / log(2))), height) - && util::math::is_equal(pow(2, (int64_t)floor(log(depth) / log(2))), depth)); + bool isPOT = (util::math::is_equal(pow(2, static_cast(floor(log(width) / log(2)))), width) + && util::math::is_equal(pow(2, static_cast(floor(log(height) / log(2)))), height) + && util::math::is_equal(pow(2, static_cast(floor(log(depth) / log(2)))), depth)); if (!isPOT) throw std::logic_error("mip mapping requires power of two dimensions"); } @@ -102,7 +101,7 @@ gs::texture::texture(std::uint32_t size, gs_color_format format, std::uint32_t m throw std::logic_error("mip_levels must be at least 1"); if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) { - bool isPOT = util::math::is_equal(pow(2, (int64_t)floor(log(size) / log(2))), size); + bool isPOT = util::math::is_equal(pow(2, static_cast(floor(log(size) / log(2)))), size); if (!isPOT) throw std::logic_error("mip mapping requires power of two dimensions"); } diff --git a/source/obs/gs/gs-texture.hpp b/source/obs/gs/gs-texture.hpp index 14fed8bd..75b2a928 100644 --- a/source/obs/gs/gs-texture.hpp +++ b/source/obs/gs/gs-texture.hpp @@ -19,7 +19,6 @@ #pragma once #include "common.hpp" -#include "utility.hpp" namespace gs { class texture { diff --git a/source/obs/gs/gs-vertex.cpp b/source/obs/gs/gs-vertex.cpp index d0c1e68c..50b92331 100644 --- a/source/obs/gs/gs-vertex.cpp +++ b/source/obs/gs/gs-vertex.cpp @@ -19,7 +19,6 @@ #include "gs-vertex.hpp" #include -#include "utility.hpp" gs::vertex::vertex() : position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr), _has_store(true), _store(nullptr) diff --git a/source/obs/gs/gs-vertexbuffer.cpp b/source/obs/gs/gs-vertexbuffer.cpp index 77024f51..3d92acbe 100644 --- a/source/obs/gs/gs-vertexbuffer.cpp +++ b/source/obs/gs/gs-vertexbuffer.cpp @@ -20,7 +20,6 @@ #include "gs-vertexbuffer.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "utility.hpp" void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers) { @@ -37,10 +36,10 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers) _data = std::make_shared(); _data->num = _capacity; _data->num_tex = _layers; - _data->points = _positions = (vec3*)util::malloc_aligned(16, sizeof(vec3) * _capacity); - _data->normals = _normals = (vec3*)util::malloc_aligned(16, sizeof(vec3) * _capacity); - _data->tangents = _tangents = (vec3*)util::malloc_aligned(16, sizeof(vec3) * _capacity); - _data->colors = _colors = (uint32_t*)util::malloc_aligned(16, sizeof(uint32_t) * _capacity); + _data->points = _positions = static_cast(util::malloc_aligned(16, sizeof(vec3) * _capacity)); + _data->normals = _normals = static_cast(util::malloc_aligned(16, sizeof(vec3) * _capacity)); + _data->tangents = _tangents = static_cast(util::malloc_aligned(16, sizeof(vec3) * _capacity)); + _data->colors = _colors = static_cast(util::malloc_aligned(16, sizeof(uint32_t) * _capacity)); // Clear the allocated memory of any data. memset(_positions, 0, sizeof(vec3) * _capacity); @@ -51,9 +50,10 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers) if (_layers == 0) { _data->tvarray = nullptr; } else { - _data->tvarray = _uv_layers = (gs_tvertarray*)util::malloc_aligned(16, sizeof(gs_tvertarray) * _layers); + _data->tvarray = _uv_layers = + static_cast(util::malloc_aligned(16, sizeof(gs_tvertarray) * _layers)); for (uint8_t n = 0; n < _layers; n++) { - _uv_layers[n].array = _uvs[n] = (vec4*)util::malloc_aligned(16, sizeof(vec4) * _capacity); + _uv_layers[n].array = _uvs[n] = static_cast(util::malloc_aligned(16, sizeof(vec4) * _capacity)); _uv_layers[n].width = 4; memset(_uvs[n], 0, sizeof(vec4) * _capacity); } @@ -62,18 +62,18 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers) // Allocate actual GPU vertex buffer. { auto gctx = gs::context(); - _buffer = - decltype(_buffer)(gs_vertexbuffer_create(_data.get(), GS_DYNAMIC | GS_DUP_BUFFER), [this](gs_vertbuffer_t* v) { - try { - auto gctx = gs::context(); - gs_vertexbuffer_destroy(v); - } catch (...) { - if (obs_get_version() < MAKE_SEMANTIC_VERSION(26, 0, 0)) { - // Fixes a memory leak with OBS Studio versions older than 26.x. - gs_vbdata_destroy(_obs_data); - } - } - }); + _buffer = decltype(_buffer)(gs_vertexbuffer_create(_data.get(), GS_DYNAMIC | GS_DUP_BUFFER), + [this](gs_vertbuffer_t* v) { + try { + auto gctx = gs::context(); + gs_vertexbuffer_destroy(v); + } catch (...) { + if (obs_get_version() < MAKE_SEMANTIC_VERSION(26, 0, 0)) { + // Fixes a memory leak with OBS Studio versions older than 26.x. + gs_vbdata_destroy(_obs_data); + } + } + }); _obs_data = gs_vertexbuffer_get_data(_buffer.get()); } diff --git a/source/obs/gs/gs-vertexbuffer.hpp b/source/obs/gs/gs-vertexbuffer.hpp index 3c87bab3..90d0498d 100644 --- a/source/obs/gs/gs-vertexbuffer.hpp +++ b/source/obs/gs/gs-vertexbuffer.hpp @@ -21,7 +21,6 @@ #include "common.hpp" #include "gs-limits.hpp" #include "gs-vertex.hpp" -#include "utility.hpp" namespace gs { class vertex_buffer { diff --git a/source/obs/obs-signal-handler.hpp b/source/obs/obs-signal-handler.hpp index 4fd1a60e..5154bea6 100644 --- a/source/obs/obs-signal-handler.hpp +++ b/source/obs/obs-signal-handler.hpp @@ -19,7 +19,7 @@ #pragma once #include "common.hpp" -#include "util-event.hpp" +#include "util/util-event.hpp" namespace obs { template diff --git a/source/obs/obs-source.cpp b/source/obs/obs-source.cpp index b19364d0..737c865c 100644 --- a/source/obs/obs-source.cpp +++ b/source/obs/obs-source.cpp @@ -785,7 +785,7 @@ obs::deprecated_source& obs::deprecated_source::operator=(deprecated_source&& ot obs_source_type obs::deprecated_source::type() { if (!_self) { - return (obs_source_type)-1; + return static_cast(-1); } return obs_source_get_type(_self); } diff --git a/source/obs/obs-source.hpp b/source/obs/obs-source.hpp index 45128724..102ac452 100644 --- a/source/obs/obs-source.hpp +++ b/source/obs/obs-source.hpp @@ -19,7 +19,7 @@ #pragma once #include "common.hpp" -#include "util-event.hpp" +#include "util/util-event.hpp" namespace obs { class deprecated_source { diff --git a/source/plugin.cpp b/source/plugin.cpp index 3c9c00a3..d22ab466 100644 --- a/source/plugin.cpp +++ b/source/plugin.cpp @@ -21,8 +21,8 @@ #include #include #include "configuration.hpp" -#include "obs/obs-source-tracker.hpp" #include "obs/gs/gs-vertexbuffer.hpp" +#include "obs/obs-source-tracker.hpp" #ifdef ENABLE_ENCODER_FFMPEG #include "encoders/encoder-ffmpeg.hpp" @@ -86,7 +86,7 @@ try { // GS Stuff { - _gs_fstri_vb = std::make_shared(3, 1); + _gs_fstri_vb = std::make_shared(uint32_t(3), uint8_t(1)); { auto vtx = _gs_fstri_vb->at(0); vec3_set(vtx.position, 0, 0, 0); diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index cf93bc6e..aa60c958 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -21,7 +21,6 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "utility.hpp" #define ST "Source.Shader" diff --git a/source/transitions/transition-shader.cpp b/source/transitions/transition-shader.cpp index f714ca91..2c80f4e4 100644 --- a/source/transitions/transition-shader.cpp +++ b/source/transitions/transition-shader.cpp @@ -21,14 +21,13 @@ #include "strings.hpp" #include #include "obs/gs/gs-helper.hpp" -#include "utility.hpp" #define ST "Transition.Shader" using namespace streamfx::transition::shader; shader_instance::shader_instance(obs_data_t* data, obs_source_t* self) - : obs::source_instance(data, self), _is_main(false) + : obs::source_instance(data, self) { _fx = std::make_shared(self, gfx::shader::shader_mode::Transition); @@ -110,7 +109,8 @@ bool shader_instance::audio_render(uint64_t* ts_out, obs_source_audio_mix* audio [](void*, float_t t) { return t; }); } -void shader_instance::transition_start() { +void shader_instance::transition_start() +{ _fx->set_active(true); } diff --git a/source/transitions/transition-shader.hpp b/source/transitions/transition-shader.hpp index c1df4787..4766e410 100644 --- a/source/transitions/transition-shader.hpp +++ b/source/transitions/transition-shader.hpp @@ -28,8 +28,6 @@ namespace streamfx::transition::shader { class shader_instance : public obs::source_instance { std::shared_ptr _fx; - bool _is_main; - public: shader_instance(obs_data_t* data, obs_source_t* self); virtual ~shader_instance(); diff --git a/source/ui/ui-about-entry.cpp b/source/ui/ui-about-entry.cpp index aba1a69a..9fb09a08 100644 --- a/source/ui/ui-about-entry.cpp +++ b/source/ui/ui-about-entry.cpp @@ -70,6 +70,8 @@ streamfx::ui::about_entry::about_entry(QWidget* parent, streamfx::ui::about::ent case streamfx::ui::about::role_type::CREATOR: title->setText(D_TRANSLATE(i18n_role_creator.data())); break; + default: + break; } std::tuple els[]{ @@ -99,6 +101,8 @@ streamfx::ui::about_entry::about_entry(QWidget* parent, streamfx::ui::about::ent case streamfx::ui::about::link_type::SOCIAL_FACEBOOK: std::get<3>(el)->setIcon(QIcon(":/linktype/facebook")); break; + default: + break; } std::get<3>(el)->setText(QString::fromUtf8(std::get<2>(el).c_str())); std::get<4>(el).setUrl(QString::fromStdString(std::get<1>(el))); diff --git a/source/util-event.hpp b/source/util/util-event.hpp similarity index 100% rename from source/util-event.hpp rename to source/util/util-event.hpp diff --git a/source/util-math.hpp b/source/util/util-math.hpp similarity index 100% rename from source/util-math.hpp rename to source/util/util-math.hpp diff --git a/source/util-memory.cpp b/source/util/util-memory.cpp similarity index 100% rename from source/util-memory.cpp rename to source/util/util-memory.cpp diff --git a/source/util-profiler.cpp b/source/util/util-profiler.cpp similarity index 96% rename from source/util-profiler.cpp rename to source/util/util-profiler.cpp index 5e451d5a..a0dcead1 100644 --- a/source/util-profiler.cpp +++ b/source/util/util-profiler.cpp @@ -34,7 +34,7 @@ void util::profiler::track(std::chrono::nanoseconds duration) std::unique_lock ul(_timings_lock); auto itr = _timings.find(duration); if (itr == _timings.end()) { - _timings.insert({duration, 1}); + _timings.emplace(duration, 1u); } else { itr->second++; } @@ -113,10 +113,7 @@ std::chrono::nanoseconds util::profiler::percentile(double_t percentile, bool by // Find largest and smallest time. std::chrono::nanoseconds smallest = copy_timings.begin()->first; std::chrono::nanoseconds largest = copy_timings.rbegin()->first; - std::chrono::nanoseconds variance = largest - smallest; - std::chrono::nanoseconds threshold = - std::chrono::nanoseconds(smallest.count() + int64_t(variance.count() * percentile)); for (auto kv : copy_timings) { double_t kv_pct = double_t((kv.first - smallest).count()) / double_t(variance.count()); diff --git a/source/util-profiler.hpp b/source/util/util-profiler.hpp similarity index 100% rename from source/util-profiler.hpp rename to source/util/util-profiler.hpp diff --git a/source/util-threadpool.cpp b/source/util/util-threadpool.cpp similarity index 88% rename from source/util-threadpool.cpp rename to source/util/util-threadpool.cpp index 06ab7acc..1c597ba2 100644 --- a/source/util-threadpool.cpp +++ b/source/util/util-threadpool.cpp @@ -101,12 +101,14 @@ void util::threadpool::work() try { local_work->_callback(local_work->_data); } catch (std::exception const& ex) { - DLOG_WARNING(LOCAL_PREFIX "Worker %lX caught exception from task (%tX, %tX) with message: %s", - local_number, local_work->_callback.target(), + DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR + ") with message: %s", + local_number, reinterpret_cast(local_work->_callback.target()), reinterpret_cast(local_work->_data.get()), ex.what()); } catch (...) { - DLOG_WARNING(LOCAL_PREFIX "Worker %lX caught exception of unknown type from task (%tX, %tX).", - local_number, local_work->_callback.target(), + DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR + ", %" PRIxPTR ").", + local_number, reinterpret_cast(local_work->_callback.target()), reinterpret_cast(local_work->_data.get())); } } diff --git a/source/util-threadpool.hpp b/source/util/util-threadpool.hpp similarity index 100% rename from source/util-threadpool.hpp rename to source/util/util-threadpool.hpp diff --git a/source/utility.cpp b/source/util/utility.cpp similarity index 100% rename from source/utility.cpp rename to source/util/utility.cpp diff --git a/source/utility.hpp b/source/util/utility.hpp similarity index 100% rename from source/utility.hpp rename to source/util/utility.hpp