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

33
main-window.cpp

@ -8,8 +8,9 @@
using namespace std;
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"),
mButtonSettings("Settings"),
mButtonExit("Exit"),
@ -38,11 +39,12 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
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);
mBoxMain.show_all();
@ -51,6 +53,16 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
version.append("OBS Version: ");
version.append(obs->GetVersion());
mLabelVersion.set_text(version);
}
MainWindow::~MainWindow()
{
mOBS->Cleanup();
}
void MainWindow::on_show()
{
Gtk::Widget::on_show();
Gdk::Rectangle rect;
auto screen = get_screen();
@ -58,11 +70,7 @@ MainWindow::MainWindow(Glib::RefPtr<Gtk::Application> app, OBSManager *obs)
screen->get_monitor_geometry(monitor, rect);
mOBS->Initialize(rect);
}
MainWindow::~MainWindow()
{
mOBS->Cleanup();
onSettingsClicked();
}
void MainWindow::onPreviewClicked()
@ -92,7 +100,6 @@ void MainWindow::onExitClicked()
void MainWindow::onCleanupDone()
{
//Gtk::Main::quit();
mApp->quit();
}

3
main-window.hpp

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

43
obs-manager.cpp

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

1
obs-manager.hpp

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

Loading…
Cancel
Save