obs.h 36 KB

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