|
|
@ -1,24 +1,30 @@ |
|
|
|
#include "obs-manager.hpp"
|
|
|
|
#include "settings-manager.hpp"
|
|
|
|
|
|
|
|
#include <obs/obs.h>
|
|
|
|
#include <gdkmm/display.h>
|
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
#include <gdk/gdkx.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <ctime>
|
|
|
|
#include <list>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <stdexcept>
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
using namespace Glib; |
|
|
|
|
|
|
|
static void obs_render(void *param, uint32_t cx, uint32_t cy) |
|
|
|
{ |
|
|
|
obs_render_main_texture(); |
|
|
|
} |
|
|
|
|
|
|
|
static void OBSStartRecording(void *data, calldata_t *params) |
|
|
|
{ |
|
|
|
OBSManager *o = static_cast<OBSManager*>(data); |
|
|
|
o->startRecording.emit(); |
|
|
|
} |
|
|
|
|
|
|
|
static void OBSStopRecording(void *data, calldata_t *params) |
|
|
|
{ |
|
|
|
OBSManager *o = static_cast<OBSManager*>(data); |
|
|
|
o->stopRecording.emit(); |
|
|
|
} |
|
|
|
|
|
|
|
OBSManager::OBSManager() |
|
|
|
{ |
|
|
|
mPlugins = { |
|
|
@ -35,9 +41,9 @@ OBSManager::~OBSManager() |
|
|
|
Cleanup(); |
|
|
|
} |
|
|
|
|
|
|
|
ustring OBSManager::GetVersion() |
|
|
|
string OBSManager::GetVersion() |
|
|
|
{ |
|
|
|
return ustring(obs_get_version_string()); |
|
|
|
return string(obs_get_version_string()); |
|
|
|
} |
|
|
|
|
|
|
|
void OBSManager::Initialize() |
|
|
@ -45,7 +51,7 @@ void OBSManager::Initialize() |
|
|
|
if (isInitialized) |
|
|
|
return; |
|
|
|
|
|
|
|
sources = list<obs_source_t*>(); |
|
|
|
mSources = list<OBSSource>(); |
|
|
|
auto settings = new SettingsManager(); |
|
|
|
LoadSettings(settings); |
|
|
|
|
|
|
@ -53,7 +59,6 @@ void OBSManager::Initialize() |
|
|
|
throw runtime_error("Failed to initialize OBS"); |
|
|
|
|
|
|
|
loadPlugins(); |
|
|
|
printTypes(); |
|
|
|
|
|
|
|
obs_video_info v = {}; |
|
|
|
v.graphics_module = "libobs-opengl.so.0"; |
|
|
@ -92,13 +97,13 @@ void OBSManager::SetPreviewWindow(XID wid, Display *wdisplay) |
|
|
|
init.window.id = wid; |
|
|
|
init.window.display = (void*)wdisplay; |
|
|
|
|
|
|
|
display = obs_display_create(&init, 0); |
|
|
|
if (display == nullptr) |
|
|
|
mDisplay = obs_display_create(&init, 0); |
|
|
|
if (mDisplay == nullptr) |
|
|
|
throw runtime_error("Failed to create display"); |
|
|
|
|
|
|
|
obs_display_add_draw_callback(display, obs_render, nullptr); |
|
|
|
obs_display_add_draw_callback(mDisplay, obs_render, nullptr); |
|
|
|
|
|
|
|
obs_scene_t *scene = obs_scene_create("scene1"); |
|
|
|
OBSScene scene = obs_scene_create("scene1"); |
|
|
|
if (scene == NULL) |
|
|
|
throw runtime_error("Couldn't create scene\n"); |
|
|
|
|
|
|
@ -106,7 +111,7 @@ void OBSManager::SetPreviewWindow(XID wid, Display *wdisplay) |
|
|
|
{ |
|
|
|
auto source = CreateScreenSource(); |
|
|
|
obs_scene_add(scene, source); |
|
|
|
sources.push_back(source); |
|
|
|
mSources.push_back(source); |
|
|
|
} |
|
|
|
|
|
|
|
if (settings->GetBool(SETTINGS_KEY_WEBCAM_ENABLED)) |
|
|
@ -117,14 +122,14 @@ void OBSManager::SetPreviewWindow(XID wid, Display *wdisplay) |
|
|
|
auto source = CreateWebcamSource(); |
|
|
|
auto item = obs_scene_add(scene, source); |
|
|
|
obs_sceneitem_set_scale(item, &scale); |
|
|
|
sources.push_back(source); |
|
|
|
mSources.push_back(source); |
|
|
|
} |
|
|
|
|
|
|
|
if (settings->GetBool(SETTINGS_KEY_AUDIO_ENABLED)) |
|
|
|
{ |
|
|
|
auto source = CreateAudioSource(); |
|
|
|
obs_scene_add(scene, source); |
|
|
|
sources.push_back(source); |
|
|
|
mSources.push_back(source); |
|
|
|
} |
|
|
|
|
|
|
|
obs_set_output_source(0, obs_scene_get_source(scene)); |
|
|
@ -153,31 +158,34 @@ void OBSManager::StartRecording() |
|
|
|
obs_data_set_string(settings, "directory", path.c_str()); |
|
|
|
obs_data_set_string(settings, "url", fileName.c_str()); |
|
|
|
|
|
|
|
output = obs_output_create("ffmpeg_output", "ffmpeg_output", nullptr, nullptr); |
|
|
|
obs_output_set_video_encoder(output, venc); |
|
|
|
obs_output_set_audio_encoder(output, aenc, 0); |
|
|
|
obs_output_update(output, settings); |
|
|
|
obs_output_set_media(output, obs_get_video(), obs_get_audio()); |
|
|
|
mOutput = obs_output_create("ffmpeg_output", "ffmpeg_output", nullptr, nullptr); |
|
|
|
obs_output_set_video_encoder(mOutput, venc); |
|
|
|
obs_output_set_audio_encoder(mOutput, aenc, 0); |
|
|
|
obs_output_update(mOutput, settings); |
|
|
|
obs_output_set_media(mOutput, obs_get_video(), obs_get_audio()); |
|
|
|
|
|
|
|
obs_data_release(settings); |
|
|
|
if (!obs_output_start(output)) |
|
|
|
if (!obs_output_start(mOutput)) |
|
|
|
throw runtime_error("Failed to start recording"); |
|
|
|
|
|
|
|
obsStartRecording.Connect(obs_output_get_signal_handler(mOutput), "start", OBSStartRecording, this); |
|
|
|
obsStopRecording.Connect(obs_output_get_signal_handler(mOutput), "stop", OBSStopRecording, this); |
|
|
|
|
|
|
|
isRecording = true; |
|
|
|
} |
|
|
|
|
|
|
|
void OBSManager::StopRecording() |
|
|
|
{ |
|
|
|
if (isRecording && output != nullptr) |
|
|
|
obs_output_stop(output); |
|
|
|
if (isRecording && mOutput != nullptr) |
|
|
|
obs_output_stop(mOutput); |
|
|
|
|
|
|
|
isRecording = false; |
|
|
|
} |
|
|
|
|
|
|
|
obs_source_t *OBSManager::CreateScreenSource() |
|
|
|
OBSSource OBSManager::CreateScreenSource() |
|
|
|
{ |
|
|
|
obs_data_t *settings = obs_data_create(); |
|
|
|
obs_source_t *source = obs_source_create("xshm_input", "Screen Source", settings, NULL); |
|
|
|
OBSSource source = obs_source_create("xshm_input", "Screen Source", settings, NULL); |
|
|
|
if (source == NULL) |
|
|
|
throw runtime_error("Couldn't create screen source"); |
|
|
|
|
|
|
@ -185,12 +193,12 @@ obs_source_t *OBSManager::CreateScreenSource() |
|
|
|
return source; |
|
|
|
} |
|
|
|
|
|
|
|
obs_source_t *OBSManager::CreateWebcamSource() |
|
|
|
OBSSource OBSManager::CreateWebcamSource() |
|
|
|
{ |
|
|
|
obs_data_t *settings = obs_data_create(); |
|
|
|
obs_data_set_string(settings, "device_id", mWebcamDeviceID.c_str()); |
|
|
|
|
|
|
|
obs_source_t *source = obs_source_create("v4l2_input", "Webcam Source", settings, NULL); |
|
|
|
OBSSource source = obs_source_create("v4l2_input", "Webcam Source", settings, NULL); |
|
|
|
if (source == NULL) |
|
|
|
throw runtime_error("Couldn't create webcam source"); |
|
|
|
|
|
|
@ -198,10 +206,10 @@ obs_source_t *OBSManager::CreateWebcamSource() |
|
|
|
return source; |
|
|
|
} |
|
|
|
|
|
|
|
obs_source_t *OBSManager::CreateAudioSource() |
|
|
|
OBSSource OBSManager::CreateAudioSource() |
|
|
|
{ |
|
|
|
obs_data_t *settings = obs_data_create(); |
|
|
|
obs_source_t *source = obs_source_create("audio_line", "Audio Source", settings, NULL); |
|
|
|
OBSSource source = obs_source_create("audio_line", "Audio Source", settings, NULL); |
|
|
|
if (source == NULL) |
|
|
|
throw runtime_error("Couldn't create screen source"); |
|
|
|
|
|
|
@ -216,13 +224,13 @@ void OBSManager::Cleanup() |
|
|
|
|
|
|
|
StopRecording(); |
|
|
|
|
|
|
|
for (auto source : sources) |
|
|
|
for (auto source : mSources) |
|
|
|
{ |
|
|
|
obs_source_remove(source); |
|
|
|
} |
|
|
|
|
|
|
|
if (display != nullptr) |
|
|
|
obs_display_destroy(display); |
|
|
|
if (mDisplay != nullptr) |
|
|
|
obs_display_destroy(mDisplay); |
|
|
|
|
|
|
|
obs_shutdown(); |
|
|
|
isInitialized = false; |
|
|
@ -235,11 +243,16 @@ void OBSManager::LoadSettings(SettingsManager *settings) |
|
|
|
mWebcamDeviceID = settings->Get(SETTINGS_KEY_VIDEO_DEVICE_ID); |
|
|
|
} |
|
|
|
|
|
|
|
void OBSManager::loadPlugin(ustring name) |
|
|
|
bool OBSManager::IsRecording() |
|
|
|
{ |
|
|
|
return isRecording; |
|
|
|
} |
|
|
|
|
|
|
|
void OBSManager::loadPlugin(string name) |
|
|
|
{ |
|
|
|
obs_module_t *module; |
|
|
|
|
|
|
|
ustring path; |
|
|
|
string path; |
|
|
|
path.append(mPluginDir); |
|
|
|
path.append(name); |
|
|
|
|
|
|
@ -253,7 +266,7 @@ void OBSManager::loadPlugin(ustring name) |
|
|
|
|
|
|
|
void OBSManager::loadPlugins() |
|
|
|
{ |
|
|
|
for (ustring plugin : mPlugins) |
|
|
|
for (string plugin : mPlugins) |
|
|
|
{ |
|
|
|
loadPlugin(plugin); |
|
|
|
} |
|
|
|