2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2019-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2018-11-07 13:07:34 +00:00
|
|
|
|
|
|
|
#include "obs-tools.hpp"
|
2022-05-10 18:51:59 +00:00
|
|
|
#include "obs-source.hpp"
|
|
|
|
#include "obs-weak-source.hpp"
|
2019-09-05 16:42:28 +00:00
|
|
|
#include "plugin.hpp"
|
2018-11-07 13:07:34 +00:00
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
struct __sfs_data {
|
|
|
|
std::set<::streamfx::obs::weak_source> sources;
|
2018-11-07 13:07:34 +00:00
|
|
|
};
|
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
void __source_find_source_enumerate(obs_source_t* haystack, __sfs_data* cbd)
|
|
|
|
{
|
|
|
|
auto tp = obs_source_get_type(haystack);
|
2018-11-07 13:07:34 +00:00
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
// Check if this source is already present in the set.
|
|
|
|
::streamfx::obs::weak_source weak_child{haystack};
|
|
|
|
if (!weak_child || (cbd->sources.find(weak_child) != cbd->sources.end())) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-07 13:07:34 +00:00
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
// If it was not in the list, add it now.
|
|
|
|
cbd->sources.insert(weak_child);
|
|
|
|
|
|
|
|
// Enumerate direct reference tree.
|
|
|
|
obs_source_enum_full_tree(
|
|
|
|
haystack,
|
|
|
|
[](obs_source_t* parent, obs_source_t* child, void* param) {
|
|
|
|
try {
|
|
|
|
__source_find_source_enumerate(child, reinterpret_cast<__sfs_data*>(param));
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cbd);
|
|
|
|
|
|
|
|
switch (tp) {
|
|
|
|
case OBS_SOURCE_TYPE_SCENE: {
|
|
|
|
obs_scene_enum_items(
|
|
|
|
obs_scene_from_source(haystack),
|
|
|
|
[](obs_scene_t* scene, obs_sceneitem_t* item, void* param) {
|
|
|
|
try {
|
|
|
|
__sfs_data* cbd = reinterpret_cast<__sfs_data*>(param);
|
|
|
|
__source_find_source_enumerate(obs_sceneitem_get_source(item), cbd);
|
|
|
|
return true;
|
|
|
|
} catch (...) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cbd);
|
|
|
|
}
|
|
|
|
#if __cplusplus >= 201700L
|
|
|
|
[[fallthrough]];
|
|
|
|
#endif
|
|
|
|
case OBS_SOURCE_TYPE_INPUT: {
|
|
|
|
// Enumerate filter tree.
|
|
|
|
obs_source_enum_filters(
|
|
|
|
haystack,
|
|
|
|
[](obs_source_t* parent, obs_source_t* child, void* param) {
|
|
|
|
try {
|
|
|
|
__sfs_data* cbd = reinterpret_cast<__sfs_data*>(param);
|
|
|
|
__source_find_source_enumerate(child, cbd);
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cbd);
|
|
|
|
}
|
|
|
|
#if __cplusplus >= 201700L
|
|
|
|
[[fallthrough]];
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-11-07 13:07:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
bool streamfx::obs::tools::source_find_source(::streamfx::obs::source haystack, ::streamfx::obs::source needle)
|
2018-11-07 13:07:34 +00:00
|
|
|
{
|
2022-05-10 18:51:59 +00:00
|
|
|
__sfs_data cbd = {};
|
|
|
|
try {
|
|
|
|
__source_find_source_enumerate(haystack.get(), &cbd);
|
|
|
|
} catch (...) {
|
2018-11-07 13:07:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
for (auto weak_source : cbd.sources) {
|
|
|
|
if (!weak_source)
|
|
|
|
continue;
|
2018-11-07 13:07:34 +00:00
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
if (weak_source == needle)
|
|
|
|
return true;
|
2018-11-07 13:07:34 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 18:51:59 +00:00
|
|
|
return false;
|
2018-11-07 13:07:34 +00:00
|
|
|
}
|