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 <GermanAizek@yandex.ru>
This commit is contained in:
lainon 2022-07-21 13:09:10 +02:00 committed by Michael Fabian 'Xaymar' Dirks
parent cbddee5b90
commit 6e1566386e
62 changed files with 200 additions and 206 deletions

View file

@ -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<int64_t>(std::thread::hardware_concurrency() * 2), 1);
static_cast<int64_t>(std::thread::hardware_concurrency()) * 2, 1);
}
};
@ -1220,9 +1220,9 @@ std::shared_ptr<handler::handler> 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<ffmpeg_manager> _ffmepg_encoder_factory_instance = nullptr;

View file

@ -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<ffmpeg_factory, ffmpeg_instance> {
@ -172,7 +172,7 @@ namespace streamfx::encoder::ffmpeg {
std::shared_ptr<handler::handler> get_handler(std::string codec);
bool has_handler(std::string codec);
bool has_handler(std::string_view codec);
public: // Singleton
static void initialize();

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -42,7 +42,7 @@ std::shared_ptr<AVFrame> avframe_queue::create_frame()
return frame;
}
avframe_queue::avframe_queue() {}
avframe_queue::avframe_queue() = default;
avframe_queue::~avframe_queue()
{

View file

@ -63,7 +63,7 @@ namespace streamfx::ffmpeg::hwapi {
virtual std::list<hwapi::device> enumerate_adapters() = 0;
virtual std::shared_ptr<hwapi::instance> create(hwapi::device target) = 0;
virtual std::shared_ptr<hwapi::instance> create(const hwapi::device& target) = 0;
virtual std::shared_ptr<hwapi::instance> create_from_obs() = 0;
};

View file

@ -102,7 +102,7 @@ std::list<device> d3d11::enumerate_adapters()
return std::move(adapters);
}
std::shared_ptr<instance> d3d11::create(device target)
std::shared_ptr<instance> d3d11::create(const device& target)
{
std::shared_ptr<d3d11_instance> inst;
ATL::CComPtr<ID3D11Device> device;
@ -156,10 +156,8 @@ struct D3D11AVFrame {
};
d3d11_instance::d3d11_instance(ATL::CComPtr<ID3D11Device> device, ATL::CComPtr<ID3D11DeviceContext> context)
{
_device = device;
_context = context;
}
: _device(device), _context(context)
{}
d3d11_instance::~d3d11_instance() {}

View file

@ -57,7 +57,7 @@ namespace streamfx::ffmpeg::hwapi {
virtual std::list<hwapi::device> enumerate_adapters() override;
virtual std::shared_ptr<hwapi::instance> create(hwapi::device target) override;
virtual std::shared_ptr<hwapi::instance> create(const hwapi::device& target) override;
virtual std::shared_ptr<hwapi::instance> create_from_obs() override;
};

View file

@ -24,7 +24,7 @@
using namespace streamfx::ffmpeg;
swscale::swscale() {}
swscale::swscale() = default;
swscale::~swscale()
{

View file

@ -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: <Error: %s>", ctx_codec->codec->name, text.c_str(),
DLOG_INFO("[%s] %s: <Error: %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 ? " <Default>" : "");
}
}
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: <Default>", ctx_codec->codec->name, text.c_str());
DLOG_INFO("[%s] %s: <Default>", ctx_codec->codec->name, text);
} else {
DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text.c_str(),
DLOG_INFO("[%s] %s: <Error: %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 ? " <Default>" : "");
DLOG_INFO("[%s] %s: %" PRId64 " %s%s", ctx_codec->codec->name, text, v, suffix, is_default ? " <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<std::string(int64_t)> 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<std::string(int64_t)> decoder)
void tools::print_av_option_string(AVCodecContext* ctx_codec, void* ctx_option, const char* option,
std::string_view text, std::function<std::string(int64_t)> 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: <Error: %s>", ctx_codec->codec->name, text.c_str(),
DLOG_INFO("[%s] %s: <Error: %s>", ctx_codec->codec->name, text,
streamfx::ffmpeg::tools::get_error_description(err));
} else {
std::string name = "<Unknown>";
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 ? " <Default>" : "");
}
}

View file

@ -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<std::string(int64_t)> 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<std::string(int64_t)> decoder);
void print_av_option_string2(AVCodecContext* context, std::string_view option, std::string_view text,

View file

@ -246,7 +246,7 @@ void autoframing_instance::update(obs_data_t* data)
// Tracking
_track_mode = static_cast<tracking_mode>(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<float>(_size.first) / static_cast<float>(_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<float>(width), 0, static_cast<float>(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<track_el> 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;

View file

@ -95,7 +95,7 @@ void displacement_instance::update(obs_data_t* settings)
_scale[0] = _scale[1] = static_cast<float_t>(obs_data_get_double(settings, ST_KEY_SCALE));
_scale_type = static_cast<float_t>(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<streamfx::obs::gs::texture>(new_file);

View file

@ -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 {

View file

@ -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<float>::lowest(),
std::numeric_limits<float>::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, "%");

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -41,8 +41,8 @@ streamfx::gfx::blur::gaussian_data::gaussian_data()
{
using namespace streamfx::util;
std::vector<double> kernel_dbl(ST_KERNEL_SIZE);
std::vector<float> kernel(ST_KERNEL_SIZE);
std::array<double, ST_KERNEL_SIZE> kernel_dbl;
std::vector<float> 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()

View file

@ -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;

View file

@ -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::obs::gs::effect>
streamfx::gfx::lut::consumer::prepare(streamfx::gfx::lut::color_depth depth,

View file

@ -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::obs::gs::texture> streamfx::gfx::lut::producer::produce(streamfx::gfx::lut::color_depth depth)
{

View file

@ -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<std::string, basic_field_type> 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;

View file

@ -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 {

View file

@ -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<std::string, texture_field_type> 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);

View file

@ -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,

View file

@ -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.");
}

View file

@ -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

View file

@ -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))

View file

@ -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);

View file

@ -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<uint8_t>(v);
_bboxes.current = 0;
// Update feature.

View file

@ -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();
}

View file

@ -62,14 +62,11 @@ streamfx::nvidia::cuda::gstexture::gstexture(std::shared_ptr<streamfx::obs::gs::
ID3D11Resource* resource = nullptr;
switch (_texture->get_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<ID3D11Resource*>(gs_texture_get_obj(_texture->get_object()));
break;
}
case streamfx::obs::gs::texture::type::Volume: {
resource = static_cast<ID3D11Resource*>(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)) {

View file

@ -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()

View file

@ -134,7 +134,7 @@ void streamfx::nvidia::vfx::superresolution::set_scale(float scale)
scale = std::clamp<float>(scale, 1., 4.);
// Match to nearest scale.
double factor = find_closest_scale_factor(scale);
float factor = static_cast<float>(find_closest_scale_factor(scale));
// If anything was changed, flag the effect as dirty.
if (!::streamfx::util::math::is_close<float>(_scale, factor, 0.01f))

View file

@ -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<gs_effect_t> 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<gs_epass_t> 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<gs_eparam_t> 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<int8_t*>(ptr), reinterpret_cast<int8_t*>(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<int8_t*>(ptr), reinterpret_cast<int8_t*>(ptr) + ptr_len - 1);
bfree(ptr);
} else {
v = "";
v.clear();
}
}

View file

@ -36,7 +36,7 @@ streamfx::obs::gs::effect_pass::effect_pass(gs_epass_t* pass, std::shared_ptr<gs
reset(pass, [](void*) {});
}
streamfx::obs::gs::effect_pass::~effect_pass() {}
streamfx::obs::gs::effect_pass::~effect_pass() = default;
std::string streamfx::obs::gs::effect_pass::name()
{
@ -58,22 +58,22 @@ streamfx::obs::gs::effect_parameter streamfx::obs::gs::effect_pass::get_vertex_p
return streamfx::obs::gs::effect_parameter((get()->vertshader_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) {

View file

@ -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

View file

@ -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;

View file

@ -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

View file

@ -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)

View file

@ -27,21 +27,21 @@
namespace streamfx::obs::gs {
class effect : public std::shared_ptr<gs_effect_t> {
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));
};

View file

@ -327,11 +327,11 @@ void streamfx::obs::gs::mipmapper::rebuild(std::shared_ptr<streamfx::obs::gs::te
// Copy from the render target to the target mip level.
#ifdef _WIN32
if (gs_get_device_type() == GS_DEVICE_DIRECT3D_11) {
d3d_copy_subregion(d3dinfo, _rt->get_texture(), mip, cwidth, cheight);
d3d_copy_subregion(d3dinfo, _rt->get_texture(), static_cast<uint32_t>(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<uint32_t>(mip), cwidth, cheight);
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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();

View file

@ -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);

View file

@ -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()
{

View file

@ -35,8 +35,8 @@ namespace streamfx::obs {
template<typename T>
class signal_handler : public signal_handler_base<T> {
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<obs_source_t> keepalive) : _keepalive(keepalive)
signal_handler(std::string_view signal, std::shared_ptr<obs_source_t> keepalive) : _keepalive(keepalive)
{
_signal = signal;
signal_handler_t* sh = obs_source_get_signal_handler(_keepalive.get());

View file

@ -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()

View file

@ -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);

View file

@ -70,7 +70,8 @@ streamfx::ui::about::about() : QDialog(reinterpret_cast<QWidget*>(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<uint64_t> rnd;
// Load entries from 'thanks.json'

View file

@ -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);

View file

@ -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);

View file

@ -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<std::recursive_mutex> lg(_lock);
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> lg(_lock);
std::lock_guard<std::recursive_mutex> lgo(other._lock);

View file

@ -45,10 +45,10 @@ streamfx::util::library::library(std::filesystem::path file) : _library(nullptr)
_library = reinterpret_cast<void*>(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);

View file

@ -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)

View file

@ -103,12 +103,12 @@ void streamfx::util::vec4a::operator delete[](void* p)
streamfx::util::free_aligned(p);
}
std::pair<int64_t, int64_t> streamfx::util::size_from_string(std::string text, bool allowSquare)
std::pair<int64_t, int64_t> 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<char*>(end);
long long res = strtoll(begin, &here, 0);

View file

@ -103,7 +103,7 @@ namespace streamfx::util {
static void operator delete[](void* p);
};
std::pair<int64_t, int64_t> size_from_string(std::string text, bool allowSquare = true);
std::pair<int64_t, int64_t> size_from_string(std::string_view text, bool allowSquare = true);
namespace math {
template<typename T>
@ -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)
{