obs.h 10 KB

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