obs.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 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 "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. /* LIBOBS_API_VER must be returned by module_version in each module */
  27. #define LIBOBS_API_MAJOR_VER 0 /* increment if major breaking changes */
  28. #define LIBOBS_API_MINOR_VER 1 /* increment if minor non-breaking additions */
  29. #define LIBOBS_API_VER ((LIBOBS_API_MAJOR_VER << 16) | \
  30. LIBOBS_API_MINOR_VER)
  31. enum obs_source_type {
  32. SOURCE_INPUT,
  33. SOURCE_FILTER,
  34. SOURCE_TRANSITION,
  35. SOURCE_SCENE
  36. };
  37. enum obs_video_type {
  38. OBS_VIDEO_YUV,
  39. OBS_VIDEO_RGB
  40. };
  41. /* used for changing the order of items (for example, filters in a source,
  42. * or items in a scene) */
  43. enum order_movement {
  44. ORDER_MOVE_UP,
  45. ORDER_MOVE_DOWN,
  46. ORDER_MOVE_TOP,
  47. ORDER_MOVE_BOTTOM
  48. };
  49. enum allow_direct_render {
  50. NO_DIRECT_RENDERING,
  51. ALLOW_DIRECT_RENDERING,
  52. };
  53. struct obs_video_info {
  54. /* graphics module to use (usually "libobs-opengl" or "libobs-d3d11") */
  55. const char *graphics_module;
  56. /* output fps numerator and denominator */
  57. uint32_t fps_num;
  58. uint32_t fps_den;
  59. /* window dimensions for what's drawn on screen */
  60. uint32_t window_width;
  61. uint32_t window_height;
  62. /* base compositing dimensions */
  63. uint32_t base_width;
  64. uint32_t base_height;
  65. /* output dimensions and format */
  66. uint32_t output_width;
  67. uint32_t output_height;
  68. enum video_format output_format;
  69. /* video adapter ID to use (NOTE: do not use for optimus laptops) */
  70. uint32_t adapter;
  71. /* window to render */
  72. struct gs_window window;
  73. };
  74. struct filtered_audio {
  75. void *data;
  76. uint32_t frames;
  77. uint64_t timestamp;
  78. };
  79. struct source_audio {
  80. const void *data;
  81. uint32_t frames;
  82. /* audio will be automatically resampled/upmixed/downmixed */
  83. enum speaker_layout speakers;
  84. enum audio_format format;
  85. uint32_t samples_per_sec;
  86. /* can be 0 if 'immediate' */
  87. uint64_t timestamp;
  88. };
  89. struct source_frame {
  90. void *data;
  91. uint32_t width;
  92. uint32_t height;
  93. uint32_t row_bytes;
  94. uint64_t timestamp;
  95. enum video_format format;
  96. float yuv_matrix[16];
  97. bool flip;
  98. };
  99. static inline void source_frame_destroy(struct source_frame *frame)
  100. {
  101. if (frame) {
  102. bfree(frame->data);
  103. bfree(frame);
  104. }
  105. }
  106. /* opaque types */
  107. struct obs_display;
  108. struct obs_source;
  109. struct obs_scene;
  110. struct obs_scene_item;
  111. struct obs_output;
  112. struct obs_service;
  113. typedef struct obs_display *obs_display_t;
  114. typedef struct obs_source *obs_source_t;
  115. typedef struct obs_scene *obs_scene_t;
  116. typedef struct obs_scene_item *obs_sceneitem_t;
  117. typedef struct obs_output *obs_output_t;
  118. typedef struct obs_service *obs_service_t;
  119. /* ------------------------------------------------------------------------- */
  120. /* OBS context */
  121. /**
  122. * Starts up and shuts down OBS
  123. *
  124. * Creates the OBS context.
  125. */
  126. EXPORT bool obs_startup(void);
  127. EXPORT void obs_shutdown(void);
  128. /**
  129. * Sets base video ouput base resolution/fps/format
  130. *
  131. * NOTE: Cannot set base video if currently streaming/recording.
  132. */
  133. EXPORT bool obs_reset_video(struct obs_video_info *ovi);
  134. /**
  135. * Sets base audio output format/channels/samples/etc
  136. *
  137. * NOTE: Cannot reset base audio if currently streaming/recording.
  138. */
  139. EXPORT bool obs_reset_audio(struct audio_info *ai);
  140. /** Gets the current video settings, returns false if none */
  141. EXPORT bool obs_get_video_info(struct obs_video_info *ovi);
  142. /** Gets the current audio settings, returns false if none */
  143. EXPORT bool obs_get_audio_info(struct audio_info *ai);
  144. /**
  145. * Loads a plugin module
  146. *
  147. * A plugin module contains exports for inputs/fitlers/transitions/outputs.
  148. * See obs-source.h and obs-output.h for more information on the exports to
  149. * use.
  150. */
  151. EXPORT int obs_load_module(const char *path);
  152. /**
  153. * Enumerates all available inputs source types.
  154. *
  155. * Inputs are general source inputs (such as capture sources, device sources,
  156. * etc).
  157. */
  158. EXPORT bool obs_enum_input_types(size_t idx, const char **id);
  159. /**
  160. * Enumerates all available filter source types.
  161. *
  162. * Filters are sources that are used to modify the video/audio output of
  163. * other sources.
  164. */
  165. EXPORT bool obs_enum_filter_types(size_t idx, const char **id);
  166. /**
  167. * Enumerates all available transition source types.
  168. *
  169. * Transitions are sources used to transition between two or more other
  170. * sources.
  171. */
  172. EXPORT bool obs_enum_transition_types(size_t idx, const char **id);
  173. /**
  174. * Enumerates all available ouput types.
  175. *
  176. * Outputs handle color space conversion, encoding, and output to file or
  177. * streams.
  178. */
  179. EXPORT bool obs_enum_output_types(size_t idx, const char **id);
  180. /** Gets the graphics context for this OBS context */
  181. EXPORT graphics_t obs_graphics(void);
  182. /** Get the media context for this OBS context (used for outputs) */
  183. EXPORT media_t obs_media(void);
  184. /**
  185. * Adds a source to the user source list and increments the reference counter
  186. * for that source.
  187. *
  188. * The user source list is the list of sources that are accessible by a user.
  189. * Typically when a transition is active, it is not meant to be accessible by
  190. * users, so there's no reason for a user to see such a source.
  191. */
  192. EXPORT bool obs_add_source(obs_source_t source);
  193. /** Sets the primary output source for a channel. */
  194. EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
  195. /**
  196. * Gets the primary output source for a channel and increments the reference
  197. * counter for that source. Use obs_source_release to release.
  198. */
  199. EXPORT obs_source_t obs_get_output_source(uint32_t channel);
  200. /**
  201. * Enumerates user sources
  202. *
  203. * Callback function returns true to continue enumeration, or false to end
  204. * enumeration.
  205. */
  206. EXPORT void obs_enum_sources(bool (*enum_proc)(obs_source_t, void*),
  207. void *param);
  208. /**
  209. * Gets a source by its name.
  210. *
  211. * Increments the source reference counter, use obs_source_release to
  212. * release it when complete.
  213. */
  214. EXPORT obs_source_t obs_get_source_by_name(const char *name);
  215. /**
  216. * Returns the location of a plugin data file.
  217. *
  218. * file: Name of file to locate. For example, "myplugin/mydata.data"
  219. * returns: Path string, or NULL if not found. Use bfree to free string.
  220. */
  221. EXPORT char *obs_find_plugin_file(const char *file);
  222. /** Returns the default effect for generic RGB/YUV drawing */
  223. EXPORT effect_t obs_get_default_effect();
  224. /* ------------------------------------------------------------------------- */
  225. /* Display context */
  226. /**
  227. * Creates an extra display context.
  228. *
  229. * An extra display can be used for things like separate previews,
  230. * viewing sources independently, and other things. Creates a new swap chain
  231. * linked to a specific window to display a source.
  232. */
  233. EXPORT obs_display_t obs_display_create(struct gs_init_data *graphics_data);
  234. EXPORT void obs_display_destroy(obs_display_t display);
  235. /** Sets the source to be used for a display context. */
  236. EXPORT void obs_display_setsource(obs_display_t display, uint32_t channel,
  237. obs_source_t source);
  238. EXPORT obs_source_t obs_display_getsource(obs_display_t display,
  239. uint32_t channel);
  240. /* ------------------------------------------------------------------------- */
  241. /* Sources */
  242. /**
  243. * Gets the translated display name of a source
  244. */
  245. EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
  246. const char *id, const char *locale);
  247. /**
  248. * Creates a source of the specified type with the specified settings.
  249. *
  250. * The "source" context is used for anything related to presenting
  251. * or modifying video/audio. Use obs_source_release to release it.
  252. */
  253. EXPORT obs_source_t obs_source_create(enum obs_source_type type,
  254. const char *id, const char *name, const char *settings);
  255. /**
  256. * Adds/releases a reference to a source. When the last reference is
  257. * released, the source is destroyed.
  258. */
  259. EXPORT int obs_source_addref(obs_source_t source);
  260. EXPORT int obs_source_release(obs_source_t source);
  261. /** Notifies all references that the source should be released */
  262. EXPORT void obs_source_remove(obs_source_t source);
  263. /** Returns true if the source should be released */
  264. EXPORT bool obs_source_removed(obs_source_t source);
  265. /**
  266. * Retrieves flags that specify what type of data the source presents/modifies.
  267. *
  268. * SOURCE_VIDEO if it presents/modifies video_frame
  269. * SOURCE_ASYNC if the video is asynchronous.
  270. * SOURCE_AUDIO if it presents/modifies audio (always async)
  271. */
  272. EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
  273. /** Specifies whether the source can be configured */
  274. EXPORT bool obs_source_hasconfig(obs_source_t source);
  275. /** Opens a configuration panel and attaches it to the parent window */
  276. EXPORT void obs_source_config(obs_source_t source, void *parent);
  277. /** Renders a video source. */
  278. EXPORT void obs_source_video_render(obs_source_t source);
  279. /** Gets the width of a source (if it has video) */
  280. EXPORT uint32_t obs_source_getwidth(obs_source_t source);
  281. /** Gets the height of a source (if it has video) */
  282. EXPORT uint32_t obs_source_getheight(obs_source_t source);
  283. /**
  284. * Gets a custom parameter from the source.
  285. *
  286. * Used for efficiently modifying source properties in real time.
  287. */
  288. EXPORT size_t obs_source_getparam(obs_source_t source, const char *param,
  289. void *buf, size_t buf_size);
  290. /**
  291. * Sets a custom parameter for the source.
  292. *
  293. * Used for efficiently modifying source properties in real time.
  294. */
  295. EXPORT void obs_source_setparam(obs_source_t source, const char *param,
  296. const void *data, size_t size);
  297. /** If the source is a filter, returns the parent source of the filter */
  298. EXPORT obs_source_t obs_filter_getparent(obs_source_t filter);
  299. /** If the source is a filter, returns the target source of the filter */
  300. EXPORT obs_source_t obs_filter_gettarget(obs_source_t filter);
  301. /** Adds a filter to the source (which is used whenever the source is used) */
  302. EXPORT void obs_source_filter_add(obs_source_t source, obs_source_t filter);
  303. /** Removes a filter from the source */
  304. EXPORT void obs_source_filter_remove(obs_source_t source, obs_source_t filter);
  305. /** Modifies the order of a specific filter */
  306. EXPORT void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
  307. enum order_movement movement);
  308. /** Gets the settings string for a source */
  309. EXPORT const char *obs_source_getsettings(obs_source_t source);
  310. /** Gets the name of a source */
  311. EXPORT const char *obs_source_getname(obs_source_t source);
  312. /** Sets the name of a source */
  313. EXPORT void obs_source_setname(obs_source_t source, const char *name);
  314. /** Gets the source type and identifier */
  315. EXPORT void obs_source_getid(obs_source_t source, enum obs_source_type *type,
  316. const char **id);
  317. /* ------------------------------------------------------------------------- */
  318. /* Functions used by sources */
  319. /** Saves the settings string for a source */
  320. EXPORT void obs_source_savesettings(obs_source_t source, const char *settings);
  321. /** Outputs asynchronous video data */
  322. EXPORT void obs_source_output_video(obs_source_t source,
  323. const struct source_frame *frame);
  324. /** Outputs audio data (always asynchronous) */
  325. EXPORT void obs_source_output_audio(obs_source_t source,
  326. const struct source_audio *audio);
  327. /** Gets the current async video frame */
  328. EXPORT struct source_frame *obs_source_getframe(obs_source_t source);
  329. /** Releases the current async video frame */
  330. EXPORT void obs_source_releaseframe(obs_source_t source,
  331. struct source_frame *frame);
  332. /** Default RGB filter handler for generic effect filters */
  333. EXPORT void obs_source_process_filter(obs_source_t filter,
  334. texrender_t texrender, effect_t effect,
  335. uint32_t width, uint32_t height,
  336. enum allow_direct_render allow_direct);
  337. /* ------------------------------------------------------------------------- */
  338. /* Scenes */
  339. /**
  340. * Creates a scene.
  341. *
  342. * A scene is a source which is a container of other sources with specific
  343. * display oriantations. Scenes can also be used like any other source.
  344. */
  345. EXPORT obs_scene_t obs_scene_create(void);
  346. EXPORT void obs_scene_destroy(obs_scene_t scene);
  347. /** Gets the scene's source context */
  348. EXPORT obs_source_t obs_scene_getsource(obs_scene_t scene);
  349. /** Adds/creates a new scene item for a source */
  350. EXPORT obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source);
  351. /** Removes/destroys a scene item */
  352. EXPORT void obs_sceneitem_destroy(obs_sceneitem_t item);
  353. /* Functions for gettings/setting specific oriantation of a scene item */
  354. EXPORT void obs_sceneitem_setpos(obs_sceneitem_t item, const struct vec2 *pos);
  355. EXPORT void obs_sceneitem_setrot(obs_sceneitem_t item, float rot);
  356. EXPORT void obs_sceneitem_setorigin(obs_sceneitem_t item,
  357. const struct vec2 *origin);
  358. EXPORT void obs_sceneitem_setscale(obs_sceneitem_t item,
  359. const struct vec2 *scale);
  360. EXPORT void obs_sceneitem_setorder(obs_sceneitem_t item,
  361. enum order_movement movement);
  362. EXPORT void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos);
  363. EXPORT float obs_sceneitem_getrot(obs_sceneitem_t item);
  364. EXPORT void obs_sceneitem_getorigin(obs_sceneitem_t item, struct vec2 *center);
  365. EXPORT void obs_sceneitem_getscale(obs_sceneitem_t item, struct vec2 *scale);
  366. /* ------------------------------------------------------------------------- */
  367. /* Outputs */
  368. /**
  369. * Creates an output.
  370. *
  371. * Outputs allow outputting to file, outputting to network, outputting to
  372. * directshow, or other custom outputs.
  373. */
  374. EXPORT obs_output_t obs_output_create(const char *name, const char *settings);
  375. EXPORT void obs_output_destroy(obs_output_t output);
  376. /** Starts the output. */
  377. EXPORT void obs_output_start(obs_output_t output);
  378. /** Stops the output. */
  379. EXPORT void obs_output_stop(obs_output_t output);
  380. /** Specifies whether the output can be configured */
  381. EXPORT bool obs_output_canconfig(obs_output_t output);
  382. /** Opens a configuration panel with the specified parent window */
  383. EXPORT void obs_output_config(obs_output_t output, void *parent);
  384. /** Specifies whether the output can be paused */
  385. EXPORT bool obs_output_canpause(obs_output_t output);
  386. /** Pauses the output (if the functionality is allowed by the output */
  387. EXPORT void obs_output_pause(obs_output_t output);
  388. /* Gets the current output settings string */
  389. EXPORT const char *obs_output_get_settings(obs_output_t output);
  390. /* Saves the output settings string, typically used only by outputs */
  391. EXPORT void obs_output_save_settings(obs_output_t output,
  392. const char *settings);
  393. /* ------------------------------------------------------------------------- */
  394. /* Stream Services */
  395. EXPORT obs_service_t obs_service_create(const char *service,
  396. const char *settings);
  397. EXPORT void obs_service_destroy(obs_service_t service);
  398. EXPORT void obs_service_setdata(obs_service_t service,const char *attribute,
  399. const char *data);
  400. EXPORT const char *obs_service_getdata(obs_service_t service,
  401. const char *attribute);
  402. #ifdef __cplusplus
  403. }
  404. #endif