Dwayne Harris 2 years ago
parent
commit
374d44a20b
  1. 33
      main-window.cpp
  2. 3
      main-window.hpp
  3. 47
      obs-manager.cpp
  4. 1
      obs-manager.hpp

33
main-window.cpp

@ -8,8 +8,9 @@
using namespace std; using namespace std;
MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs) MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
: mBoxMain(Gtk::Orientation::ORIENTATION_VERTICAL, 2),
mButtonPreview("Start Preview"),
: mBoxMain(Gtk::Orientation::ORIENTATION_VERTICAL, 6),
mBoxSpacer(Gtk::Orientation::ORIENTATION_VERTICAL, 0),
mButtonPreview("View Preview"),
mButtonStart("Start Recording"), mButtonStart("Start Recording"),
mButtonSettings("Settings"), mButtonSettings("Settings"),
mButtonExit("Exit"), mButtonExit("Exit"),
@ -38,11 +39,12 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
mButtonStart.set_sensitive(false); mButtonStart.set_sensitive(false);
mBoxMain.add(mButtonPreview);
mBoxMain.add(mButtonStart);
mBoxMain.add(mButtonSettings);
mBoxMain.add(mButtonExit);
mBoxMain.add(mLabelVersion);
mBoxMain.pack_start(mButtonPreview, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mButtonStart, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mBoxSpacer, Gtk::PACK_EXPAND_WIDGET);
mBoxMain.pack_start(mButtonSettings, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mButtonExit, Gtk::PACK_SHRINK);
mBoxMain.pack_start(mLabelVersion, Gtk::PACK_SHRINK);
add(mBoxMain); add(mBoxMain);
mBoxMain.show_all(); mBoxMain.show_all();
@ -51,6 +53,16 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
version.append("OBS Version: "); version.append("OBS Version: ");
version.append(obs->GetVersion()); version.append(obs->GetVersion());
mLabelVersion.set_text(version); mLabelVersion.set_text(version);
}
MainWindow::~MainWindow()
{
mOBS->Cleanup();
}
void MainWindow::on_show()
{
Gtk::Widget::on_show();
Gdk::Rectangle rect; Gdk::Rectangle rect;
auto screen = get_screen(); auto screen = get_screen();
@ -58,11 +70,7 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
screen->get_monitor_geometry(monitor, rect); screen->get_monitor_geometry(monitor, rect);
mOBS->Initialize(rect); mOBS->Initialize(rect);
}
MainWindow::~MainWindow()
{
mOBS->Cleanup();
onSettingsClicked();
} }
void MainWindow::onPreviewClicked() void MainWindow::onPreviewClicked()
@ -92,7 +100,6 @@ void MainWindow::onExitClicked()
void MainWindow::onCleanupDone() void MainWindow::onCleanupDone()
{ {
//Gtk::Main::quit();
mApp->quit(); mApp->quit();
} }

3
main-window.hpp

@ -21,6 +21,7 @@ private:
void onExitClicked(); void onExitClicked();
void onCleanupDone(); void onCleanupDone();
Gtk::Box mBoxMain; Gtk::Box mBoxMain;
Gtk::Box mBoxSpacer;
Gtk::Button mButtonPreview; Gtk::Button mButtonPreview;
Gtk::Button mButtonStart; Gtk::Button mButtonStart;
Gtk::Button mButtonSettings; Gtk::Button mButtonSettings;
@ -33,6 +34,8 @@ private:
void onPreviewStarted(); void onPreviewStarted();
void onRecordingStarted(); void onRecordingStarted();
void onRecordingStopped(); void onRecordingStopped();
void on_show();
}; };
#endif #endif

47
obs-manager.cpp

@ -73,7 +73,6 @@ void OBSManager::Initialize(Gdk::Rectangle rect)
mScreenWidth = rect.get_width(); mScreenWidth = rect.get_width();
mScreenHeight = rect.get_height(); mScreenHeight = rect.get_height();
mSources = list<OBSSource>();
auto settings = new SettingsManager(); auto settings = new SettingsManager();
LoadSettings(settings); LoadSettings(settings);
@ -122,10 +121,12 @@ void OBSManager::StartPreview(XID wid, Display *wdisplay)
if (mDisplay == nullptr) if (mDisplay == nullptr)
throw runtime_error("Failed to create display"); throw runtime_error("Failed to create display");
obs_display_resize(mDisplay, PreviewWidth, PreviewHeight);
//obs_display_resize(mDisplay, PreviewWidth, PreviewHeight);
obs_display_add_draw_callback(mDisplay, OBSRender, nullptr); obs_display_add_draw_callback(mDisplay, OBSRender, nullptr);
OBSScene scene = obs_scene_create("scene1");
auto sources = new list<OBSSource>();
OBSScene scene = obs_scene_create("Main");
if (scene == NULL) if (scene == NULL)
throw runtime_error("Couldn't create scene\n"); throw runtime_error("Couldn't create scene\n");
@ -133,7 +134,7 @@ void OBSManager::StartPreview(XID wid, Display *wdisplay)
{ {
auto source = CreateScreenSource(); auto source = CreateScreenSource();
obs_scene_add(scene, source); obs_scene_add(scene, source);
mSources.push_back(source);
sources->push_back(source);
} }
if (mWebcamEnabled) if (mWebcamEnabled)
@ -144,27 +145,29 @@ void OBSManager::StartPreview(XID wid, Display *wdisplay)
auto source = CreateWebcamSource(); auto source = CreateWebcamSource();
auto item = obs_scene_add(scene, source); auto item = obs_scene_add(scene, source);
obs_sceneitem_set_scale(item, &scale); obs_sceneitem_set_scale(item, &scale);
mSources.push_back(source);
sources->push_back(source);
} }
if (mAudioEnabled) if (mAudioEnabled)
{ {
auto source = CreateAudioSource(); auto source = CreateAudioSource();
obs_scene_add(scene, source); obs_scene_add(scene, source);
mSources.push_back(source);
sources->push_back(source);
} }
obs_set_output_source(0, obs_scene_get_source(scene)); obs_set_output_source(0, obs_scene_get_source(scene));
obs_scene_release(scene);
for (auto source : *sources)
{
obs_source_release(source);
}
sigStartPreview.emit(); sigStartPreview.emit();
} }
void OBSManager::StopPreview() void OBSManager::StopPreview()
{ {
for (auto source : mSources)
{
obs_source_remove(source);
}
if (mDisplay != nullptr) if (mDisplay != nullptr)
obs_display_destroy(mDisplay); obs_display_destroy(mDisplay);
@ -207,6 +210,10 @@ void OBSManager::StartRecording()
obsStartRecording.Connect(obs_output_get_signal_handler(mOutput), "start", OBSStartRecording, this); obsStartRecording.Connect(obs_output_get_signal_handler(mOutput), "start", OBSStartRecording, this);
obsStopRecording.Connect(obs_output_get_signal_handler(mOutput), "stop", OBSStopRecording, this); obsStopRecording.Connect(obs_output_get_signal_handler(mOutput), "stop", OBSStopRecording, this);
obs_encoder_release(venc);
obs_encoder_release(aenc);
obs_output_release(mOutput);
isRecording = true; isRecording = true;
} }
@ -225,14 +232,16 @@ bool OBSManager::IsRecording()
void OBSManager::Cleanup() void OBSManager::Cleanup()
{ {
if (!isInitialized)
return;
StopRecording();
StopPreview();
obs_shutdown();
isInitialized = false;
if (isInitialized)
{
StopRecording();
StopPreview();
if (obs_initialized())
obs_shutdown();
isInitialized = false;
}
sigCleanup.emit(); sigCleanup.emit();
} }

1
obs-manager.hpp

@ -56,7 +56,6 @@ private:
string mAudioDeviceID; string mAudioDeviceID;
OBSDisplay mDisplay; OBSDisplay mDisplay;
OBSOutput mOutput; OBSOutput mOutput;
list<OBSSource> mSources;
OBSSignal obsStartRecording; OBSSignal obsStartRecording;
OBSSignal obsStopRecording; OBSSignal obsStopRecording;

Loading…
Cancel
Save