mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-10 22:05:06 +00:00
util: Apply coding guidelines
This commit is contained in:
parent
1c067b3b5d
commit
d62da72ce5
33 changed files with 297 additions and 277 deletions
|
@ -1038,7 +1038,7 @@ obs_properties_t* ffmpeg_factory::get_properties2(instance_t* data)
|
|||
if (_handler && _handler->has_keyframe_support(this)) {
|
||||
// Key-Frame Options
|
||||
obs_properties_t* grp = props;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
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;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
auto prs = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_I18N_FFMPEG, D_TRANSLATE(ST_I18N_FFMPEG), OBS_GROUP_NORMAL, prs);
|
||||
grp = prs;
|
||||
|
|
|
@ -117,7 +117,7 @@ bool streamfx::encoder::ffmpeg::handler::amf::is_available()
|
|||
#endif
|
||||
#endif
|
||||
try {
|
||||
util::library::load(lib_name);
|
||||
streamfx::util::library::load(lib_name);
|
||||
return true;
|
||||
} catch (...) {
|
||||
return false;
|
||||
|
@ -210,10 +210,10 @@ void amf::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
|||
}
|
||||
}
|
||||
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_LOOKAHEAD,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_LOOKAHEAD));
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_FRAMESKIPPING,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_FRAMESKIPPING));
|
||||
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_LOOKAHEAD,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_LOOKAHEAD));
|
||||
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_FRAMESKIPPING,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_FRAMESKIPPING));
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -267,17 +267,18 @@ void amf::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
|||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_BFRAMEREFERENCES,
|
||||
D_TRANSLATE(ST_I18N_OTHER_BFRAMEREFERENCES));
|
||||
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_BFRAMEREFERENCES,
|
||||
D_TRANSLATE(ST_I18N_OTHER_BFRAMEREFERENCES));
|
||||
{
|
||||
auto p = obs_properties_add_int_slider(grp, ST_KEY_OTHER_REFERENCEFRAMES,
|
||||
D_TRANSLATE(ST_I18N_OTHER_REFERENCEFRAMES), -1, 16, 1);
|
||||
obs_property_int_set_suffix(p, " frames");
|
||||
}
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ENFORCEHRD, D_TRANSLATE(ST_I18N_OTHER_ENFORCEHRD));
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_VBAQ, D_TRANSLATE(ST_I18N_OTHER_VBAQ));
|
||||
util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER,
|
||||
D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER));
|
||||
streamfx::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_VBAQ, D_TRANSLATE(ST_I18N_OTHER_VBAQ));
|
||||
streamfx::util::obs_properties_add_tristate(grp, ST_KEY_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)
|
||||
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);
|
||||
}
|
||||
|
||||
// Frame Skipping (Drop frames to maintain bitrate limits)
|
||||
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) {
|
||||
av_opt_set_int(context->priv_data, "frame_skipping", la, AV_OPT_SEARCH_CHILDREN);
|
||||
} 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -406,15 +407,16 @@ void amf::update(obs_data_t* settings, const AVCodec* codec, AVCodecContext* con
|
|||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ void nvenc_h264_handler::get_encoder_properties(obs_properties_t* props, const A
|
|||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, S_CODEC_H264, D_TRANSLATE(S_CODEC_H264), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
|
|
@ -154,7 +154,7 @@ void nvenc_hevc_handler::get_encoder_properties(obs_properties_t* props, const A
|
|||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, S_CODEC_HEVC, D_TRANSLATE(S_CODEC_HEVC), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ bool streamfx::encoder::ffmpeg::handler::nvenc::is_available()
|
|||
std::filesystem::path lib_name = "libnvidia-encode.so.1";
|
||||
#endif
|
||||
try {
|
||||
util::library::load(lib_name);
|
||||
streamfx::util::library::load(lib_name);
|
||||
return true;
|
||||
} catch (...) {
|
||||
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
|
||||
{
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
|||
{
|
||||
{ // Rate Control
|
||||
obs_properties_t* grp = props;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_I18N_RATECONTROL, D_TRANSLATE(ST_I18N_RATECONTROL), OBS_GROUP_NORMAL,
|
||||
grp);
|
||||
|
@ -316,8 +316,8 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
|||
}
|
||||
|
||||
{
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_TWOPASS,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_TWOPASS));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_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,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEI));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEI,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEI));
|
||||
}
|
||||
|
||||
if (strcmp(codec->name, "h264_nvenc") == 0) {
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEB,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEB));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_RATECONTROL_ADAPTIVEB,
|
||||
D_TRANSLATE(ST_I18N_RATECONTROL_ADAPTIVEB));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
obs_properties_t* grp = props;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_I18N_RATECONTROL_LIMITS, D_TRANSLATE(ST_I18N_RATECONTROL_LIMITS),
|
||||
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;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_I18N_RATECONTROL_QP, D_TRANSLATE(ST_I18N_RATECONTROL_QP),
|
||||
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;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
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);
|
||||
}
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
{
|
||||
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;
|
||||
if (!util::are_property_groups_broken()) {
|
||||
if (!streamfx::util::are_property_groups_broken()) {
|
||||
grp = obs_properties_create();
|
||||
obs_properties_add_group(props, ST_I18N_OTHER, D_TRANSLATE(ST_I18N_OTHER), OBS_GROUP_NORMAL, grp);
|
||||
}
|
||||
|
@ -451,23 +453,23 @@ void nvenc::get_properties_post(obs_properties_t* props, const AVCodec* codec)
|
|||
}
|
||||
|
||||
{
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ZEROLATENCY,
|
||||
D_TRANSLATE(ST_I18N_OTHER_ZEROLATENCY));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ZEROLATENCY,
|
||||
D_TRANSLATE(ST_I18N_OTHER_ZEROLATENCY));
|
||||
}
|
||||
|
||||
{
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_WEIGHTEDPREDICTION,
|
||||
D_TRANSLATE(ST_I18N_OTHER_WEIGHTEDPREDICTION));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_WEIGHTEDPREDICTION,
|
||||
D_TRANSLATE(ST_I18N_OTHER_WEIGHTEDPREDICTION));
|
||||
}
|
||||
|
||||
{
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_NONREFERENCEPFRAMES,
|
||||
D_TRANSLATE(ST_I18N_OTHER_NONREFERENCEPFRAMES));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_OTHER_NONREFERENCEPFRAMES,
|
||||
D_TRANSLATE(ST_I18N_OTHER_NONREFERENCEPFRAMES));
|
||||
}
|
||||
|
||||
{
|
||||
auto p = util::obs_properties_add_tristate(grp, ST_KEY_OTHER_ACCESSUNITDELIMITER,
|
||||
D_TRANSLATE(ST_I18N_OTHER_ACCESSUNITDELIMITER));
|
||||
auto p = streamfx::util::obs_properties_add_tristate(grp, ST_KEY_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
|
||||
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);
|
||||
}
|
||||
|
||||
// Adaptive I-Frames
|
||||
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.
|
||||
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";
|
||||
if (h264_encoder_name == codec->name) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
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);
|
||||
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);
|
||||
} 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);
|
||||
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);
|
||||
}
|
||||
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)
|
||||
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)
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -62,14 +62,14 @@ face_tracking_instance::face_tracking_instance(obs_data_t* settings, obs_source_
|
|||
{
|
||||
#ifdef ENABLE_PROFILING
|
||||
// Profiling
|
||||
_profile_capture = util::profiler::create();
|
||||
_profile_capture_realloc = util::profiler::create();
|
||||
_profile_capture_copy = util::profiler::create();
|
||||
_profile_ar_realloc = util::profiler::create();
|
||||
_profile_ar_copy = util::profiler::create();
|
||||
_profile_ar_transfer = util::profiler::create();
|
||||
_profile_ar_run = util::profiler::create();
|
||||
_profile_ar_calc = util::profiler::create();
|
||||
_profile_capture = streamfx::util::profiler::create();
|
||||
_profile_capture_realloc = streamfx::util::profiler::create();
|
||||
_profile_capture_copy = streamfx::util::profiler::create();
|
||||
_profile_ar_realloc = streamfx::util::profiler::create();
|
||||
_profile_ar_copy = streamfx::util::profiler::create();
|
||||
_profile_ar_transfer = streamfx::util::profiler::create();
|
||||
_profile_ar_run = streamfx::util::profiler::create();
|
||||
_profile_ar_calc = streamfx::util::profiler::create();
|
||||
#endif
|
||||
|
||||
{ // 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;
|
||||
|
||||
// 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));
|
||||
bsx = bsy * aspect;
|
||||
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);
|
||||
|
||||
double_t kalman_q = 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_q = streamfx::util::math::lerp<double_t>(1.0, 1e-6, _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[1] = 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[1] = util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[1]};
|
||||
_filters.center[0] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[0]};
|
||||
_filters.center[1] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.center[1]};
|
||||
_filters.size[0] = streamfx::util::math::kalman1D<double_t>{kalman_q, kalman_r, 1., _values.size[0]};
|
||||
_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)
|
||||
|
@ -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");
|
||||
|
||||
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},
|
||||
{"Copy", _profile_capture_copy}, {"AR Reallocate", _profile_ar_realloc},
|
||||
{"AR Copy", _profile_ar_copy}, {"AR Convert", _profile_ar_transfer},
|
||||
|
|
|
@ -52,8 +52,8 @@ namespace streamfx::filter::nvidia {
|
|||
// Operational Data
|
||||
std::shared_ptr<gs::vertex_buffer> _geometry;
|
||||
struct {
|
||||
util::math::kalman1D<double_t> center[2];
|
||||
util::math::kalman1D<double_t> size[2];
|
||||
streamfx::util::math::kalman1D<double_t> center[2];
|
||||
streamfx::util::math::kalman1D<double_t> size[2];
|
||||
} _filters;
|
||||
struct {
|
||||
std::mutex lock;
|
||||
|
@ -84,19 +84,19 @@ namespace streamfx::filter::nvidia {
|
|||
NvCVImage _ar_image_temp;
|
||||
|
||||
// Tasks
|
||||
std::shared_ptr<::util::threadpool::task> _async_initialize;
|
||||
std::shared_ptr<::util::threadpool::task> _async_track;
|
||||
std::shared_ptr<::streamfx::util::threadpool::task> _async_initialize;
|
||||
std::shared_ptr<::streamfx::util::threadpool::task> _async_track;
|
||||
|
||||
#ifdef ENABLE_PROFILING
|
||||
// Profiling
|
||||
std::shared_ptr<util::profiler> _profile_capture;
|
||||
std::shared_ptr<util::profiler> _profile_capture_realloc;
|
||||
std::shared_ptr<util::profiler> _profile_capture_copy;
|
||||
std::shared_ptr<util::profiler> _profile_ar_realloc;
|
||||
std::shared_ptr<util::profiler> _profile_ar_copy;
|
||||
std::shared_ptr<util::profiler> _profile_ar_transfer;
|
||||
std::shared_ptr<util::profiler> _profile_ar_run;
|
||||
std::shared_ptr<util::profiler> _profile_ar_calc;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_capture;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_capture_realloc;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_capture_copy;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_ar_realloc;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_ar_copy;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_ar_transfer;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_ar_run;
|
||||
std::shared_ptr<streamfx::util::profiler> _profile_ar_calc;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
|
@ -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);
|
||||
_vertex_buffer = std::make_shared<gs::vertex_buffer>(uint32_t(4u), uint8_t(1u));
|
||||
|
||||
_position = std::make_unique<util::vec3a>();
|
||||
_rotation = std::make_unique<util::vec3a>();
|
||||
_scale = std::make_unique<util::vec3a>();
|
||||
_shear = std::make_unique<util::vec3a>();
|
||||
_position = std::make_unique<streamfx::util::vec3a>();
|
||||
_rotation = std::make_unique<streamfx::util::vec3a>();
|
||||
_scale = std::make_unique<streamfx::util::vec3a>();
|
||||
_shear = std::make_unique<streamfx::util::vec3a>();
|
||||
|
||||
vec3_set(_position.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) {
|
||||
double_t aspect = double_t(base_width) / double_t(base_height);
|
||||
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_height =
|
||||
std::clamp(uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(cache_height))), 1u, 16384u);
|
||||
cache_width =
|
||||
std::clamp(uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(cache_width))), 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) {
|
||||
cache_height = std::clamp(
|
||||
uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(uint64_t(cache_width * aspect2)))), 1u,
|
||||
16384u);
|
||||
uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(uint64_t(cache_width * aspect2)))),
|
||||
1u, 16384u);
|
||||
} else if (aspect < 1.0) {
|
||||
cache_width = std::clamp(
|
||||
uint32_t(pow(2, util::math::get_power_of_two_exponent_ceil(uint64_t(cache_height * aspect)))), 1u,
|
||||
16384u);
|
||||
uint32_t(pow(2, streamfx::util::math::get_power_of_two_exponent_ceil(uint64_t(cache_height * aspect)))),
|
||||
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"};
|
||||
#endif
|
||||
|
||||
std::size_t mip_levels = std::max(util::math::get_power_of_two_exponent_ceil(cache_width),
|
||||
util::math::get_power_of_two_exponent_ceil(cache_height));
|
||||
std::size_t mip_levels = std::max(streamfx::util::math::get_power_of_two_exponent_ceil(cache_width),
|
||||
streamfx::util::math::get_power_of_two_exponent_ceil(cache_height));
|
||||
_mipmap_texture =
|
||||
std::make_shared<gs::texture>(cache_width, cache_height, GS_RGBA, static_cast<uint32_t>(mip_levels),
|
||||
nullptr, gs::texture::flags::None);
|
||||
|
|
|
@ -46,13 +46,13 @@ namespace streamfx::filter::transform {
|
|||
std::shared_ptr<gs::texture> _source_texture;
|
||||
|
||||
// Mesh
|
||||
bool _update_mesh;
|
||||
std::shared_ptr<gs::vertex_buffer> _vertex_buffer;
|
||||
uint32_t _rotation_order;
|
||||
std::unique_ptr<util::vec3a> _position;
|
||||
std::unique_ptr<util::vec3a> _rotation;
|
||||
std::unique_ptr<util::vec3a> _scale;
|
||||
std::unique_ptr<util::vec3a> _shear;
|
||||
bool _update_mesh;
|
||||
std::shared_ptr<gs::vertex_buffer> _vertex_buffer;
|
||||
uint32_t _rotation_order;
|
||||
std::unique_ptr<streamfx::util::vec3a> _position;
|
||||
std::unique_ptr<streamfx::util::vec3a> _rotation;
|
||||
std::unique_ptr<streamfx::util::vec3a> _scale;
|
||||
std::unique_ptr<streamfx::util::vec3a> _shear;
|
||||
|
||||
// Camera
|
||||
bool _camera_orthographic;
|
||||
|
|
|
@ -53,7 +53,8 @@ gfx::blur::gaussian_linear_data::gaussian_linear_data()
|
|||
|
||||
// Find actual kernel width.
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -62,7 +63,7 @@ gfx::blur::gaussian_linear_data::gaussian_linear_data()
|
|||
// Calculate and normalize
|
||||
double_t sum = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ gfx::blur::gaussian_data::gaussian_data()
|
|||
|
||||
// Find actual kernel width.
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@ -63,7 +64,7 @@ gfx::blur::gaussian_data::gaussian_data()
|
|||
// Calculate and normalize
|
||||
double_t sum = 0;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ nvidia::cuda::cuda::cuda() : _library()
|
|||
|
||||
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.
|
||||
// Initialization
|
||||
|
|
|
@ -176,7 +176,7 @@ namespace nvidia::cuda {
|
|||
};
|
||||
|
||||
class cuda {
|
||||
std::shared_ptr<util::library> _library;
|
||||
std::shared_ptr<streamfx::util::library> _library;
|
||||
|
||||
public:
|
||||
~cuda();
|
||||
|
|
|
@ -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");
|
||||
|
||||
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)
|
||||
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");
|
||||
|
||||
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)
|
||||
&& util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(height) / log(2)))), height)
|
||||
&& util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(depth) / log(2)))), depth));
|
||||
bool isPOT =
|
||||
(streamfx::util::math::is_equal(pow(2, static_cast<int64_t>(floor(log(width) / log(2)))), width)
|
||||
&& 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)
|
||||
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");
|
||||
|
||||
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)
|
||||
throw std::logic_error("mip mapping requires power of two dimensions");
|
||||
}
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
gs::vertex::vertex()
|
||||
: 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;
|
||||
|
||||
|
@ -48,7 +49,7 @@ gs::vertex::vertex()
|
|||
gs::vertex::~vertex()
|
||||
{
|
||||
if (_has_store) {
|
||||
util::free_aligned(_store);
|
||||
streamfx::util::free_aligned(_store);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,10 +36,10 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers)
|
|||
_data = std::make_shared<decltype(_data)::element_type>();
|
||||
_data->num = _capacity;
|
||||
_data->num_tex = _layers;
|
||||
_data->points = _positions = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity));
|
||||
_data->normals = _normals = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity));
|
||||
_data->tangents = _tangents = static_cast<vec3*>(util::malloc_aligned(16, sizeof(vec3) * _capacity));
|
||||
_data->colors = _colors = static_cast<uint32_t*>(util::malloc_aligned(16, sizeof(uint32_t) * _capacity));
|
||||
_data->points = _positions = static_cast<vec3*>(streamfx::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*>(streamfx::util::malloc_aligned(16, sizeof(vec3) * _capacity));
|
||||
_data->colors = _colors = static_cast<uint32_t*>(streamfx::util::malloc_aligned(16, sizeof(uint32_t) * _capacity));
|
||||
|
||||
// Clear the allocated memory of any data.
|
||||
memset(_positions, 0, sizeof(vec3) * _capacity);
|
||||
|
@ -51,10 +51,11 @@ void gs::vertex_buffer::initialize(uint32_t capacity, uint8_t layers)
|
|||
_data->tvarray = nullptr;
|
||||
} else {
|
||||
_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++) {
|
||||
_uv_layers[n].array = _uvs[n] = static_cast<vec4*>(util::malloc_aligned(16, sizeof(vec4) * _capacity));
|
||||
_uv_layers[n].width = 4;
|
||||
_uv_layers[n].array = _uvs[n] =
|
||||
static_cast<vec4*>(streamfx::util::malloc_aligned(16, sizeof(vec4) * _capacity));
|
||||
_uv_layers[n].width = 4;
|
||||
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()
|
||||
{
|
||||
// Free data
|
||||
util::free_aligned(_positions);
|
||||
util::free_aligned(_normals);
|
||||
util::free_aligned(_tangents);
|
||||
util::free_aligned(_colors);
|
||||
util::free_aligned(_uv_layers);
|
||||
streamfx::util::free_aligned(_positions);
|
||||
streamfx::util::free_aligned(_normals);
|
||||
streamfx::util::free_aligned(_tangents);
|
||||
streamfx::util::free_aligned(_colors);
|
||||
streamfx::util::free_aligned(_uv_layers);
|
||||
for (std::size_t n = 0; n < _layers; n++) {
|
||||
util::free_aligned(_uvs[n]);
|
||||
streamfx::util::free_aligned(_uvs[n]);
|
||||
}
|
||||
|
||||
_buffer.reset();
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace obs {
|
|||
std::string _signal;
|
||||
|
||||
public:
|
||||
util::event<T, calldata*> event;
|
||||
streamfx::util::event<T, calldata*> event;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -88,7 +88,7 @@ namespace obs {
|
|||
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
|
||||
|
|
|
@ -89,49 +89,49 @@ namespace obs {
|
|||
public: // Events
|
||||
struct {
|
||||
// Destroy and Remove
|
||||
util::event<obs::deprecated_source*> destroy;
|
||||
util::event<obs::deprecated_source*> remove;
|
||||
streamfx::util::event<obs::deprecated_source*> destroy;
|
||||
streamfx::util::event<obs::deprecated_source*> remove;
|
||||
|
||||
// Saving, Loading and Update
|
||||
util::event<obs::deprecated_source*> save;
|
||||
util::event<obs::deprecated_source*> load;
|
||||
util::event<obs::deprecated_source*> update_properties;
|
||||
streamfx::util::event<obs::deprecated_source*> save;
|
||||
streamfx::util::event<obs::deprecated_source*> load;
|
||||
streamfx::util::event<obs::deprecated_source*> update_properties;
|
||||
|
||||
// Activate, Deactivate
|
||||
util::event<obs::deprecated_source*> activate;
|
||||
util::event<obs::deprecated_source*> deactivate;
|
||||
streamfx::util::event<obs::deprecated_source*> activate;
|
||||
streamfx::util::event<obs::deprecated_source*> deactivate;
|
||||
|
||||
// Show Hide
|
||||
util::event<obs::deprecated_source*> show;
|
||||
util::event<obs::deprecated_source*> hide;
|
||||
streamfx::util::event<obs::deprecated_source*> show;
|
||||
streamfx::util::event<obs::deprecated_source*> hide;
|
||||
|
||||
// Other
|
||||
util::event<obs::deprecated_source*, bool> enable;
|
||||
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*, bool> enable;
|
||||
streamfx::util::event<obs::deprecated_source*, std::string, std::string> rename;
|
||||
streamfx::util::event<obs::deprecated_source*, long long> update_flags;
|
||||
|
||||
// Hotkeys (PtM, PtT)
|
||||
util::event<obs::deprecated_source*, bool> push_to_mute_changed;
|
||||
util::event<obs::deprecated_source*, long long> push_to_mute_delay;
|
||||
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*, bool> push_to_mute_changed;
|
||||
streamfx::util::event<obs::deprecated_source*, long long> push_to_mute_delay;
|
||||
streamfx::util::event<obs::deprecated_source*, bool> push_to_talk_changed;
|
||||
streamfx::util::event<obs::deprecated_source*, long long> push_to_talk_delay;
|
||||
|
||||
// Audio
|
||||
util::event<obs::deprecated_source*, bool> mute;
|
||||
util::event<obs::deprecated_source*, double&> volume;
|
||||
util::event<obs::deprecated_source*, long long&> audio_sync;
|
||||
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*, bool> mute;
|
||||
streamfx::util::event<obs::deprecated_source*, double&> volume;
|
||||
streamfx::util::event<obs::deprecated_source*, long long&> audio_sync;
|
||||
streamfx::util::event<obs::deprecated_source*, long long&> audio_mixers;
|
||||
streamfx::util::event<obs::deprecated_source*, const audio_data*, bool> audio;
|
||||
|
||||
// Filters
|
||||
util::event<obs::deprecated_source*, obs_source_t*> filter_add;
|
||||
util::event<obs::deprecated_source*, obs_source_t*> filter_remove;
|
||||
util::event<obs::deprecated_source*> reorder_filters;
|
||||
streamfx::util::event<obs::deprecated_source*, obs_source_t*> filter_add;
|
||||
streamfx::util::event<obs::deprecated_source*, obs_source_t*> filter_remove;
|
||||
streamfx::util::event<obs::deprecated_source*> reorder_filters;
|
||||
|
||||
// Transition
|
||||
util::event<obs::deprecated_source*> transition_start;
|
||||
util::event<obs::deprecated_source*> transition_video_stop;
|
||||
util::event<obs::deprecated_source*> transition_stop;
|
||||
streamfx::util::event<obs::deprecated_source*> transition_start;
|
||||
streamfx::util::event<obs::deprecated_source*> transition_video_stop;
|
||||
streamfx::util::event<obs::deprecated_source*> transition_stop;
|
||||
} events;
|
||||
};
|
||||
} // namespace obs
|
||||
|
|
|
@ -73,8 +73,8 @@
|
|||
//static std::shared_ptr<streamfx::updater> _updater;
|
||||
#endif
|
||||
|
||||
static std::shared_ptr<util::threadpool> _threadpool;
|
||||
static std::shared_ptr<gs::vertex_buffer> _gs_fstri_vb;
|
||||
static std::shared_ptr<streamfx::util::threadpool> _threadpool;
|
||||
static std::shared_ptr<gs::vertex_buffer> _gs_fstri_vb;
|
||||
|
||||
MODULE_EXPORT bool obs_module_load(void)
|
||||
try {
|
||||
|
@ -84,7 +84,7 @@ try {
|
|||
streamfx::configuration::initialize();
|
||||
|
||||
// Initialize global Thread Pool.
|
||||
_threadpool = std::make_shared<util::threadpool>();
|
||||
_threadpool = std::make_shared<streamfx::util::threadpool>();
|
||||
|
||||
// Initialize Source Tracker
|
||||
obs::source_tracker::initialize();
|
||||
|
@ -260,7 +260,7 @@ try {
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
namespace streamfx {
|
||||
// Threadpool
|
||||
std::shared_ptr<util::threadpool> threadpool();
|
||||
std::shared_ptr<streamfx::util::threadpool> threadpool();
|
||||
|
||||
void gs_draw_fullscreen_tri();
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ bool streamfx::update_info::is_newer(update_info& other)
|
|||
return true;
|
||||
}
|
||||
|
||||
void streamfx::updater::task(util::threadpool_data_t)
|
||||
void streamfx::updater::task(streamfx::util::threadpool_data_t)
|
||||
try {
|
||||
{
|
||||
std::vector<char> buffer;
|
||||
|
@ -227,8 +227,8 @@ 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";
|
||||
|
||||
util::curl curl;
|
||||
size_t buffer_offset = 0;
|
||||
streamfx::util::curl curl;
|
||||
size_t buffer_offset = 0;
|
||||
|
||||
// Set headers (User-Agent is needed so Github can contact us!).
|
||||
curl.set_header("User-Agent", "StreamFX Updater v" STREAMFX_VERSION_STRING);
|
||||
|
|
|
@ -50,8 +50,8 @@ namespace streamfx {
|
|||
|
||||
class updater {
|
||||
// Internal
|
||||
std::mutex _lock;
|
||||
std::weak_ptr<::util::threadpool::task> _task;
|
||||
std::mutex _lock;
|
||||
std::weak_ptr<::streamfx::util::threadpool::task> _task;
|
||||
|
||||
// Options
|
||||
std::atomic_bool _gdpr;
|
||||
|
@ -66,7 +66,7 @@ namespace streamfx {
|
|||
bool _dirty;
|
||||
|
||||
private:
|
||||
void task(util::threadpool_data_t);
|
||||
void task(streamfx::util::threadpool_data_t);
|
||||
void task_query(std::vector<char>& buffer);
|
||||
void task_parse(std::vector<char>& buffer);
|
||||
|
||||
|
@ -101,12 +101,12 @@ namespace streamfx {
|
|||
|
||||
public:
|
||||
struct _ {
|
||||
util::event<updater&, bool> gdpr_changed;
|
||||
util::event<updater&, bool> automation_changed;
|
||||
util::event<updater&, update_channel> channel_changed;
|
||||
streamfx::util::event<updater&, bool> gdpr_changed;
|
||||
streamfx::util::event<updater&, bool> automation_changed;
|
||||
streamfx::util::event<updater&, update_channel> channel_changed;
|
||||
|
||||
util::event<updater&, std::string&> error;
|
||||
util::event<updater&> refreshed;
|
||||
streamfx::util::event<updater&, std::string&> error;
|
||||
streamfx::util::event<updater&> refreshed;
|
||||
} events;
|
||||
|
||||
public:
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#include "util-curl.hpp"
|
||||
#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) {
|
||||
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;
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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();
|
||||
set_read_callback(nullptr);
|
||||
|
@ -112,22 +114,22 @@ util::curl::curl() : _curl(), _read_callback(), _write_callback(), _headers()
|
|||
#endif
|
||||
}
|
||||
|
||||
util::curl::~curl()
|
||||
streamfx::util::curl::~curl()
|
||||
{
|
||||
curl_easy_cleanup(_curl);
|
||||
}
|
||||
|
||||
void util::curl::clear_headers()
|
||||
void streamfx::util::curl::clear_headers()
|
||||
{
|
||||
_headers.clear();
|
||||
}
|
||||
|
||||
void util::curl::clear_header(std::string header)
|
||||
void streamfx::util::curl::clear_header(std::string 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);
|
||||
}
|
||||
|
@ -137,7 +139,7 @@ size_t perform_get_kv_size(std::string a, std::string b)
|
|||
return a.size() + 2 + b.size() + 1;
|
||||
};
|
||||
|
||||
CURLcode util::curl::perform()
|
||||
CURLcode streamfx::util::curl::perform()
|
||||
{
|
||||
std::vector<char> buffer;
|
||||
struct curl_slist* headers = nullptr;
|
||||
|
@ -177,12 +179,12 @@ CURLcode util::curl::perform()
|
|||
return res;
|
||||
}
|
||||
|
||||
void util::curl::reset()
|
||||
void streamfx::util::curl::reset()
|
||||
{
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
if (CURLcode res = curl_easy_setopt(_curl, CURLOPT_DEBUGDATA, this); res != CURLE_OK)
|
||||
|
|
|
@ -33,7 +33,7 @@ extern "C" {
|
|||
#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<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;
|
||||
|
@ -46,10 +46,11 @@ namespace util {
|
|||
curl_debug_callback_t _debug_callback;
|
||||
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 size_t read_helper(void*, size_t, size_t, util::curl*);
|
||||
static size_t write_helper(void*, size_t, size_t, util::curl*);
|
||||
static int32_t xferinfo_callback(util::curl*, curl_off_t, curl_off_t, curl_off_t, curl_off_t);
|
||||
static int32_t debug_helper(CURL* handle, curl_infotype type, char* data, size_t size,
|
||||
streamfx::util::curl* userptr);
|
||||
static size_t read_helper(void*, size_t, size_t, streamfx::util::curl*);
|
||||
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:
|
||||
curl();
|
||||
|
@ -126,4 +127,4 @@ namespace util {
|
|||
|
||||
CURLcode set_debug_callback(curl_debug_callback_t cb);
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace streamfx::util
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <list>
|
||||
#include <mutex>
|
||||
|
||||
namespace util {
|
||||
namespace streamfx::util {
|
||||
template<typename... _args>
|
||||
class event {
|
||||
std::list<std::function<void(_args...)>> _listeners;
|
||||
|
@ -171,4 +171,4 @@ namespace util {
|
|||
this->_cb_clear = cb;
|
||||
}
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace streamfx::util
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
||||
util::library::library(std::filesystem::path file) : _library(nullptr)
|
||||
streamfx::util::library::library(std::filesystem::path file) : _library(nullptr)
|
||||
{
|
||||
#if defined(ST_WINDOWS)
|
||||
SetLastError(ERROR_SUCCESS);
|
||||
|
@ -64,7 +64,7 @@ util::library::library(std::filesystem::path file) : _library(nullptr)
|
|||
#endif
|
||||
}
|
||||
|
||||
util::library::~library()
|
||||
streamfx::util::library::~library()
|
||||
{
|
||||
#if defined(ST_WINDOWS)
|
||||
FreeLibrary(reinterpret_cast<HMODULE>(_library));
|
||||
|
@ -73,7 +73,7 @@ util::library::~library()
|
|||
#endif
|
||||
}
|
||||
|
||||
void* util::library::load_symbol(std::string_view name)
|
||||
void* streamfx::util::library::load_symbol(std::string_view name)
|
||||
{
|
||||
#if defined(ST_WINDOWS)
|
||||
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
|
||||
}
|
||||
|
||||
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());
|
||||
if (kv != libraries.end()) {
|
||||
|
@ -93,13 +93,13 @@ std::shared_ptr<::util::library> util::library::load(std::filesystem::path file)
|
|||
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);
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include <memory>
|
||||
#include <string_view>
|
||||
|
||||
namespace util {
|
||||
namespace streamfx::util {
|
||||
class library {
|
||||
void* _library;
|
||||
|
||||
|
@ -33,8 +33,8 @@ namespace util {
|
|||
|
||||
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
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "common.hpp"
|
||||
#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 = {
|
||||
{level::LEVEL_DEBUG, LOG_DEBUG},
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
|
||||
#define P_LOG(...) util::logging::log(__VA_ARGS__);
|
||||
#define P_LOG_ERROR(...) P_LOG(util::logging::level::LEVEL_ERROR, __VA_ARGS__)
|
||||
#define P_LOG_WARN(...) P_LOG(util::logging::level::LEVEL_WARN, __VA_ARGS__)
|
||||
#define P_LOG_INFO(...) P_LOG(util::logging::level::LEVEL_INFO, __VA_ARGS__)
|
||||
#define P_LOG(...) streamfx::util::logging::log(__VA_ARGS__);
|
||||
#define P_LOG_ERROR(...) P_LOG(streamfx::util::logging::level::LEVEL_ERROR, __VA_ARGS__)
|
||||
#define P_LOG_WARN(...) P_LOG(streamfx::util::logging::level::LEVEL_WARN, __VA_ARGS__)
|
||||
#define P_LOG_INFO(...) P_LOG(streamfx::util::logging::level::LEVEL_INFO, __VA_ARGS__)
|
||||
#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
|
||||
#define P_LOG_DEBUG(...)
|
||||
#endif
|
||||
|
@ -46,7 +46,7 @@
|
|||
#define __FUNCTION_NAME__ __func__
|
||||
#endif
|
||||
|
||||
namespace util::logging {
|
||||
namespace streamfx::util::logging {
|
||||
enum class level {
|
||||
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.
|
||||
|
@ -55,4 +55,4 @@ namespace util::logging {
|
|||
};
|
||||
|
||||
void log(level lvl, const char* format, ...);
|
||||
} // namespace util::logging
|
||||
} // namespace streamfx::util::logging
|
||||
|
|
|
@ -21,20 +21,21 @@
|
|||
#include "common.hpp"
|
||||
#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.
|
||||
#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++) {
|
||||
_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;
|
||||
_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);
|
||||
_tasks.emplace_back(task);
|
||||
|
@ -57,17 +59,17 @@ std::shared_ptr<::util::threadpool::task> util::threadpool::push(threadpool_call
|
|||
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) {
|
||||
work->_is_dead.store(true);
|
||||
}
|
||||
}
|
||||
|
||||
void util::threadpool::work()
|
||||
void streamfx::util::threadpool::work()
|
||||
{
|
||||
std::shared_ptr<util::threadpool::task> local_work{};
|
||||
uint32_t local_number = _worker_idx.fetch_add(1);
|
||||
std::shared_ptr<streamfx::util::threadpool::task> local_work{};
|
||||
uint32_t local_number = _worker_idx.fetch_add(1);
|
||||
|
||||
while (!_worker_stop) {
|
||||
// Wait for more work, or immediately continue if there is still work to do.
|
||||
|
@ -101,13 +103,13 @@ void util::threadpool::work()
|
|||
try {
|
||||
local_work->_callback(local_work->_data);
|
||||
} catch (std::exception const& ex) {
|
||||
DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR
|
||||
") with message: %s",
|
||||
DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR
|
||||
") with message: %s",
|
||||
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
|
||||
reinterpret_cast<ptrdiff_t>(local_work->_data.get()), ex.what());
|
||||
} catch (...) {
|
||||
DLOG_WARNING(LOCAL_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR
|
||||
", %" PRIxPTR ").",
|
||||
DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR
|
||||
", %" PRIxPTR ").",
|
||||
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
|
||||
reinterpret_cast<ptrdiff_t>(local_work->_data.get()));
|
||||
}
|
||||
|
@ -120,7 +122,8 @@ void util::threadpool::work()
|
|||
_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)
|
||||
{}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
namespace util {
|
||||
namespace streamfx::util {
|
||||
typedef std::shared_ptr<void> threadpool_data_t;
|
||||
typedef std::function<void(threadpool_data_t)> threadpool_callback_t;
|
||||
|
||||
|
@ -43,26 +43,27 @@ namespace util {
|
|||
task();
|
||||
task(threadpool_callback_t callback_function, threadpool_data_t data);
|
||||
|
||||
friend class util::threadpool;
|
||||
friend class streamfx::util::threadpool;
|
||||
};
|
||||
|
||||
private:
|
||||
std::list<std::thread> _workers;
|
||||
std::atomic_bool _worker_stop;
|
||||
std::atomic<uint32_t> _worker_idx;
|
||||
std::list<std::shared_ptr<::util::threadpool::task>> _tasks;
|
||||
std::mutex _tasks_lock;
|
||||
std::condition_variable _tasks_cv;
|
||||
std::list<std::thread> _workers;
|
||||
std::atomic_bool _worker_stop;
|
||||
std::atomic<uint32_t> _worker_idx;
|
||||
std::list<std::shared_ptr<::streamfx::util::threadpool::task>> _tasks;
|
||||
std::mutex _tasks_lock;
|
||||
std::condition_variable _tasks_cv;
|
||||
|
||||
public:
|
||||
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:
|
||||
void work();
|
||||
};
|
||||
} // namespace util
|
||||
} // namespace streamfx::util
|
||||
|
|
|
@ -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_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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
@ -193,7 +193,7 @@ std::pair<int64_t, int64_t> util::size_from_string(std::string text, bool allowS
|
|||
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
|
||||
return _aligned_malloc(size, align);
|
||||
|
@ -217,7 +217,7 @@ void* util::malloc_aligned(std::size_t align, std::size_t size)
|
|||
#endif
|
||||
}
|
||||
|
||||
void util::free_aligned(void* mem)
|
||||
void streamfx::util::free_aligned(void* mem)
|
||||
{
|
||||
#ifdef USE_MSC_ALLOC
|
||||
_aligned_free(mem);
|
||||
|
|
|
@ -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_VSTR(s) D_STR(s)
|
||||
|
||||
namespace util {
|
||||
namespace streamfx::util {
|
||||
bool inline are_property_groups_broken()
|
||||
{
|
||||
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 free_aligned(void* mem);
|
||||
} // namespace util
|
||||
} // namespace streamfx::util
|
||||
|
|
Loading…
Reference in a new issue