obs-internal.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include "util/c99defs.h"
  16. #include "util/darray.h"
  17. #include "util/dstr.h"
  18. #include "util/threading.h"
  19. #include "callback/signal.h"
  20. #include "callback/proc.h"
  21. #include "graphics/graphics.h"
  22. #include "media-io/audio-resampler.h"
  23. #include "media-io/video-io.h"
  24. #include "media-io/audio-io.h"
  25. #include "obs.h"
  26. #define NUM_TEXTURES 2
  27. struct draw_callback {
  28. void (*draw)(void *param, uint32_t cx, uint32_t cy);
  29. void *param;
  30. };
  31. /* ------------------------------------------------------------------------- */
  32. /* modules */
  33. struct obs_module {
  34. char *name;
  35. void *module;
  36. };
  37. extern void free_module(struct obs_module *mod);
  38. /* ------------------------------------------------------------------------- */
  39. /* views */
  40. struct obs_view {
  41. pthread_mutex_t channels_mutex;
  42. obs_source_t channels[MAX_CHANNELS];
  43. };
  44. extern bool obs_view_init(struct obs_view *view);
  45. extern void obs_view_free(struct obs_view *view);
  46. /* ------------------------------------------------------------------------- */
  47. /* displays */
  48. struct obs_display {
  49. bool size_changed;
  50. uint32_t cx, cy;
  51. swapchain_t swap;
  52. pthread_mutex_t draw_callbacks_mutex;
  53. DARRAY(struct draw_callback) draw_callbacks;
  54. };
  55. extern bool obs_display_init(struct obs_display *display,
  56. struct gs_init_data *graphics_data);
  57. extern void obs_display_free(struct obs_display *display);
  58. /* ------------------------------------------------------------------------- */
  59. /* core */
  60. struct obs_core_video {
  61. graphics_t graphics;
  62. stagesurf_t copy_surfaces[NUM_TEXTURES];
  63. texture_t render_textures[NUM_TEXTURES];
  64. texture_t output_textures[NUM_TEXTURES];
  65. texture_t convert_textures[NUM_TEXTURES];
  66. bool textures_rendered[NUM_TEXTURES];
  67. bool textures_output[NUM_TEXTURES];
  68. bool textures_copied[NUM_TEXTURES];
  69. bool textures_converted[NUM_TEXTURES];
  70. struct source_frame convert_frames[NUM_TEXTURES];
  71. effect_t default_effect;
  72. effect_t conversion_effect;
  73. stagesurf_t mapped_surface;
  74. int cur_texture;
  75. video_t video;
  76. pthread_t video_thread;
  77. bool thread_initialized;
  78. bool gpu_conversion;
  79. const char *conversion_tech;
  80. uint32_t conversion_height;
  81. uint32_t plane_offsets[3];
  82. uint32_t plane_sizes[3];
  83. uint32_t plane_linewidth[3];
  84. uint32_t output_width;
  85. uint32_t output_height;
  86. uint32_t base_width;
  87. uint32_t base_height;
  88. struct obs_display main_display;
  89. };
  90. struct obs_core_audio {
  91. /* TODO: sound output subsystem */
  92. audio_t audio;
  93. float user_volume;
  94. float present_volume;
  95. };
  96. /* user sources, output channels, and displays */
  97. struct obs_core_data {
  98. /* arrays of pointers jim? you should really stop being lazy and use
  99. * linked lists. */
  100. DARRAY(struct obs_display*) displays;
  101. DARRAY(struct obs_source*) sources;
  102. DARRAY(struct obs_output*) outputs;
  103. DARRAY(struct obs_encoder*) encoders;
  104. pthread_mutex_t sources_mutex;
  105. pthread_mutex_t displays_mutex;
  106. pthread_mutex_t outputs_mutex;
  107. pthread_mutex_t encoders_mutex;
  108. struct obs_view main_view;
  109. volatile bool valid;
  110. };
  111. struct obs_core {
  112. DARRAY(struct obs_module) modules;
  113. DARRAY(struct obs_source_info) input_types;
  114. DARRAY(struct obs_source_info) filter_types;
  115. DARRAY(struct obs_source_info) transition_types;
  116. DARRAY(struct obs_output_info) output_types;
  117. DARRAY(struct obs_encoder_info) encoder_types;
  118. DARRAY(struct obs_service_info) service_types;
  119. DARRAY(struct obs_modal_ui) modal_ui_callbacks;
  120. DARRAY(struct obs_modeless_ui) modeless_ui_callbacks;
  121. signal_handler_t signals;
  122. proc_handler_t procs;
  123. /* segmented into multiple sub-structures to keep things a bit more
  124. * clean and organized */
  125. struct obs_core_video video;
  126. struct obs_core_audio audio;
  127. struct obs_core_data data;
  128. };
  129. extern struct obs_core *obs;
  130. extern void *obs_video_thread(void *param);
  131. /* ------------------------------------------------------------------------- */
  132. /* sources */
  133. struct obs_source {
  134. volatile int refs;
  135. struct obs_source_info info;
  136. /* source-specific data */
  137. char *name; /* user-defined name */
  138. obs_data_t settings;
  139. void *data;
  140. signal_handler_t signals;
  141. proc_handler_t procs;
  142. /* ensures show/hide are only called once */
  143. int show_refs;
  144. /* ensures activate/deactivate are only called once */
  145. int activate_refs;
  146. /* prevents infinite recursion when enumerating sources */
  147. int enum_refs;
  148. /* used to indicate that the source has been removed and all
  149. * references to it should be released (not exactly how I would prefer
  150. * to handle things but it's the best option) */
  151. bool removed;
  152. /* timing (if video is present, is based upon video) */
  153. volatile bool timing_set;
  154. volatile uint64_t timing_adjust;
  155. volatile int audio_reset_ref;
  156. uint64_t next_audio_ts_min;
  157. uint64_t last_frame_ts;
  158. uint64_t last_sys_timestamp;
  159. /* audio */
  160. bool audio_failed;
  161. struct resample_info sample_info;
  162. audio_resampler_t resampler;
  163. audio_line_t audio_line;
  164. pthread_mutex_t audio_mutex;
  165. struct filtered_audio audio_data;
  166. size_t audio_storage_size;
  167. float user_volume;
  168. float present_volume;
  169. int64_t sync_offset;
  170. /* transition volume is meant to store the sum of transitioning volumes
  171. * of a source, i.e. if a source is within both the "to" and "from"
  172. * targets of a transition, it would add both volumes to this variable,
  173. * and then when the transition frame is complete, is applies the value
  174. * to the presentation volume. */
  175. float transition_volume;
  176. /* async video data */
  177. texture_t output_texture;
  178. DARRAY(struct source_frame*) video_frames;
  179. pthread_mutex_t video_mutex;
  180. /* filters */
  181. struct obs_source *filter_parent;
  182. struct obs_source *filter_target;
  183. DARRAY(struct obs_source*) filters;
  184. pthread_mutex_t filter_mutex;
  185. texrender_t filter_texrender;
  186. bool rendering_filter;
  187. };
  188. bool obs_source_init_handlers(struct obs_source *source);
  189. extern bool obs_source_init(struct obs_source *source,
  190. const struct obs_source_info *info);
  191. enum view_type {
  192. MAIN_VIEW,
  193. AUX_VIEW
  194. };
  195. extern void obs_source_activate(obs_source_t source, enum view_type type);
  196. extern void obs_source_deactivate(obs_source_t source, enum view_type type);
  197. extern void obs_source_video_tick(obs_source_t source, float seconds);
  198. /* ------------------------------------------------------------------------- */
  199. /* outputs */
  200. struct obs_output {
  201. char *name;
  202. void *data;
  203. struct obs_output_info info;
  204. obs_data_t settings;
  205. };
  206. /* ------------------------------------------------------------------------- */
  207. /* encoders */
  208. struct encoder_callback {
  209. void (*new_packet)(void *param, struct encoder_packet *packet);
  210. void *param;
  211. };
  212. struct obs_encoder {
  213. char *name;
  214. void *data;
  215. struct obs_encoder_info info;
  216. obs_data_t settings;
  217. pthread_mutex_t data_callbacks_mutex;
  218. DARRAY(struct encoder_callback) data_callbacks;
  219. };