obs.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  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 obs_audio_data {
  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 obs_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. /** Helper function for entering the OBS graphics context */
  320. EXPORT void obs_enter_graphics(void);
  321. /** Helper function for leaving the OBS graphics context */
  322. EXPORT void obs_leave_graphics(void);
  323. /** Gets the main audio output handler for this OBS context */
  324. EXPORT audio_t obs_get_audio(void);
  325. /** Gets the main video output handler for this OBS context */
  326. EXPORT video_t obs_get_video(void);
  327. /**
  328. * Adds a source to the user source list and increments the reference counter
  329. * for that source.
  330. *
  331. * The user source list is the list of sources that are accessible by a user.
  332. * Typically when a transition is active, it is not meant to be accessible by
  333. * users, so there's no reason for a user to see such a source.
  334. */
  335. EXPORT bool obs_add_source(obs_source_t source);
  336. /** Sets the primary output source for a channel. */
  337. EXPORT void obs_set_output_source(uint32_t channel, obs_source_t source);
  338. /**
  339. * Gets the primary output source for a channel and increments the reference
  340. * counter for that source. Use obs_source_release to release.
  341. */
  342. EXPORT obs_source_t obs_get_output_source(uint32_t channel);
  343. /**
  344. * Enumerates user sources
  345. *
  346. * Callback function returns true to continue enumeration, or false to end
  347. * enumeration.
  348. */
  349. EXPORT void obs_enum_sources(bool (*enum_proc)(void*, obs_source_t),
  350. void *param);
  351. /** Enumerates outputs */
  352. EXPORT void obs_enum_outputs(bool (*enum_proc)(void*, obs_output_t),
  353. void *param);
  354. /** Enumerates encoders */
  355. EXPORT void obs_enum_encoders(bool (*enum_proc)(void*, obs_encoder_t),
  356. void *param);
  357. /** Enumerates encoders */
  358. EXPORT void obs_enum_services(bool (*enum_proc)(void*, obs_service_t),
  359. void *param);
  360. /**
  361. * Gets a source by its name.
  362. *
  363. * Increments the source reference counter, use obs_source_release to
  364. * release it when complete.
  365. */
  366. EXPORT obs_source_t obs_get_source_by_name(const char *name);
  367. /** Gets an output by its name. */
  368. EXPORT obs_output_t obs_get_output_by_name(const char *name);
  369. /** Gets an encoder by its name. */
  370. EXPORT obs_encoder_t obs_get_encoder_by_name(const char *name);
  371. /** Gets an service by its name. */
  372. EXPORT obs_service_t obs_get_service_by_name(const char *name);
  373. /** Returns the default effect for generic RGB/YUV drawing */
  374. EXPORT gs_effect_t obs_get_default_effect(void);
  375. /** Returns the solid effect for drawing solid colors */
  376. EXPORT gs_effect_t obs_get_solid_effect(void);
  377. /** Returns the primary obs signal handler */
  378. EXPORT signal_handler_t obs_get_signal_handler(void);
  379. /** Returns the primary obs procedure handler */
  380. EXPORT proc_handler_t obs_get_proc_handler(void);
  381. /** Adds a draw callback to the main render context */
  382. EXPORT void obs_add_draw_callback(
  383. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  384. void *param);
  385. /** Removes a draw callback to the main render context */
  386. EXPORT void obs_remove_draw_callback(
  387. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  388. void *param);
  389. /** Changes the size of the main view */
  390. EXPORT void obs_resize(uint32_t cx, uint32_t cy);
  391. /** Renders the main view */
  392. EXPORT void obs_render_main_view(void);
  393. /** Sets the master user volume */
  394. EXPORT void obs_set_master_volume(float volume);
  395. /** Sets the master presentation volume */
  396. EXPORT void obs_set_present_volume(float volume);
  397. /** Gets the master user volume */
  398. EXPORT float obs_get_master_volume(void);
  399. /** Gets the master presentation volume */
  400. EXPORT float obs_get_present_volume(void);
  401. /** Saves a source to settings data */
  402. EXPORT obs_data_t obs_save_source(obs_source_t source);
  403. /** Loads a source from settings data */
  404. EXPORT obs_source_t obs_load_source(obs_data_t data);
  405. /** Loads sources from a data array */
  406. EXPORT void obs_load_sources(obs_data_array_t array);
  407. /** Saves sources to a data array */
  408. EXPORT obs_data_array_t obs_save_sources(void);
  409. /* ------------------------------------------------------------------------- */
  410. /* View context */
  411. /**
  412. * Creates a view context.
  413. *
  414. * A view can be used for things like separate previews, or drawing
  415. * sources separately.
  416. */
  417. EXPORT obs_view_t obs_view_create(void);
  418. /** Destroys this view context */
  419. EXPORT void obs_view_destroy(obs_view_t view);
  420. /** Sets the source to be used for this view context. */
  421. EXPORT void obs_view_set_source(obs_view_t view, uint32_t channel,
  422. obs_source_t source);
  423. /** Gets the source currently in use for this view context */
  424. EXPORT obs_source_t obs_view_get_source(obs_view_t view,
  425. uint32_t channel);
  426. /** Renders the sources of this view context */
  427. EXPORT void obs_view_render(obs_view_t view);
  428. /* ------------------------------------------------------------------------- */
  429. /* Display context */
  430. /**
  431. * Adds a new window display linked to the main render pipeline. This creates
  432. * a new swap chain which updates every frame.
  433. *
  434. * @param graphics_data The swap chain initialization data.
  435. * @return The new display context, or NULL if failed.
  436. */
  437. EXPORT obs_display_t obs_display_create(struct gs_init_data *graphics_data);
  438. /** Destroys a display context */
  439. EXPORT void obs_display_destroy(obs_display_t display);
  440. /** Changes the size of this display */
  441. EXPORT void obs_display_resize(obs_display_t display, uint32_t cx, uint32_t cy);
  442. /**
  443. * Adds a draw callback for this display context
  444. *
  445. * @param display The display context.
  446. * @param draw The draw callback which is called each time a frame
  447. * updates.
  448. * @param param The user data to be associated with this draw callback.
  449. */
  450. EXPORT void obs_display_add_draw_callback(obs_display_t display,
  451. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  452. void *param);
  453. /** Removes a draw callback for this display context */
  454. EXPORT void obs_display_remove_draw_callback(obs_display_t display,
  455. void (*draw)(void *param, uint32_t cx, uint32_t cy),
  456. void *param);
  457. /* ------------------------------------------------------------------------- */
  458. /* Sources */
  459. /** Returns the translated display name of a source */
  460. EXPORT const char *obs_source_get_display_name(enum obs_source_type type,
  461. const char *id);
  462. /**
  463. * Creates a source of the specified type with the specified settings.
  464. *
  465. * The "source" context is used for anything related to presenting
  466. * or modifying video/audio. Use obs_source_release to release it.
  467. */
  468. EXPORT obs_source_t obs_source_create(enum obs_source_type type,
  469. const char *id, const char *name, obs_data_t settings);
  470. /**
  471. * Adds/releases a reference to a source. When the last reference is
  472. * released, the source is destroyed.
  473. */
  474. EXPORT void obs_source_addref(obs_source_t source);
  475. EXPORT void obs_source_release(obs_source_t source);
  476. /** Notifies all references that the source should be released */
  477. EXPORT void obs_source_remove(obs_source_t source);
  478. /** Returns true if the source should be released */
  479. EXPORT bool obs_source_removed(obs_source_t source);
  480. /**
  481. * Retrieves flags that specify what type of data the source presents/modifies.
  482. */
  483. EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
  484. /** Gets the default settings for a source type */
  485. EXPORT obs_data_t obs_get_source_defaults(enum obs_source_type type,
  486. const char *id);
  487. /** Returns the property list, if any. Free with obs_properties_destroy */
  488. EXPORT obs_properties_t obs_get_source_properties(enum obs_source_type type,
  489. const char *id);
  490. /**
  491. * Returns the properties list for a specific existing source. Free with
  492. * obs_properties_destroy
  493. */
  494. EXPORT obs_properties_t obs_source_properties(obs_source_t source);
  495. /** Updates settings for this source */
  496. EXPORT void obs_source_update(obs_source_t source, obs_data_t settings);
  497. /** Renders a video source. */
  498. EXPORT void obs_source_video_render(obs_source_t source);
  499. /** Gets the width of a source (if it has video) */
  500. EXPORT uint32_t obs_source_get_width(obs_source_t source);
  501. /** Gets the height of a source (if it has video) */
  502. EXPORT uint32_t obs_source_get_height(obs_source_t source);
  503. /** If the source is a filter, returns the parent source of the filter */
  504. EXPORT obs_source_t obs_filter_get_parent(obs_source_t filter);
  505. /** If the source is a filter, returns the target source of the filter */
  506. EXPORT obs_source_t obs_filter_get_target(obs_source_t filter);
  507. /** Adds a filter to the source (which is used whenever the source is used) */
  508. EXPORT void obs_source_filter_add(obs_source_t source, obs_source_t filter);
  509. /** Removes a filter from the source */
  510. EXPORT void obs_source_filter_remove(obs_source_t source, obs_source_t filter);
  511. /** Modifies the order of a specific filter */
  512. EXPORT void obs_source_filter_set_order(obs_source_t source,
  513. obs_source_t filter, enum obs_order_movement movement);
  514. /** Gets the settings string for a source */
  515. EXPORT obs_data_t obs_source_get_settings(obs_source_t source);
  516. /** Gets the name of a source */
  517. EXPORT const char *obs_source_get_name(obs_source_t source);
  518. /** Sets the name of a source */
  519. EXPORT void obs_source_set_name(obs_source_t source, const char *name);
  520. /** Gets the source type */
  521. EXPORT enum obs_source_type obs_source_get_type(obs_source_t source);
  522. /** Gets the source identifier */
  523. EXPORT const char *obs_source_get_id(obs_source_t source);
  524. /** Returns the signal handler for a source */
  525. EXPORT signal_handler_t obs_source_get_signal_handler(obs_source_t source);
  526. /** Returns the procedure handler for a source */
  527. EXPORT proc_handler_t obs_source_get_proc_handler(obs_source_t source);
  528. /** Sets the user volume for a source that has audio output */
  529. EXPORT void obs_source_set_volume(obs_source_t source, float volume);
  530. /** Sets the presentation volume for a source */
  531. EXPORT void obs_source_set_present_volume(obs_source_t source, float volume);
  532. /** Gets the user volume for a source that has audio output */
  533. EXPORT float obs_source_get_volume(obs_source_t source);
  534. /** Gets the presentation volume for a source */
  535. EXPORT float obs_source_get_present_volume(obs_source_t source);
  536. /** Sets the audio sync offset (in nanoseconds) for a source */
  537. EXPORT void obs_source_set_sync_offset(obs_source_t source, int64_t offset);
  538. /** Gets the audio sync offset (in nanoseconds) for a source */
  539. EXPORT int64_t obs_source_get_sync_offset(obs_source_t source);
  540. /** Enumerates child sources used by this source */
  541. EXPORT void obs_source_enum_sources(obs_source_t source,
  542. obs_source_enum_proc_t enum_callback,
  543. void *param);
  544. /** Enumerates the entire child source tree used by this source */
  545. EXPORT void obs_source_enum_tree(obs_source_t source,
  546. obs_source_enum_proc_t enum_callback,
  547. void *param);
  548. /** Returns true if active, false if not */
  549. EXPORT bool obs_source_active(obs_source_t source);
  550. /**
  551. * Sometimes sources need to be told when to save their settings so they
  552. * don't have to constantly update and keep track of their settings. This will
  553. * call the source's 'save' callback if any, which will save its current
  554. * data to its settings.
  555. */
  556. EXPORT void obs_source_save(obs_source_t source);
  557. /**
  558. * Sometimes sources need to be told when they are loading their settings
  559. * from prior saved data. This is different from a source 'update' in that
  560. * it's meant to be used after the source has been created and loaded from
  561. * somewhere (such as a saved file).
  562. */
  563. EXPORT void obs_source_load(obs_source_t source);
  564. /* ------------------------------------------------------------------------- */
  565. /* Functions used by sources */
  566. /** Outputs asynchronous video data */
  567. EXPORT void obs_source_output_video(obs_source_t source,
  568. const struct obs_source_frame *frame);
  569. /** Outputs audio data (always asynchronous) */
  570. EXPORT void obs_source_output_audio(obs_source_t source,
  571. const struct obs_source_audio *audio);
  572. /** Gets the current async video frame */
  573. EXPORT struct obs_source_frame *obs_source_get_frame(obs_source_t source);
  574. /** Releases the current async video frame */
  575. EXPORT void obs_source_release_frame(obs_source_t source,
  576. struct obs_source_frame *frame);
  577. /** Default RGB filter handler for generic effect filters */
  578. EXPORT void obs_source_process_filter(obs_source_t filter, gs_effect_t effect,
  579. uint32_t width, uint32_t height, enum gs_color_format format,
  580. enum obs_allow_direct_render allow_direct);
  581. /**
  582. * Adds a child source. Must be called by parent sources on child sources
  583. * when the child is added. This ensures that the source is properly activated
  584. * if the parent is active.
  585. */
  586. EXPORT void obs_source_add_child(obs_source_t parent, obs_source_t child);
  587. /**
  588. * Removes a child source. Must be called by parent sources on child sources
  589. * when the child is removed. This ensures that the source is properly
  590. * deactivated if the parent is active.
  591. */
  592. EXPORT void obs_source_remove_child(obs_source_t parent, obs_source_t child);
  593. /** Begins transition frame. Sets all transitioning volume values to 0.0f. */
  594. EXPORT void obs_transition_begin_frame(obs_source_t transition);
  595. /**
  596. * Adds a transitioning volume value to a source that's being transitioned.
  597. * This value is applied to all the sources within the the source.
  598. */
  599. EXPORT void obs_source_set_transition_vol(obs_source_t source, float vol);
  600. /** Ends transition frame and applies new presentation volumes to all sources */
  601. EXPORT void obs_transition_end_frame(obs_source_t transition);
  602. /* ------------------------------------------------------------------------- */
  603. /* Scenes */
  604. /**
  605. * Creates a scene.
  606. *
  607. * A scene is a source which is a container of other sources with specific
  608. * display oriantations. Scenes can also be used like any other source.
  609. */
  610. EXPORT obs_scene_t obs_scene_create(const char *name);
  611. EXPORT void obs_scene_addref(obs_scene_t scene);
  612. EXPORT void obs_scene_release(obs_scene_t scene);
  613. /** Gets the scene's source context */
  614. EXPORT obs_source_t obs_scene_get_source(obs_scene_t scene);
  615. /** Gets the scene from its source, or NULL if not a scene */
  616. EXPORT obs_scene_t obs_scene_from_source(obs_source_t source);
  617. /** Determines whether a source is within a scene */
  618. EXPORT obs_sceneitem_t obs_scene_find_source(obs_scene_t scene,
  619. const char *name);
  620. /** Enumerates sources within a scene */
  621. EXPORT void obs_scene_enum_items(obs_scene_t scene,
  622. bool (*callback)(obs_scene_t, obs_sceneitem_t, void*),
  623. void *param);
  624. /** Adds/creates a new scene item for a source */
  625. EXPORT obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source);
  626. EXPORT void obs_sceneitem_addref(obs_sceneitem_t item);
  627. EXPORT void obs_sceneitem_release(obs_sceneitem_t item);
  628. /** Removes a scene item. */
  629. EXPORT void obs_sceneitem_remove(obs_sceneitem_t item);
  630. /** Gets the scene parent associated with the scene item. */
  631. EXPORT obs_scene_t obs_sceneitem_get_scene(obs_sceneitem_t item);
  632. /** Gets the source of a scene item. */
  633. EXPORT obs_source_t obs_sceneitem_get_source(obs_sceneitem_t item);
  634. EXPORT void obs_sceneitem_select(obs_sceneitem_t item, bool select);
  635. EXPORT bool obs_sceneitem_selected(obs_sceneitem_t item);
  636. /* Functions for gettings/setting specific orientation of a scene item */
  637. EXPORT void obs_sceneitem_set_pos(obs_sceneitem_t item, const struct vec2 *pos);
  638. EXPORT void obs_sceneitem_set_rot(obs_sceneitem_t item, float rot_deg);
  639. EXPORT void obs_sceneitem_set_scale(obs_sceneitem_t item,
  640. const struct vec2 *scale);
  641. EXPORT void obs_sceneitem_set_alignment(obs_sceneitem_t item,
  642. uint32_t alignment);
  643. EXPORT void obs_sceneitem_set_order(obs_sceneitem_t item,
  644. enum obs_order_movement movement);
  645. EXPORT void obs_sceneitem_set_bounds_type(obs_sceneitem_t item,
  646. enum obs_bounds_type type);
  647. EXPORT void obs_sceneitem_set_bounds_alignment(obs_sceneitem_t item,
  648. uint32_t alignment);
  649. EXPORT void obs_sceneitem_set_bounds(obs_sceneitem_t item,
  650. const struct vec2 *bounds);
  651. EXPORT void obs_sceneitem_get_pos(obs_sceneitem_t item, struct vec2 *pos);
  652. EXPORT float obs_sceneitem_get_rot(obs_sceneitem_t item);
  653. EXPORT void obs_sceneitem_get_scale(obs_sceneitem_t item, struct vec2 *scale);
  654. EXPORT uint32_t obs_sceneitem_get_alignment(obs_sceneitem_t item);
  655. EXPORT enum obs_bounds_type obs_sceneitem_get_bounds_type(obs_sceneitem_t item);
  656. EXPORT uint32_t obs_sceneitem_get_bounds_alignment(obs_sceneitem_t item);
  657. EXPORT void obs_sceneitem_get_bounds(obs_sceneitem_t item, struct vec2 *bounds);
  658. EXPORT void obs_sceneitem_get_info(obs_sceneitem_t item,
  659. struct obs_transform_info *info);
  660. EXPORT void obs_sceneitem_set_info(obs_sceneitem_t item,
  661. const struct obs_transform_info *info);
  662. EXPORT void obs_sceneitem_get_draw_transform(obs_sceneitem_t item,
  663. struct matrix4 *transform);
  664. EXPORT void obs_sceneitem_get_box_transform(obs_sceneitem_t item,
  665. struct matrix4 *transform);
  666. /* ------------------------------------------------------------------------- */
  667. /* Outputs */
  668. EXPORT const char *obs_output_get_display_name(const char *id);
  669. /**
  670. * Creates an output.
  671. *
  672. * Outputs allow outputting to file, outputting to network, outputting to
  673. * directshow, or other custom outputs.
  674. */
  675. EXPORT obs_output_t obs_output_create(const char *id, const char *name,
  676. obs_data_t settings);
  677. EXPORT void obs_output_destroy(obs_output_t output);
  678. EXPORT const char *obs_output_get_name(obs_output_t output);
  679. /** Starts the output. */
  680. EXPORT bool obs_output_start(obs_output_t output);
  681. /** Stops the output. */
  682. EXPORT void obs_output_stop(obs_output_t output);
  683. /** Returns whether the output is active */
  684. EXPORT bool obs_output_active(obs_output_t output);
  685. /** Gets the default settings for an output type */
  686. EXPORT obs_data_t obs_output_defaults(const char *id);
  687. /** Returns the property list, if any. Free with obs_properties_destroy */
  688. EXPORT obs_properties_t obs_get_output_properties(const char *id);
  689. /**
  690. * Returns the property list of an existing output, if any. Free with
  691. * obs_properties_destroy
  692. */
  693. EXPORT obs_properties_t obs_output_properties(obs_output_t output);
  694. /** Updates the settings for this output context */
  695. EXPORT void obs_output_update(obs_output_t output, obs_data_t settings);
  696. /** Specifies whether the output can be paused */
  697. EXPORT bool obs_output_canpause(obs_output_t output);
  698. /** Pauses the output (if the functionality is allowed by the output */
  699. EXPORT void obs_output_pause(obs_output_t output);
  700. /* Gets the current output settings string */
  701. EXPORT obs_data_t obs_output_get_settings(obs_output_t output);
  702. /** Returns the signal handler for an output */
  703. EXPORT signal_handler_t obs_output_get_signal_handler(obs_output_t output);
  704. /** Returns the procedure handler for an output */
  705. EXPORT proc_handler_t obs_output_get_proc_handler(obs_output_t output);
  706. /**
  707. * Sets the current video media context associated with this output,
  708. * required for non-encoded outputs
  709. */
  710. EXPORT void obs_output_set_video(obs_output_t output, video_t video);
  711. /**
  712. * Sets the current audio/video media contexts associated with this output,
  713. * required for non-encoded outputs. Can be null.
  714. */
  715. EXPORT void obs_output_set_media(obs_output_t output,
  716. video_t video, audio_t audio);
  717. /** Returns the video media context associated with this output */
  718. EXPORT video_t obs_output_video(obs_output_t output);
  719. /** Returns the audio media context associated with this output */
  720. EXPORT audio_t obs_output_audio(obs_output_t output);
  721. /**
  722. * Sets the current video encoder associated with this output,
  723. * required for encoded outputs
  724. */
  725. EXPORT void obs_output_set_video_encoder(obs_output_t output,
  726. obs_encoder_t encoder);
  727. /**
  728. * Sets the current audio encoder associated with this output,
  729. * required for encoded outputs
  730. */
  731. EXPORT void obs_output_set_audio_encoder(obs_output_t output,
  732. obs_encoder_t encoder);
  733. /** Returns the current video encoder associated with this output */
  734. EXPORT obs_encoder_t obs_output_get_video_encoder(obs_output_t output);
  735. /** Returns the current audio encoder associated with this output */
  736. EXPORT obs_encoder_t obs_output_get_audio_encoder(obs_output_t output);
  737. /** Sets the current service associated with this output. */
  738. EXPORT void obs_output_set_service(obs_output_t output, obs_service_t service);
  739. /** Gets the current service associated with this output. */
  740. EXPORT obs_service_t obs_output_get_service(obs_output_t output);
  741. /**
  742. * Sets the reconnect settings. Set retry_count to 0 to disable reconnecting.
  743. */
  744. EXPORT void obs_output_set_reconnect_settings(obs_output_t output,
  745. int retry_count, int retry_sec);
  746. EXPORT uint64_t obs_output_get_total_bytes(obs_output_t output);
  747. EXPORT int obs_output_get_frames_dropped(obs_output_t output);
  748. EXPORT int obs_output_get_total_frames(obs_output_t output);
  749. /* ------------------------------------------------------------------------- */
  750. /* Functions used by outputs */
  751. /** Optionally sets the video conversion info. Used only for raw output */
  752. EXPORT void obs_output_set_video_conversion(obs_output_t output,
  753. const struct video_scale_info *conversion);
  754. /** Optionally sets the audio conversion info. Used only for raw output */
  755. EXPORT void obs_output_set_audio_conversion(obs_output_t output,
  756. const struct audio_convert_info *conversion);
  757. /** Returns whether data capture can begin with the specified flags */
  758. EXPORT bool obs_output_can_begin_data_capture(obs_output_t output,
  759. uint32_t flags);
  760. /** Initializes encoders (if any) */
  761. EXPORT bool obs_output_initialize_encoders(obs_output_t output, uint32_t flags);
  762. /**
  763. * Begins data capture from media/encoders.
  764. *
  765. * @param output Output context
  766. * @param flags Set this to 0 to use default output flags set in the
  767. * obs_output_info structure, otherwise set to a either
  768. * OBS_OUTPUT_VIDEO or OBS_OUTPUT_AUDIO to specify whether to
  769. * connect audio or video. This is useful for things like
  770. * ffmpeg which may or may not always want to use both audio
  771. * and video.
  772. * @return true if successful, false otherwise.
  773. */
  774. EXPORT bool obs_output_begin_data_capture(obs_output_t output, uint32_t flags);
  775. /** Ends data capture from media/encoders */
  776. EXPORT void obs_output_end_data_capture(obs_output_t output);
  777. /**
  778. * Signals that the output has stopped itself.
  779. *
  780. * @param output Output context
  781. * @param code Error code (or OBS_OUTPUT_SUCCESS if not an error)
  782. */
  783. EXPORT void obs_output_signal_stop(obs_output_t output, int code);
  784. /* ------------------------------------------------------------------------- */
  785. /* Encoders */
  786. EXPORT const char *obs_encoder_getdisplayname(const char *id);
  787. /**
  788. * Creates a video encoder context
  789. *
  790. * @param id Video encoder ID
  791. * @param name Name to assign to this context
  792. * @param settings Settings
  793. * @return The video encoder context, or NULL if failed or not found.
  794. */
  795. EXPORT obs_encoder_t obs_video_encoder_create(const char *id, const char *name,
  796. obs_data_t settings);
  797. /**
  798. * Creates an audio encoder context
  799. *
  800. * @param id Audio Encoder ID
  801. * @param name Name to assign to this context
  802. * @param settings Settings
  803. * @return The video encoder context, or NULL if failed or not found.
  804. */
  805. EXPORT obs_encoder_t obs_audio_encoder_create(const char *id, const char *name,
  806. obs_data_t settings);
  807. /** Destroys an encoder context */
  808. EXPORT void obs_encoder_destroy(obs_encoder_t encoder);
  809. EXPORT const char *obs_encoder_get_name(obs_encoder_t encoder);
  810. /** Returns the codec of the encoder */
  811. EXPORT const char *obs_encoder_get_codec(obs_encoder_t encoder);
  812. /** Gets the default settings for an encoder type */
  813. EXPORT obs_data_t obs_encoder_defaults(const char *id);
  814. /** Returns the property list, if any. Free with obs_properties_destroy */
  815. EXPORT obs_properties_t obs_get_encoder_properties(const char *id);
  816. /**
  817. * Returns the property list of an existing encoder, if any. Free with
  818. * obs_properties_destroy
  819. */
  820. EXPORT obs_properties_t obs_encoder_properties(obs_encoder_t encoder);
  821. /**
  822. * Updates the settings of the encoder context. Usually used for changing
  823. * bitrate while active
  824. */
  825. EXPORT void obs_encoder_update(obs_encoder_t encoder, obs_data_t settings);
  826. /** Gets extra data (headers) associated with this context */
  827. EXPORT bool obs_encoder_get_extra_data(obs_encoder_t encoder,
  828. uint8_t **extra_data, size_t *size);
  829. /** Returns the current settings for this encoder */
  830. EXPORT obs_data_t obs_encoder_get_settings(obs_encoder_t encoder);
  831. /** Sets the video output context to be used with this encoder */
  832. EXPORT void obs_encoder_set_video(obs_encoder_t encoder, video_t video);
  833. /** Sets the audio output context to be used with this encoder */
  834. EXPORT void obs_encoder_set_audio(obs_encoder_t encoder, audio_t audio);
  835. /**
  836. * Returns the video output context used with this encoder, or NULL if not
  837. * a video context
  838. */
  839. EXPORT video_t obs_encoder_video(obs_encoder_t encoder);
  840. /**
  841. * Returns the audio output context used with this encoder, or NULL if not
  842. * a audio context
  843. */
  844. EXPORT audio_t obs_encoder_audio(obs_encoder_t encoder);
  845. /** Returns true if encoder is active, false otherwise */
  846. EXPORT bool obs_encoder_active(obs_encoder_t encoder);
  847. /** Duplicates an encoder packet */
  848. EXPORT void obs_duplicate_encoder_packet(struct encoder_packet *dst,
  849. const struct encoder_packet *src);
  850. EXPORT void obs_free_encoder_packet(struct encoder_packet *packet);
  851. /* ------------------------------------------------------------------------- */
  852. /* Stream Services */
  853. EXPORT const char *obs_service_get_display_name(const char *id);
  854. EXPORT obs_service_t obs_service_create(const char *id, const char *name,
  855. obs_data_t settings);
  856. EXPORT void obs_service_destroy(obs_service_t service);
  857. EXPORT const char *obs_service_get_name(obs_service_t service);
  858. /** Gets the default settings for a service */
  859. EXPORT obs_data_t obs_service_defaults(const char *id);
  860. /** Returns the property list, if any. Free with obs_properties_destroy */
  861. EXPORT obs_properties_t obs_get_service_properties(const char *id);
  862. /**
  863. * Returns the property list of an existing service context, if any. Free with
  864. * obs_properties_destroy
  865. */
  866. EXPORT obs_properties_t obs_service_properties(obs_service_t service);
  867. /** Gets the service type */
  868. EXPORT const char *obs_service_gettype(obs_service_t service);
  869. /** Updates the settings of the service context */
  870. EXPORT void obs_service_update(obs_service_t service, obs_data_t settings);
  871. /** Returns the current settings for this service */
  872. EXPORT obs_data_t obs_service_get_settings(obs_service_t service);
  873. /** Returns the URL for this service context */
  874. EXPORT const char *obs_service_get_url(obs_service_t service);
  875. /** Returns the stream key (if any) for this service context */
  876. EXPORT const char *obs_service_get_key(obs_service_t service);
  877. /** Returns the username (if any) for this service context */
  878. EXPORT const char *obs_service_get_username(obs_service_t service);
  879. /** Returns the password (if any) for this service context */
  880. EXPORT const char *obs_service_get_password(obs_service_t service);
  881. /* ------------------------------------------------------------------------- */
  882. /* Source frame allocation functions */
  883. EXPORT void obs_source_frame_init(struct obs_source_frame *frame,
  884. enum video_format format, uint32_t width, uint32_t height);
  885. static inline void obs_source_frame_free(struct obs_source_frame *frame)
  886. {
  887. if (frame) {
  888. bfree(frame->data[0]);
  889. memset(frame, 0, sizeof(*frame));
  890. }
  891. }
  892. static inline struct obs_source_frame *obs_source_frame_create(
  893. enum video_format format, uint32_t width, uint32_t height)
  894. {
  895. struct obs_source_frame *frame;
  896. frame = (struct obs_source_frame*)bzalloc(sizeof(*frame));
  897. obs_source_frame_init(frame, format, width, height);
  898. return frame;
  899. }
  900. static inline void obs_source_frame_destroy(struct obs_source_frame *frame)
  901. {
  902. if (frame) {
  903. bfree(frame->data[0]);
  904. bfree(frame);
  905. }
  906. }
  907. #ifdef __cplusplus
  908. }
  909. #endif