You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
5.9 KiB
201 lines
5.9 KiB
#include <stdio.h>
|
|
#include <GL/freeglut.h>
|
|
#include <gtk/gtk.h>
|
|
#include <gdk/gdkx.h>
|
|
#include <obs/obs.h>
|
|
|
|
char version[256];
|
|
const int window_width = 1280;
|
|
const int window_height = 720;
|
|
obs_display_t *display;
|
|
|
|
const char* go_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", go_get_version());
|
|
}
|
|
|
|
static void obs_render(void *param, uint32_t cx, uint32_t cy)
|
|
{
|
|
obs_render_main_texture();
|
|
}
|
|
|
|
static bool enum_sources(void *param, obs_source_t *source)
|
|
{
|
|
GtkWidget *box = param;
|
|
const char *source_name = obs_source_get_name(source);
|
|
uint32_t flags = obs_source_get_output_flags(source);
|
|
|
|
if ((flags & OBS_SOURCE_VIDEO) != 0)
|
|
printf("video source!\n");
|
|
|
|
printf("source: %s\n", source_name);
|
|
gtk_container_add(GTK_CONTAINER(box), gtk_label_new(source_name));
|
|
return true;
|
|
}
|
|
|
|
static void render_sources_window(GtkApplication *app, GtkWidget *parent_window)
|
|
{
|
|
GtkWidget *window, *box;
|
|
const char *t;
|
|
|
|
printf("rendering sources\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_source_types(i, &t); ++i)
|
|
{
|
|
printf("source type: %s\n", t);
|
|
//gtk_container_add(GTK_CONTAINER(box), gtk_label_new(t));
|
|
}
|
|
|
|
for (int i = 0; obs_enum_input_types(i, &t); ++i)
|
|
{
|
|
printf("input type: %s\n", t);
|
|
//gtk_container_add(GTK_CONTAINER(box), gtk_label_new(t));
|
|
}
|
|
|
|
obs_enum_sources(enum_sources, box);
|
|
|
|
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 - Progrium");
|
|
gtk_window_set_default_size(GTK_WINDOW(window), window_width, window_height);
|
|
gtk_window_present(GTK_WINDOW(window));
|
|
|
|
struct gs_init_data info = {
|
|
.cx = window_width,
|
|
.cy = window_height,
|
|
.window.id = gdk_x11_window_get_xid(gtk_widget_get_window(window)),
|
|
.window.display = gdk_window_get_display(gtk_widget_get_window(window)),
|
|
.format = GS_BGRA,
|
|
.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);
|
|
|
|
obs_data_t *settings = obs_data_create();
|
|
//obs_data_set_default_int(settings, "input", -1);
|
|
//obs_data_set_default_int(settings, "pixelformat", -1);
|
|
//obs_data_set_default_int(settings, "standard", -1);
|
|
//obs_data_set_default_int(settings, "dv_timing", -1);
|
|
//obs_data_set_default_int(settings, "resolution", -1);
|
|
//obs_data_set_default_int(settings, "framerate", -1);
|
|
//obs_data_set_default_int(settings, "color_range", VIDEO_RANGE_DEFAULT);
|
|
//obs_data_set_default_bool(settings, "buffering", true);
|
|
//obs_data_set_default_bool(settings, "auto_reset", false);
|
|
//obs_data_set_default_int(settings, "timeout_frames", 5);
|
|
|
|
obs_data_set_string(settings, "device_id", "/dev/video2");
|
|
//obs_data_set_string(settings, "format", "NV12");
|
|
|
|
obs_source_t *source = obs_source_create("v4l2_input", "Source", settings, NULL);
|
|
if (source == NULL)
|
|
printf("couldn't create source");
|
|
|
|
obs_scene_t *scene = obs_scene_create("scene1");
|
|
if (scene == NULL)
|
|
printf("couldn't create scene");
|
|
|
|
obs_scene_add(scene, source);
|
|
obs_set_output_source(0, obs_scene_get_source(scene));
|
|
|
|
render_sources_window(app, window);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
GtkApplication* app;
|
|
obs_module_t *module;
|
|
int status, res;
|
|
|
|
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 next line crashes the app on load
|
|
//obs_load_all_modules();
|
|
|
|
// This just initializes OpenGL.
|
|
// The program won't run if OpenGL hasn't been initialized.
|
|
glutInit(&argc, argv);
|
|
|
|
res = obs_open_module(&module, "/usr/lib/x86_64-linux-gnu/obs-plugins/obs-ffmpeg.so", NULL);
|
|
if (res != MODULE_SUCCESS)
|
|
printf("error opening plugin\n");
|
|
|
|
obs_init_module(module);
|
|
|
|
res = obs_open_module(&module, "/usr/lib/x86_64-linux-gnu/obs-plugins/linux-v4l2.so", NULL);
|
|
if (res != MODULE_SUCCESS)
|
|
printf("error opening v4l2 plugin\n");
|
|
|
|
obs_init_module(module);
|
|
|
|
obs_post_load_modules();
|
|
|
|
struct obs_video_info v = {
|
|
.graphics_module = "libobs-opengl.so.0",
|
|
.fps_num = 30000,
|
|
.fps_den = 1001,
|
|
.base_width = window_width,
|
|
.base_height = window_height,
|
|
.output_width = window_width,
|
|
.output_height = window_height,
|
|
.output_format = VIDEO_FORMAT_NV12,
|
|
.adapter = 0,
|
|
.gpu_conversion = true,
|
|
.colorspace = VIDEO_CS_601,
|
|
.range = VIDEO_RANGE_PARTIAL,
|
|
.scale_type = OBS_SCALE_BICUBIC,
|
|
};
|
|
|
|
struct obs_audio_info a = {
|
|
.samples_per_sec = 44100,
|
|
.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;
|
|
}
|