diff --git a/Makefile b/Makefile index 11c8035..3b8f28b 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,13 @@ all: build build: - gcc -Wall main.c -lobs -lglut -lGL `pkg-config --cflags --libs gtk4` -o main + gcc -Wall obs.c -lobs -lglut -lGL `pkg-config --cflags --libs gtk+-3.0` -o obs + +gbuild: + c-for-go obs.yml run: build - ./main + ./obs clean: - rm main + rm ./obs diff --git a/main.c b/main.c deleted file mode 100644 index 7d94585..0000000 --- a/main.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include -#include -#include - -const int window_width = 1280; -const int window_height = 720; -Window xw; - -void -print_obs_version_string() -{ - const char* version = obs_get_version_string(); - printf("OBS version: %s\n", version); -} - -void -obs_render (void* param, - uint32_t cx, - uint32_t cy) -{ - obs_render_main_texture (); -} - -static void -activate (GtkApplication* app, - gpointer user_data) -{ - GtkWidget* window = gtk_application_window_new (app); - gtk_window_set_title (GTK_WINDOW(window), "OBS"); - gtk_window_set_default_size (GTK_WINDOW(window), window_width, window_height); - gtk_window_present (GTK_WINDOW(window)); - xw = gdk_x11_window_get_xid (gtk_widget_get_window(window)); -} - -void -render_sources(GtkApplication* app) -{ - GtkWidget* window = gtk_application_window_new (app); - gtk_window_set_title (GTK_WINDOW(window), "OBS - Sources"); - gtk_window_set_default_size (GTK_WINDOW(window), 500, 500); - gtk_window_present (GTK_WINDOW(window)); -} - -int -main(int argc, char** argv) -{ - GtkApplication* app; - obs_display_t* display; - int status; - - app = gtk_application_new("xyz.dwayne.obs", G_APPLICATION_FLAGS_NONE); - g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); - - print_obs_version_string(); - - if (!obs_initialized()) - { - if (!obs_startup("en-US", NULL, NULL)) - { - printf("Failed to start OBS...\n"); - return 1; - } - - glutInit(&argc, argv); - - struct obs_video_info v; - struct obs_audio_info a; - - v.graphics_module = "libobs-opengl.so.0"; - v.fps_num = 30000; - v.fps_den = 1001; - v.base_width = window_width; - v.base_height = window_height; - v.output_width = window_width; - v.output_height = window_height; - v.output_format = VIDEO_FORMAT_NV12; - v.adapter = 0; - v.gpu_conversion = true; - v.colorspace = VIDEO_CS_601; - v.range = VIDEO_RANGE_PARTIAL; - v.scale_type = OBS_SCALE_BICUBIC; - - a.samples_per_sec = 44100; - a.speakers = SPEAKERS_STEREO; - - obs_reset_video (&v); - obs_reset_audio (&a); - } - - // struct gs_init_data info; - // info.cx = window_width; - // info.cy = window_height; - // info.window = NULL; // xw?? - // info.format = GS_BGRA; - // info.zsformat = GS_ZS_NONE; - - // display = obs_display_create (&info, 0); - // if (display == NULL) - // { - // printf("error creating display!\n"); - // } - - // obs_display_add_draw_callback (display, obs_render, NULL); - - status = g_application_run (G_APPLICATION (app), argc, argv); - - // obs_display_destroy (display); - obs_shutdown (); - g_object_unref (app); - - return status; -} diff --git a/obs.c b/obs.c new file mode 100644 index 0000000..e41d450 --- /dev/null +++ b/obs.c @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include + +char version[256]; +const int window_width = 1280; +const int window_height = 720; +obs_display_t *display; + +const char * +get_version() +{ + sprintf (version, "Version: 0.0.1; OBS version: %s\n", obs_get_version_string ()); + return version; +} + +void +print_version_string() +{ + printf ("%s\n", get_version ()); +} + +void +obs_render (void *param, + uint32_t cx, + uint32_t cy) +{ + obs_render_main_texture (); +} + +void +render_input_types_window(GtkApplication *app, + GtkWidget *parent_window) +{ + GtkWidget *window, *box; + const char *input_type; + + printf("rendering input types\n"); + + window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "OBS - Sources"); + gtk_window_set_default_size (GTK_WINDOW (window), 500, 500); + + box = gtk_list_box_new (); + for (int i = 0; obs_enum_input_types (i, &input_type); ++i) + { + printf("input type: %s\n", input_type); + gtk_container_add (GTK_CONTAINER (box), gtk_label_new (input_type)); + } + + gtk_container_add ( GTK_CONTAINER (window), box); + gtk_widget_show_all (box); + gtk_window_present (GTK_WINDOW (window)); +} + +static void +activate (GtkApplication *app, + gpointer user_data) +{ + GtkWidget *window = gtk_application_window_new (app); + gtk_window_set_title (GTK_WINDOW (window), "OBS"); + gtk_window_set_default_size (GTK_WINDOW (window), window_width, window_height); + gtk_window_present (GTK_WINDOW (window)); + + struct gs_init_data info; + info.cx = window_width; + info.cy = window_height; + info.window.id = gdk_x11_window_get_xid (gtk_widget_get_window (window)); + info.window.display = gdk_window_get_display (gtk_widget_get_window (window)); + info.format = GS_BGRA; + info.zsformat = GS_ZS_NONE; + + display = obs_display_create (&info, 0); + if (display == NULL) + { + printf("error creating display!\n"); + } + + obs_display_add_draw_callback (display, obs_render, NULL); + render_input_types_window (app, window); +} + +int +main(int argc, + char **argv) +{ + GtkApplication* app; + int status; + + app = gtk_application_new("xyz.dwayne.obs", G_APPLICATION_FLAGS_NONE); + g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); + + print_version_string(); + + if (!obs_initialized()) + { + if (!obs_startup("en-US", NULL, NULL)) + { + printf("Failed to start OBS...\n"); + return 1; + } + + // This just initializes OpenGL + glutInit(&argc, argv); + + struct obs_video_info v; + struct obs_audio_info a; + + v.graphics_module = "libobs-opengl.so.0"; + v.fps_num = 30000; + v.fps_den = 1001; + v.base_width = window_width; + v.base_height = window_height; + v.output_width = window_width; + v.output_height = window_height; + v.output_format = VIDEO_FORMAT_NV12; + v.adapter = 0; + v.gpu_conversion = true; + v.colorspace = VIDEO_CS_601; + v.range = VIDEO_RANGE_PARTIAL; + v.scale_type = OBS_SCALE_BICUBIC; + + a.samples_per_sec = 44100; + a.speakers = SPEAKERS_STEREO; + + obs_reset_video (&v); + obs_reset_audio (&a); + } + + status = g_application_run (G_APPLICATION (app), argc, argv); + + if (display != NULL) + obs_display_destroy (display); + + obs_shutdown (); + g_object_unref (app); + + return status; +} diff --git a/obs.h b/obs.h new file mode 100644 index 0000000..3faa6a0 --- /dev/null +++ b/obs.h @@ -0,0 +1,14 @@ +#ifndef OBS_H +#define OBS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +extern const char * get_version (void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/obs.yml b/obs.yml new file mode 100644 index 0000000..e6cee80 --- /dev/null +++ b/obs.yml @@ -0,0 +1,11 @@ +--- +GENERATOR: + PackageName: obs-sample + PackageDescription: "Go bindings." + PackageLicense: "None" + Includes: + - obs.h + +PARSER: + IncludePaths: [/usr/include] + SourcesPaths: [obs.h]