You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.8 KiB
92 lines
1.8 KiB
#include "obs-manager.hpp"
|
|
#include "settings-manager.hpp"
|
|
#include <obs/obs.h>
|
|
#include <glibmm/ustring.h>
|
|
#include <filesystem>
|
|
#include <stdexcept>
|
|
|
|
using namespace Glib;
|
|
|
|
OBSManager::OBSManager()
|
|
{
|
|
plugins = {
|
|
"obs-ffmpeg.so",
|
|
"linux-v4l2.so",
|
|
"linux-capture.so",
|
|
};
|
|
}
|
|
|
|
OBSManager::~OBSManager()
|
|
{
|
|
if (display != nullptr)
|
|
obs_display_destroy(display);
|
|
}
|
|
|
|
ustring OBSManager::GetVersion()
|
|
{
|
|
return ustring(obs_get_version_string());
|
|
}
|
|
|
|
void OBSManager::Initialize()
|
|
{
|
|
if (isInitialized)
|
|
return;
|
|
|
|
if (!obs_startup("en-US", NULL, NULL))
|
|
throw std::runtime_error("Failed to initialize OBS");
|
|
|
|
struct gs_init_data info = {
|
|
.cx = 1280,
|
|
.cy = 720,
|
|
.format = GS_BGRA,
|
|
.zsformat = GS_ZS_NONE,
|
|
};
|
|
|
|
display = obs_display_create(&info, 0);
|
|
if (display == nullptr)
|
|
throw std::runtime_error("Failed to create display");
|
|
}
|
|
|
|
void OBSManager::LoadSettings(SettingsManager *settings)
|
|
{
|
|
string pluginsDir = settings->Get("pluginsdir");
|
|
if (pluginsDir == "")
|
|
pluginsDir = "/usr/lib/x86_64-linux-gnu/obs-plugins/";
|
|
|
|
PluginsDir = pluginsDir;
|
|
|
|
string outputDir = settings->Get("outputdir");
|
|
if (outputDir == "")
|
|
outputDir = std::filesystem::current_path();
|
|
|
|
OutputDir = outputDir;
|
|
}
|
|
|
|
void OBSManager::loadPlugin(ustring name)
|
|
{
|
|
obs_module_t *module;
|
|
|
|
ustring path;
|
|
path.append(PluginsDir);
|
|
path.append(name);
|
|
|
|
int res = obs_open_module(&module, path.c_str(), nullptr);
|
|
if (res != MODULE_SUCCESS)
|
|
throw std::runtime_error("Failed to open plugin");
|
|
|
|
obs_init_module(module);
|
|
}
|
|
|
|
|
|
void OBSManager::loadPlugins()
|
|
{
|
|
for (ustring plugin : plugins)
|
|
{
|
|
loadPlugin(plugin);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|