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.

141 lines
3.6 KiB

3 years ago
  1. #include <stdio.h>
  2. #include <GL/freeglut.h>
  3. #include <gtk/gtk.h>
  4. #include <gdk/gdkx.h>
  5. #include <obs/obs.h>
  6. char version[256];
  7. const int window_width = 1280;
  8. const int window_height = 720;
  9. obs_display_t *display;
  10. const char *
  11. get_version()
  12. {
  13. sprintf (version, "Version: 0.0.1; OBS version: %s\n", obs_get_version_string ());
  14. return version;
  15. }
  16. void
  17. print_version_string()
  18. {
  19. printf ("%s\n", get_version ());
  20. }
  21. void
  22. obs_render (void *param,
  23. uint32_t cx,
  24. uint32_t cy)
  25. {
  26. obs_render_main_texture ();
  27. }
  28. void
  29. render_input_types_window(GtkApplication *app,
  30. GtkWidget *parent_window)
  31. {
  32. GtkWidget *window, *box;
  33. const char *input_type;
  34. printf("rendering input types\n");
  35. window = gtk_application_window_new (app);
  36. gtk_window_set_title (GTK_WINDOW (window), "OBS - Sources");
  37. gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
  38. box = gtk_list_box_new ();
  39. for (int i = 0; obs_enum_input_types (i, &input_type); ++i)
  40. {
  41. printf("input type: %s\n", input_type);
  42. gtk_container_add (GTK_CONTAINER (box), gtk_label_new (input_type));
  43. }
  44. gtk_container_add ( GTK_CONTAINER (window), box);
  45. gtk_widget_show_all (box);
  46. gtk_window_present (GTK_WINDOW (window));
  47. }
  48. static void
  49. activate (GtkApplication *app,
  50. gpointer user_data)
  51. {
  52. GtkWidget *window = gtk_application_window_new (app);
  53. gtk_window_set_title (GTK_WINDOW (window), "OBS");
  54. gtk_window_set_default_size (GTK_WINDOW (window), window_width, window_height);
  55. gtk_window_present (GTK_WINDOW (window));
  56. struct gs_init_data info;
  57. info.cx = window_width;
  58. info.cy = window_height;
  59. info.window.id = gdk_x11_window_get_xid (gtk_widget_get_window (window));
  60. info.window.display = gdk_window_get_display (gtk_widget_get_window (window));
  61. info.format = GS_BGRA;
  62. info.zsformat = GS_ZS_NONE;
  63. display = obs_display_create (&info, 0);
  64. if (display == NULL)
  65. {
  66. printf("error creating display!\n");
  67. }
  68. obs_display_add_draw_callback (display, obs_render, NULL);
  69. render_input_types_window (app, window);
  70. }
  71. int
  72. main(int argc,
  73. char **argv)
  74. {
  75. GtkApplication* app;
  76. int status;
  77. app = gtk_application_new("xyz.dwayne.obs", G_APPLICATION_FLAGS_NONE);
  78. g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
  79. print_version_string();
  80. if (!obs_initialized())
  81. {
  82. if (!obs_startup("en-US", NULL, NULL))
  83. {
  84. printf("Failed to start OBS...\n");
  85. return 1;
  86. }
  87. // This just initializes OpenGL
  88. glutInit(&argc, argv);
  89. struct obs_video_info v;
  90. struct obs_audio_info a;
  91. v.graphics_module = "libobs-opengl.so.0";
  92. v.fps_num = 30000;
  93. v.fps_den = 1001;
  94. v.base_width = window_width;
  95. v.base_height = window_height;
  96. v.output_width = window_width;
  97. v.output_height = window_height;
  98. v.output_format = VIDEO_FORMAT_NV12;
  99. v.adapter = 0;
  100. v.gpu_conversion = true;
  101. v.colorspace = VIDEO_CS_601;
  102. v.range = VIDEO_RANGE_PARTIAL;
  103. v.scale_type = OBS_SCALE_BICUBIC;
  104. a.samples_per_sec = 44100;
  105. a.speakers = SPEAKERS_STEREO;
  106. obs_reset_video (&v);
  107. obs_reset_audio (&a);
  108. }
  109. status = g_application_run (G_APPLICATION (app), argc, argv);
  110. if (display != NULL)
  111. obs_display_destroy (display);
  112. obs_shutdown ();
  113. g_object_unref (app);
  114. return status;
  115. }