obs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /******************************************************************************
  2. Copyright (C) 2013 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 3 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 "graphics/graphics.h"
  17. #include "graphics/vec2.h"
  18. #include "media-io/media-io.h"
  19. #include "obs-defs.h"
  20. /*
  21. * Main libobs header used by applications.
  22. */
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. enum obs_source_type {
  27. SOURCE_INPUT,
  28. SOURCE_FILTER,
  29. SOURCE_TRANSITION,
  30. SOURCE_SCENE
  31. };
  32. /* used for changing the order of items (for example, filters in a source,
  33. * or items in a scene) */
  34. enum order_movement {
  35. ORDER_MOVE_UP,
  36. ORDER_MOVE_DOWN,
  37. ORDER_MOVE_TOP,
  38. ORDER_MOVE_BOTTOM
  39. };
  40. struct filtered_audio {
  41. void *data;
  42. uint32_t frames;
  43. uint64_t timestamp;
  44. };
  45. struct source_audio {
  46. const void *data;
  47. uint32_t frames;
  48. /* audio will be automatically resampled/upmixed/downmixed */
  49. enum speaker_layout speakers;
  50. enum audio_format format;
  51. uint32_t samples_per_sec;
  52. /* can be 0 if 'immediate' */
  53. uint64_t timestamp;
  54. };
  55. struct source_frame {
  56. void *data;
  57. uint32_t width;
  58. uint32_t height;
  59. uint32_t row_bytes;
  60. uint64_t timestamp;
  61. enum video_format format;
  62. float yuv_matrix[16];
  63. bool flip;
  64. };
  65. static inline void source_frame_destroy(struct source_frame *frame)
  66. {
  67. if (frame) {
  68. bfree(frame->data);
  69. bfree(frame);
  70. }
  71. }
  72. /* opaque types */
  73. struct obs_display;
  74. struct obs_source;
  75. struct obs_scene;
  76. struct obs_scene_item;
  77. struct obs_output;
  78. typedef struct obs_display *obs_display_t;
  79. typedef struct obs_source *obs_source_t;
  80. typedef struct obs_scene *obs_scene_t;
  81. typedef struct obs_scene_item *obs_sceneitem_t;
  82. typedef struct obs_output *obs_output_t;
  83. /* ------------------------------------------------------------------------- */
  84. /* OBS context */
  85. /**
  86. * Starts up and shuts down OBS
  87. *
  88. * Using the graphics module specified, creates an OBS context and sets the
  89. * primary video/audio output information.
  90. */
  91. EXPORT bool obs_startup(const char *graphics_module,
  92. struct gs_init_data *graphics_data,
  93. struct video_info *vi, struct audio_info *ai);
  94. EXPORT void obs_shutdown(void);
  95. /**
  96. * Sets base video ouput base resolution/fps/format
  97. *
  98. * NOTE: Cannot reset base video if currently streaming/recording.
  99. */
  100. EXPORT bool obs_reset_video(struct video_info *vi);
  101. /**
  102. * Sets base audio output format/channels/samples/etc
  103. *
  104. * NOTE: Cannot reset base audio if currently streaming/recording.
  105. */
  106. EXPORT bool obs_reset_audio(struct audio_info *ai);
  107. /**
  108. * Loads a plugin module
  109. *
  110. * A plugin module contains exports for inputs/fitlers/transitions/outputs.
  111. * See obs-source.h and obs-output.h for more information on the exports to
  112. * use.
  113. */
  114. EXPORT int obs_load_module(const char *path);
  115. /**
  116. * Enumerates all available inputs.
  117. *
  118. * Inputs are general source inputs (such as capture sources, device sources,
  119. * etc).
  120. */
  121. EXPORT bool obs_enum_inputs(size_t idx, const char **name);
  122. /**
  123. * Enumerates all available filters.
  124. *
  125. * Filters are sources that are used to modify the video/audio output of
  126. * other sources.
  127. */
  128. EXPORT bool obs_enum_filters(size_t idx, const char **name);
  129. /**
  130. * Enumerates all available transitions.
  131. *
  132. * Transitions are sources used to transition between two or more other
  133. * sources.
  134. */
  135. EXPORT bool obs_enum_transitions(size_t idx, const char **name);
  136. /**
  137. * Enumerates all available ouputs.
  138. *
  139. * Outputs handle color space conversion, encoding, and output to file or
  140. * streams.
  141. */
  142. EXPORT bool obs_enum_outputs(size_t idx, const char **name);
  143. /** Gets the graphics context for this OBS context */
  144. EXPORT graphics_t obs_graphics(void);
  145. /** Get the media context for this OBS context (used for outputs) */
  146. EXPORT media_t obs_media(void);
  147. /**
  148. * Sets/gets the primary output source.
  149. *
  150. * The primary source is the source that's presented.
  151. */
  152. EXPORT void obs_set_primary_source(obs_source_t source);
  153. EXPORT obs_source_t obs_get_primary_source(void);
  154. /* ------------------------------------------------------------------------- */
  155. /* Display context */
  156. /**
  157. * Creates an extra display context.
  158. *
  159. * An extra display can be used for things like separate previews,
  160. * viewing sources independently, and other things. Creates a new swap chain
  161. * linked to a specific window to display a source.
  162. */
  163. EXPORT obs_display_t obs_display_create(struct gs_init_data *graphics_data);
  164. EXPORT void obs_display_destroy(obs_display_t display);
  165. /** Sets the source to be used for a display context. */
  166. EXPORT void obs_display_setsource(obs_display_t display, obs_source_t source);
  167. EXPORT obs_source_t obs_display_getsource(obs_display_t display);
  168. /* ------------------------------------------------------------------------- */
  169. /* Sources */
  170. /**
  171. * Creates a source of the specified type with the specified settings.
  172. *
  173. * The "source" context is used for anything related to presenting
  174. * or modifying video/audio.
  175. */
  176. EXPORT obs_source_t obs_source_create(enum obs_source_type type,
  177. const char *name, const char *settings);
  178. EXPORT void obs_source_destroy(obs_source_t source);
  179. /**
  180. * Retrieves flags that specify what type of data the source presents/modifies.
  181. *
  182. * SOURCE_VIDEO if it presents/modifies video_frame
  183. * SOURCE_ASYNC if the video is asynchronous.
  184. * SOURCE_AUDIO if it presents/modifies audio (always async)
  185. */
  186. EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
  187. /** Specifies whether the source can be configured */
  188. EXPORT bool obs_source_hasconfig(obs_source_t source);
  189. /** Opens a configuration panel and attaches it to the parent window */
  190. EXPORT void obs_source_config(obs_source_t source, void *parent);
  191. /** Renders a video source. */
  192. EXPORT void obs_source_video_render(obs_source_t source);
  193. /** Gets the width of a source (if it has video) */
  194. EXPORT uint32_t obs_source_getwidth(obs_source_t source);
  195. /** Gets the height of a source (if it has video) */
  196. EXPORT uint32_t obs_source_getheight(obs_source_t source);
  197. /**
  198. * Gets a custom parameter from the source.
  199. *
  200. * Used for efficiently modifying source properties in real time.
  201. */
  202. EXPORT size_t obs_source_getparam(obs_source_t source, const char *param,
  203. void *buf, size_t buf_size);
  204. /**
  205. * Sets a custom parameter for the source.
  206. *
  207. * Used for efficiently modifying source properties in real time.
  208. */
  209. EXPORT void obs_source_setparam(obs_source_t source, const char *param,
  210. const void *data, size_t size);
  211. /** Enumerates child sources this source has */
  212. EXPORT bool obs_source_enum_children(obs_source_t source, size_t idx,
  213. obs_source_t *child);
  214. /** If the source is a filter, returns the target source of the filter */
  215. EXPORT obs_source_t obs_filter_gettarget(obs_source_t filter);
  216. /** Adds a filter to the source (which is used whenever the source is used) */
  217. EXPORT void obs_source_filter_add(obs_source_t source,obs_source_t filter);
  218. /** Removes a filter from the source */
  219. EXPORT void obs_source_filter_remove(obs_source_t source, obs_source_t filter);
  220. /** Modifies the order of a specific filter */
  221. EXPORT void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
  222. enum order_movement movement);
  223. /** Gets the settings string for a source */
  224. EXPORT const char *obs_source_get_settings(obs_source_t source);
  225. /* ------------------------------------------------------------------------- */
  226. /* Functions used by sources */
  227. /** Saves the settings string for a source */
  228. EXPORT void obs_source_save_settings(obs_source_t source, const char *settings);
  229. /** Outputs asynchronous video data */
  230. EXPORT void obs_source_obs_async_video(obs_source_t source,
  231. const struct source_frame *frame);
  232. /** Outputs audio data (always asynchronous) */
  233. EXPORT void obs_source_obs_async_audio(obs_source_t source,
  234. const struct source_audio *audio);
  235. /** Gets the current async video frame */
  236. EXPORT struct source_frame *obs_source_getframe(obs_source_t source);
  237. /** Releases the current async video frame */
  238. EXPORT void obs_source_releaseframe(obs_source_t source,
  239. struct source_frame *frame);
  240. /* ------------------------------------------------------------------------- */
  241. /* Scenes */
  242. /**
  243. * Creates a scene.
  244. *
  245. * A scene is a source which is a container of other sources with specific
  246. * display oriantations. Scenes can also be used like any other source.
  247. */
  248. EXPORT obs_scene_t obs_scene_create(void);
  249. EXPORT void obs_scene_destroy(obs_scene_t scene);
  250. /** Gets the scene's source context */
  251. EXPORT obs_source_t obs_scene_getsource(obs_scene_t scene);
  252. /** Adds/creates a new scene item for a source */
  253. EXPORT obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source);
  254. /** Removes/destroys a scene item */
  255. EXPORT void obs_sceneitem_destroy(obs_sceneitem_t item);
  256. /* Functions for gettings/setting specific oriantation of a scene item */
  257. EXPORT void obs_sceneitem_setpos(obs_sceneitem_t item, const struct vec2 *pos);
  258. EXPORT void obs_sceneitem_setrot(obs_sceneitem_t item, float rot);
  259. EXPORT void obs_sceneitem_setorigin(obs_sceneitem_t item,
  260. const struct vec2 *origin);
  261. EXPORT void obs_sceneitem_setscale(obs_sceneitem_t item,
  262. const struct vec2 *scale);
  263. EXPORT void obs_sceneitem_setorder(obs_sceneitem_t item,
  264. enum order_movement movement);
  265. EXPORT void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos);
  266. EXPORT float obs_sceneitem_getrot(obs_sceneitem_t item);
  267. EXPORT void obs_sceneitem_getorigin(obs_sceneitem_t item, struct vec2 *center);
  268. EXPORT void obs_sceneitem_getscale(obs_sceneitem_t item, struct vec2 *scale);
  269. /* ------------------------------------------------------------------------- */
  270. /* Outputs */
  271. /**
  272. * Creates an output.
  273. *
  274. * Outputs allow outputting to file, outputting to network, outputting to
  275. * directshow, or other custom outputs.
  276. */
  277. EXPORT obs_output_t obs_output_create(const char *name, const char *settings);
  278. EXPORT void obs_output_destroy(obs_output_t output);
  279. /** Starts the output. */
  280. EXPORT void obs_output_start(obs_output_t output);
  281. /** Stops the output. */
  282. EXPORT void obs_output_stop(obs_output_t output);
  283. /** Specifies whether the output can be configured */
  284. EXPORT bool obs_output_canconfig(obs_output_t output);
  285. /** Opens a configuration panel with the specified parent window */
  286. EXPORT void obs_output_config(obs_output_t output, void *parent);
  287. /** Specifies whether the output can be paused */
  288. EXPORT bool obs_output_canpause(obs_output_t output);
  289. /** Pauses the output (if the functionality is allowed by the output */
  290. EXPORT void obs_output_pause(obs_output_t output);
  291. /* Gets the current output settings string */
  292. EXPORT const char *obs_output_get_settings(obs_output_t output);
  293. /* Saves the output settings string, typically used only by outputs */
  294. EXPORT void obs_output_save_settings(obs_output_t output,
  295. const char *settings);
  296. #ifdef __cplusplus
  297. }
  298. #endif