diff --git a/.kdev4/screen-recorder.kdev4 b/.kdev4/screen-recorder.kdev4 index 9fbe86d..017eeb6 100644 --- a/.kdev4/screen-recorder.kdev4 +++ b/.kdev4/screen-recorder.kdev4 @@ -62,6 +62,7 @@ Name=GCC 2=/usr/include/ 3=/usr/lib/x86_64-linux-gnu/ 4=/usr/include/sigc++-2.0/ +5=/usr/include/glibmm-2.4/ [Launch] Launch Configurations=Launch Configuration 0 @@ -91,3 +92,6 @@ Start With=ApplicationOutput Use External Terminal=false Working Directory= isExecutable=true + +[Project] +VersionControlSupport=kdevgit diff --git a/.obs-manager.hpp.kate-swp b/.obs-manager.hpp.kate-swp new file mode 100644 index 0000000..fd3ae3f Binary files /dev/null and b/.obs-manager.hpp.kate-swp differ diff --git a/Makefile b/Makefile index 37d5de7..fc02f7c 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,23 @@ CC = g++ -CFLAGS = -g -Wall --std=c++17 +CFLAGS = -g -Wall -std=c++17 GCFLAGS = `pkg-config --cflags --libs gtkmm-3.0` -lobs TARGET = screenrecorder -$(TARGET): main.o recording-window.o - $(CC) $(CFLAGS) -o $(TARGET) main.o recording-window.o $(GCFLAGS) +$(TARGET): main.o obs-manager.o recording-window.o settings-window.o + $(CC) $(CFLAGS) -o $(TARGET) main.o obs-manager.o recording-window.o settings-window.o $(GCFLAGS) main.o: $(CC) $(CFLAGS) -c main.cpp $(GCFLAGS) +obs-manager.o: obs-manager.cpp obs-manager.hpp + $(CC) $(CFLAGS) -c obs-manager.cpp $(GCFLAGS) + recording-window.o: recording-window.cpp recording-window.hpp $(CC) $(CFLAGS) -c recording-window.cpp $(GCFLAGS) +settings-window.o: settings-window.cpp settings-window.hpp + $(CC) $(CFLAGS) -c settings-window.cpp $(GCFLAGS) + clean: - rm $(TARGET) main.o recording-window.o + rm $(TARGET) main.o obs-manager.o recording-window.o settings-window.o diff --git a/main.cpp b/main.cpp index 441c0b5..13d6f39 100644 --- a/main.cpp +++ b/main.cpp @@ -1,10 +1,13 @@ #include "recording-window.hpp" +#include "obs-manager.hpp" #include int main(int argc, char *argv[]) { auto app = Gtk::Application::create(argc, argv, "xyz.dwayne.screenrecorder"); - RecordingWindow win; + auto obs = new OBSManager(); + + RecordingWindow win(obs); return app->run(win); } diff --git a/obs-manager.cpp b/obs-manager.cpp new file mode 100644 index 0000000..fa4d4d8 --- /dev/null +++ b/obs-manager.cpp @@ -0,0 +1,80 @@ +#include "obs-manager.hpp" +#include +#include +#include + +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"); +} + +ustring OBSManager::GetPluginDir() +{ + return pluginDir; +} + +void OBSManager::loadPlugin(ustring name) +{ + obs_module_t *module; + + ustring path; + path.append(pluginDir); + 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); + } +} + + + + + diff --git a/obs-manager.hpp b/obs-manager.hpp new file mode 100644 index 0000000..fbcb6e6 --- /dev/null +++ b/obs-manager.hpp @@ -0,0 +1,31 @@ +#ifndef SCREEN_RECORDER_OBS_MANAGER_HPP +#define SCREEN_RECORDER_OBS_MANAGER_HPP + +#include +#include +#include + +using namespace Glib; + +class OBSManager +{ +public: + OBSManager(); + virtual ~OBSManager(); + ustring GetVersion(); + void Initialize(); + void Cleanup(); + ustring GetPluginDir(); + +private: + ustring pluginDir = "/usr/lib/x86_64-linux-gnu/obs-plugins/"; + std::list plugins; + + bool isInitialized = false; + obs_display_t *display = nullptr; + + void loadPlugin(ustring name); + void loadPlugins(); +}; + +#endif diff --git a/recording-window.cpp b/recording-window.cpp index e5f186d..fb57f52 100644 --- a/recording-window.cpp +++ b/recording-window.cpp @@ -1,40 +1,57 @@ #include "recording-window.hpp" +#include "obs-manager.hpp" #include -#include +#include -RecordingWindow::RecordingWindow() -: m_box_main(Gtk::Orientation::ORIENTATION_VERTICAL, 2), - m_button_start("Start Recording"), - m_label_version("Version: ") +using namespace std; + +RecordingWindow::RecordingWindow(OBSManager *obs) +: mBoxMain(Gtk::Orientation::ORIENTATION_VERTICAL, 2), + mButtonStart("Start Recording"), + mButtonSettings("Settings"), + mLabelVersion("Version: "), + mSettingsWindow(obs) { set_title("New Recording"); - set_default_size(640, 480); + set_default_size(1048, 720); set_border_width(10); - m_button_start.signal_clicked().connect(sigc::mem_fun(*this, &RecordingWindow::on_button_clicked)); + mButtonStart.signal_clicked().connect( + sigc::mem_fun(*this, &RecordingWindow::onStartClicked)); + mButtonSettings.signal_clicked().connect( + sigc::mem_fun(*this, &RecordingWindow::onSettingsClicked)); - //m_box_main.set_margin(10); - m_box_main.add(m_button_start); - m_box_main.add(m_label_version); + mBoxMain.add(mButtonStart); + mBoxMain.add(mButtonSettings); + mBoxMain.add(mLabelVersion); - m_button_start.show(); - m_label_version.show(); + mButtonStart.show(); + mButtonSettings.show(); + mLabelVersion.show(); - add(m_box_main); - m_box_main.show(); + add(mBoxMain); + mBoxMain.show(); - std::string version = "OBS Version: "; - version.append(obs_get_version_string()); + string version; + version.append("OBS Version: "); + version.append(obs->GetVersion()); - m_label_version.set_text(version); + mLabelVersion.set_text(version); } RecordingWindow::~RecordingWindow() { } -void RecordingWindow::on_button_clicked() +void RecordingWindow::onStartClicked() { - std::cout << "Clicked" << std::endl; + cout << "Clicked" << endl; } +void RecordingWindow::onSettingsClicked() +{ + mSettingsWindow.set_transient_for(*this); + mSettingsWindow.show(); +} + + diff --git a/recording-window.hpp b/recording-window.hpp index 9e01b2f..594ef06 100644 --- a/recording-window.hpp +++ b/recording-window.hpp @@ -1,21 +1,23 @@ -#ifndef SCREEN_RECORDER_RECORDING_WINDOW_H -#define SCREEN_RECORDER_RECORDING_WINDOW_H +#ifndef SCREEN_RECORDER_RECORDING_WINDOW_HPP +#define SCREEN_RECORDER_RECORDING_WINDOW_HPP -#include -#include -#include -#include +#include +#include "obs-manager.hpp" +#include "settings-window.hpp" class RecordingWindow : public Gtk::Window { public: - RecordingWindow(); + RecordingWindow(OBSManager *obs); virtual ~RecordingWindow(); protected: - void on_button_clicked(); - Gtk::Box m_box_main; - Gtk::Button m_button_start; - Gtk::Label m_label_version; + void onStartClicked(); + void onSettingsClicked(); + Gtk::Box mBoxMain; + Gtk::Button mButtonStart; + Gtk::Button mButtonSettings; + Gtk::Label mLabelVersion; + SettingsWindow mSettingsWindow; }; #endif diff --git a/screenrecorder b/screenrecorder new file mode 100755 index 0000000..f886fcb Binary files /dev/null and b/screenrecorder differ diff --git a/settings-window.cpp b/settings-window.cpp new file mode 100644 index 0000000..319acd3 --- /dev/null +++ b/settings-window.cpp @@ -0,0 +1,82 @@ +#include "settings-window.hpp" + +SettingsWindow::SettingsWindow(OBSManager* obs) +: mBox(Gtk::Orientation::ORIENTATION_VERTICAL, 2), + mBoxSettings(Gtk::Orientation::ORIENTATION_VERTICAL, 2), + mBoxPluginDir(Gtk::Orientation::ORIENTATION_HORIZONTAL, 2), + mLabelPluginDir("Plugin Dir: "), + mBoxOutputDir(Gtk::Orientation::ORIENTATION_HORIZONTAL, 2), + mLabelOutputDir("Saved Files Dir: "), + mButtonClose("Close"), + mButtonSave("Save") +{ + set_title("Settings"); + set_default_size(640, 480); + set_border_width(10); + set_modal(true); + set_type_hint(Gdk::WindowTypeHint::WINDOW_TYPE_HINT_DIALOG); + + signal_key_press_event().connect( + sigc::mem_fun(*this, &SettingsWindow::onKeyPressed)); + + mButtonClose.signal_clicked().connect( + sigc::mem_fun(*this, &SettingsWindow::onClosePressed)); + mButtonSave.signal_clicked().connect( + sigc::mem_fun(*this, &SettingsWindow::onSavePressed)); + + mBoxSettings.set_border_width(10); + + mEntryPluginDir.set_hexpand(true); + mEntryPluginDir.set_text(obs->GetPluginDir().c_str()); + + mBoxPluginDir.set_border_width(10); + mBoxPluginDir.add(mLabelPluginDir); + mBoxPluginDir.add(mEntryPluginDir); + + mEntryOutputDir.set_hexpand(true); + + mBoxOutputDir.set_border_width(10); + mBoxOutputDir.add(mLabelOutputDir); + mBoxOutputDir.add(mEntryOutputDir); + + mBoxSettings.add(mBoxPluginDir); + mBoxSettings.add(mBoxOutputDir); + + mFrameSettings.set_label("Settings"); + mFrameSettings.set_border_width(10); + mFrameSettings.add(mBoxSettings); + + mActionBar.pack_end(mButtonClose); + mActionBar.pack_end(mButtonSave); + + mBox.add(mFrameSettings); + mBox.add(mActionBar); + + mBox.show_all(); + add(mBox); +} + +SettingsWindow::~SettingsWindow() +{ +} + +bool SettingsWindow::onKeyPressed(GdkEventKey *event) +{ + if (event->keyval == GDK_KEY_Escape) + { + close(); + return true; + } + + return false; +} + +void SettingsWindow::onClosePressed() +{ + close(); +} + +void SettingsWindow::onSavePressed() +{ +} + diff --git a/settings-window.hpp b/settings-window.hpp new file mode 100644 index 0000000..fff2e4e --- /dev/null +++ b/settings-window.hpp @@ -0,0 +1,32 @@ +#ifndef SCREEN_RECORDER_SETTINGS_WINDOW_HPP +#define SCREEN_RECORDER_SETTINGS_WINDOW_HPP + +#include +#include "obs-manager.hpp" + +class SettingsWindow : public Gtk::Window +{ +public: + SettingsWindow(OBSManager *obs); + virtual ~SettingsWindow(); +private: + Gtk::Box mBox; + Gtk::Frame mFrameSettings; + Gtk::Box mBoxSettings; + Gtk::Box mBoxPluginDir; + Gtk::Label mLabelPluginDir; + Gtk::Entry mEntryPluginDir; + Gtk::Box mBoxOutputDir; + Gtk::Label mLabelOutputDir; + Gtk::Entry mEntryOutputDir; + + Gtk::ActionBar mActionBar; + Gtk::Button mButtonClose; + Gtk::Button mButtonSave; + + bool onKeyPressed(GdkEventKey* event); + void onClosePressed(); + void onSavePressed(); +}; + +#endif