obs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 source_type {
  27. SOURCE_INPUT,
  28. SOURCE_FILTER,
  29. SOURCE_TRANSITION,
  30. SOURCE_SCENE
  31. };
  32. enum order_movement {
  33. ORDER_MOVE_UP,
  34. ORDER_MOVE_DOWN,
  35. ORDER_MOVE_TOP,
  36. ORDER_MOVE_BOTTOM
  37. };
  38. /* opaque types */
  39. struct obs_data;
  40. struct obs_display;
  41. struct obs_source;
  42. struct obs_scene;
  43. struct obs_scene_item;
  44. struct obs_output;
  45. typedef struct obs_data *obs_t;
  46. typedef struct obs_display *display_t;
  47. typedef struct obs_source *source_t;
  48. typedef struct obs_scene *scene_t;
  49. typedef struct obs_scene_item *sceneitem_t;
  50. typedef struct obs_output *output_t;
  51. /* ------------------------------------------------------------------------- */
  52. /* OBS context */
  53. /**
  54. * Creates the OBS context.
  55. *
  56. * Using the graphics module specified, creates an OBS context and sets the
  57. * primary video/audio output information.
  58. */
  59. EXPORT obs_t obs_create(const char *graphics_module,
  60. struct gs_init_data *graphics_data,
  61. struct video_info *vi, struct audio_info *ai);
  62. EXPORT void obs_destroy(obs_t obs);
  63. /**
  64. * Sets base video ouput base resolution/fps/format
  65. *
  66. * NOTE: Cannot reset base video if currently streaming/recording.
  67. */
  68. EXPORT bool obs_reset_video(obs_t obs, struct video_info *vi);
  69. /**
  70. * Sets base audio output format/channels/samples/etc
  71. *
  72. * NOTE: Cannot reset base audio if currently streaming/recording.
  73. */
  74. EXPORT bool obs_reset_audio(obs_t obs, struct audio_info *ai);
  75. /**
  76. * Loads a plugin module
  77. *
  78. * A plugin module contains exports for inputs/fitlers/transitions/outputs.
  79. * See obs-source.h and obs-output.h for more information on the exports to
  80. * use.
  81. */
  82. EXPORT int obs_load_module(obs_t obs, const char *path);
  83. /**
  84. * Enumerates all available inputs.
  85. *
  86. * Inputs are general source inputs (such as capture sources, device sources,
  87. * etc).
  88. */
  89. EXPORT bool obs_enum_inputs(obs_t obs, size_t idx, const char **name);
  90. /**
  91. * Enumerates all available filters.
  92. *
  93. * Filters are sources that are used to modify the video/audio output of
  94. * other sources.
  95. */
  96. EXPORT bool obs_enum_filters(obs_t obs, size_t idx, const char **name);
  97. /**
  98. * Enumerates all available transitions.
  99. *
  100. * Transitions are sources used to transition between two or more other
  101. * sources.
  102. */
  103. EXPORT bool obs_enum_transitions(obs_t obs, size_t idx,
  104. const char **name);
  105. /**
  106. * Enumerates all available ouputs.
  107. *
  108. * Outputs handle color space conversion, encoding, and output to file or
  109. * streams.
  110. */
  111. EXPORT bool obs_enum_outputs(obs_t obs, size_t idx, const char **name);
  112. /** Gets the graphics context for this OBS context */
  113. EXPORT graphics_t obs_graphics(obs_t obs);
  114. /** Get the media context for this OBS context (used for outputs) */
  115. EXPORT media_t obs_media(obs_t obs);
  116. /**
  117. * Sets/gets the primary output source.
  118. *
  119. * The primary source is the source that's broadcasted/saved.
  120. */
  121. EXPORT void obs_set_primary_source(obs_t obs, source_t source);
  122. EXPORT source_t obs_get_primary_source(obs_t obs);
  123. /* ------------------------------------------------------------------------- */
  124. /* Display context */
  125. /**
  126. * Creates an extra display context.
  127. *
  128. * An extra display can be used for things like separate previews,
  129. * viewing sources independently, and other things. Creates a new swap chain
  130. * linked to a specific window to display a source.
  131. */
  132. EXPORT display_t display_create(obs_t obs, struct gs_init_data *graphics_data);
  133. EXPORT void display_destroy(display_t display);
  134. /** Sets the source to be used for a display context. */
  135. EXPORT void display_setsource(display_t display, source_t source);
  136. EXPORT source_t display_getsource(display_t display);
  137. /* ------------------------------------------------------------------------- */
  138. /* Sources */
  139. /**
  140. * Creates a source of the specified type with the specified settings.
  141. *
  142. * The "source" context is used for anything related to presenting
  143. * or modifying video/audio.
  144. */
  145. EXPORT source_t source_create(obs_t obs, enum source_type type,
  146. const char *name, const char *settings);
  147. EXPORT void source_destroy(source_t source);
  148. /**
  149. * Retrieves flags that specify what type of data the source presents/modifies.
  150. *
  151. * SOURCE_VIDEO if it presents/modifies video_frame
  152. * SOURCE_ASYNC if the video is asynchronous.
  153. * SOURCE_AUDIO if it presents/modifies audio (always async)
  154. */
  155. EXPORT uint32_t source_get_output_flags(source_t source);
  156. /** Specifies whether the source can be configured */
  157. EXPORT bool source_hasconfig(source_t source);
  158. /** Opens a configuration panel and attaches it to the parent window */
  159. EXPORT void source_config(source_t source, void *parent);
  160. /** Renders a video source. */
  161. EXPORT void source_video_render(source_t source);
  162. /** Gets the width of a source (if it has video) */
  163. EXPORT int source_getwidth(source_t source);
  164. /** Gets the height of a source (if it has video) */
  165. EXPORT int source_getheight(source_t source);
  166. /**
  167. * Gets a custom parameter from the source.
  168. *
  169. * Used for efficiently modifying source properties in real time.
  170. */
  171. EXPORT size_t source_getparam(source_t source, const char *param, void *buf,
  172. size_t buf_size);
  173. /**
  174. * Sets a custom parameter for the source.
  175. *
  176. * Used for efficiently modifying source properties in real time.
  177. */
  178. EXPORT void source_setparam(source_t source, const char *param,
  179. const void *data, size_t size);
  180. /**
  181. * Enumerates child sources this source has
  182. */
  183. EXPORT bool source_enum_children(source_t source, size_t idx,
  184. source_t *child);
  185. /** If the source is a filter, returns the target source of the filter */
  186. EXPORT source_t filter_gettarget(source_t filter);
  187. /** Adds a filter to the source (which is used whenever the source is used) */
  188. EXPORT void source_filter_add(source_t source, source_t filter);
  189. /** Removes a filter from the source */
  190. EXPORT void source_filter_remove(source_t source, source_t filter);
  191. /** Modifies the order of a specific filter */
  192. EXPORT void source_filter_setorder(source_t source, source_t filter,
  193. enum order_movement movement);
  194. /** Gets the settings string for a source */
  195. EXPORT const char *source_get_settings(source_t source);
  196. /* ------------------------------------------------------------------------- */
  197. /* Functions used by sources */
  198. /** Saves the settings string for a source */
  199. EXPORT void source_save_settings(source_t source, const char *settings);
  200. /** Outputs asynchronous video data */
  201. EXPORT void source_output_video(source_t source, struct video_frame *frame);
  202. /** Outputs audio data (always asynchronous) */
  203. EXPORT void source_output_audio(source_t source, struct audio_data *audio);
  204. /* ------------------------------------------------------------------------- */
  205. /* Scenes */
  206. /**
  207. * Creates a scene.
  208. *
  209. * A scene is a source which is a container of other sources with specific
  210. * display oriantations. Scenes can also be used like any other source.
  211. */
  212. EXPORT scene_t scene_create(obs_t obs);
  213. EXPORT void scene_destroy(scene_t scene);
  214. /** Gets the scene's source context */
  215. EXPORT source_t scene_source(scene_t scene);
  216. /** Adds/creates a new scene item for a source */
  217. EXPORT sceneitem_t scene_add(scene_t scene, source_t source);
  218. /** Removes/destroys a scene item */
  219. EXPORT void sceneitem_destroy(sceneitem_t item);
  220. /* Functions for gettings/setting specific oriantation of a scene item */
  221. EXPORT void sceneitem_setpos(sceneitem_t item, const struct vec2 *pos);
  222. EXPORT void sceneitem_setrot(sceneitem_t item, float rot);
  223. EXPORT void sceneitem_setorigin(sceneitem_t item, const struct vec2 *origin);
  224. EXPORT void sceneitem_setscale(sceneitem_t item, const struct vec2 *scale);
  225. EXPORT void sceneitem_setorder(sceneitem_t item, enum order_movement movement);
  226. EXPORT void sceneitem_getpos(sceneitem_t item, struct vec2 *pos);
  227. EXPORT float sceneitem_getrot(sceneitem_t item);
  228. EXPORT void sceneitem_getorigin(sceneitem_t item, struct vec2 *center);
  229. EXPORT void sceneitem_getscale(sceneitem_t item, struct vec2 *scale);
  230. /* ------------------------------------------------------------------------- */
  231. /* Outputs */
  232. /**
  233. * Creates an output.
  234. *
  235. * Outputs allow outputting to file, outputting to network, outputting to
  236. * directshow, or other custom outputs.
  237. */
  238. EXPORT output_t output_create(obs_t obs, const char *name,
  239. const char *settings);
  240. EXPORT void output_destroy(output_t output);
  241. /** Starts the output. */
  242. EXPORT void output_start(output_t output);
  243. /** Stops the output. */
  244. EXPORT void output_stop(output_t output);
  245. /** Specifies whether the output can be configured */
  246. EXPORT bool output_canconfig(output_t output);
  247. /** Opens a configuration panel with the specified parent window */
  248. EXPORT void output_config(output_t output, void *parent);
  249. /** Specifies whether the output can be paused */
  250. EXPORT bool output_canpause(output_t output);
  251. /** Pauses the output (if the functionality is allowed by the output */
  252. EXPORT void output_pause(output_t output);
  253. /* Gets the current output settings string */
  254. EXPORT const char *output_get_settings(output_t output);
  255. /* Saves the output settings string, typically used only by outputs */
  256. EXPORT void output_save_settings(output_t output, const char *settings);
  257. #ifdef __cplusplus
  258. }
  259. #endif