util: Apply coding guidelines

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-06-08 04:18:02 +02:00
parent 1c067b3b5d
commit d62da72ce5
33 changed files with 297 additions and 277 deletions

View file

@ -1038,7 +1038,7 @@ obs_properties_t* ffmpeg_factory::get_properties2(instance_t* data)
if (_handler && _handler->has_keyframe_support(this)) { if (_handler && _handler->has_keyframe_support(this)) {
// Key-Frame Options // Key-Frame Options
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_KEYFRAMES, D_TRANSLATE(ST_I18N_KEYFRAMES), OBS_GROUP_NORMAL, grp); obs_properties_add_group(props, ST_I18N_KEYFRAMES, D_TRANSLATE(ST_I18N_KEYFRAMES), OBS_GROUP_NORMAL, grp);
} }
@ -1067,7 +1067,7 @@ obs_properties_t* ffmpeg_factory::get_properties2(instance_t* data)
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
auto prs = obs_properties_create(); auto prs = obs_properties_create();
obs_properties_add_group(props, ST_I18N_FFMPEG, D_TRANSLATE(ST_I18N_FFMPEG), OBS_GROUP_NORMAL, prs); obs_properties_add_group(props, ST_I18N_FFMPEG, D_TRANSLATE(ST_I18N_FFMPEG), OBS_GROUP_NORMAL, prs);
grp = prs; grp = prs;

View file

@ -117,7 +117,7 @@ bool streamfx::encoder::ffmpeg::handler::amf::is_available()
#endif #endif
#endif #endif
try { try {
util::library::load(lib_name); streamfx::util::library::load(lib_name);
return true; return true;
} catch (...) { } catch (...) {
return false; return false;
@ -210,9 +210,9 @@ void amf::get_properties_post(obs_properties_t* props, const AVCodec* codec)
} }
} }
util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_LOOKAHEAD, streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_LOOKAHEAD,
D_TRANSLATE(ST_I18N_RATECONTROL_LOOKAHEAD)); D_TRANSLATE(ST_I18N_RATECONTROL_LOOKAHEAD));
util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_FRAMESKIPPING, streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_FRAMESKIPPING,
D_TRANSLATE(ST_I18N_RATECONTROL_FRAMESKIPPING)); D_TRANSLATE(ST_I18N_RATECONTROL_FRAMESKIPPING));
} }
@ -267,16 +267,17 @@ void amf::get_properties_post(obs_properties_t* props, const AVCodec* codec)
obs_property_int_set_suffix(p, " frames"); obs_property_int_set_suffix(p, " frames");
} }
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_BFRAMEREFERENCES, streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_BFRAMEREFERENCES,
D_TRANSLATE(ST_I18N_OTHER_BFRAMEREFERENCES)); D_TRANSLATE(ST_I18N_OTHER_BFRAMEREFERENCES));
{ {
auto p = obs_properties_add_int_slider(grp, ST_KEY_OTHER_REFERENCEFRAMES, auto p = obs_properties_add_int_slider(grp, ST_KEY_OTHER_REFERENCEFRAMES,
D_TRANSLATE(ST_I18N_OTHER_REFERENCEFRAMES), -1, 16, 1); D_TRANSLATE(ST_I18N_OTHER_REFERENCEFRAMES), -1, 16, 1);
obs_property_int_set_suffix(p, " frames"); obs_property_int_set_suffix(p, " frames");
} }
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ENFORCEHRD, D_TRANSLATE(ST_I18N_OTHER_ENFORCEHRD)); streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ENFORCEHRD,
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_VBAQ, D_TRANSLATE(ST_I18N_OTHER_VBAQ)); D_TRANSLATE(ST_I18N_OTHER_ENFORCEHRD));
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER, streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_VBAQ, D_TRANSLATE(ST_I18N_OTHER_VBAQ));
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER,
D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER)); D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER));
} }
} }
@ -332,13 +333,13 @@ void amf::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* con
// Look Ahead (Pre-analysis, single frame lookahead) // Look Ahead (Pre-analysis, single frame lookahead)
if (int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD)); if (int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD));
!util::is_tristate_default(la)) { !streamfx::util::is_tristate_default(la)) {
av_opt_set_int(context->priv_data, "preanalysis", la, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "preanalysis", la, AV_OPT_SEARCH_CHILDREN);
} }
// Frame Skipping (Drop frames to maintain bitrate limits) // Frame Skipping (Drop frames to maintain bitrate limits)
if (int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_FRAMESKIPPING)); if (int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_FRAMESKIPPING));
!util::is_tristate_default(la)) { !streamfx::util::is_tristate_default(la)) {
if (std::string_view("amf_h264") == codec->name) { if (std::string_view("amf_h264") == codec->name) {
av_opt_set_int(context->priv_data, "frame_skipping", la, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "frame_skipping", la, AV_OPT_SEARCH_CHILDREN);
} else { } else {
@ -397,7 +398,7 @@ void amf::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* con
context->max_b_frames = static_cast<int>(bf); context->max_b_frames = static_cast<int>(bf);
} }
if (int64_t zl = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMEREFERENCES); if (int64_t zl = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMEREFERENCES);
!util::is_tristate_default(zl)) { !streamfx::util::is_tristate_default(zl)) {
av_opt_set_int(context->priv_data, "bf_ref", zl, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "bf_ref", zl, AV_OPT_SEARCH_CHILDREN);
} }
} }
@ -406,15 +407,16 @@ void amf::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* con
context->refs = static_cast<int>(refs); context->refs = static_cast<int>(refs);
} }
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ENFORCEHRD); !util::is_tristate_default(v)) { if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ENFORCEHRD); !streamfx::util::is_tristate_default(v)) {
av_opt_set_int(context->priv_data, "enforce_hrd", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "enforce_hrd", v, AV_OPT_SEARCH_CHILDREN);
} }
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_VBAQ); !util::is_tristate_default(v)) { if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_VBAQ); !streamfx::util::is_tristate_default(v)) {
av_opt_set_int(context->priv_data, "vbaq", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "vbaq", v, AV_OPT_SEARCH_CHILDREN);
} }
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ACCESSUNITDELIMITER); !util::is_tristate_default(v)) { if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ACCESSUNITDELIMITER);
!streamfx::util::is_tristate_default(v)) {
av_opt_set_int(context->priv_data, "aud", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "aud", v, AV_OPT_SEARCH_CHILDREN);
} }

View file

@ -146,7 +146,7 @@ void nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const A
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, S_CODEC_H264, D_TRANSLATE(S_CODEC_H264), OBS_GROUP_NORMAL, grp); obs_properties_add_group(props, S_CODEC_H264, D_TRANSLATE(S_CODEC_H264), OBS_GROUP_NORMAL, grp);
} }

View file

@ -154,7 +154,7 @@ void nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const A
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, S_CODEC_HEVC, D_TRANSLATE(S_CODEC_HEVC), OBS_GROUP_NORMAL, grp); obs_properties_add_group(props, S_CODEC_HEVC, D_TRANSLATE(S_CODEC_HEVC), OBS_GROUP_NORMAL, grp);
} }

View file

@ -162,7 +162,7 @@ bool streamfx::encoder::ffmpeg::handler::nvenc::is_available()
std::filesystem::path lib_name = "libnvidia-encode.so.1"; std::filesystem::path lib_name = "libnvidia-encode.so.1";
#endif #endif
try { try {
util::library::load(lib_name); streamfx::util::library::load(lib_name);
return true; return true;
} catch (...) { } catch (...) {
return false; return false;
@ -282,7 +282,7 @@ static bool modified_ratecontrol(obs_properties_t* props, obs_property_t*, obs_d
static bool modified_aq(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept static bool modified_aq(obs_properties_t* props, obs_property_t*, obs_data_t* settings) noexcept
{ {
bool spatial_aq = util::is_tristate_enabled(obs_data_get_int(settings, ST_KEY_AQ_SPATIAL)); bool spatial_aq = streamfx::util::is_tristate_enabled(obs_data_get_int(settings, ST_KEY_AQ_SPATIAL));
obs_property_set_visible(obs_properties_get(props, ST_KEY_AQ_STRENGTH), spatial_aq); obs_property_set_visible(obs_properties_get(props, ST_KEY_AQ_STRENGTH), spatial_aq);
return true; return true;
} }
@ -300,7 +300,7 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
{ {
{ // Rate Control { // Rate Control
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_RATECONTROL, D_TRANSLATE(ST_I18N_RATECONTROL), OBS_GROUP_NORMAL, obs_properties_add_group(props, ST_I18N_RATECONTROL, D_TRANSLATE(ST_I18N_RATECONTROL), OBS_GROUP_NORMAL,
grp); grp);
@ -316,7 +316,7 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_TWOPASS, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_TWOPASS,
D_TRANSLATE(ST_I18N_RATECONTROL_TWOPASS)); D_TRANSLATE(ST_I18N_RATECONTROL_TWOPASS));
} }
@ -328,19 +328,19 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEI, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEI,
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEI)); D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEI));
} }
if (strcmp(codec->name, "h264_nvenc") == 0) { if (strcmp(codec->name, "h264_nvenc") == 0) {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEB, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEB,
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEB)); D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEB));
} }
} }
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_RATECONTROL_LIMITS, D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS), obs_properties_add_group(props, ST_I18N_RATECONTROL_LIMITS, D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS),
OBS_GROUP_NORMAL, grp); OBS_GROUP_NORMAL, grp);
@ -375,7 +375,7 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_RATECONTROL_QP, D_TRANSLATE(ST_I18N_RATECONTROL_QP), obs_properties_add_group(props, ST_I18N_RATECONTROL_QP, D_TRANSLATE(ST_I18N_RATECONTROL_QP),
OBS_GROUP_NORMAL, grp); OBS_GROUP_NORMAL, grp);
@ -406,13 +406,14 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_AQ, D_TRANSLATE(ST_I18N_AQ), OBS_GROUP_NORMAL, grp); obs_properties_add_group(props, ST_I18N_AQ, D_TRANSLATE(ST_I18N_AQ), OBS_GROUP_NORMAL, grp);
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_AQ_SPATIAL, D_TRANSLATE(ST_I18N_AQ_SPATIAL)); auto p =
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_AQ_SPATIAL, D_TRANSLATE(ST_I18N_AQ_SPATIAL));
obs_property_set_modified_callback(p, modified_aq); obs_property_set_modified_callback(p, modified_aq);
} }
{ {
@ -420,13 +421,14 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
obs_properties_add_int_slider(grp, ST_KEY_AQ_STRENGTH, D_TRANSLATE(ST_I18N_AQ_STRENGTH), -1, 15, 1); obs_properties_add_int_slider(grp, ST_KEY_AQ_STRENGTH, D_TRANSLATE(ST_I18N_AQ_STRENGTH), -1, 15, 1);
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_AQ_TEMPORAL, D_TRANSLATE(ST_I18N_AQ_TEMPORAL)); auto p =
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_AQ_TEMPORAL, D_TRANSLATE(ST_I18N_AQ_TEMPORAL));
} }
} }
{ {
obs_properties_t* grp = props; obs_properties_t* grp = props;
if (!util::are_property_groups_broken()) { if (!streamfx::util::are_property_groups_broken()) {
grp = obs_properties_create(); grp = obs_properties_create();
obs_properties_add_group(props, ST_I18N_OTHER, D_TRANSLATE(ST_I18N_OTHER), OBS_GROUP_NORMAL, grp); obs_properties_add_group(props, ST_I18N_OTHER, D_TRANSLATE(ST_I18N_OTHER), OBS_GROUP_NORMAL, grp);
} }
@ -451,22 +453,22 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ZEROLATENCY, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ZEROLATENCY,
D_TRANSLATE(ST_I18N_OTHER_ZEROLATENCY)); D_TRANSLATE(ST_I18N_OTHER_ZEROLATENCY));
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_WEIGHTEDPREDICTION, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_WEIGHTEDPREDICTION,
D_TRANSLATE(ST_I18N_OTHER_WEIGHTEDPREDICTION)); D_TRANSLATE(ST_I18N_OTHER_WEIGHTEDPREDICTION));
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_NONREFERENCEPFRAMES, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_NONREFERENCEPFRAMES,
D_TRANSLATE(ST_I18N_OTHER_NONREFERENCEPFRAMES)); D_TRANSLATE(ST_I18N_OTHER_NONREFERENCEPFRAMES));
} }
{ {
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER, auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER,
D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER)); D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER));
} }
@ -569,13 +571,13 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c
// Look Ahead # of Frames // Look Ahead # of Frames
int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD)); int la = static_cast<int>(obs_data_get_int(settings, ST_KEY_RATECONTROL_LOOKAHEAD));
if (!util::is_tristate_default(la)) { if (!streamfx::util::is_tristate_default(la)) {
av_opt_set_int(context->priv_data, "rc-lookahead", la, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "rc-lookahead", la, AV_OPT_SEARCH_CHILDREN);
} }
// Adaptive I-Frames // Adaptive I-Frames
if (int64_t adapt_i = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEI); if (int64_t adapt_i = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEI);
!util::is_tristate_default(adapt_i) && (la != 0)) { !streamfx::util::is_tristate_default(adapt_i) && (la != 0)) {
// no-scenecut is inverted compared to our UI. // no-scenecut is inverted compared to our UI.
av_opt_set_int(context->priv_data, "no-scenecut", 1 - adapt_i, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "no-scenecut", 1 - adapt_i, AV_OPT_SEARCH_CHILDREN);
} }
@ -584,7 +586,7 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c
constexpr std::string_view h264_encoder_name = "h264_nvenc"; constexpr std::string_view h264_encoder_name = "h264_nvenc";
if (h264_encoder_name == codec->name) { if (h264_encoder_name == codec->name) {
if (int64_t adapt_b = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEB); if (int64_t adapt_b = obs_data_get_int(settings, ST_KEY_RATECONTROL_ADAPTIVEB);
!util::is_tristate_default(adapt_b) && (la != 0)) { !streamfx::util::is_tristate_default(adapt_b) && (la != 0)) {
av_opt_set_int(context->priv_data, "b_adapt", adapt_b, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "b_adapt", adapt_b, AV_OPT_SEARCH_CHILDREN);
} }
} }
@ -647,17 +649,17 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c
int64_t taq = obs_data_get_int(settings, ST_KEY_AQ_TEMPORAL); int64_t taq = obs_data_get_int(settings, ST_KEY_AQ_TEMPORAL);
if (strcmp(codec->name, "h264_nvenc") == 0) { if (strcmp(codec->name, "h264_nvenc") == 0) {
if (!util::is_tristate_default(saq)) if (!streamfx::util::is_tristate_default(saq))
av_opt_set_int(context->priv_data, "spatial-aq", saq, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "spatial-aq", saq, AV_OPT_SEARCH_CHILDREN);
if (!util::is_tristate_default(taq)) if (!streamfx::util::is_tristate_default(taq))
av_opt_set_int(context->priv_data, "temporal-aq", taq, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "temporal-aq", taq, AV_OPT_SEARCH_CHILDREN);
} else { } else {
if (!util::is_tristate_default(saq)) if (!streamfx::util::is_tristate_default(saq))
av_opt_set_int(context->priv_data, "spatial_aq", saq, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "spatial_aq", saq, AV_OPT_SEARCH_CHILDREN);
if (!util::is_tristate_default(taq)) if (!streamfx::util::is_tristate_default(taq))
av_opt_set_int(context->priv_data, "temporal_aq", taq, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "temporal_aq", taq, AV_OPT_SEARCH_CHILDREN);
} }
if (util::is_tristate_enabled(saq)) if (streamfx::util::is_tristate_enabled(saq))
if (int64_t aqs = obs_data_get_int(settings, ST_KEY_AQ_STRENGTH); aqs > -1) if (int64_t aqs = obs_data_get_int(settings, ST_KEY_AQ_STRENGTH); aqs > -1)
av_opt_set_int(context->priv_data, "aq-strength", static_cast<int>(aqs), AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "aq-strength", static_cast<int>(aqs), AV_OPT_SEARCH_CHILDREN);
} }
@ -666,20 +668,22 @@ void nvenc::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* c
if (int64_t bf = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMES); bf > -1) if (int64_t bf = obs_data_get_int(settings, ST_KEY_OTHER_BFRAMES); bf > -1)
context->max_b_frames = static_cast<int>(bf); context->max_b_frames = static_cast<int>(bf);
if (int64_t zl = obs_data_get_int(settings, ST_KEY_OTHER_ZEROLATENCY); !util::is_tristate_default(zl)) if (int64_t zl = obs_data_get_int(settings, ST_KEY_OTHER_ZEROLATENCY); !streamfx::util::is_tristate_default(zl))
av_opt_set_int(context->priv_data, "zerolatency", zl, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "zerolatency", zl, AV_OPT_SEARCH_CHILDREN);
if (int64_t nrp = obs_data_get_int(settings, ST_KEY_OTHER_NONREFERENCEPFRAMES); !util::is_tristate_default(nrp)) if (int64_t nrp = obs_data_get_int(settings, ST_KEY_OTHER_NONREFERENCEPFRAMES);
!streamfx::util::is_tristate_default(nrp))
av_opt_set_int(context->priv_data, "nonref_p", nrp, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "nonref_p", nrp, AV_OPT_SEARCH_CHILDREN);
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ACCESSUNITDELIMITER); !util::is_tristate_default(v)) if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_ACCESSUNITDELIMITER);
!streamfx::util::is_tristate_default(v))
av_opt_set_int(context->priv_data, "aud", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "aud", v, AV_OPT_SEARCH_CHILDREN);
if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_DECODEDPICTUREBUFFERSIZE); v > -1) if (int64_t v = obs_data_get_int(settings, ST_KEY_OTHER_DECODEDPICTUREBUFFERSIZE); v > -1)
av_opt_set_int(context->priv_data, "dpb_size", v, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "dpb_size", v, AV_OPT_SEARCH_CHILDREN);
int64_t wp = obs_data_get_int(settings, ST_KEY_OTHER_WEIGHTEDPREDICTION); int64_t wp = obs_data_get_int(settings, ST_KEY_OTHER_WEIGHTEDPREDICTION);
if ((context->max_b_frames > 0) && util::is_tristate_enabled(wp)) { if ((context->max_b_frames > 0) && streamfx::util::is_tristate_enabled(wp)) {
DLOG_WARNING("[%s] Weighted Prediction disabled because of B-Frames being used.", codec->name); DLOG_WARNING("[%s] Weighted Prediction disabled because of B-Frames being used.", codec->name);
av_opt_set_int(context->priv_data, "weighted_pred", 0, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "weighted_pred", 0, AV_OPT_SEARCH_CHILDREN);
} else if (!util::is_tristate_default(wp)) { } else if (!streamfx::util::is_tristate_default(wp)) {
av_opt_set_int(context->priv_data, "weighted_pred", wp, AV_OPT_SEARCH_CHILDREN); av_opt_set_int(context->priv_data, "weighted_pred", wp, AV_OPT_SEARCH_CHILDREN);
} }

View file

@ -62,14 +62,14 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_
{ {
#ifdef ENABLE_PROFILING #ifdef ENABLE_PROFILING
// Profiling // Profiling
_profile_capture = util::profiler::create(); _profile_capture = streamfx::util::profiler::create();
_profile_capture_realloc = util::profiler::create(); _profile_capture_realloc = streamfx::util::profiler::create();
_profile_capture_copy = util::profiler::create(); _profile_capture_copy = streamfx::util::profiler::create();
_profile_ar_realloc = util::profiler::create(); _profile_ar_realloc = streamfx::util::profiler::create();
_profile_ar_copy = util::profiler::create(); _profile_ar_copy = streamfx::util::profiler::create();
_profile_ar_transfer = util::profiler::create(); _profile_ar_transfer = streamfx::util::profiler::create();
_profile_ar_run = util::profiler::create(); _profile_ar_run = streamfx::util::profiler::create();
_profile_ar_calc = util::profiler::create(); _profile_ar_calc = streamfx::util::profiler::create();
#endif #endif
{ // Create render target, vertex buffer, and CUDA stream. { // Create render target, vertex buffer, and CUDA stream.
@ -404,7 +404,7 @@ void face_tracking_instance::async_track(std::shared_ptr<void> ptr)
double_t bcy = _ar_bboxes.boxes[0].y + bsy / 2.0; double_t bcy = _ar_bboxes.boxes[0].y + bsy / 2.0;
// Zoom, Aspect Ratio, Offset // Zoom, Aspect Ratio, Offset
bsy = util::math::lerp<double_t>(sy, bsy, _cfg_zoom); bsy = streamfx::util::math::lerp<double_t>(sy, bsy, _cfg_zoom);
bsy = std::clamp(bsy, 10 * aspect, static_cast<double_t>(_size.second)); bsy = std::clamp(bsy, 10 * aspect, static_cast<double_t>(_size.second));
bsx = bsy * aspect; bsx = bsy * aspect;
bcx += _ar_bboxes.boxes[0].width * _cfg_offset.first; bcx += _ar_bboxes.boxes[0].width * _cfg_offset.first;
@ -469,13 +469,14 @@ void face_tracking_instance::refresh_region_of_interest()
{ {
std::unique_lock<std::mutex> tlk(_values.lock); std::unique_lock<std::mutex> tlk(_values.lock);
double_t kalman_q = util::math::lerp<double_t>(1.0, 1e-6, _cfg_stability); double_t kalman_q = streamfx::util::math::lerp<double_t>(1.0, 1e-6, _cfg_stability);
double_t kalman_r = util::math::lerp<double_t>(std::numeric_limits<double_t>::epsilon(), 1e+2, _cfg_stability); double_t kalman_r =
streamfx::util::math::lerp<double_t>(std::numeric_limits<double_t>::epsilon(), 1e+2, _cfg_stability);
_filters.center[0] = util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[0]}; _filters.center[0] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[0]};
_filters.center[1] = util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[1]}; _filters.center[1] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[1]};
_filters.size[0] = util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[0]}; _filters.size[0] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[0]};
_filters.size[1] = util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[1]}; _filters.size[1] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[1]};
} }
void face_tracking_instance::load(obs_data_t* data) void face_tracking_instance::load(obs_data_t* data)
@ -593,7 +594,7 @@ bool face_tracking_instance::button_profile(obs_properties_t* props, obs_propert
{ {
DLOG_INFO("%-22s: %-10s %-10s %-10s %-10s %-10s", "Task", "Total", "Count", "Average", "99.9%ile", "95.0%ile"); DLOG_INFO("%-22s: %-10s %-10s %-10s %-10s %-10s", "Task", "Total", "Count", "Average", "99.9%ile", "95.0%ile");
std::pair<std::string, std::shared_ptr<util::profiler>> profilers[]{ std::pair<std::string, std::shared_ptr<streamfx::util::profiler>> profilers[]{
{"Capture", _profile_capture}, {"Reallocate", _profile_capture_realloc}, {"Capture", _profile_capture}, {"Reallocate", _profile_capture_realloc},
{"Copy", _profile_capture_copy}, {"AR Reallocate", _profile_ar_realloc}, {"Copy", _profile_capture_copy}, {"AR Reallocate", _profile_ar_realloc},
{"AR Copy", _profile_ar_copy}, {"AR Convert", _profile_ar_transfer}, {"AR Copy", _profile_ar_copy}, {"AR Convert", _profile_ar_transfer},

View file

@ -52,8 +52,8 @@ namespace streamfx::filter::nvidia {
// Operational Data // Operational Data
std::shared_ptr<gs::vertex_buffer> _geometry; std::shared_ptr<gs::vertex_buffer> _geometry;
struct { struct {
util::math::kalman1D<double_t> center[2]; streamfx::util::math::kalman1D<double_t> center[2];
util::math::kalman1D<double_t> size[2]; streamfx::util::math::kalman1D<double_t> size[2];
} _filters; } _filters;
struct { struct {
std::mutex lock; std::mutex lock;
@ -84,19 +84,19 @@ namespace streamfx::filter::nvidia {
NvCVImage _ar_image_temp; NvCVImage _ar_image_temp;
// Tasks // Tasks
std::shared_ptr<::util::threadpool::task> _async_initialize; std::shared_ptr<::streamfx::util::threadpool::task> _async_initialize;
std::shared_ptr<::util::threadpool::task> _async_track; std::shared_ptr<::streamfx::util::threadpool::task> _async_track;
#ifdef ENABLE_PROFILING #ifdef ENABLE_PROFILING
// Profiling // Profiling
std::shared_ptr<util::profiler> _profile_capture; std::shared_ptr<streamfx::util::profiler> _profile_capture;
std::shared_ptr<util::profiler> _profile_capture_realloc; std::shared_ptr<streamfx::util::profiler> _profile_capture_realloc;
std::shared_ptr<util::profiler> _profile_capture_copy; std::shared_ptr<streamfx::util::profiler> _profile_capture_copy;
std::shared_ptr<util::profiler> _profile_ar_realloc; std::shared_ptr<streamfx::util::profiler> _profile_ar_realloc;
std::shared_ptr<util::profiler> _profile_ar_copy; std::shared_ptr<streamfx::util::profiler> _profile_ar_copy;
std::shared_ptr<util::profiler> _profile_ar_transfer; std::shared_ptr<streamfx::util::profiler> _profile_ar_transfer;
std::shared_ptr<util::profiler> _profile_ar_run; std::shared_ptr<streamfx::util::profiler> _profile_ar_run;
std::shared_ptr<util::profiler> _profile_ar_calc; std::shared_ptr<streamfx::util::profiler> _profile_ar_calc;
#endif #endif
public: public:

View file

@ -89,10 +89,10 @@ transform_instance::transform_instance(obs_data_t* data, obs_source_t* context)
_source_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE); _source_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
_vertex_buffer = std::make_shared<gs::vertex_buffer>(uint32_t(4u), uint8_t(1u)); _vertex_buffer = std::make_shared<gs::vertex_buffer>(uint32_t(4u), uint8_t(1u));
_position = std::make_unique<util::vec3a>(); _position = std::make_unique<streamfx::util::vec3a>();
_rotation = std::make_unique<util::vec3a>(); _rotation = std::make_unique<streamfx::util::vec3a>();
_scale = std::make_unique<util::vec3a>(); _scale = std::make_unique<streamfx::util::vec3a>();
_shear = std::make_unique<util::vec3a>(); _shear = std::make_unique<streamfx::util::vec3a>();
vec3_set(_position.get(), 0, 0, 0); vec3_set(_position.get(), 0, 0, 0);
vec3_set(_rotation.get(), 0, 0, 0); vec3_set(_rotation.get(), 0, 0, 0);
@ -298,18 +298,19 @@ void transform_instance::video_render(gs_effect_t* effect)
if (_mipmap_enabled) { if (_mipmap_enabled) {
double_t aspect = double_t(base_width) / double_t(base_height); double_t aspect = double_t(base_width) / double_t(base_height);
double_t aspect2 = 1.0 / aspect; double_t aspect2 = 1.0 / aspect;
cache_width = std::clamp(uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(cache_width))), 1u, 16384u); cache_width =
cache_height = std::clamp(uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(cache_width))), 1u, 16384u);
std::clamp(uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(cache_height))), 1u, 16384u); cache_height = std::clamp(uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(cache_height))),
1u, 16384u);
if (aspect > 1.0) { if (aspect > 1.0) {
cache_height = std::clamp( cache_height = std::clamp(
uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(uint64_t(cache_width * aspect2)))), 1u, uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(uint64_t(cache_width * aspect2)))),
16384u); 1u, 16384u);
} else if (aspect < 1.0) { } else if (aspect < 1.0) {
cache_width = std::clamp( cache_width = std::clamp(
uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(uint64_t(cache_height * aspect)))), 1u, uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(uint64_t(cache_height * aspect)))),
16384u); 1u, 16384u);
} }
} }
@ -364,8 +365,8 @@ void transform_instance::video_render(gs_effect_t* effect)
gs::debug_marker gdr{gs::debug_color_allocate, "Allocate Mipmapped Texture"}; gs::debug_marker gdr{gs::debug_color_allocate, "Allocate Mipmapped Texture"};
#endif #endif
std::size_t mip_levels = std::max(util::math::get_power_of_two_exponent_ceil(cache_width), std::size_t mip_levels = std::max(streamfx::util::math::get_power_of_two_exponent_ceil(cache_width),
util::math::get_power_of_two_exponent_ceil(cache_height)); streamfx::util::math::get_power_of_two_exponent_ceil(cache_height));
_mipmap_texture = _mipmap_texture =
std::make_shared<gs::texture>(cache_width, cache_height, GS_RGBA, static_cast<uint32_t>(mip_levels), std::make_shared<gs::texture>(cache_width, cache_height, GS_RGBA, static_cast<uint32_t>(mip_levels),
nullptr, gs::texture::flags::None); nullptr, gs::texture::flags::None);

View file

@ -49,10 +49,10 @@ namespace streamfx::filter::transform {
bool _update_mesh; bool _update_mesh;
std::shared_ptr<gs::vertex_buffer> _vertex_buffer; std::shared_ptr<gs::vertex_buffer> _vertex_buffer;
uint32_t _rotation_order; uint32_t _rotation_order;
std::unique_ptr<util::vec3a> _position; std::unique_ptr<streamfx::util::vec3a> _position;
std::unique_ptr<util::vec3a> _rotation; std::unique_ptr<streamfx::util::vec3a> _rotation;
std::unique_ptr<util::vec3a> _scale; std::unique_ptr<streamfx::util::vec3a> _scale;
std::unique_ptr<util::vec3a> _shear; std::unique_ptr<streamfx::util::vec3a> _shear;
// Camera // Camera
bool _camera_orthographic; bool _camera_orthographic;

View file

@ -53,7 +53,8 @@ gfx::blur::gaussian_linear_data::gaussian_linear_data()
// Find actual kernel width. // Find actual kernel width.
for (double_t h = SEARCH_DENSITY; h < SEARCH_RANGE; h += SEARCH_DENSITY) { for (double_t h = SEARCH_DENSITY; h < SEARCH_RANGE; h += SEARCH_DENSITY) {
if (util::math::gaussian<double_t>(double_t(kernel_size + SEARCH_EXTENSION), h) > SEARCH_THRESHOLD) { if (streamfx::util::math::gaussian<double_t>(double_t(kernel_size + SEARCH_EXTENSION), h)
> SEARCH_THRESHOLD) {
actual_width = h; actual_width = h;
break; break;
} }
@ -62,7 +63,7 @@ gfx::blur::gaussian_linear_data::gaussian_linear_data()
// Calculate and normalize // Calculate and normalize
double_t sum = 0; double_t sum = 0;
for (std::size_t p = 0; p <= kernel_size; p++) { for (std::size_t p = 0; p <= kernel_size; p++) {
kernel_math[p] = util::math::gaussian<double_t>(double_t(p), actual_width); kernel_math[p] = streamfx::util::math::gaussian<double_t>(double_t(p), actual_width);
sum += kernel_math[p] * (p > 0 ? 2 : 1); sum += kernel_math[p] * (p > 0 ? 2 : 1);
} }

View file

@ -54,7 +54,8 @@ gfx::blur::gaussian_data::gaussian_data()
// Find actual kernel width. // Find actual kernel width.
for (double_t h = SEARCH_DENSITY; h < SEARCH_RANGE; h += SEARCH_DENSITY) { for (double_t h = SEARCH_DENSITY; h < SEARCH_RANGE; h += SEARCH_DENSITY) {
if (util::math::gaussian<double_t>(double_t(kernel_size + SEARCH_EXTENSION), h) > SEARCH_THRESHOLD) { if (streamfx::util::math::gaussian<double_t>(double_t(kernel_size + SEARCH_EXTENSION), h)
> SEARCH_THRESHOLD) {
actual_width = h; actual_width = h;
break; break;
} }
@ -63,7 +64,7 @@ gfx::blur::gaussian_data::gaussian_data()
// Calculate and normalize // Calculate and normalize
double_t sum = 0; double_t sum = 0;
for (std::size_t p = 0; p <= kernel_size; p++) { for (std::size_t p = 0; p <= kernel_size; p++) {
kernel_math[p] = util::math::gaussian<double_t>(double_t(p), actual_width); kernel_math[p] = streamfx::util::math::gaussian<double_t>(double_t(p), actual_width);
sum += kernel_math[p] * (p > 0 ? 2 : 1); sum += kernel_math[p] * (p > 0 ? 2 : 1);
} }

View file

@ -91,7 +91,7 @@ nvidia::cuda::cuda::cuda() : _library()
D_LOG_DEBUG("Initialization... (Addr: 0x%" PRIuPTR ")", this); D_LOG_DEBUG("Initialization... (Addr: 0x%" PRIuPTR ")", this);
_library = util::library::load(std::string_view(CUDA_NAME)); _library = streamfx::util::library::load(std::string_view(CUDA_NAME));
{ // 1. Load critical initialization functions. { // 1. Load critical initialization functions.
// Initialization // Initialization

View file

@ -176,7 +176,7 @@ namespace nvidia::cuda {
}; };
class cuda { class cuda {
std::shared_ptr<util::library> _library; std::shared_ptr<streamfx::util::library> _library;
public: public:
~cuda(); ~cuda();

View file

@ -48,7 +48,7 @@ gs::texture::texture(uint32_t width, uint32_t height, gs_color_format format, ui
throw std::logic_error("mip_levels must be at least 1"); throw std::logic_error("mip_levels must be at least 1");
if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) { if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) {
bool isPOT = util::math::is_power_of_two(width) && util::math::is_power_of_two(height); bool isPOT = streamfx::util::math::is_power_of_two(width) && streamfx::util::math::is_power_of_two(height);
if (!isPOT) if (!isPOT)
throw std::logic_error("mip mapping requires power of two dimensions"); throw std::logic_error("mip mapping requires power of two dimensions");
} }
@ -77,9 +77,10 @@ gs::texture::texture(uint32_t width, uint32_t height, uint32_t depth, gs_color_f
throw std::logic_error("mip_levels must be at least 1"); throw std::logic_error("mip_levels must be at least 1");
if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) { if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) {
bool isPOT = (util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(width) / log(2)))), width) bool isPOT =
&& util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(height) / log(2)))), height) (streamfx::util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(width) / log(2)))), width)
&& util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(depth) / log(2)))), depth)); && streamfx::util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(height) / log(2)))), height)
&& streamfx::util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(depth) / log(2)))), depth));
if (!isPOT) if (!isPOT)
throw std::logic_error("mip mapping requires power of two dimensions"); throw std::logic_error("mip mapping requires power of two dimensions");
} }
@ -105,7 +106,7 @@ gs::texture::texture(uint32_t size, gs_color_format format, uint32_t mip_levels,
throw std::logic_error("mip_levels must be at least 1"); throw std::logic_error("mip_levels must be at least 1");
if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) { if (mip_levels > 1 || ((texture_flags & flags::BuildMipMaps) == flags::BuildMipMaps)) {
bool isPOT = util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(size) / log(2)))), size); bool isPOT = streamfx::util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(size) / log(2)))), size);
if (!isPOT) if (!isPOT)
throw std::logic_error("mip mapping requires power of two dimensions"); throw std::logic_error("mip mapping requires power of two dimensions");
} }

View file

@ -23,7 +23,8 @@
gs::vertex::vertex() gs::vertex::vertex()
: position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr), _has_store(true), _store(nullptr) : position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr), _has_store(true), _store(nullptr)
{ {
_store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4) * MAXIMUM_UVW_LAYERS); _store =
streamfx::util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4) * MAXIMUM_UVW_LAYERS);
std::size_t offset = 0; std::size_t offset = 0;
@ -48,7 +49,7 @@ gs::vertex::vertex()
gs::vertex::~vertex() gs::vertex::~vertex()
{ {
if (_has_store) { if (_has_store) {
util::free_aligned(_store); streamfx::util::free_aligned(_store);
} }
} }

View file

@ -36,10 +36,10 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers)
_data = std::make_shared<decltype(_data)::element_type>(); _data = std::make_shared<decltype(_data)::element_type>();
_data->num = _capacity; _data->num = _capacity;
_data->num_tex = _layers; _data->num_tex = _layers;
_data->points = _positions = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity)); _data->points = _positions = static_cast<vec3*>(streamfx::util::malloc_aligned(16, sizeof(vec3) * _capacity));
_data->normals = _normals = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity)); _data->normals = _normals = static_cast<vec3*>(streamfx::util::malloc_aligned(16, sizeof(vec3) * _capacity));
_data->tangents = _tangents = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity)); _data->tangents = _tangents = static_cast<vec3*>(streamfx::util::malloc_aligned(16, sizeof(vec3) * _capacity));
_data->colors = _colors = static_cast<uint32_t*>(util::malloc_aligned(16, sizeof(uint32_t) * _capacity)); _data->colors = _colors = static_cast<uint32_t*>(streamfx::util::malloc_aligned(16, sizeof(uint32_t) * _capacity));
// Clear the allocated memory of any data. // Clear the allocated memory of any data.
memset(_positions, 0, sizeof(vec3) * _capacity); memset(_positions, 0, sizeof(vec3) * _capacity);
@ -51,9 +51,10 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers)
_data->tvarray = nullptr; _data->tvarray = nullptr;
} else { } else {
_data->tvarray = _uv_layers = _data->tvarray = _uv_layers =
static_cast<gs_tvertarray*>(util::malloc_aligned(16, sizeof(gs_tvertarray) * _layers)); static_cast<gs_tvertarray*>(streamfx::util::malloc_aligned(16, sizeof(gs_tvertarray) * _layers));
for (uint8_t n = 0; n < _layers; n++) { for (uint8_t n = 0; n < _layers; n++) {
_uv_layers[n].array = _uvs[n] = static_cast<vec4*>(util::malloc_aligned(16, sizeof(vec4) * _capacity)); _uv_layers[n].array = _uvs[n] =
static_cast<vec4*>(streamfx::util::malloc_aligned(16, sizeof(vec4) * _capacity));
_uv_layers[n].width = 4; _uv_layers[n].width = 4;
memset(_uvs[n], 0, sizeof(vec4) * _capacity); memset(_uvs[n], 0, sizeof(vec4) * _capacity);
} }
@ -85,13 +86,13 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers)
void gs::vertex_buffer::finalize() void gs::vertex_buffer::finalize()
{ {
// Free data // Free data
util::free_aligned(_positions); streamfx::util::free_aligned(_positions);
util::free_aligned(_normals); streamfx::util::free_aligned(_normals);
util::free_aligned(_tangents); streamfx::util::free_aligned(_tangents);
util::free_aligned(_colors); streamfx::util::free_aligned(_colors);
util::free_aligned(_uv_layers); streamfx::util::free_aligned(_uv_layers);
for (std::size_t n = 0; n < _layers; n++) { for (std::size_t n = 0; n < _layers; n++) {
util::free_aligned(_uvs[n]); streamfx::util::free_aligned(_uvs[n]);
} }
_buffer.reset(); _buffer.reset();

View file

@ -28,7 +28,7 @@ namespace obs {
std::string _signal; std::string _signal;
public: public:
util::event<T, calldata*> event; streamfx::util::event<T, calldata*> event;
}; };
template<typename T> template<typename T>
@ -88,7 +88,7 @@ namespace obs {
obs_source_remove_audio_capture_callback(_keepalive.get(), handle_audio, this); obs_source_remove_audio_capture_callback(_keepalive.get(), handle_audio, this);
} }
util::event<std::shared_ptr<obs_source_t>, const struct audio_data*, bool> event; streamfx::util::event<std::shared_ptr<obs_source_t>, const struct audio_data*, bool> event;
}; };
} // namespace obs } // namespace obs

View file

@ -89,49 +89,49 @@ namespace obs {
public: // Events public: // Events
struct { struct {
// Destroy and Remove // Destroy and Remove
util::event<obs::deprecated_source*> destroy; streamfx::util::event<obs::deprecated_source*> destroy;
util::event<obs::deprecated_source*> remove; streamfx::util::event<obs::deprecated_source*> remove;
// Saving, Loading and Update // Saving, Loading and Update
util::event<obs::deprecated_source*> save; streamfx::util::event<obs::deprecated_source*> save;
util::event<obs::deprecated_source*> load; streamfx::util::event<obs::deprecated_source*> load;
util::event<obs::deprecated_source*> update_properties; streamfx::util::event<obs::deprecated_source*> update_properties;
// Activate, Deactivate // Activate, Deactivate
util::event<obs::deprecated_source*> activate; streamfx::util::event<obs::deprecated_source*> activate;
util::event<obs::deprecated_source*> deactivate; streamfx::util::event<obs::deprecated_source*> deactivate;
// Show Hide // Show Hide
util::event<obs::deprecated_source*> show; streamfx::util::event<obs::deprecated_source*> show;
util::event<obs::deprecated_source*> hide; streamfx::util::event<obs::deprecated_source*> hide;
// Other // Other
util::event<obs::deprecated_source*, bool> enable; streamfx::util::event<obs::deprecated_source*, bool> enable;
util::event<obs::deprecated_source*, std::string, std::string> rename; streamfx::util::event<obs::deprecated_source*, std::string, std::string> rename;
util::event<obs::deprecated_source*, long long> update_flags; streamfx::util::event<obs::deprecated_source*, long long> update_flags;
// Hotkeys (PtM, PtT) // Hotkeys (PtM, PtT)
util::event<obs::deprecated_source*, bool> push_to_mute_changed; streamfx::util::event<obs::deprecated_source*, bool> push_to_mute_changed;
util::event<obs::deprecated_source*, long long> push_to_mute_delay; streamfx::util::event<obs::deprecated_source*, long long> push_to_mute_delay;
util::event<obs::deprecated_source*, bool> push_to_talk_changed; streamfx::util::event<obs::deprecated_source*, bool> push_to_talk_changed;
util::event<obs::deprecated_source*, long long> push_to_talk_delay; streamfx::util::event<obs::deprecated_source*, long long> push_to_talk_delay;
// Audio // Audio
util::event<obs::deprecated_source*, bool> mute; streamfx::util::event<obs::deprecated_source*, bool> mute;
util::event<obs::deprecated_source*, double&> volume; streamfx::util::event<obs::deprecated_source*, double&> volume;
util::event<obs::deprecated_source*, long long&> audio_sync; streamfx::util::event<obs::deprecated_source*, long long&> audio_sync;
util::event<obs::deprecated_source*, long long&> audio_mixers; streamfx::util::event<obs::deprecated_source*, long long&> audio_mixers;
util::event<obs::deprecated_source*, const audio_data*, bool> audio; streamfx::util::event<obs::deprecated_source*, const audio_data*, bool> audio;
// Filters // Filters
util::event<obs::deprecated_source*, obs_source_t*> filter_add; streamfx::util::event<obs::deprecated_source*, obs_source_t*> filter_add;
util::event<obs::deprecated_source*, obs_source_t*> filter_remove; streamfx::util::event<obs::deprecated_source*, obs_source_t*> filter_remove;
util::event<obs::deprecated_source*> reorder_filters; streamfx::util::event<obs::deprecated_source*> reorder_filters;
// Transition // Transition
util::event<obs::deprecated_source*> transition_start; streamfx::util::event<obs::deprecated_source*> transition_start;
util::event<obs::deprecated_source*> transition_video_stop; streamfx::util::event<obs::deprecated_source*> transition_video_stop;
util::event<obs::deprecated_source*> transition_stop; streamfx::util::event<obs::deprecated_source*> transition_stop;
} events; } events;
}; };
} // namespace obs } // namespace obs

View file

@ -73,7 +73,7 @@
//static std::shared_ptr<streamfx::updater> _updater; //static std::shared_ptr<streamfx::updater> _updater;
#endif #endif
static std::shared_ptr<util::threadpool> _threadpool; static std::shared_ptr<streamfx::util::threadpool> _threadpool;
static std::shared_ptr<gs::vertex_buffer> _gs_fstri_vb; static std::shared_ptr<gs::vertex_buffer> _gs_fstri_vb;
MODULE_EXPORT bool obs_module_load(void) MODULE_EXPORT bool obs_module_load(void)
@ -84,7 +84,7 @@ try {
streamfx::configuration::initialize(); streamfx::configuration::initialize();
// Initialize global Thread Pool. // Initialize global Thread Pool.
_threadpool = std::make_shared<util::threadpool>(); _threadpool = std::make_shared<streamfx::util::threadpool>();
// Initialize Source Tracker // Initialize Source Tracker
obs::source_tracker::initialize(); obs::source_tracker::initialize();
@ -260,7 +260,7 @@ try {
DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__); DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
} }
std::shared_ptr<util::threadpool> streamfx::threadpool() std::shared_ptr<streamfx::util::threadpool> streamfx::threadpool()
{ {
return _threadpool; return _threadpool;
} }

View file

@ -22,7 +22,7 @@
namespace streamfx { namespace streamfx {
// Threadpool // Threadpool
std::shared_ptr<util::threadpool> threadpool(); std::shared_ptr<streamfx::util::threadpool> threadpool();
void gs_draw_fullscreen_tri(); void gs_draw_fullscreen_tri();

View file

@ -178,7 +178,7 @@ bool streamfx::update_info::is_newer(update_info& other)
return true; return true;
} }
void streamfx::updater::task(util::threadpool_data_t) void streamfx::updater::task(streamfx::util::threadpool_data_t)
try { try {
{ {
std::vector<char> buffer; std::vector<char> buffer;
@ -227,7 +227,7 @@ void streamfx::updater::task_query(std::vector<char>& buffer)
{ {
static constexpr std::string_view ST_API_URL = "https://api.github.com/repos/Xaymar/obs-StreamFX/releases"; static constexpr std::string_view ST_API_URL = "https://api.github.com/repos/Xaymar/obs-StreamFX/releases";
util::curl curl; streamfx::util::curl curl;
size_t buffer_offset = 0; size_t buffer_offset = 0;
// Set headers (User-Agent is needed so Github can contact us!). // Set headers (User-Agent is needed so Github can contact us!).

View file

@ -51,7 +51,7 @@ namespace streamfx {
class updater { class updater {
// Internal // Internal
std::mutex _lock; std::mutex _lock;
std::weak_ptr<::util::threadpool::task> _task; std::weak_ptr<::streamfx::util::threadpool::task> _task;
// Options // Options
std::atomic_bool _gdpr; std::atomic_bool _gdpr;
@ -66,7 +66,7 @@ namespace streamfx {
bool _dirty; bool _dirty;
private: private:
void task(util::threadpool_data_t); void task(streamfx::util::threadpool_data_t);
void task_query(std::vector<char>& buffer); void task_query(std::vector<char>& buffer);
void task_parse(std::vector<char>& buffer); void task_parse(std::vector<char>& buffer);
@ -101,12 +101,12 @@ namespace streamfx {
public: public:
struct _ { struct _ {
util::event<updater&, bool> gdpr_changed; streamfx::util::event<updater&, bool> gdpr_changed;
util::event<updater&, bool> automation_changed; streamfx::util::event<updater&, bool> automation_changed;
util::event<updater&, update_channel> channel_changed; streamfx::util::event<updater&, update_channel> channel_changed;
util::event<updater&, std::string&> error; streamfx::util::event<updater&, std::string&> error;
util::event<updater&> refreshed; streamfx::util::event<updater&> refreshed;
} events; } events;
public: public:

View file

@ -21,7 +21,8 @@
#include "util-curl.hpp" #include "util-curl.hpp"
#include <sstream> #include <sstream>
int32_t util::curl::debug_helper(CURL* handle, curl_infotype type, char* data, size_t size, util::curl* self) int32_t streamfx::util::curl::debug_helper(CURL* handle, curl_infotype type, char* data, size_t size,
streamfx::util::curl* self)
{ {
if (self->_debug_callback) { if (self->_debug_callback) {
self->_debug_callback(handle, type, data, size); self->_debug_callback(handle, type, data, size);
@ -65,7 +66,7 @@ int32_t util::curl::debug_helper(CURL* handle, curl_infotype type, char* data, s
return 0; return 0;
} }
size_t util::curl::read_helper(void* ptr, size_t size, size_t count, util::curl* self) size_t streamfx::util::curl::read_helper(void* ptr, size_t size, size_t count, streamfx::util::curl* self)
{ {
if (self->_read_callback) { if (self->_read_callback) {
return self->_read_callback(ptr, size, count); return self->_read_callback(ptr, size, count);
@ -74,7 +75,7 @@ size_t util::curl::read_helper(void* ptr, size_t size, size_t count, util::curl*
} }
} }
size_t util::curl::write_helper(void* ptr, size_t size, size_t count, util::curl* self) size_t streamfx::util::curl::write_helper(void* ptr, size_t size, size_t count, streamfx::util::curl* self)
{ {
if (self->_write_callback) { if (self->_write_callback) {
return self->_write_callback(ptr, size, count); return self->_write_callback(ptr, size, count);
@ -83,7 +84,8 @@ size_t util::curl::write_helper(void* ptr, size_t size, size_t count, util::curl
} }
} }
int32_t util::curl::xferinfo_callback(util::curl* self, curl_off_t dlt, curl_off_t dln, curl_off_t ult, curl_off_t uln) int32_t streamfx::util::curl::xferinfo_callback(streamfx::util::curl* self, curl_off_t dlt, curl_off_t dln,
curl_off_t ult, curl_off_t uln)
{ {
if (self->_xferinfo_callback) { if (self->_xferinfo_callback) {
return self->_xferinfo_callback(static_cast<uint64_t>(dlt), static_cast<uint64_t>(dln), return self->_xferinfo_callback(static_cast<uint64_t>(dlt), static_cast<uint64_t>(dln),
@ -93,7 +95,7 @@ int32_t util::curl::xferinfo_callback(util::curl* self, curl_off_t dlt, curl_off
} }
} }
util::curl::curl() : _curl(), _read_callback(), _write_callback(), _headers() streamfx::util::curl::curl() : _curl(), _read_callback(), _write_callback(), _headers()
{ {
_curl = curl_easy_init(); _curl = curl_easy_init();
set_read_callback(nullptr); set_read_callback(nullptr);
@ -112,22 +114,22 @@ util::curl::curl() : _curl(), _read_callback(), _write_callback(), _headers()
#endif #endif
} }
util::curl::~curl() streamfx::util::curl::~curl()
{ {
curl_easy_cleanup(_curl); curl_easy_cleanup(_curl);
} }
void util::curl::clear_headers() void streamfx::util::curl::clear_headers()
{ {
_headers.clear(); _headers.clear();
} }
void util::curl::clear_header(std::string header) void streamfx::util::curl::clear_header(std::string header)
{ {
_headers.erase(header); _headers.erase(header);
} }
void util::curl::set_header(std::string header, std::string value) void streamfx::util::curl::set_header(std::string header, std::string value)
{ {
_headers.insert_or_assign(header, value); _headers.insert_or_assign(header, value);
} }
@ -137,7 +139,7 @@ size_t perform_get_kv_size(std::string a, std::string b)
return a.size() + 2 + b.size() + 1; return a.size() + 2 + b.size() + 1;
}; };
CURLcode util::curl::perform() CURLcode streamfx::util::curl::perform()
{ {
std::vector<char> buffer; std::vector<char> buffer;
struct curl_slist* headers = nullptr; struct curl_slist* headers = nullptr;
@ -177,12 +179,12 @@ CURLcode util::curl::perform()
return res; return res;
} }
void util::curl::reset() void streamfx::util::curl::reset()
{ {
curl_easy_reset(_curl); curl_easy_reset(_curl);
} }
CURLcode util::curl::set_read_callback(curl_io_callback_t cb) CURLcode streamfx::util::curl::set_read_callback(curl_io_callback_t cb)
{ {
_read_callback = cb; _read_callback = cb;
if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_READDATA, this); res != CURLE_OK) if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_READDATA, this); res != CURLE_OK)
@ -190,7 +192,7 @@ CURLcode util::curl::set_read_callback(curl_io_callback_t cb)
return curl_easy_setopt(_curl, CURLOPT_READFUNCTION, &read_helper); return curl_easy_setopt(_curl, CURLOPT_READFUNCTION, &read_helper);
} }
CURLcode util::curl::set_write_callback(curl_io_callback_t cb) CURLcode streamfx::util::curl::set_write_callback(curl_io_callback_t cb)
{ {
_write_callback = cb; _write_callback = cb;
if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this); res != CURLE_OK) if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_WRITEDATA, this); res != CURLE_OK)
@ -198,7 +200,7 @@ CURLcode util::curl::set_write_callback(curl_io_callback_t cb)
return curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, &write_helper); return curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, &write_helper);
} }
CURLcode util::curl::set_xferinfo_callback(curl_xferinfo_callback_t cb) CURLcode streamfx::util::curl::set_xferinfo_callback(curl_xferinfo_callback_t cb)
{ {
_xferinfo_callback = cb; _xferinfo_callback = cb;
if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_XFERINFODATA, this); res != CURLE_OK) if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_XFERINFODATA, this); res != CURLE_OK)
@ -206,7 +208,7 @@ CURLcode util::curl::set_xferinfo_callback(curl_xferinfo_callback_t cb)
return curl_easy_setopt(_curl, CURLOPT_XFERINFOFUNCTION, &xferinfo_callback); return curl_easy_setopt(_curl, CURLOPT_XFERINFOFUNCTION, &xferinfo_callback);
} }
CURLcode util::curl::set_debug_callback(curl_debug_callback_t cb) CURLcode streamfx::util::curl::set_debug_callback(curl_debug_callback_t cb)
{ {
_debug_callback = cb; _debug_callback = cb;
if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_DEBUGDATA, this); res != CURLE_OK) if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_DEBUGDATA, this); res != CURLE_OK)

View file

@ -33,7 +33,7 @@ extern "C" {
#include <curl/curl.h> #include <curl/curl.h>
} }
namespace util { namespace streamfx::util {
typedef std::function<size_t(void*, size_t, size_t)> curl_io_callback_t; typedef std::function<size_t(void*, size_t, size_t)> curl_io_callback_t;
typedef std::function<int32_t(uint64_t, uint64_t, uint64_t, uint64_t)> curl_xferinfo_callback_t; typedef std::function<int32_t(uint64_t, uint64_t, uint64_t, uint64_t)> curl_xferinfo_callback_t;
typedef std::function<void(CURL*, curl_infotype, char*, size_t)> curl_debug_callback_t; typedef std::function<void(CURL*, curl_infotype, char*, size_t)> curl_debug_callback_t;
@ -46,10 +46,11 @@ namespace util {
curl_debug_callback_t _debug_callback; curl_debug_callback_t _debug_callback;
std::map<std::string, std::string> _headers; std::map<std::string, std::string> _headers;
static int32_t debug_helper(CURL* handle, curl_infotype type, char* data, size_t size, util::curl* userptr); static int32_t debug_helper(CURL* handle, curl_infotype type, char* data, size_t size,
static size_t read_helper(void*, size_t, size_t, util::curl*); streamfx::util::curl* userptr);
static size_t write_helper(void*, size_t, size_t, util::curl*); static size_t read_helper(void*, size_t, size_t, streamfx::util::curl*);
static int32_t xferinfo_callback(util::curl*, curl_off_t, curl_off_t, curl_off_t, curl_off_t); static size_t write_helper(void*, size_t, size_t, streamfx::util::curl*);
static int32_t xferinfo_callback(streamfx::util::curl*, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
public: public:
curl(); curl();
@ -126,4 +127,4 @@ namespace util {
CURLcode set_debug_callback(curl_debug_callback_t cb); CURLcode set_debug_callback(curl_debug_callback_t cb);
}; };
} // namespace util } // namespace streamfx::util

View file

@ -23,7 +23,7 @@
#include <list> #include <list>
#include <mutex> #include <mutex>
namespace util { namespace streamfx::util {
template<typename... _args> template<typename... _args>
class event { class event {
std::list<std::function<void(_args...)>> _listeners; std::list<std::function<void(_args...)>> _listeners;
@ -171,4 +171,4 @@ namespace util {
this->_cb_clear = cb; this->_cb_clear = cb;
} }
}; };
} // namespace util } // namespace streamfx::util

View file

@ -33,7 +33,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#endif #endif
util::library::library(std::filesystem::path file) : _library(nullptr) streamfx::util::library::library(std::filesystem::path file) : _library(nullptr)
{ {
#if defined(ST_WINDOWS) #if defined(ST_WINDOWS)
SetLastError(ERROR_SUCCESS); SetLastError(ERROR_SUCCESS);
@ -64,7 +64,7 @@ util::library::library(std::filesystem::path file) : _library(nullptr)
#endif #endif
} }
util::library::~library() streamfx::util::library::~library()
{ {
#if defined(ST_WINDOWS) #if defined(ST_WINDOWS)
FreeLibrary(reinterpret_cast<HMODULE>(_library)); FreeLibrary(reinterpret_cast<HMODULE>(_library));
@ -73,7 +73,7 @@ util::library::~library()
#endif #endif
} }
void* util::library::load_symbol(std::string_view name) void* streamfx::util::library::load_symbol(std::string_view name)
{ {
#if defined(ST_WINDOWS) #if defined(ST_WINDOWS)
return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(_library), name.data())); return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(_library), name.data()));
@ -82,9 +82,9 @@ void* util::library::load_symbol(std::string_view name)
#endif #endif
} }
static std::unordered_map<std::string, std::weak_ptr<::util::library>> libraries; static std::unordered_map<std::string, std::weak_ptr<::streamfx::util::library>> libraries;
std::shared_ptr<::util::library> util::library::load(std::filesystem::path file) std::shared_ptr<::streamfx::util::library> streamfx::util::library::load(std::filesystem::path file)
{ {
auto kv = libraries.find(file.u8string()); auto kv = libraries.find(file.u8string());
if (kv != libraries.end()) { if (kv != libraries.end()) {
@ -93,13 +93,13 @@ std::shared_ptr<::util::library> util::library::load(std::filesystem::path file)
libraries.erase(kv); libraries.erase(kv);
} }
auto ptr = std::make_shared<::util::library>(file); auto ptr = std::make_shared<::streamfx::util::library>(file);
libraries.emplace(file.u8string(), ptr); libraries.emplace(file.u8string(), ptr);
return ptr; return ptr;
} }
std::shared_ptr<::util::library> util::library::load(std::string_view name) std::shared_ptr<::streamfx::util::library> streamfx::util::library::load(std::string_view name)
{ {
return load(std::filesystem::u8path(name)); return load(std::filesystem::u8path(name));
} }

View file

@ -23,7 +23,7 @@
#include <memory> #include <memory>
#include <string_view> #include <string_view>
namespace util { namespace streamfx::util {
class library { class library {
void* _library; void* _library;
@ -33,8 +33,8 @@ namespace util {
void* load_symbol(std::string_view name); void* load_symbol(std::string_view name);
static std::shared_ptr<::util::library> load(std::filesystem::path file); static std::shared_ptr<::streamfx::util::library> load(std::filesystem::path file);
static std::shared_ptr<::util::library> load(std::string_view name); static std::shared_ptr<::streamfx::util::library> load(std::string_view name);
}; };
} // namespace util } // namespace streamfx::util

View file

@ -21,7 +21,7 @@
#include "common.hpp" #include "common.hpp"
#include <stdarg.h> #include <stdarg.h>
void util::logging::log(level lvl, const char* format, ...) void streamfx::util::logging::log(level lvl, const char* format, ...)
{ {
const static std::map<level, int32_t> level_map = { const static std::map<level, int32_t> level_map = {
{level::LEVEL_DEBUG, LOG_DEBUG}, {level::LEVEL_DEBUG, LOG_DEBUG},

View file

@ -21,12 +21,12 @@
#include <cinttypes> #include <cinttypes>
#include <cstdint> #include <cstdint>
#define P_LOG(...) util::logging::log(__VA_ARGS__); #define P_LOG(...) streamfx::util::logging::log(__VA_ARGS__);
#define P_LOG_ERROR(...) P_LOG(util::logging::level::LEVEL_ERROR, __VA_ARGS__) #define P_LOG_ERROR(...) P_LOG(streamfx::util::logging::level::LEVEL_ERROR, __VA_ARGS__)
#define P_LOG_WARN(...) P_LOG(util::logging::level::LEVEL_WARN, __VA_ARGS__) #define P_LOG_WARN(...) P_LOG(streamfx::util::logging::level::LEVEL_WARN, __VA_ARGS__)
#define P_LOG_INFO(...) P_LOG(util::logging::level::LEVEL_INFO, __VA_ARGS__) #define P_LOG_INFO(...) P_LOG(streamfx::util::logging::level::LEVEL_INFO, __VA_ARGS__)
#ifdef _DEBUG #ifdef _DEBUG
#define P_LOG_DEBUG(...) P_LOG(util::logging::level::LEVEL_DEBUG, __VA_ARGS__) #define P_LOG_DEBUG(...) P_LOG(streamfx::util::logging::level::LEVEL_DEBUG, __VA_ARGS__)
#else #else
#define P_LOG_DEBUG(...) #define P_LOG_DEBUG(...)
#endif #endif
@ -46,7 +46,7 @@
#define __FUNCTION_NAME__ __func__ #define __FUNCTION_NAME__ __func__
#endif #endif
namespace util::logging { namespace streamfx::util::logging {
enum class level { enum class level {
LEVEL_DEBUG, // Debug information, which is not necessary to know at runtime. LEVEL_DEBUG, // Debug information, which is not necessary to know at runtime.
LEVEL_INFO, // Runtime information, which may or may not be needed for support. LEVEL_INFO, // Runtime information, which may or may not be needed for support.
@ -55,4 +55,4 @@ namespace util::logging {
}; };
void log(level lvl, const char* format, ...); void log(level lvl, const char* format, ...);
} // namespace util::logging } // namespace streamfx::util::logging

View file

@ -21,20 +21,21 @@
#include "common.hpp" #include "common.hpp"
#include <cstddef> #include <cstddef>
#define LOCAL_PREFIX "<util::threadpool> " #define ST_PREFIX "<util::threadpool> "
// Most Tasks likely wait for IO, so we can use that time for other tasks. // Most Tasks likely wait for IO, so we can use that time for other tasks.
#define CONCURRENCY_MULTIPLIER 2 #define ST_CONCURRENCY_MULTIPLIER 2
util::threadpool::threadpool() : _workers(), _worker_stop(false), _worker_idx(0), _tasks(), _tasks_lock(), _tasks_cv() streamfx::util::threadpool::threadpool()
: _workers(), _worker_stop(false), _worker_idx(0), _tasks(), _tasks_lock(), _tasks_cv()
{ {
std::size_t concurrency = static_cast<size_t>(std::thread::hardware_concurrency() * CONCURRENCY_MULTIPLIER); std::size_t concurrency = static_cast<size_t>(std::thread::hardware_concurrency() * ST_CONCURRENCY_MULTIPLIER);
for (std::size_t n = 0; n < concurrency; n++) { for (std::size_t n = 0; n < concurrency; n++) {
_workers.emplace_back(std::bind(&util::threadpool::work, this)); _workers.emplace_back(std::bind(&streamfx::util::threadpool::work, this));
} }
} }
util::threadpool::~threadpool() streamfx::util::threadpool::~threadpool()
{ {
_worker_stop = true; _worker_stop = true;
_tasks_cv.notify_all(); _tasks_cv.notify_all();
@ -46,9 +47,10 @@ util::threadpool::~threadpool()
} }
} }
std::shared_ptr<::util::threadpool::task> util::threadpool::push(threadpool_callback_t fn, threadpool_data_t data) std::shared_ptr<::streamfx::util::threadpool::task> streamfx::util::threadpool::push(threadpool_callback_t fn,
threadpool_data_t data)
{ {
auto task = std::make_shared<util::threadpool::task>(fn, data); auto task = std::make_shared<streamfx::util::threadpool::task>(fn, data);
std::unique_lock<std::mutex> lock(_tasks_lock); std::unique_lock<std::mutex> lock(_tasks_lock);
_tasks.emplace_back(task); _tasks.emplace_back(task);
@ -57,16 +59,16 @@ std::shared_ptr<::util::threadpool::task> util::threadpool::push(threadpool_call
return task; return task;
} }
void util::threadpool::pop(std::shared_ptr<::util::threadpool::task> work) void streamfx::util::threadpool::pop(std::shared_ptr<::streamfx::util::threadpool::task> work)
{ {
if (work) { if (work) {
work->_is_dead.store(true); work->_is_dead.store(true);
} }
} }
void util::threadpool::work() void streamfx::util::threadpool::work()
{ {
std::shared_ptr<util::threadpool::task> local_work{}; std::shared_ptr<streamfx::util::threadpool::task> local_work{};
uint32_t local_number = _worker_idx.fetch_add(1); uint32_t local_number = _worker_idx.fetch_add(1);
while (!_worker_stop) { while (!_worker_stop) {
@ -101,12 +103,12 @@ void util::threadpool::work()
try { try {
local_work->_callback(local_work->_data); local_work->_callback(local_work->_data);
} catch (std::exception const& ex) { } catch (std::exception const& ex) {
DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR
") with message: %s", ") with message: %s",
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()), local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
reinterpret_cast<ptrdiff_t>(local_work->_data.get()), ex.what()); reinterpret_cast<ptrdiff_t>(local_work->_data.get()), ex.what());
} catch (...) { } catch (...) {
DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR
", %" PRIxPTR ").", ", %" PRIxPTR ").",
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()), local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
reinterpret_cast<ptrdiff_t>(local_work->_data.get())); reinterpret_cast<ptrdiff_t>(local_work->_data.get()));
@ -120,7 +122,8 @@ void util::threadpool::work()
_worker_idx.fetch_sub(1); _worker_idx.fetch_sub(1);
} }
util::threadpool::task::task() {} streamfx::util::threadpool::task::task() {}
util::threadpool::task::task(threadpool_callback_t fn, threadpool_data_t dt) : _is_dead(false), _callback(fn), _data(dt) streamfx::util::threadpool::task::task(threadpool_callback_t fn, threadpool_data_t dt)
: _is_dead(false), _callback(fn), _data(dt)
{} {}

View file

@ -27,7 +27,7 @@
#include <stdexcept> #include <stdexcept>
#include <thread> #include <thread>
namespace util { namespace streamfx::util {
typedef std::shared_ptr<void> threadpool_data_t; typedef std::shared_ptr<void> threadpool_data_t;
typedef std::function<void(threadpool_data_t)> threadpool_callback_t; typedef std::function<void(threadpool_data_t)> threadpool_callback_t;
@ -43,14 +43,14 @@ namespace util {
task(); task();
task(threadpool_callback_t callback_function, threadpool_data_t data); task(threadpool_callback_t callback_function, threadpool_data_t data);
friend class util::threadpool; friend class streamfx::util::threadpool;
}; };
private: private:
std::list<std::thread> _workers; std::list<std::thread> _workers;
std::atomic_bool _worker_stop; std::atomic_bool _worker_stop;
std::atomic<uint32_t> _worker_idx; std::atomic<uint32_t> _worker_idx;
std::list<std::shared_ptr<::util::threadpool::task>> _tasks; std::list<std::shared_ptr<::streamfx::util::threadpool::task>> _tasks;
std::mutex _tasks_lock; std::mutex _tasks_lock;
std::condition_variable _tasks_cv; std::condition_variable _tasks_cv;
@ -58,11 +58,12 @@ namespace util {
threadpool(); threadpool();
~threadpool(); ~threadpool();
std::shared_ptr<::util::threadpool::task> push(threadpool_callback_t callback_function, threadpool_data_t data); std::shared_ptr<::streamfx::util::threadpool::task> push(threadpool_callback_t callback_function,
threadpool_data_t data);
void pop(std::shared_ptr<::util::threadpool::task> work); void pop(std::shared_ptr<::streamfx::util::threadpool::task> work);
private: private:
void work(); void work();
}; };
} // namespace util } // namespace streamfx::util

View file

@ -84,7 +84,7 @@ const char* obs_module_recursive_text(const char* to_translate, std::size_t dept
} }
} }
obs_property_t* util::obs_properties_add_tristate(obs_properties_t* props, const char* name, const char* desc) obs_property_t* streamfx::util::obs_properties_add_tristate(obs_properties_t* props, const char* name, const char* desc)
{ {
obs_property_t* p = obs_properties_add_list(props, name, desc, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); obs_property_t* p = obs_properties_add_list(props, name, desc, OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_property_list_add_int(p, D_TRANSLATE(S_STATE_DEFAULT), -1); obs_property_list_add_int(p, D_TRANSLATE(S_STATE_DEFAULT), -1);
@ -93,67 +93,67 @@ obs_property_t* util::obs_properties_add_tristate(obs_properties_t* props, const
return p; return p;
} }
void* util::vec2a::operator new(std::size_t count) void* streamfx::util::vec2a::operator new(std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void* util::vec2a::operator new[](std::size_t count) void* streamfx::util::vec2a::operator new[](std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void util::vec2a::operator delete(void* p) void streamfx::util::vec2a::operator delete(void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
void util::vec2a::operator delete[](void* p) void streamfx::util::vec2a::operator delete[](void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
void* util::vec3a::operator new(std::size_t count) void* streamfx::util::vec3a::operator new(std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void* util::vec3a::operator new[](std::size_t count) void* streamfx::util::vec3a::operator new[](std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void util::vec3a::operator delete(void* p) void streamfx::util::vec3a::operator delete(void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
void util::vec3a::operator delete[](void* p) void streamfx::util::vec3a::operator delete[](void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
void* util::vec4a::operator new(std::size_t count) void* streamfx::util::vec4a::operator new(std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void* util::vec4a::operator new[](std::size_t count) void* streamfx::util::vec4a::operator new[](std::size_t count)
{ {
return util::malloc_aligned(16, count); return streamfx::util::malloc_aligned(16, count);
} }
void util::vec4a::operator delete(void* p) void streamfx::util::vec4a::operator delete(void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
void util::vec4a::operator delete[](void* p) void streamfx::util::vec4a::operator delete[](void* p)
{ {
util::free_aligned(p); streamfx::util::free_aligned(p);
} }
std::pair<int64_t, int64_t> util::size_from_string(std::string text, bool allowSquare) std::pair<int64_t, int64_t> streamfx::util::size_from_string(std::string text, bool allowSquare)
{ {
int64_t width, height; int64_t width, height;
@ -193,7 +193,7 @@ std::pair<int64_t, int64_t> util::size_from_string(std::string text, bool allowS
return {width, height}; return {width, height};
} }
void* util::malloc_aligned(std::size_t align, std::size_t size) void* streamfx::util::malloc_aligned(std::size_t align, std::size_t size)
{ {
#ifdef USE_MSC_ALLOC #ifdef USE_MSC_ALLOC
return _aligned_malloc(size, align); return _aligned_malloc(size, align);
@ -217,7 +217,7 @@ void* util::malloc_aligned(std::size_t align, std::size_t size)
#endif #endif
} }
void util::free_aligned(void* mem) void streamfx::util::free_aligned(void* mem)
{ {
#ifdef USE_MSC_ALLOC #ifdef USE_MSC_ALLOC
_aligned_free(mem); _aligned_free(mem);

View file

@ -51,7 +51,7 @@ const char* obs_module_recursive_text(const char* to_translate, std::size_t dept
#define D_STR(s) #s #define D_STR(s) #s
#define D_VSTR(s) D_STR(s) #define D_VSTR(s) D_STR(s)
namespace util { namespace streamfx::util {
bool inline are_property_groups_broken() bool inline are_property_groups_broken()
{ {
return obs_get_version() < MAKE_SEMANTIC_VERSION(24, 0, 0); return obs_get_version() < MAKE_SEMANTIC_VERSION(24, 0, 0);
@ -238,4 +238,4 @@ namespace util {
} }
void* malloc_aligned(std::size_t align, std::size_t size); void* malloc_aligned(std::size_t align, std::size_t size);
void free_aligned(void* mem); void free_aligned(void* mem);
} // namespace util } // namespace streamfx::util