reference-core.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. OBS Core API Reference
  2. ======================
  3. .. code:: cpp
  4. #include <obs.h>
  5. .. _obs_init_shutdown_reference:
  6. Initialization, Shutdown, and Information
  7. -----------------------------------------
  8. .. function:: bool obs_startup(const char *locale, const char *module_config_path, profiler_name_store_t *store)
  9. Initializes the OBS core context.
  10. :param locale: The locale to use for modules
  11. (E.G. "en-US")
  12. :param module_config_path: Path to module config storage directory
  13. (or *NULL* if none)
  14. :param store: The profiler name store for OBS to use or NULL
  15. :return: *false* if already initialized or failed
  16. to initialize
  17. ---------------------
  18. .. function:: void obs_shutdown(void)
  19. Releases all data associated with OBS and terminates the OBS context.
  20. ---------------------
  21. .. function:: bool obs_initialized(void)
  22. :return: true if the main OBS context has been initialized
  23. ---------------------
  24. .. function:: uint32_t obs_get_version(void)
  25. :return: The current core version
  26. ---------------------
  27. .. function:: const char *obs_get_version_string(void)
  28. :return: The current core version string
  29. ---------------------
  30. .. function:: void obs_set_locale(const char *locale)
  31. Sets a new locale to use for modules. This will call
  32. obs_module_set_locale for each module with the new locale.
  33. :param locale: The locale to use for modules
  34. ---------------------
  35. .. function:: const char *obs_get_locale(void)
  36. :return: The current locale
  37. ---------------------
  38. .. function:: profiler_name_store_t *obs_get_profiler_name_store(void)
  39. :return: The profiler name store (see util/profiler.h) used by OBS,
  40. which is either a name store passed to obs_startup, an
  41. internal name store, or NULL in case obs_initialized()
  42. returns false.
  43. ---------------------
  44. .. function:: int obs_reset_video(struct obs_video_info *ovi)
  45. Sets base video output base resolution/fps/format.
  46. Note: This data cannot be changed if an output is currently active.
  47. Note: The graphics module cannot be changed without fully destroying
  48. the OBS context.
  49. :param ovi: Pointer to an obs_video_info structure containing the
  50. specification of the graphics subsystem,
  51. :return: | OBS_VIDEO_SUCCESS - Success
  52. | OBS_VIDEO_NOT_SUPPORTED - The adapter lacks capabilities
  53. | OBS_VIDEO_INVALID_PARAM - A parameter is invalid
  54. | OBS_VIDEO_CURRENTLY_ACTIVE - Video is currently active
  55. | OBS_VIDEO_MODULE_NOT_FOUND - The graphics module is not found
  56. | OBS_VIDEO_FAIL - Generic failure
  57. Relevant data types used with this function:
  58. .. code:: cpp
  59. struct obs_video_info {
  60. /**
  61. * Graphics module to use (usually "libobs-opengl" or "libobs-d3d11")
  62. */
  63. const char *graphics_module;
  64. uint32_t fps_num; /**< Output FPS numerator */
  65. uint32_t fps_den; /**< Output FPS denominator */
  66. uint32_t base_width; /**< Base compositing width */
  67. uint32_t base_height; /**< Base compositing height */
  68. uint32_t output_width; /**< Output width */
  69. uint32_t output_height; /**< Output height */
  70. enum video_format output_format; /**< Output format */
  71. /** Video adapter index to use (NOTE: avoid for optimus laptops) */
  72. uint32_t adapter;
  73. /** Use shaders to convert to different color formats */
  74. bool gpu_conversion;
  75. enum video_colorspace colorspace; /**< YUV type (if YUV) */
  76. enum video_range_type range; /**< YUV range (if YUV) */
  77. enum obs_scale_type scale_type; /**< How to scale if scaling */
  78. };
  79. ---------------------
  80. .. function:: bool obs_reset_audio(const struct obs_audio_info *oai)
  81. Sets base audio output format/channels/samples/etc.
  82. Note: Cannot reset base audio if an output is currently active.
  83. :return: *true* if successful, *false* otherwise
  84. Relevant data types used with this function:
  85. .. code:: cpp
  86. struct obs_audio_info {
  87. uint32_t samples_per_sec;
  88. enum speaker_layout speakers;
  89. };
  90. ---------------------
  91. .. function:: bool obs_get_video_info(struct obs_video_info *ovi)
  92. Gets the current video settings.
  93. :return: *false* if no video
  94. ---------------------
  95. .. function:: bool obs_get_audio_info(struct obs_audio_info *oai)
  96. Gets the current audio settings.
  97. :return: *false* if no audio
  98. ---------------------
  99. Libobs Objects
  100. --------------
  101. .. function:: bool obs_enum_source_types(size_t idx, const char **id)
  102. Enumerates all source types (inputs, filters, transitions, etc).
  103. ---------------------
  104. .. function:: bool obs_enum_input_types(size_t idx, const char **id)
  105. Enumerates all available inputs source types.
  106. Inputs are general source inputs (such as capture sources, device sources,
  107. etc).
  108. ---------------------
  109. .. function:: bool obs_enum_filter_types(size_t idx, const char **id)
  110. Enumerates all available filter source types.
  111. Filters are sources that are used to modify the video/audio output of
  112. other sources.
  113. ---------------------
  114. .. function:: bool obs_enum_transition_types(size_t idx, const char **id)
  115. Enumerates all available transition source types.
  116. Transitions are sources used to transition between two or more other
  117. sources.
  118. ---------------------
  119. .. function:: bool obs_enum_output_types(size_t idx, const char **id)
  120. Enumerates all available output types.
  121. ---------------------
  122. .. function:: bool obs_enum_encoder_types(size_t idx, const char **id)
  123. Enumerates all available encoder types.
  124. ---------------------
  125. .. function:: bool obs_enum_service_types(size_t idx, const char **id)
  126. Enumerates all available service types.
  127. ---------------------
  128. .. function:: void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t*), void *param)
  129. Enumerates all input sources.
  130. Callback function returns true to continue enumeration, or false to end
  131. enumeration.
  132. Use :c:func:`obs_source_get_ref()` or
  133. :c:func:`obs_source_get_weak_source()` if you want to retain a
  134. reference after obs_enum_sources finishes.
  135. ---------------------
  136. .. function:: void obs_enum_scenes(bool (*enum_proc)(void*, obs_source_t*), void *param)
  137. Enumerates all scenes.
  138. Callback function returns true to continue enumeration, or false to end
  139. enumeration.
  140. Use :c:func:`obs_source_get_ref()` or
  141. :c:func:`obs_source_get_weak_source()` if you want to retain a
  142. reference after obs_enum_scenes finishes.
  143. ---------------------
  144. .. function:: void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t*), void *param)
  145. Enumerates outputs.
  146. ---------------------
  147. .. function:: void obs_enum_encoders(bool (*enum_proc)(void*, obs_encoder_t*), void *param)
  148. Enumerates encoders.
  149. ---------------------
  150. .. function:: obs_source_t *obs_get_source_by_name(const char *name)
  151. Gets a source by its name.
  152. Increments the source reference counter, use
  153. :c:func:`obs_source_release()` to release it when complete.
  154. ---------------------
  155. .. function:: obs_source_t *obs_get_transition_by_name(const char *name)
  156. Gets a transition by its name.
  157. Increments the source reference counter, use
  158. :c:func:`obs_source_release()` to release it when complete.
  159. ---------------------
  160. .. function:: obs_output_t *obs_get_output_by_name(const char *name)
  161. Gets an output by its name.
  162. Increments the output reference counter, use
  163. :c:func:`obs_output_release()` to release it when complete.
  164. ---------------------
  165. .. function:: obs_encoder_t *obs_get_encoder_by_name(const char *name)
  166. Gets an encoder by its name.
  167. Increments the encoder reference counter, use
  168. :c:func:`obs_encoder_release()` to release it when complete.
  169. ---------------------
  170. .. function:: obs_service_t *obs_get_service_by_name(const char *name)
  171. Gets an service by its name.
  172. Increments the service reference counter, use
  173. :c:func:`obs_service_release()` to release it when complete.
  174. ---------------------
  175. .. function:: obs_data_t *obs_save_source(obs_source_t *source)
  176. :return: A new reference to a source's saved data
  177. ---------------------
  178. .. function:: obs_source_t *obs_load_source(obs_data_t *data)
  179. :return: A source created from saved data
  180. ---------------------
  181. .. function:: void obs_load_sources(obs_data_array_t *array, obs_load_source_cb cb, void *private_data)
  182. Helper function to load active sources from a data array.
  183. Relevant data types used with this function:
  184. .. code:: cpp
  185. typedef void (*obs_load_source_cb)(void *private_data, obs_source_t *source);
  186. ---------------------
  187. .. function:: obs_data_array_t *obs_save_sources(void)
  188. :return: A data array with the saved data of all active sources
  189. ---------------------
  190. .. function:: obs_data_array_t *obs_save_sources_filtered(obs_save_source_filter_cb cb, void *data)
  191. :return: A data array with the saved data of all active sources,
  192. filtered by the *cb* function
  193. Relevant data types used with this function:
  194. .. code:: cpp
  195. typedef bool (*obs_save_source_filter_cb)(void *data, obs_source_t *source);
  196. ---------------------
  197. Video, Audio, and Graphics
  198. --------------------------
  199. .. function:: void obs_enter_graphics(void)
  200. Helper function for entering the OBS graphics context.
  201. ---------------------
  202. .. function:: void obs_leave_graphics(void)
  203. Helper function for leaving the OBS graphics context.
  204. ---------------------
  205. .. function:: audio_t *obs_get_audio(void)
  206. :return: The main audio output handler for this OBS context
  207. ---------------------
  208. .. function:: video_t *obs_get_video(void)
  209. :return: The main video output handler for this OBS context
  210. ---------------------
  211. .. function:: void obs_set_output_source(uint32_t channel, obs_source_t *source)
  212. Sets the primary output source for a channel.
  213. ---------------------
  214. .. function:: obs_source_t *obs_get_output_source(uint32_t channel)
  215. Gets the primary output source for a channel and increments the reference
  216. counter for that source. Use :c:func:`obs_source_release()` to release.
  217. ---------------------
  218. .. function:: gs_effect_t *obs_get_base_effect(enum obs_base_effect effect)
  219. Returns a commoinly used base effect.
  220. :param effect: | Can be one of the following values:
  221. | OBS_EFFECT_DEFAULT - RGB/YUV
  222. | OBS_EFFECT_DEFAULT_RECT - RGB/YUV (using texture_rect)
  223. | OBS_EFFECT_OPAQUE - RGB/YUV (alpha set to 1.0)
  224. | OBS_EFFECT_SOLID - RGB/YUV (solid color only)
  225. | OBS_EFFECT_BICUBIC - Bicubic downscale
  226. | OBS_EFFECT_LANCZOS - Lanczos downscale
  227. | OBS_EFFECT_BILINEAR_LOWRES - Bilinear low resolution downscale
  228. | OBS_EFFECT_PREMULTIPLIED_ALPHA - Premultiplied alpha
  229. ---------------------
  230. .. function:: void obs_render_main_view(void)
  231. Renders the main view.
  232. Note: This function is deprecated.
  233. ---------------------
  234. .. function:: void obs_render_main_texture(void)
  235. Renders the main output texture. Useful for rendering a preview pane
  236. of the main output.
  237. ---------------------
  238. .. function:: void obs_set_master_volume(float volume)
  239. Sets the master user volume.
  240. ---------------------
  241. .. function:: float obs_get_master_volume(void)
  242. :return: The master user volume
  243. ---------------------
  244. .. function:: bool obs_audio_monitoring_supported(void)
  245. :return: Whether audio monitoring is supported on the current platform
  246. ---------------------
  247. .. function:: void obs_enum_audio_monitoring_devices(obs_enum_audio_device_cb cb, void *data)
  248. Enumerates audio devices which can be used for audio monitoring.
  249. Relevant data types used with this function:
  250. .. code:: cpp
  251. typedef bool (*obs_enum_audio_device_cb)(void *data, const char *name, const char *id);
  252. ---------------------
  253. .. function:: bool obs_set_audio_monitoring_device(const char *name, const char *id)
  254. Sets the current audio device for audio monitoring.
  255. ---------------------
  256. .. function:: void obs_get_audio_monitoring_device(const char **name, const char **id)
  257. Gets the current audio device for audio monitoring.
  258. ---------------------
  259. .. function:: void obs_add_main_render_callback(void (*draw)(void *param, uint32_t cx, uint32_t cy), void *param)
  260. void obs_remove_main_render_callback(void (*draw)(void *param, uint32_t cx, uint32_t cy), void *param)
  261. Adds/removes a main rendering callback. Allows custom rendering to
  262. the main stream/recording output.
  263. ---------------------
  264. .. function:: void obs_add_raw_video_callback(const struct video_scale_info *conversion, void (*callback)(void *param, struct video_data *frame), void *param)
  265. void obs_remove_raw_video_callback(void (*callback)(void *param, struct video_data *frame), void *param)
  266. Adds/removes a raw video callback. Allows the ability to obtain raw
  267. video frames without necessarily using an output.
  268. :param conversion: Specifies conversion requirements. Can be NULL.
  269. :param callback: The callback that receives raw video frames.
  270. :param param: The private data associated with the callback.
  271. Primary signal/procedure handlers
  272. ---------------------------------
  273. .. function:: signal_handler_t *obs_get_signal_handler(void)
  274. :return: The primary obs signal handler
  275. See :ref:`core_signal_handler_reference` for more information on
  276. core signals.
  277. ---------------------
  278. .. function:: proc_handler_t *obs_get_proc_handler(void)
  279. :return: The primary obs procedure handler
  280. .. _core_signal_handler_reference:
  281. Core OBS Signals
  282. ----------------
  283. **source_create** (ptr source)
  284. Called when a source has been created.
  285. **source_destroy** (ptr source)
  286. Called when a source has been destroyed.
  287. **source_remove** (ptr source)
  288. Called when a source has been removed (:c:func:`obs_source_remove()`
  289. has been called on the source).
  290. **source_save** (ptr source)
  291. Called when a source is being saved.
  292. **source_load** (ptr source)
  293. Called when a source is being loaded.
  294. **source_activate** (ptr source)
  295. Called when a source has been activated in the main view (visible on
  296. stream/recording).
  297. **source_deactivate** (ptr source)
  298. Called when a source has been deactivated from the main view (no
  299. longer visible on stream/recording).
  300. **source_show** (ptr source)
  301. Called when a source is visible on any display and/or on the main
  302. view.
  303. **source_hide** (ptr source)
  304. Called when a source is no longer visible on any display and/or on
  305. the main view.
  306. **source_rename** (ptr source, string new_name, string prev_name)
  307. Called when a source has been renamed.
  308. **source_volume** (ptr source, in out float volume)
  309. Called when a source's volume has changed.
  310. **source_transition_start** (ptr source)
  311. Called when a transition has started its transition.
  312. **source_transition_video_stop** (ptr source)
  313. Called when a transition has stopped its video transitioning.
  314. **source_transition_stop** (ptr source)
  315. Called when a transition has stopped its transition.
  316. **channel_change** (int channel, in out ptr source, ptr prev_source)
  317. Called when :c:func:`obs_set_output_source()` has been called.
  318. **master_volume** (in out float volume)
  319. Called when the master volume has changed.
  320. **hotkey_layout_change** ()
  321. Called when the hotkey layout has changed.
  322. **hotkey_register** (ptr hotkey)
  323. Called when a hotkey has been registered.
  324. **hotkey_unregister** (ptr hotkey)
  325. Called when a hotkey has been unregistered.
  326. **hotkey_bindings_changed** (ptr hotkey)
  327. Called when a hotkey's bindings has changed.
  328. ---------------------
  329. .. _display_reference:
  330. Displays
  331. --------
  332. .. function:: obs_display_t *obs_display_create(const struct gs_init_data *graphics_data)
  333. Adds a new window display linked to the main render pipeline. This creates
  334. a new swap chain which updates every frame.
  335. *(Important note: do not use more than one display widget within the
  336. hierarchy of the same base window; this will cause presentation
  337. stalls on Macs.)*
  338. :param graphics_data: The swap chain initialization data
  339. :return: The new display context, or NULL if failed
  340. Relevant data types used with this function:
  341. .. code:: cpp
  342. enum gs_color_format {
  343. [...]
  344. GS_RGBA,
  345. GS_BGRX,
  346. GS_BGRA,
  347. GS_RGBA16F,
  348. GS_RGBA32F,
  349. [...]
  350. };
  351. enum gs_zstencil_format {
  352. GS_ZS_NONE,
  353. GS_Z16,
  354. GS_Z24_S8,
  355. GS_Z32F,
  356. GS_Z32F_S8X24
  357. };
  358. struct gs_window {
  359. #if defined(_WIN32)
  360. void *hwnd;
  361. #elif defined(__APPLE__)
  362. __unsafe_unretained id view;
  363. #elif defined(__linux__) || defined(__FreeBSD__)
  364. uint32_t id;
  365. void *display;
  366. #endif
  367. };
  368. struct gs_init_data {
  369. struct gs_window window;
  370. uint32_t cx, cy;
  371. uint32_t num_backbuffers;
  372. enum gs_color_format format;
  373. enum gs_zstencil_format zsformat;
  374. uint32_t adapter;
  375. };
  376. ---------------------
  377. .. function:: void obs_display_destroy(obs_display_t *display)
  378. Destroys a display context.
  379. ---------------------
  380. .. function:: void obs_display_resize(obs_display_t *display, uint32_t cx, uint32_t cy)
  381. Changes the size of a display context.
  382. ---------------------
  383. .. function:: void obs_display_add_draw_callback(obs_display_t *display, void (*draw)(void *param, uint32_t cx, uint32_t cy), void *param)
  384. Adds a draw callback for a display context, which will be called
  385. whenever the display is rendered.
  386. :param display: The display context
  387. :param draw: The draw callback which is called each time a frame
  388. updates
  389. :param param: The user data to be associated with this draw callback
  390. ---------------------
  391. .. function:: void obs_display_remove_draw_callback(obs_display_t *display, void (*draw)(void *param, uint32_t cx, uint32_t cy), void *param)
  392. Removes a draw callback for a display context.
  393. ---------------------
  394. .. function:: void obs_display_set_enabled(obs_display_t *display, bool enable)
  395. Enables/disables a display context.
  396. ---------------------
  397. .. function:: bool obs_display_enabled(obs_display_t *display)
  398. :return: *true* if the display is enabled, *false* otherwise
  399. ---------------------
  400. .. function:: void obs_display_set_background_color(obs_display_t *display, uint32_t color)
  401. Sets the background (clear) color for the display context.