obs.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 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 "util/bmem.h"
  17. #include "util/text-lookup.h"
  18. #include "graphics/graphics.h"
  19. #include "graphics/vec2.h"
  20. #include "graphics/vec3.h"
  21. #include "media-io/audio-io.h"
  22. #include "media-io/video-io.h"
  23. #include "callback/signal.h"
  24. #include "callback/proc.h"
  25. #include "obs-config.h"
  26. #include "obs-defs.h"
  27. #include "obs-data.h"
  28. #include "obs-ui.h"
  29. #include "obs-properties.h"
  30. struct matrix4;
  31. /* opaque types */
  32. struct obs_display;
  33. struct obs_view;
  34. struct obs_source;
  35. struct obs_scene;
  36. struct obs_scene_item;
  37. struct obs_output;
  38. struct obs_encoder;
  39. struct obs_service;
  40. struct obs_module;
  41. typedef struct obs_display *obs_display_t;
  42. typedef struct obs_view *obs_view_t;
  43. typedef struct obs_source *obs_source_t;
  44. typedef struct obs_scene *obs_scene_t;
  45. typedef struct obs_scene_item *obs_sceneitem_t;
  46. typedef struct obs_output *obs_output_t;
  47. typedef struct obs_encoder *obs_encoder_t;
  48. typedef struct obs_service *obs_service_t;
  49. typedef struct obs_module *obs_module_t;
  50. #include "obs-source.h"
  51. #include "obs-encoder.h"
  52. #include "obs-output.h"
  53. #include "obs-service.h"
  54. /*
  55. * @file
  56. *
  57. * Main libobs header used by applications.
  58. */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. /** Used for changing the order of items (for example, filters in a source,
  63. * or items in a scene) */
  64. enum obs_order_movement {
  65. OBS_ORDER_MOVE_UP,
  66. OBS_ORDER_MOVE_DOWN,
  67. OBS_ORDER_MOVE_TOP,
  68. OBS_ORDER_MOVE_BOTTOM
  69. };
  70. /**
  71. * Used with obs_source_process_filter to specify whether the filter should
  72. * render the source directly with the specified effect, or whether it should
  73. * render it to a texture
  74. */
  75. enum obs_allow_direct_render {
  76. OBS_NO_DIRECT_RENDERING,
  77. OBS_ALLOW_DIRECT_RENDERING,
  78. };
  79. /**
  80. * Used with scene items to indicate the type of bounds to use for scene items.
  81. * Mostly determines how the image will be scaled within those bounds, or
  82. * whether to use bounds at all.
  83. */
  84. enum obs_bounds_type {
  85. OBS_BOUNDS_NONE, /**< no bounds */
  86. OBS_BOUNDS_STRETCH, /**< stretch (ignores base scale) */
  87. OBS_BOUNDS_SCALE_INNER, /**< scales to inner rectangle */
  88. OBS_BOUNDS_SCALE_OUTER, /**< scales to outer rectangle */
  89. OBS_BOUNDS_SCALE_TO_WIDTH, /**< scales to the width */
  90. OBS_BOUNDS_SCALE_TO_HEIGHT, /**< scales to the height */
  91. OBS_BOUNDS_MAX_ONLY, /**< no scaling, maximum size only */
  92. };
  93. struct obs_transform_info {
  94. struct vec2 pos;
  95. float rot;
  96. struct vec2 scale;
  97. uint32_t alignment;
  98. enum obs_bounds_type bounds_type;
  99. uint32_t bounds_alignment;
  100. struct vec2 bounds;
  101. };
  102. /**
  103. * Video initialization structure
  104. */
  105. struct obs_video_info {
  106. /**
  107. * Graphics module to use (usually "libobs-opengl" or "libobs-d3d11")
  108. */
  109. const char *graphics_module;
  110. uint32_t fps_num; /**< Output FPS numerator */
  111. uint32_t fps_den; /**< Output FPS denominator */
  112. uint32_t window_width; /**< Window width */
  113. uint32_t window_height; /**< Window height */
  114. uint32_t base_width; /**< Base compositing width */
  115. uint32_t base_height; /**< Base compositing height */
  116. uint32_t output_width; /**< Output width */
  117. uint32_t output_height; /**< Output height */
  118. enum video_format output_format; /**< Output format */
  119. /** Video adapter index to use (NOTE: avoid for optimus laptops) */
  120. uint32_t adapter;
  121. struct gs_window window; /**< Window to render to */
  122. /** Use shaders to convert to different color formats */
  123. bool gpu_conversion;
  124. };
  125. /**
  126. * Sent to source filters via the filter_audio callback to allow filtering of
  127. * audio data
  128. */
  129. struct filtered_audio {
  130. uint8_t *data[MAX_AV_PLANES];
  131. uint32_t frames;
  132. uint64_t timestamp;
  133. };
  134. /**
  135. * Source audio output structure. Used with obs_source_output_audio to output
  136. * source audio. Audio is automatically resampled and remixed as necessary.
  137. */
  138. struct source_audio {
  139. const uint8_t *data[MAX_AV_PLANES];
  140. uint32_t frames;
  141. enum speaker_layout speakers;
  142. enum audio_format format;
  143. uint32_t samples_per_sec;
  144. uint64_t timestamp;
  145. };
  146. /**
  147. * Source asynchronous video output structure. Used with
  148. * obs_source_output_video to output asynchronous video. Video is buffered as
  149. * necessary to play according to timestamps. When used with audio output,
  150. * audio is synced to video as it is played.
  151. *
  152. * If a YUV format is specified, it will be automatically upsampled and
  153. * converted to RGB via shader on the graphics processor.
  154. */
  155. struct obs_source_frame {
  156. uint8_t *data[MAX_AV_PLANES];
  157. uint32_t linesize[MAX_AV_PLANES];
  158. uint32_t width;
  159. uint32_t height;
  160. uint64_t timestamp;
  161. enum video_format format;
  162. float color_matrix[16];
  163. bool full_range;
  164. float color_range_min[3];
  165. float color_range_max[3];
  166. bool flip;
  167. };
  168. /* ------------------------------------------------------------------------- */
  169. /* OBS context */
  170. /**
  171. * Initializes OBS
  172. *
  173. * @param locale The locale to use for modules
  174. */
  175. EXPORT bool obs_startup(const char *locale);
  176. /** Releases all data associated with OBS and terminates the OBS context */
  177. EXPORT void obs_shutdown(void);
  178. /** @return true if the main OBS context has been initialized */
  179. EXPORT bool obs_initialized(void);
  180. /** @return The current core version */
  181. EXPORT uint32_t obs_get_version(void);
  182. /**
  183. * Sets a new locale to use for modules. This will call obs_module_set_locale
  184. * for each module with the new locale.
  185. *
  186. * @param locale The locale to use for modules
  187. */
  188. EXPORT void obs_set_locale(const char *locale);
  189. /** @return the current locale */
  190. EXPORT const char *obs_get_locale(void);
  191. /**
  192. * Sets base video ouput base resolution/fps/format.
  193. *
  194. * @note This data cannot be changed if an output is corrently active.
  195. * @note The graphics module cannot be changed without fully destroying the
  196. * OBS context.
  197. *
  198. * @param ovi Pointer to an obs_video_info structure containing the
  199. * specification of the graphics subsystem,
  200. * @return OBS_VIDEO_SUCCESS if sucessful
  201. * OBS_VIDEO_NOT_SUPPORTED if the adapter lacks capabilities
  202. * OBS_VIDEO_INVALID_PARAM if a parameter is invalid
  203. * OBS_VIDEO_CURRENTLY_ACTIVE if video is currently active
  204. * OBS_VIDEO_MODULE_NOT_FOUND if the graphics module is not found
  205. * OBS_VIDEO_FAIL for generic failure
  206. */
  207. EXPORT int obs_reset_video(struct obs_video_info *ovi);
  208. /**
  209. * Sets base audio output format/channels/samples/etc
  210. *
  211. * @note Cannot reset base audio if an output is currently active.
  212. */
  213. EXPORT bool obs_reset_audio(struct audio_output_info *ai);
  214. /** Gets the current video settings, returns false if no video */
  215. EXPORT bool obs_get_video_info(struct obs_video_info *ovi);
  216. /** Gets the current audio settings, returns false if no audio */
  217. EXPORT bool obs_get_audio_info(struct audio_output_info *ai);
  218. /**
  219. * Opens a plugin module directly from a specific path.
  220. *
  221. * If the module already exists then the function will return successful, and
  222. * the module parameter will be given the pointer to the existing module.
  223. *
  224. * This does not initialize the module, it only loads the module image. To
  225. * initialize the module, call obs_init_module.
  226. *
  227. * @param module The pointer to the created module.
  228. * @param path Specifies the path to the module library file. If the
  229. * extension is not specified, it will use the extension
  230. * appropriate to the operating system.
  231. * @param data_path Specifies the path to the directory where the module's
  232. * data files are stored.
  233. * @returns MODULE_SUCCESS if successful
  234. * MODULE_ERROR if a generic error occurred
  235. * MODULE_FILE_NOT_FOUND if the module was not found
  236. * MODULE_MISSING_EXPORTS if required exports are missing
  237. * MODULE_INCOMPATIBLE_VER if incompatible version
  238. */
  239. EXPORT int obs_open_module(obs_module_t *module, const char *path,
  240. const char *data_path);
  241. /**
  242. * Initializes the module, which calls its obs_module_load export. If the
  243. * module is alrady loaded, then this function does nothing and returns
  244. * successful.
  245. */
  246. EXPORT bool obs_init_module(obs_module_t module);
  247. /** Returns the module file name */
  248. EXPORT const char *obs_get_module_file_name(obs_module_t module);
  249. /** Returns the module full name */
  250. EXPORT const char *obs_get_module_name(obs_module_t module);
  251. /** Returns the module author(s) */
  252. EXPORT const char *obs_get_module_author(obs_module_t module);
  253. /** Returns the module description */
  254. EXPORT const char *obs_get_module_description(obs_module_t module);
  255. /**
  256. * Adds a module search path to be used with obs_find_modules. If the search
  257. * path strings contain %module%, that text will be replaced with the module
  258. * name when used.
  259. *
  260. * @param bin Specifies the module's binary directory search path.
  261. * @param data Specifies the module's data directory search path.
  262. */
  263. EXPORT void obs_add_module_path(const char *bin, const char *data);
  264. /** Automatically loads all modules from module paths (convenience function) */
  265. EXPORT void obs_load_all_modules(void);
  266. struct obs_module_info {
  267. const char *bin_path;
  268. const char *data_path;
  269. };
  270. typedef void (*obs_find_module_callback_t)(void *param,
  271. const struct obs_module_info *info);
  272. /** Finds all modules within the search paths added by obs_add_module_path. */
  273. EXPORT void obs_find_modules(obs_find_module_callback_t callback, void *param);
  274. typedef void (*obs_enum_module_callback_t)(void *param, obs_module_t module);
  275. /** Enumerates all loaded modules */
  276. EXPORT void obs_enum_modules(obs_enum_module_callback_t callback, void *param);
  277. /** Helper function for using default module locale */
  278. EXPORT lookup_t obs_module_load_locale(obs_module_t module,
  279. const char *default_locale, const char *locale);
  280. /**
  281. * Returns the location of a plugin module data file.
  282. *
  283. * @note Modules should use obs_module_file function defined in obs-module.h
  284. * as a more elegant means of getting their files without having to
  285. * specify the module parameter.
  286. *
  287. * @param module The module associated with the file to locate
  288. * @param file The file to locate
  289. * @return Path string, or NULL if not found. Use bfree to free string.
  290. */
  291. EXPORT char *obs_find_module_file(obs_module_t module, const char *file);
  292. /**
  293. * Enumerates all available inputs source types.
  294. *
  295. * Inputs are general source inputs (such as capture sources, device sources,
  296. * etc).
  297. */
  298. EXPORT bool obs_enum_input_types(size_t idx, const char **id);
  299. /**
  300. * Enumerates all available filter source types.
  301. *
  302. * Filters are sources that are used to modify the video/audio output of
  303. * other sources.
  304. */
  305. EXPORT bool obs_enum_filter_types(size_t idx, const char **id);
  306. /**
  307. * Enumerates all available transition source types.
  308. *
  309. * Transitions are sources used to transition between two or more other
  310. * sources.
  311. */
  312. EXPORT bool obs_enum_transition_types(size_t idx, const char **id);
  313. /** Enumerates all available output types. */
  314. EXPORT bool obs_enum_output_types(size_t idx, const char **id);
  315. /** Enumerates all available encoder types. */
  316. EXPORT bool obs_enum_encoder_types(size_t idx, const char **id);
  317. /** Enumerates all available service types. */
  318. EXPORT bool obs_enum_service_types(size_t idx, const char **id);
  319. /** Gets the main graphics context for this OBS context */
  320. EXPORT graphics_t obs_graphics(void);
  321. /** Gets the main audio output handler for this OBS context */
  322. EXPORT audio_t obs_audio(void);
  323. /** Gets the main video output handler for this OBS context */
  324. EXPORT video_t obs_video(void);
  325. /**
  326. * Adds a source to the user source list and increments the reference counter
  327. * for that source.
  328. *
  329. * The user source list is the list of sources that are accessible by a user.
  330. * Typically when a transition is active, it is not meant to be accessible by
  331. * users, so there's no reason for a user to see such a source.
  332. */
  333. EXPORT bool obs_add_source(obs_source_t source);
  334. /** Sets the primary output source for a channel. */
  335. EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
  336. /**
  337. * Gets the primary output source for a channel and increments the reference
  338. * counter for that source. Use obs_source_release to release.
  339. */
  340. EXPORT obs_source_t obs_get_output_source(uint32_t channel);
  341. /**
  342. * Enumerates user sources
  343. *
  344. * Callback function returns true to continue enumeration, or false to end
  345. * enumeration.
  346. */
  347. EXPORT void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t),
  348. void *param);
  349. /** Enumerates outputs */
  350. EXPORT void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t),
  351. void *param);
  352. /** Enumerates encoders */
  353. EXPORT void obs_enum_encoders(bool (*enum_proc)(void*, obs_encoder_t),
  354. void *param);
  355. /** Enumerates encoders */
  356. EXPORT void obs_enum_services(bool (*enum_proc)(void*, obs_service_t),
  357. void *param);
  358. /**
  359. * Gets a source by its name.
  360. *
  361. * Increments the source reference counter, use obs_source_release to
  362. * release it when complete.
  363. */
  364. EXPORT obs_source_t obs_get_source_by_name(const char *name);
  365. /** Gets an output by its name. */
  366. EXPORT obs_output_t obs_get_output_by_name(const char *name);
  367. /** Gets an encoder by its name. */
  368. EXPORT obs_encoder_t obs_get_encoder_by_name(const char *name);
  369. /** Gets an service by its name. */
  370. EXPORT obs_service_t obs_get_service_by_name(const char *name);
  371. /** Returns the default effect for generic RGB/YUV drawing */
  372. EXPORT effect_t obs_get_default_effect(void);
  373. /** Returns the solid effect for drawing solid colors */
  374. EXPORT effect_t obs_get_solid_effect(void);
  375. /** Returns the primary obs signal handler */
  376. EXPORT signal_handler_t obs_signalhandler(void);
  377. /** Returns the primary obs procedure handler */
  378. EXPORT proc_handler_t obs_prochandler(void);
  379. /** Adds a draw callback to the main render context */
  380. EXPORT void obs_add_draw_callback(
  381. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  382. void *param);
  383. /** Removes a draw callback to the main render context */
  384. EXPORT void obs_remove_draw_callback(
  385. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  386. void *param);
  387. /** Changes the size of the main view */
  388. EXPORT void obs_resize(uint32_t cx, uint32_t cy);
  389. /** Renders the main view */
  390. EXPORT void obs_render_main_view(void);
  391. /** Sets the master user volume */
  392. EXPORT void obs_set_master_volume(float volume);
  393. /** Sets the master presentation volume */
  394. EXPORT void obs_set_present_volume(float volume);
  395. /** Gets the master user volume */
  396. EXPORT float obs_get_master_volume(void);
  397. /** Gets the master presentation volume */
  398. EXPORT float obs_get_present_volume(void);
  399. /** Saves a source to settings data */
  400. EXPORT obs_data_t obs_save_source(obs_source_t source);
  401. /** Loads a source from settings data */
  402. EXPORT obs_source_t obs_load_source(obs_data_t data);
  403. /** Loads sources from a data array */
  404. EXPORT void obs_load_sources(obs_data_array_t array);
  405. /** Saves sources to a data array */
  406. EXPORT obs_data_array_t obs_save_sources(void);
  407. /* ------------------------------------------------------------------------- */
  408. /* View context */
  409. /**
  410. * Creates a view context.
  411. *
  412. * A view can be used for things like separate previews, or drawing
  413. * sources separately.
  414. */
  415. EXPORT obs_view_t obs_view_create(void);
  416. /** Destroys this view context */
  417. EXPORT void obs_view_destroy(obs_view_t view);
  418. /** Sets the source to be used for this view context. */
  419. EXPORT void obs_view_setsource(obs_view_t view, uint32_t channel,
  420. obs_source_t source);
  421. /** Gets the source currently in use for this view context */
  422. EXPORT obs_source_t obs_view_getsource(obs_view_t view,
  423. uint32_t channel);
  424. /** Renders the sources of this view context */
  425. EXPORT void obs_view_render(obs_view_t view);
  426. /* ------------------------------------------------------------------------- */
  427. /* Display context */
  428. /**
  429. * Adds a new window display linked to the main render pipeline. This creates
  430. * a new swap chain which updates every frame.
  431. *
  432. * @param graphics_data The swap chain initialization data.
  433. * @return The new display context, or NULL if failed.
  434. */
  435. EXPORT obs_display_t obs_display_create(struct gs_init_data *graphics_data);
  436. /** Destroys a display context */
  437. EXPORT void obs_display_destroy(obs_display_t display);
  438. /** Changes the size of this display */
  439. EXPORT void obs_display_resize(obs_display_t display, uint32_t cx, uint32_t cy);
  440. /**
  441. * Adds a draw callback for this display context
  442. *
  443. * @param display The display context.
  444. * @param draw The draw callback which is called each time a frame
  445. * updates.
  446. * @param param The user data to be associated with this draw callback.
  447. */
  448. EXPORT void obs_display_add_draw_callback(obs_display_t display,
  449. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  450. void *param);
  451. /** Removes a draw callback for this display context */
  452. EXPORT void obs_display_remove_draw_callback(obs_display_t display,
  453. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  454. void *param);
  455. /* ------------------------------------------------------------------------- */
  456. /* Sources */
  457. /** Returns the translated display name of a source */
  458. EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
  459. const char *id);
  460. /**
  461. * Creates a source of the specified type with the specified settings.
  462. *
  463. * The "source" context is used for anything related to presenting
  464. * or modifying video/audio. Use obs_source_release to release it.
  465. */
  466. EXPORT obs_source_t obs_source_create(enum obs_source_type type,
  467. const char *id, const char *name, obs_data_t settings);
  468. /**
  469. * Adds/releases a reference to a source. When the last reference is
  470. * released, the source is destroyed.
  471. */
  472. EXPORT void obs_source_addref(obs_source_t source);
  473. EXPORT void obs_source_release(obs_source_t source);
  474. /** Notifies all references that the source should be released */
  475. EXPORT void obs_source_remove(obs_source_t source);
  476. /** Returns true if the source should be released */
  477. EXPORT bool obs_source_removed(obs_source_t source);
  478. /**
  479. * Retrieves flags that specify what type of data the source presents/modifies.
  480. */
  481. EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
  482. /** Gets the default settings for a source type */
  483. EXPORT obs_data_t obs_get_source_defaults(enum obs_source_type type,
  484. const char *id);
  485. /** Returns the property list, if any. Free with obs_properties_destroy */
  486. EXPORT obs_properties_t obs_get_source_properties(enum obs_source_type type,
  487. const char *id);
  488. /**
  489. * Returns the properties list for a specific existing source. Free with
  490. * obs_properties_destroy
  491. */
  492. EXPORT obs_properties_t obs_source_properties(obs_source_t source);
  493. /** Updates settings for this source */
  494. EXPORT void obs_source_update(obs_source_t source, obs_data_t settings);
  495. /** Renders a video source. */
  496. EXPORT void obs_source_video_render(obs_source_t source);
  497. /** Gets the width of a source (if it has video) */
  498. EXPORT uint32_t obs_source_getwidth(obs_source_t source);
  499. /** Gets the height of a source (if it has video) */
  500. EXPORT uint32_t obs_source_getheight(obs_source_t source);
  501. /** If the source is a filter, returns the parent source of the filter */
  502. EXPORT obs_source_t obs_filter_getparent(obs_source_t filter);
  503. /** If the source is a filter, returns the target source of the filter */
  504. EXPORT obs_source_t obs_filter_gettarget(obs_source_t filter);
  505. /** Adds a filter to the source (which is used whenever the source is used) */
  506. EXPORT void obs_source_filter_add(obs_source_t source, obs_source_t filter);
  507. /** Removes a filter from the source */
  508. EXPORT void obs_source_filter_remove(obs_source_t source, obs_source_t filter);
  509. /** Modifies the order of a specific filter */
  510. EXPORT void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
  511. enum obs_order_movement movement);
  512. /** Gets the settings string for a source */
  513. EXPORT obs_data_t obs_source_getsettings(obs_source_t source);
  514. /** Gets the name of a source */
  515. EXPORT const char *obs_source_getname(obs_source_t source);
  516. /** Sets the name of a source */
  517. EXPORT void obs_source_setname(obs_source_t source, const char *name);
  518. /** Gets the source type and identifier */
  519. EXPORT void obs_source_gettype(obs_source_t source, enum obs_source_type *type,
  520. const char **id);
  521. /** Returns the signal handler for a source */
  522. EXPORT signal_handler_t obs_source_signalhandler(obs_source_t source);
  523. /** Returns the procedure handler for a source */
  524. EXPORT proc_handler_t obs_source_prochandler(obs_source_t source);
  525. /** Sets the user volume for a source that has audio output */
  526. EXPORT void obs_source_setvolume(obs_source_t source, float volume);
  527. /** Sets the presentation volume for a source */
  528. EXPORT void obs_source_set_present_volume(obs_source_t source, float volume);
  529. /** Gets the user volume for a source that has audio output */
  530. EXPORT float obs_source_getvolume(obs_source_t source);
  531. /** Gets the presentation volume for a source */
  532. EXPORT float obs_source_get_present_volume(obs_source_t source);
  533. /** Sets the audio sync offset (in nanoseconds) for a source */
  534. EXPORT void obs_source_set_sync_offset(obs_source_t source, int64_t offset);
  535. /** Gets the audio sync offset (in nanoseconds) for a source */
  536. EXPORT int64_t obs_source_get_sync_offset(obs_source_t source);
  537. /** Enumerates child sources used by this source */
  538. EXPORT void obs_source_enum_sources(obs_source_t source,
  539. obs_source_enum_proc_t enum_callback,
  540. void *param);
  541. /** Enumerates the entire child source tree used by this source */
  542. EXPORT void obs_source_enum_tree(obs_source_t source,
  543. obs_source_enum_proc_t enum_callback,
  544. void *param);
  545. /** Returns true if active, false if not */
  546. EXPORT bool obs_source_active(obs_source_t source);
  547. /**
  548. * Sometimes sources need to be told when to save their settings so they
  549. * don't have to constantly update and keep track of their settings. This will
  550. * call the source's 'save' callback if any, which will save its current
  551. * data to its settings.
  552. */
  553. EXPORT void obs_source_save(obs_source_t source);
  554. /**
  555. * Sometimes sources need to be told when they are loading their settings
  556. * from prior saved data. This is different from a source 'update' in that
  557. * it's meant to be used after the source has been created and loaded from
  558. * somewhere (such as a saved file).
  559. */
  560. EXPORT void obs_source_load(obs_source_t source);
  561. /* ------------------------------------------------------------------------- */
  562. /* Functions used by sources */
  563. /** Outputs asynchronous video data */
  564. EXPORT void obs_source_output_video(obs_source_t source,
  565. const struct obs_source_frame *frame);
  566. /** Outputs audio data (always asynchronous) */
  567. EXPORT void obs_source_output_audio(obs_source_t source,
  568. const struct source_audio *audio);
  569. /** Gets the current async video frame */
  570. EXPORT struct obs_source_frame *obs_source_get_frame(obs_source_t source);
  571. /** Releases the current async video frame */
  572. EXPORT void obs_source_release_frame(obs_source_t source,
  573. struct obs_source_frame *frame);
  574. /** Default RGB filter handler for generic effect filters */
  575. EXPORT void obs_source_process_filter(obs_source_t filter, effect_t effect,
  576. uint32_t width, uint32_t height, enum gs_color_format format,
  577. enum obs_allow_direct_render allow_direct);
  578. /**
  579. * Adds a child source. Must be called by parent sources on child sources
  580. * when the child is added. This ensures that the source is properly activated
  581. * if the parent is active.
  582. */
  583. EXPORT void obs_source_add_child(obs_source_t parent, obs_source_t child);
  584. /**
  585. * Removes a child source. Must be called by parent sources on child sources
  586. * when the child is removed. This ensures that the source is properly
  587. * deactivated if the parent is active.
  588. */
  589. EXPORT void obs_source_remove_child(obs_source_t parent, obs_source_t child);
  590. /** Begins transition frame. Sets all transitioning volume values to 0.0f. */
  591. EXPORT void obs_transition_begin_frame(obs_source_t transition);
  592. /**
  593. * Adds a transitioning volume value to a source that's being transitioned.
  594. * This value is applied to all the sources within the the source.
  595. */
  596. EXPORT void obs_source_set_transition_vol(obs_source_t source, float vol);
  597. /** Ends transition frame and applies new presentation volumes to all sources */
  598. EXPORT void obs_transition_end_frame(obs_source_t transition);
  599. /* ------------------------------------------------------------------------- */
  600. /* Scenes */
  601. /**
  602. * Creates a scene.
  603. *
  604. * A scene is a source which is a container of other sources with specific
  605. * display oriantations. Scenes can also be used like any other source.
  606. */
  607. EXPORT obs_scene_t obs_scene_create(const char *name);
  608. EXPORT void obs_scene_addref(obs_scene_t scene);
  609. EXPORT void obs_scene_release(obs_scene_t scene);
  610. /** Gets the scene's source context */
  611. EXPORT obs_source_t obs_scene_getsource(obs_scene_t scene);
  612. /** Gets the scene from its source, or NULL if not a scene */
  613. EXPORT obs_scene_t obs_scene_fromsource(obs_source_t source);
  614. /** Determines whether a source is within a scene */
  615. EXPORT obs_sceneitem_t obs_scene_findsource(obs_scene_t scene,
  616. const char *name);
  617. /** Enumerates sources within a scene */
  618. EXPORT void obs_scene_enum_items(obs_scene_t scene,
  619. bool (*callback)(obs_scene_t, obs_sceneitem_t, void*),
  620. void *param);
  621. /** Adds/creates a new scene item for a source */
  622. EXPORT obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source);
  623. EXPORT void obs_sceneitem_addref(obs_sceneitem_t item);
  624. EXPORT void obs_sceneitem_release(obs_sceneitem_t item);
  625. /** Removes a scene item. */
  626. EXPORT void obs_sceneitem_remove(obs_sceneitem_t item);
  627. /** Gets the scene parent associated with the scene item. */
  628. EXPORT obs_scene_t obs_sceneitem_getscene(obs_sceneitem_t item);
  629. /** Gets the source of a scene item. */
  630. EXPORT obs_source_t obs_sceneitem_getsource(obs_sceneitem_t item);
  631. EXPORT void obs_sceneitem_select(obs_sceneitem_t item, bool select);
  632. EXPORT bool obs_sceneitem_selected(obs_sceneitem_t item);
  633. /* Functions for gettings/setting specific orientation of a scene item */
  634. EXPORT void obs_sceneitem_setpos(obs_sceneitem_t item, const struct vec2 *pos);
  635. EXPORT void obs_sceneitem_setrot(obs_sceneitem_t item, float rot_deg);
  636. EXPORT void obs_sceneitem_setscale(obs_sceneitem_t item,
  637. const struct vec2 *scale);
  638. EXPORT void obs_sceneitem_setalignment(obs_sceneitem_t item,
  639. uint32_t alignment);
  640. EXPORT void obs_sceneitem_setorder(obs_sceneitem_t item,
  641. enum obs_order_movement movement);
  642. EXPORT void obs_sceneitem_set_bounds_type(obs_sceneitem_t item,
  643. enum obs_bounds_type type);
  644. EXPORT void obs_sceneitem_set_bounds_alignment(obs_sceneitem_t item,
  645. uint32_t alignment);
  646. EXPORT void obs_sceneitem_set_bounds(obs_sceneitem_t item,
  647. const struct vec2 *bounds);
  648. EXPORT void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos);
  649. EXPORT float obs_sceneitem_getrot(obs_sceneitem_t item);
  650. EXPORT void obs_sceneitem_getscale(obs_sceneitem_t item, struct vec2 *scale);
  651. EXPORT uint32_t obs_sceneitem_getalignment(obs_sceneitem_t item);
  652. EXPORT enum obs_bounds_type obs_sceneitem_get_bounds_type(obs_sceneitem_t item);
  653. EXPORT uint32_t obs_sceneitem_get_bounds_alignment(obs_sceneitem_t item);
  654. EXPORT void obs_sceneitem_get_bounds(obs_sceneitem_t item, struct vec2 *bounds);
  655. EXPORT void obs_sceneitem_get_info(obs_sceneitem_t item,
  656. struct obs_transform_info *info);
  657. EXPORT void obs_sceneitem_set_info(obs_sceneitem_t item,
  658. const struct obs_transform_info *info);
  659. EXPORT void obs_sceneitem_get_draw_transform(obs_sceneitem_t item,
  660. struct matrix4 *transform);
  661. EXPORT void obs_sceneitem_get_box_transform(obs_sceneitem_t item,
  662. struct matrix4 *transform);
  663. /* ------------------------------------------------------------------------- */
  664. /* Outputs */
  665. EXPORT const char *obs_output_getdisplayname(const char *id);
  666. /**
  667. * Creates an output.
  668. *
  669. * Outputs allow outputting to file, outputting to network, outputting to
  670. * directshow, or other custom outputs.
  671. */
  672. EXPORT obs_output_t obs_output_create(const char *id, const char *name,
  673. obs_data_t settings);
  674. EXPORT void obs_output_destroy(obs_output_t output);
  675. EXPORT const char *obs_output_getname(obs_output_t output);
  676. /** Starts the output. */
  677. EXPORT bool obs_output_start(obs_output_t output);
  678. /** Stops the output. */
  679. EXPORT void obs_output_stop(obs_output_t output);
  680. /** Returns whether the output is active */
  681. EXPORT bool obs_output_active(obs_output_t output);
  682. /** Gets the default settings for an output type */
  683. EXPORT obs_data_t obs_output_defaults(const char *id);
  684. /** Returns the property list, if any. Free with obs_properties_destroy */
  685. EXPORT obs_properties_t obs_get_output_properties(const char *id);
  686. /**
  687. * Returns the property list of an existing output, if any. Free with
  688. * obs_properties_destroy
  689. */
  690. EXPORT obs_properties_t obs_output_properties(obs_output_t output);
  691. /** Updates the settings for this output context */
  692. EXPORT void obs_output_update(obs_output_t output, obs_data_t settings);
  693. /** Specifies whether the output can be paused */
  694. EXPORT bool obs_output_canpause(obs_output_t output);
  695. /** Pauses the output (if the functionality is allowed by the output */
  696. EXPORT void obs_output_pause(obs_output_t output);
  697. /* Gets the current output settings string */
  698. EXPORT obs_data_t obs_output_get_settings(obs_output_t output);
  699. /** Returns the signal handler for an output */
  700. EXPORT signal_handler_t obs_output_signalhandler(obs_output_t output);
  701. /** Returns the procedure handler for an output */
  702. EXPORT proc_handler_t obs_output_prochandler(obs_output_t output);
  703. /**
  704. * Sets the current video media context associated with this output,
  705. * required for non-encoded outputs
  706. */
  707. EXPORT void obs_output_set_video(obs_output_t output, video_t video);
  708. /**
  709. * Sets the current audio/video media contexts associated with this output,
  710. * required for non-encoded outputs. Can be null.
  711. */
  712. EXPORT void obs_output_set_media(obs_output_t output,
  713. video_t video, audio_t audio);
  714. /** Returns the video media context associated with this output */
  715. EXPORT video_t obs_output_video(obs_output_t output);
  716. /** Returns the audio media context associated with this output */
  717. EXPORT audio_t obs_output_audio(obs_output_t output);
  718. /**
  719. * Sets the current video encoder associated with this output,
  720. * required for encoded outputs
  721. */
  722. EXPORT void obs_output_set_video_encoder(obs_output_t output,
  723. obs_encoder_t encoder);
  724. /**
  725. * Sets the current audio encoder associated with this output,
  726. * required for encoded outputs
  727. */
  728. EXPORT void obs_output_set_audio_encoder(obs_output_t output,
  729. obs_encoder_t encoder);
  730. /** Returns the current video encoder associated with this output */
  731. EXPORT obs_encoder_t obs_output_get_video_encoder(obs_output_t output);
  732. /** Returns the current audio encoder associated with this output */
  733. EXPORT obs_encoder_t obs_output_get_audio_encoder(obs_output_t output);
  734. /** Sets the current service associated with this output. */
  735. EXPORT void obs_output_set_service(obs_output_t output, obs_service_t service);
  736. /** Gets the current service associated with this output. */
  737. EXPORT obs_service_t obs_output_get_service(obs_output_t output);
  738. /**
  739. * Sets the reconnect settings. Set retry_count to 0 to disable reconnecting.
  740. */
  741. EXPORT void obs_output_set_reconnect_settings(obs_output_t output,
  742. int retry_count, int retry_sec);
  743. EXPORT uint64_t obs_output_get_total_bytes(obs_output_t output);
  744. EXPORT int obs_output_get_frames_dropped(obs_output_t output);
  745. EXPORT int obs_output_get_total_frames(obs_output_t output);
  746. /* ------------------------------------------------------------------------- */
  747. /* Functions used by outputs */
  748. /** Optionally sets the video conversion info. Used only for raw output */
  749. EXPORT void obs_output_set_video_conversion(obs_output_t output,
  750. const struct video_scale_info *conversion);
  751. /** Optionally sets the audio conversion info. Used only for raw output */
  752. EXPORT void obs_output_set_audio_conversion(obs_output_t output,
  753. const struct audio_convert_info *conversion);
  754. /** Returns whether data capture can begin with the specified flags */
  755. EXPORT bool obs_output_can_begin_data_capture(obs_output_t output,
  756. uint32_t flags);
  757. /** Initializes encoders (if any) */
  758. EXPORT bool obs_output_initialize_encoders(obs_output_t output, uint32_t flags);
  759. /**
  760. * Begins data capture from media/encoders.
  761. *
  762. * @param output Output context
  763. * @param flags Set this to 0 to use default output flags set in the
  764. * obs_output_info structure, otherwise set to a either
  765. * OBS_OUTPUT_VIDEO or OBS_OUTPUT_AUDIO to specify whether to
  766. * connect audio or video. This is useful for things like
  767. * ffmpeg which may or may not always want to use both audio
  768. * and video.
  769. * @return true if successful, false otherwise.
  770. */
  771. EXPORT bool obs_output_begin_data_capture(obs_output_t output, uint32_t flags);
  772. /** Ends data capture from media/encoders */
  773. EXPORT void obs_output_end_data_capture(obs_output_t output);
  774. /**
  775. * Signals that the output has stopped itself.
  776. *
  777. * @param output Output context
  778. * @param code Error code (or OBS_OUTPUT_SUCCESS if not an error)
  779. */
  780. EXPORT void obs_output_signal_stop(obs_output_t output, int code);
  781. /* ------------------------------------------------------------------------- */
  782. /* Encoders */
  783. EXPORT const char *obs_encoder_getdisplayname(const char *id);
  784. /**
  785. * Creates a video encoder context
  786. *
  787. * @param id Video encoder ID
  788. * @param name Name to assign to this context
  789. * @param settings Settings
  790. * @return The video encoder context, or NULL if failed or not found.
  791. */
  792. EXPORT obs_encoder_t obs_video_encoder_create(const char *id, const char *name,
  793. obs_data_t settings);
  794. /**
  795. * Creates an audio encoder context
  796. *
  797. * @param id Audio Encoder ID
  798. * @param name Name to assign to this context
  799. * @param settings Settings
  800. * @return The video encoder context, or NULL if failed or not found.
  801. */
  802. EXPORT obs_encoder_t obs_audio_encoder_create(const char *id, const char *name,
  803. obs_data_t settings);
  804. /** Destroys an encoder context */
  805. EXPORT void obs_encoder_destroy(obs_encoder_t encoder);
  806. EXPORT const char *obs_encoder_getname(obs_encoder_t encoder);
  807. /** Returns the codec of the encoder */
  808. EXPORT const char *obs_encoder_get_codec(obs_encoder_t encoder);
  809. /** Gets the default settings for an encoder type */
  810. EXPORT obs_data_t obs_encoder_defaults(const char *id);
  811. /** Returns the property list, if any. Free with obs_properties_destroy */
  812. EXPORT obs_properties_t obs_get_encoder_properties(const char *id);
  813. /**
  814. * Returns the property list of an existing encoder, if any. Free with
  815. * obs_properties_destroy
  816. */
  817. EXPORT obs_properties_t obs_encoder_properties(obs_encoder_t encoder);
  818. /**
  819. * Updates the settings of the encoder context. Usually used for changing
  820. * bitrate while active
  821. */
  822. EXPORT void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings);
  823. /** Gets extra data (headers) associated with this context */
  824. EXPORT bool obs_encoder_get_extra_data(obs_encoder_t encoder,
  825. uint8_t **extra_data, size_t *size);
  826. /** Returns the current settings for this encoder */
  827. EXPORT obs_data_t obs_encoder_get_settings(obs_encoder_t encoder);
  828. /** Sets the video output context to be used with this encoder */
  829. EXPORT void obs_encoder_set_video(obs_encoder_t encoder, video_t video);
  830. /** Sets the audio output context to be used with this encoder */
  831. EXPORT void obs_encoder_set_audio(obs_encoder_t encoder, audio_t audio);
  832. /**
  833. * Returns the video output context used with this encoder, or NULL if not
  834. * a video context
  835. */
  836. EXPORT video_t obs_encoder_video(obs_encoder_t encoder);
  837. /**
  838. * Returns the audio output context used with this encoder, or NULL if not
  839. * a audio context
  840. */
  841. EXPORT audio_t obs_encoder_audio(obs_encoder_t encoder);
  842. /** Returns true if encoder is active, false otherwise */
  843. EXPORT bool obs_encoder_active(obs_encoder_t encoder);
  844. /** Duplicates an encoder packet */
  845. EXPORT void obs_duplicate_encoder_packet(struct encoder_packet *dst,
  846. const struct encoder_packet *src);
  847. EXPORT void obs_free_encoder_packet(struct encoder_packet *packet);
  848. /* ------------------------------------------------------------------------- */
  849. /* Stream Services */
  850. EXPORT const char *obs_service_getdisplayname(const char *id);
  851. EXPORT obs_service_t obs_service_create(const char *id, const char *name,
  852. obs_data_t settings);
  853. EXPORT void obs_service_destroy(obs_service_t service);
  854. EXPORT const char *obs_service_getname(obs_service_t service);
  855. /** Gets the default settings for a service */
  856. EXPORT obs_data_t obs_service_defaults(const char *id);
  857. /** Returns the property list, if any. Free with obs_properties_destroy */
  858. EXPORT obs_properties_t obs_get_service_properties(const char *id);
  859. /**
  860. * Returns the property list of an existing service context, if any. Free with
  861. * obs_properties_destroy
  862. */
  863. EXPORT obs_properties_t obs_service_properties(obs_service_t service);
  864. /** Gets the service type */
  865. EXPORT const char *obs_service_gettype(obs_service_t service);
  866. /** Updates the settings of the service context */
  867. EXPORT void obs_service_update(obs_service_t service, obs_data_t settings);
  868. /** Returns the current settings for this service */
  869. EXPORT obs_data_t obs_service_get_settings(obs_service_t service);
  870. /** Returns the URL for this service context */
  871. EXPORT const char *obs_service_get_url(obs_service_t service);
  872. /** Returns the stream key (if any) for this service context */
  873. EXPORT const char *obs_service_get_key(obs_service_t service);
  874. /** Returns the username (if any) for this service context */
  875. EXPORT const char *obs_service_get_username(obs_service_t service);
  876. /** Returns the password (if any) for this service context */
  877. EXPORT const char *obs_service_get_password(obs_service_t service);
  878. /* ------------------------------------------------------------------------- */
  879. /* Source frame allocation functions */
  880. EXPORT void obs_source_frame_init(struct obs_source_frame *frame,
  881. enum video_format format, uint32_t width, uint32_t height);
  882. static inline void obs_source_frame_free(struct obs_source_frame *frame)
  883. {
  884. if (frame) {
  885. bfree(frame->data[0]);
  886. memset(frame, 0, sizeof(*frame));
  887. }
  888. }
  889. static inline struct obs_source_frame *obs_source_frame_create(
  890. enum video_format format, uint32_t width, uint32_t height)
  891. {
  892. struct obs_source_frame *frame;
  893. frame = (struct obs_source_frame*)bzalloc(sizeof(*frame));
  894. obs_source_frame_init(frame, format, width, height);
  895. return frame;
  896. }
  897. static inline void obs_source_frame_destroy(struct obs_source_frame *frame)
  898. {
  899. if (frame) {
  900. bfree(frame->data[0]);
  901. bfree(frame);
  902. }
  903. }
  904. #ifdef __cplusplus
  905. }
  906. #endif