obs.h 33 KB

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