2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2017-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2017-06-28 21:21:42 +00:00
|
|
|
|
2019-01-14 10:23:21 +00:00
|
|
|
#include "plugin.hpp"
|
2020-04-22 20:58:33 +00:00
|
|
|
#include "configuration.hpp"
|
2021-11-09 10:33:07 +00:00
|
|
|
#include "gfx/gfx-opengl.hpp"
|
|
|
|
#include "obs/gs/gs-helper.hpp"
|
2020-07-26 19:44:13 +00:00
|
|
|
#include "obs/gs/gs-vertexbuffer.hpp"
|
2020-01-13 21:40:15 +00:00
|
|
|
|
2021-06-17 11:28:13 +00:00
|
|
|
#ifdef ENABLE_NVIDIA_CUDA
|
|
|
|
#include "nvidia/cuda/nvidia-cuda-obs.hpp"
|
|
|
|
#endif
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
#include "ui/ui.hpp"
|
|
|
|
#endif
|
|
|
|
|
2020-09-09 03:06:15 +00:00
|
|
|
#ifdef ENABLE_UPDATER
|
|
|
|
#include "updater.hpp"
|
|
|
|
#endif
|
|
|
|
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-disable.hpp"
|
|
|
|
#include <fstream>
|
2023-05-14 04:50:27 +00:00
|
|
|
#include <list>
|
|
|
|
#include <map>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include "warning-enable.hpp"
|
|
|
|
|
2023-05-14 04:50:27 +00:00
|
|
|
static std::shared_ptr<streamfx::gfx::opengl> _streamfx_gfx_opengl;
|
2020-03-03 00:49:26 +00:00
|
|
|
|
2023-05-14 04:50:27 +00:00
|
|
|
namespace streamfx {
|
|
|
|
typedef std::list<loader_function_t> loader_list_t;
|
|
|
|
typedef std::map<loader_priority_t, loader_list_t> loader_map_t;
|
|
|
|
|
|
|
|
loader_map_t& get_initializers()
|
|
|
|
{
|
|
|
|
static loader_map_t initializers;
|
|
|
|
return initializers;
|
|
|
|
}
|
|
|
|
|
|
|
|
loader_map_t& get_finalizers()
|
|
|
|
{
|
|
|
|
static loader_map_t finalizers;
|
|
|
|
return finalizers;
|
|
|
|
}
|
|
|
|
|
|
|
|
loader::loader(loader_function_t initializer, loader_function_t finalizer, loader_priority_t priority)
|
|
|
|
{
|
|
|
|
auto init_kv = get_initializers().find(priority);
|
|
|
|
if (init_kv != get_initializers().end()) {
|
|
|
|
init_kv->second.push_back(initializer);
|
|
|
|
} else {
|
|
|
|
get_initializers().emplace(priority, loader_list_t{initializer});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invert the order for finalizers.
|
|
|
|
auto ipriority = priority ^ static_cast<loader_priority_t>(0xFFFFFFFFFFFFFFFF);
|
|
|
|
auto fina_kv = get_finalizers().find(ipriority);
|
|
|
|
if (fina_kv != get_finalizers().end()) {
|
|
|
|
fina_kv->second.push_back(finalizer);
|
|
|
|
} else {
|
|
|
|
get_finalizers().emplace(ipriority, loader_list_t{finalizer});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace streamfx
|
|
|
|
|
2019-12-21 16:04:38 +00:00
|
|
|
MODULE_EXPORT bool obs_module_load(void)
|
2022-08-27 11:17:47 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
DLOG_INFO("Loading Version %s", STREAMFX_VERSION_STRING);
|
2019-09-05 16:42:28 +00:00
|
|
|
|
2022-08-27 11:17:47 +00:00
|
|
|
// Initialize GLAD (OpenGL)
|
|
|
|
{
|
|
|
|
streamfx::obs::gs::context gctx{};
|
2022-11-28 06:43:46 +00:00
|
|
|
if (gs_get_device_type() == GS_DEVICE_OPENGL) {
|
|
|
|
_streamfx_gfx_opengl = streamfx::gfx::opengl::get();
|
|
|
|
}
|
2022-08-27 11:17:47 +00:00
|
|
|
}
|
2021-11-09 10:33:07 +00:00
|
|
|
|
2021-06-17 11:28:13 +00:00
|
|
|
#ifdef ENABLE_NVIDIA_CUDA
|
2022-08-27 11:17:47 +00:00
|
|
|
// Initialize CUDA if features requested it.
|
|
|
|
std::shared_ptr<::streamfx::nvidia::cuda::obs> cuda;
|
|
|
|
try {
|
|
|
|
cuda = ::streamfx::nvidia::cuda::obs::get();
|
|
|
|
} catch (...) {
|
|
|
|
// If CUDA failed to load, it is considered safe to ignore.
|
|
|
|
}
|
2021-06-17 11:28:13 +00:00
|
|
|
#endif
|
|
|
|
|
2023-05-14 07:02:23 +00:00
|
|
|
// Run all initializers.
|
|
|
|
for (auto kv : streamfx::get_initializers()) {
|
|
|
|
for (auto init : kv.second) {
|
|
|
|
try {
|
|
|
|
init();
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
DLOG_ERROR("Initializer threw exception: %s", ex.what());
|
|
|
|
} catch (...) {
|
|
|
|
DLOG_ERROR("Initializer threw unknown exception.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-27 11:17:47 +00:00
|
|
|
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
|
|
|
return true;
|
|
|
|
} catch (std::exception const& ex) {
|
|
|
|
DLOG_ERROR("Unexpected exception in function '%s': %s", __FUNCTION_NAME__, ex.what());
|
|
|
|
return false;
|
|
|
|
} catch (...) {
|
|
|
|
DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-28 21:21:42 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 11:28:08 +00:00
|
|
|
MODULE_EXPORT void obs_module_post_load(void) {}
|
|
|
|
|
2019-12-21 16:04:38 +00:00
|
|
|
MODULE_EXPORT void obs_module_unload(void)
|
2022-08-27 11:17:47 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
2020-01-13 21:40:15 +00:00
|
|
|
|
2023-05-14 04:50:27 +00:00
|
|
|
// Run all finalizers.
|
|
|
|
for (auto kv : streamfx::get_finalizers()) {
|
|
|
|
for (auto init : kv.second) {
|
|
|
|
try {
|
|
|
|
init();
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
DLOG_ERROR("Finalizer threw exception: %s", ex.what());
|
|
|
|
} catch (...) {
|
|
|
|
DLOG_ERROR("Finalizer threw unknown exception.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-14 07:02:23 +00:00
|
|
|
// Finalize GLAD (OpenGL)
|
|
|
|
{
|
|
|
|
streamfx::obs::gs::context gctx{};
|
|
|
|
_streamfx_gfx_opengl.reset();
|
|
|
|
}
|
|
|
|
|
2022-08-27 11:17:47 +00:00
|
|
|
DLOG_INFO("Unloaded Version %s", STREAMFX_VERSION_STRING);
|
|
|
|
} catch (std::exception const& ex) {
|
|
|
|
DLOG_ERROR("Unexpected exception in function '%s': %s", __FUNCTION_NAME__, ex.what());
|
|
|
|
} catch (...) {
|
|
|
|
DLOG_ERROR("Unexpected exception in function '%s'.", __FUNCTION_NAME__);
|
|
|
|
}
|
2017-06-28 21:21:42 +00:00
|
|
|
}
|
|
|
|
|
2022-09-18 16:30:15 +00:00
|
|
|
std::shared_ptr<streamfx::util::threadpool::threadpool> streamfx::threadpool()
|
2020-03-03 00:49:26 +00:00
|
|
|
{
|
2023-05-14 04:50:27 +00:00
|
|
|
return streamfx::util::threadpool::threadpool::instance();
|
2020-03-03 00:49:26 +00:00
|
|
|
}
|
2020-05-02 16:36:57 +00:00
|
|
|
|
2020-11-28 14:38:56 +00:00
|
|
|
std::filesystem::path streamfx::data_file_path(std::string_view file)
|
|
|
|
{
|
|
|
|
const char* root_path = obs_get_module_data_path(obs_current_module());
|
|
|
|
if (root_path) {
|
|
|
|
auto ret = std::filesystem::u8path(root_path);
|
|
|
|
ret.append(file.data());
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("obs_get_module_data_path returned nullptr");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::filesystem::path streamfx::config_file_path(std::string_view file)
|
|
|
|
{
|
|
|
|
char* root_path = obs_module_get_config_path(obs_current_module(), file.data());
|
|
|
|
if (root_path) {
|
|
|
|
auto ret = std::filesystem::u8path(root_path);
|
|
|
|
bfree(root_path);
|
|
|
|
return ret;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error("obs_module_get_config_path returned nullptr");
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 23:42:54 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
bool streamfx::open_url(std::string_view url)
|
|
|
|
{
|
|
|
|
QUrl qurl = QString::fromUtf8(url.data());
|
|
|
|
return QDesktopServices::openUrl(qurl);
|
|
|
|
}
|
|
|
|
#endif
|