obs.h 35 KB

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