obs.h 30 KB

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