obs.h 33 KB

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