obs.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /******************************************************************************
  2. Copyright (C) 2013 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. /*
  25. * Main libobs header used by applications.
  26. */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* LIBOBS_API_VER must be returned by module_version in each module */
  31. #define LIBOBS_API_MAJOR_VER 0 /* increment if major breaking changes */
  32. #define LIBOBS_API_MINOR_VER 1 /* increment if minor non-breaking additions */
  33. #define LIBOBS_API_VER ((LIBOBS_API_MAJOR_VER << 16) | \
  34. LIBOBS_API_MINOR_VER)
  35. enum obs_source_type {
  36. SOURCE_INPUT,
  37. SOURCE_FILTER,
  38. SOURCE_TRANSITION,
  39. SOURCE_SCENE
  40. };
  41. enum obs_encoder_type {
  42. ENCODER_VIDEO,
  43. ENCODER_AUDIO
  44. };
  45. enum obs_video_type {
  46. OBS_VIDEO_YUV,
  47. OBS_VIDEO_RGB
  48. };
  49. /* used for changing the order of items (for example, filters in a source,
  50. * or items in a scene) */
  51. enum order_movement {
  52. ORDER_MOVE_UP,
  53. ORDER_MOVE_DOWN,
  54. ORDER_MOVE_TOP,
  55. ORDER_MOVE_BOTTOM
  56. };
  57. enum allow_direct_render {
  58. NO_DIRECT_RENDERING,
  59. ALLOW_DIRECT_RENDERING,
  60. };
  61. struct obs_video_info {
  62. /* graphics module to use (usually "libobs-opengl" or "libobs-d3d11") */
  63. const char *graphics_module;
  64. /* output fps numerator and denominator */
  65. uint32_t fps_num;
  66. uint32_t fps_den;
  67. /* window dimensions for what's drawn on screen */
  68. uint32_t window_width;
  69. uint32_t window_height;
  70. /* base compositing dimensions */
  71. uint32_t base_width;
  72. uint32_t base_height;
  73. /* output dimensions and format */
  74. uint32_t output_width;
  75. uint32_t output_height;
  76. enum video_format output_format;
  77. /* video adapter ID to use (NOTE: do not use for optimus laptops) */
  78. uint32_t adapter;
  79. /* window to render */
  80. struct gs_window window;
  81. };
  82. struct filtered_audio {
  83. void *data;
  84. uint32_t frames;
  85. uint64_t timestamp;
  86. };
  87. struct source_audio {
  88. const void *data;
  89. uint32_t frames;
  90. /* audio will be automatically resampled/upmixed/downmixed */
  91. enum speaker_layout speakers;
  92. enum audio_format format;
  93. uint32_t samples_per_sec;
  94. /* can be 0 if 'immediate' */
  95. uint64_t timestamp;
  96. };
  97. struct source_frame {
  98. void *data;
  99. uint32_t width;
  100. uint32_t height;
  101. uint32_t row_bytes;
  102. uint64_t timestamp;
  103. enum video_format format;
  104. float yuv_matrix[16];
  105. bool flip;
  106. };
  107. static inline void source_frame_destroy(struct source_frame *frame)
  108. {
  109. if (frame) {
  110. bfree(frame->data);
  111. bfree(frame);
  112. }
  113. }
  114. enum packet_priority {
  115. PACKET_PRIORITY_DISPOSABLE,
  116. PACKET_PRIORITY_LOW,
  117. PACKET_PRIORITY_PFRAME,
  118. PACKET_PRIORITY_IFRAME,
  119. PACKET_PRIORITY_OTHER /* audio usually */
  120. };
  121. struct encoder_packet {
  122. int64_t dts;
  123. int64_t pts;
  124. void *data;
  125. size_t size;
  126. enum packet_priority priority;
  127. };
  128. /* opaque types */
  129. struct obs_display;
  130. struct obs_source;
  131. struct obs_scene;
  132. struct obs_scene_item;
  133. struct obs_output;
  134. struct obs_encoder;
  135. struct obs_service;
  136. typedef struct obs_display *obs_display_t;
  137. typedef struct obs_source *obs_source_t;
  138. typedef struct obs_scene *obs_scene_t;
  139. typedef struct obs_scene_item *obs_sceneitem_t;
  140. typedef struct obs_output *obs_output_t;
  141. typedef struct obs_encoder *obs_encoder_t;
  142. typedef struct obs_service *obs_service_t;
  143. /* ------------------------------------------------------------------------- */
  144. /* OBS context */
  145. /**
  146. * Starts up and shuts down OBS
  147. *
  148. * Creates the OBS context.
  149. */
  150. EXPORT bool obs_startup(void);
  151. EXPORT void obs_shutdown(void);
  152. /**
  153. * Sets base video ouput base resolution/fps/format
  154. *
  155. * NOTE: Cannot set base video if currently streaming/recording.
  156. */
  157. EXPORT bool obs_reset_video(struct obs_video_info *ovi);
  158. /**
  159. * Sets base audio output format/channels/samples/etc
  160. *
  161. * NOTE: Cannot reset base audio if currently streaming/recording.
  162. */
  163. EXPORT bool obs_reset_audio(struct audio_output_info *ai);
  164. /** Gets the current video settings, returns false if none */
  165. EXPORT bool obs_get_video_info(struct obs_video_info *ovi);
  166. /** Gets the current audio settings, returns false if none */
  167. EXPORT bool obs_get_audio_info(struct audio_output_info *ai);
  168. /**
  169. * Loads a plugin module
  170. *
  171. * A plugin module contains exports for inputs/fitlers/transitions/outputs.
  172. * See obs-source.h and obs-output.h for more information on the exports to
  173. * use.
  174. */
  175. EXPORT int obs_load_module(const char *path);
  176. /**
  177. * Enumerates all available inputs source types.
  178. *
  179. * Inputs are general source inputs (such as capture sources, device sources,
  180. * etc).
  181. */
  182. EXPORT bool obs_enum_input_types(size_t idx, const char **id);
  183. /**
  184. * Enumerates all available filter source types.
  185. *
  186. * Filters are sources that are used to modify the video/audio output of
  187. * other sources.
  188. */
  189. EXPORT bool obs_enum_filter_types(size_t idx, const char **id);
  190. /**
  191. * Enumerates all available transition source types.
  192. *
  193. * Transitions are sources used to transition between two or more other
  194. * sources.
  195. */
  196. EXPORT bool obs_enum_transition_types(size_t idx, const char **id);
  197. /**
  198. * Enumerates all available ouput types.
  199. *
  200. * Outputs handle color space conversion, encoding, and output to file or
  201. * streams.
  202. */
  203. EXPORT bool obs_enum_output_types(size_t idx, const char **id);
  204. /** Gets the graphics context for this OBS context */
  205. EXPORT graphics_t obs_graphics(void);
  206. EXPORT audio_t obs_audio(void);
  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. /* ------------------------------------------------------------------------- */
  259. /* Display context */
  260. /**
  261. * Creates an extra display context.
  262. *
  263. * An extra display can be used for things like separate previews,
  264. * viewing sources independently, and other things. Creates a new swap chain
  265. * linked to a specific window to display a source.
  266. */
  267. EXPORT obs_display_t obs_display_create(struct gs_init_data *graphics_data);
  268. EXPORT void obs_display_destroy(obs_display_t display);
  269. /** Sets the source to be used for a display context. */
  270. EXPORT void obs_display_setsource(obs_display_t display, uint32_t channel,
  271. obs_source_t source);
  272. EXPORT obs_source_t obs_display_getsource(obs_display_t display,
  273. uint32_t channel);
  274. /* ------------------------------------------------------------------------- */
  275. /* Sources */
  276. /**
  277. * Gets the translated display name of a source
  278. */
  279. EXPORT const char *obs_source_getdisplayname(enum obs_source_type type,
  280. const char *id, const char *locale);
  281. /**
  282. * Creates a source of the specified type with the specified settings.
  283. *
  284. * The "source" context is used for anything related to presenting
  285. * or modifying video/audio. Use obs_source_release to release it.
  286. */
  287. EXPORT obs_source_t obs_source_create(enum obs_source_type type,
  288. const char *id, const char *name, const char *settings);
  289. /**
  290. * Adds/releases a reference to a source. When the last reference is
  291. * released, the source is destroyed.
  292. */
  293. EXPORT int obs_source_addref(obs_source_t source);
  294. EXPORT int obs_source_release(obs_source_t source);
  295. /** Notifies all references that the source should be released */
  296. EXPORT void obs_source_remove(obs_source_t source);
  297. /** Returns true if the source should be released */
  298. EXPORT bool obs_source_removed(obs_source_t source);
  299. /**
  300. * Retrieves flags that specify what type of data the source presents/modifies.
  301. *
  302. * SOURCE_VIDEO if it presents/modifies video_frame
  303. * SOURCE_ASYNC if the video is asynchronous.
  304. * SOURCE_AUDIO if it presents/modifies audio (always async)
  305. */
  306. EXPORT uint32_t obs_source_get_output_flags(obs_source_t source);
  307. /** Specifies whether the source can be configured */
  308. EXPORT bool obs_source_hasconfig(obs_source_t source);
  309. /** Opens a configuration panel and attaches it to the parent window */
  310. EXPORT void obs_source_config(obs_source_t source, void *parent);
  311. /** Renders a video source. */
  312. EXPORT void obs_source_video_render(obs_source_t source);
  313. /** Gets the width of a source (if it has video) */
  314. EXPORT uint32_t obs_source_getwidth(obs_source_t source);
  315. /** Gets the height of a source (if it has video) */
  316. EXPORT uint32_t obs_source_getheight(obs_source_t source);
  317. /**
  318. * Gets a custom parameter from the source.
  319. *
  320. * Used for efficiently modifying source properties in real time.
  321. */
  322. EXPORT size_t obs_source_getparam(obs_source_t source, const char *param,
  323. void *buf, size_t buf_size);
  324. /**
  325. * Sets a custom parameter for the source.
  326. *
  327. * Used for efficiently modifying source properties in real time.
  328. */
  329. EXPORT void obs_source_setparam(obs_source_t source, const char *param,
  330. const void *data, size_t size);
  331. /** If the source is a filter, returns the parent source of the filter */
  332. EXPORT obs_source_t obs_filter_getparent(obs_source_t filter);
  333. /** If the source is a filter, returns the target source of the filter */
  334. EXPORT obs_source_t obs_filter_gettarget(obs_source_t filter);
  335. /** Adds a filter to the source (which is used whenever the source is used) */
  336. EXPORT void obs_source_filter_add(obs_source_t source, obs_source_t filter);
  337. /** Removes a filter from the source */
  338. EXPORT void obs_source_filter_remove(obs_source_t source, obs_source_t filter);
  339. /** Modifies the order of a specific filter */
  340. EXPORT void obs_source_filter_setorder(obs_source_t source, obs_source_t filter,
  341. enum order_movement movement);
  342. /** Gets the settings string for a source */
  343. EXPORT const char *obs_source_getsettings(obs_source_t source);
  344. /** Gets the name of a source */
  345. EXPORT const char *obs_source_getname(obs_source_t source);
  346. /** Sets the name of a source */
  347. EXPORT void obs_source_setname(obs_source_t source, const char *name);
  348. /** Gets the source type and identifier */
  349. EXPORT void obs_source_gettype(obs_source_t source, enum obs_source_type *type,
  350. const char **id);
  351. /** Returns the signal handler for a source */
  352. EXPORT signal_handler_t obs_source_signalhandler(obs_source_t source);
  353. /** Returns the procedure handler for a source */
  354. EXPORT proc_handler_t obs_source_prochandler(obs_source_t source);
  355. /** Sets the volume for a source that has audio output */
  356. EXPORT void obs_source_setvolume(obs_source_t source, float volume);
  357. /** Gets the volume for a source that has audio output */
  358. EXPORT float obs_source_getvolume(obs_source_t source);
  359. /* ------------------------------------------------------------------------- */
  360. /* Functions used by sources */
  361. /** Saves the settings string for a source */
  362. EXPORT void obs_source_savesettings(obs_source_t source, const char *settings);
  363. /** Outputs asynchronous video data */
  364. EXPORT void obs_source_output_video(obs_source_t source,
  365. const struct source_frame *frame);
  366. /** Outputs audio data (always asynchronous) */
  367. EXPORT void obs_source_output_audio(obs_source_t source,
  368. const struct source_audio *audio);
  369. /** Gets the current async video frame */
  370. EXPORT struct source_frame *obs_source_getframe(obs_source_t source);
  371. /** Releases the current async video frame */
  372. EXPORT void obs_source_releaseframe(obs_source_t source,
  373. struct source_frame *frame);
  374. /** Default RGB filter handler for generic effect filters */
  375. EXPORT void obs_source_process_filter(obs_source_t filter,
  376. texrender_t texrender, effect_t effect,
  377. uint32_t width, uint32_t height,
  378. enum allow_direct_render allow_direct);
  379. /* ------------------------------------------------------------------------- */
  380. /* Scenes */
  381. /**
  382. * Creates a scene.
  383. *
  384. * A scene is a source which is a container of other sources with specific
  385. * display oriantations. Scenes can also be used like any other source.
  386. */
  387. EXPORT obs_scene_t obs_scene_create(const char *name);
  388. EXPORT int obs_scene_addref(obs_scene_t scene);
  389. EXPORT int obs_scene_release(obs_scene_t scene);
  390. /** Gets the scene's source context */
  391. EXPORT obs_source_t obs_scene_getsource(obs_scene_t scene);
  392. /** Gets the scene from its source, or NULL if not a scene */
  393. EXPORT obs_scene_t obs_scene_fromsource(obs_source_t source);
  394. /** Determines whether a source is within a scene */
  395. EXPORT obs_sceneitem_t obs_scene_findsource(obs_scene_t scene,
  396. const char *name);
  397. /** Enumerates sources within a scene */
  398. EXPORT void obs_scene_enum_items(obs_scene_t scene,
  399. bool (*callback)(obs_scene_t, obs_sceneitem_t, void*),
  400. void *param);
  401. /** Adds/creates a new scene item for a source */
  402. EXPORT obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source);
  403. /** Removes/destroys a scene item. Returns the source reference counter
  404. * (if any) */
  405. EXPORT int obs_sceneitem_destroy(obs_sceneitem_t item);
  406. /** Gets the scene parent associated with the scene item */
  407. EXPORT obs_scene_t obs_sceneitem_getscene(obs_sceneitem_t item);
  408. /** Gets the source of a scene item */
  409. EXPORT obs_source_t obs_sceneitem_getsource(obs_sceneitem_t item);
  410. /* Functions for gettings/setting specific oriantation of a scene item */
  411. EXPORT void obs_sceneitem_setpos(obs_sceneitem_t item, const struct vec2 *pos);
  412. EXPORT void obs_sceneitem_setrot(obs_sceneitem_t item, float rot);
  413. EXPORT void obs_sceneitem_setorigin(obs_sceneitem_t item,
  414. const struct vec2 *origin);
  415. EXPORT void obs_sceneitem_setscale(obs_sceneitem_t item,
  416. const struct vec2 *scale);
  417. EXPORT void obs_sceneitem_setorder(obs_sceneitem_t item,
  418. enum order_movement movement);
  419. EXPORT void obs_sceneitem_getpos(obs_sceneitem_t item, struct vec2 *pos);
  420. EXPORT float obs_sceneitem_getrot(obs_sceneitem_t item);
  421. EXPORT void obs_sceneitem_getorigin(obs_sceneitem_t item, struct vec2 *center);
  422. EXPORT void obs_sceneitem_getscale(obs_sceneitem_t item, struct vec2 *scale);
  423. /* ------------------------------------------------------------------------- */
  424. /* Outputs */
  425. EXPORT const char *obs_output_getdisplayname(const char *id,
  426. const char *locale);
  427. /**
  428. * Creates an output.
  429. *
  430. * Outputs allow outputting to file, outputting to network, outputting to
  431. * directshow, or other custom outputs.
  432. */
  433. EXPORT obs_output_t obs_output_create(const char *id, const char *name,
  434. const char *settings);
  435. EXPORT void obs_output_destroy(obs_output_t output);
  436. /** Starts the output. */
  437. EXPORT bool obs_output_start(obs_output_t output);
  438. /** Stops the output. */
  439. EXPORT void obs_output_stop(obs_output_t output);
  440. /** Returns whether the output is active */
  441. EXPORT bool obs_output_active(obs_output_t output);
  442. /** Updates the settings for this output context */
  443. EXPORT void obs_output_update(obs_output_t output, const char *settings);
  444. /** Specifies whether the output can be paused */
  445. EXPORT bool obs_output_canpause(obs_output_t output);
  446. /** Pauses the output (if the functionality is allowed by the output */
  447. EXPORT void obs_output_pause(obs_output_t output);
  448. /* Gets the current output settings string */
  449. EXPORT const char *obs_output_get_settings(obs_output_t output);
  450. /* Saves the output settings string, typically used only by outputs */
  451. EXPORT void obs_output_save_settings(obs_output_t output,
  452. const char *settings);
  453. /* ------------------------------------------------------------------------- */
  454. /* Stream Encoders */
  455. EXPORT const char *obs_encoder_getdisplayname(const char *id,
  456. const char *locale);
  457. EXPORT obs_encoder_t obs_encoder_create(const char *id, const char *name,
  458. const char *settings);
  459. EXPORT void obs_encoder_destroy(obs_encoder_t encoder);
  460. EXPORT void obs_encoder_update(obs_encoder_t encoder, const char *settings);
  461. EXPORT bool obs_encoder_reset(obs_encoder_t encoder);
  462. EXPORT bool obs_encoder_encode(obs_encoder_t encoder, void *frames,
  463. size_t size);
  464. EXPORT int obs_encoder_getheader(obs_encoder_t encoder,
  465. struct encoder_packet **packets);
  466. EXPORT bool obs_encoder_start(obs_encoder_t encoder,
  467. void (*new_packet)(void *param, struct encoder_packet *packet),
  468. void *param);
  469. EXPORT bool obs_encoder_stop(obs_encoder_t encoder,
  470. void (*new_packet)(void *param, struct encoder_packet *packet),
  471. void *param);
  472. EXPORT bool obs_encoder_setbitrate(obs_encoder_t encoder, uint32_t bitrate,
  473. uint32_t buffersize);
  474. EXPORT bool obs_encoder_request_keyframe(obs_encoder_t encoder);
  475. EXPORT const char *obs_encoder_get_settings(obs_encoder_t encoder);
  476. EXPORT void obs_encoder_save_settings(obs_encoder_t encoder,
  477. const char *settings);
  478. /* ------------------------------------------------------------------------- */
  479. /* Stream Services */
  480. EXPORT const char *obs_service_getdisplayname(const char *id,
  481. const char *locale);
  482. EXPORT obs_service_t obs_service_create(const char *service,
  483. const char *settings);
  484. EXPORT void obs_service_destroy(obs_service_t service);
  485. EXPORT void obs_service_setdata(obs_service_t service, const char *attribute,
  486. const char *data);
  487. EXPORT const char *obs_service_getdata(obs_service_t service,
  488. const char *attribute);
  489. #ifdef __cplusplus
  490. }
  491. #endif