1
0

reference-sources.rst 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. Source API Reference (obs_source_t)
  2. ===================================
  3. Sources are used to render video and/or audio on stream. Things such as
  4. capturing displays/games/audio, playing a video, showing an image, or
  5. playing audio. Sources can also be used to implement audio and video
  6. filters as well as transitions. The `libobs/obs-source.h`_ file is the
  7. dedicated header for implementing sources.
  8. .. type:: obs_source_t
  9. A reference-counted video/audio input source.
  10. .. type:: obs_weak_source_t
  11. A weak reference to an video/audio input source.
  12. .. code:: cpp
  13. #include <obs.h>
  14. Source Definition Structure (obs_source_info)
  15. ---------------------------------------------
  16. .. type:: struct obs_source_info
  17. Source definition structure.
  18. .. member:: const char *obs_source_info.id
  19. Unique string identifier for the source (required).
  20. .. member:: enum obs_source_type obs_source_info.type
  21. Type of source.
  22. - **OBS_SOURCE_TYPE_INPUT** - Video/Audio Input
  23. - **OBS_SOURCE_TYPE_FILTER** - Filter
  24. - **OBS_SOURCE_TYPE_TRANSITION** - Transition
  25. .. member:: uint32_t obs_source_info.output_flags
  26. Source output capability flags (required).
  27. (Author's note: This should be renamed to "capability_flags")
  28. A bitwise OR combination of one or more of the following values:
  29. - **OBS_SOURCE_VIDEO** - Source has video
  30. Unless SOURCE_ASYNC_VIDEO is specified, the source must include the
  31. :c:member:`obs_source_info.video_render` callback in the source
  32. definition structure.
  33. - **OBS_SOURCE_AUDIO** - Source has audio
  34. Use the :c:func:`obs_source_output_audio()` function to pass raw
  35. audio data, which will be automatically converted and uploaded. If
  36. used with OBS_SOURCE_ASYNC_VIDEO, audio will automatically be
  37. synced up to the video output based upon their mutual timestamps.
  38. - **OBS_SOURCE_ASYNC** - Video is asynchronous (use
  39. OBS_SOURCE_ASYNC_VIDEO instead to automatically combine this flag
  40. with the OBS_SOURCE_VIDEO flag).
  41. - **OBS_SOURCE_ASYNC_VIDEO** - Source passes raw video data via RAM
  42. Use the :c:func:`obs_source_output_video()` function to pass raw
  43. video data, which will be automatically drawn at a timing relative
  44. to the provided timestamp.
  45. If audio is also present on the source, the audio will
  46. automatically be synced to the video based upon their mutual
  47. timestamps.
  48. - **OBS_SOURCE_CUSTOM_DRAW** - Source uses custom graphics calls,
  49. rather than just rendering a single texture.
  50. This capability flag must be used if the source does not use
  51. :c:func:`obs_source_draw()` to render a single texture.
  52. This capability flag is an important hint to turn off a specific
  53. optimization that allows the first effect filter in the filter
  54. chain to render the source directly with that effect filter. The
  55. optimization does not work if there are custom graphics calls, and
  56. the source must be rendered to a texture first before being sent to
  57. the first filter in the filter chain.
  58. (Author's note: Ironically, not many sources render with that
  59. optimization. I should have made it so that the optimization isn't
  60. used by default, and a flag should have been used to turn on the
  61. optimization -- not turn it off).
  62. - **OBS_SOURCE_INTERACTION** - Source can be interacted with by the
  63. user.
  64. When this is used, the source will receive interaction events if
  65. theese callbacks are provided:
  66. :c:member:`obs_source_info.mouse_click`,
  67. :c:member:`obs_source_info.mouse_move`,
  68. :c:member:`obs_source_info.mouse_wheel`,
  69. :c:member:`obs_source_info.focus`, and
  70. :c:member:`obs_source_info.key_click`.
  71. - **OBS_SOURCE_COMPOSITE** - Source composites child sources
  72. When used, specifies that the source composites one or more child
  73. sources. Scenes and transitions are examples of sources that
  74. contain and render child sources.
  75. Sources that render sub-sources must implement the audio_render
  76. callback in order to perform custom audio mixing of child sources.
  77. This capability flag is always set for transitions.
  78. - **OBS_SOURCE_DO_NOT_DUPLICATE** - Source should not be fully
  79. duplicated.
  80. When this is used, specifies that the source should not be fully
  81. duplicated, and should prefer to duplicate via holding references
  82. rather than full duplication.
  83. When functions such as :c:func:`obs_source_duplicate()` or
  84. :c:func:`obs_scene_duplicate()` are called, sources or child
  85. sources with this flag will never be fully duplicated, and will
  86. instead only be referenced.
  87. An example of the type of sources that should not be fully
  88. duplicated are video devices, browsers, and video/audio captures,
  89. as they will either not function correctly or will cause
  90. performance or resource issues when duplicated.
  91. - **OBS_SOURCE_DEPRECATED** - Source is deprecated and should not be
  92. used.
  93. - **OBS_SOURCE_DO_NOT_SELF_MONITOR** - Audio of this source should
  94. not allow monitoring if the current monitoring device is the same
  95. device being captured by the source.
  96. This flag is used as a hint to the back-end to prevent the source
  97. from creating an audio feedback loop. This is primarily only used
  98. with desktop audio capture sources.
  99. .. member:: const char *(*obs_source_info.get_name)(void *type_data)
  100. Get the translated name of the source type.
  101. :param type_data: The type_data variable of this structure
  102. :return: The translated name of the source type
  103. .. member:: void *(*obs_source_info.create)(obs_data_t *settings, obs_source_t *source)
  104. Creates the implementation data for the source.
  105. :param settings: Settings to initialize the source with
  106. :param source: Source that this data is associated with
  107. :return: The implementation data associated with this source
  108. .. member:: void (*obs_source_info.destroy)(void *data)
  109. Destroys the implementation data for the source.
  110. Async sources must not call obs_source_output_video after returning
  111. from destroy.
  112. .. member:: uint32_t (*obs_source_info.get_width)(void *data)
  113. uint32_t (*obs_source_info.get_height)(void *data);
  114. Returns the width/height of the source. These callbacks are required
  115. if this is a video source and is synchronous.
  116. (Author's note: These should really be consolidated in to one
  117. function, not two)
  118. :return: The width/height of the video
  119. .. member:: void (*obs_source_info.get_defaults)(obs_data_t *settings)
  120. void (*obs_source_info.get_defaults2)(void *type_data, obs_data_t *settings)
  121. Sets the default settings for this source.
  122. :param settings: Default settings. Call obs_data_set_default*
  123. functions on this object to set default setting
  124. values
  125. .. member:: obs_properties_t *(*obs_source_info.get_properties)(void *data)
  126. obs_properties_t *(*obs_source_info.get_properties2)(void *data, void *type_data)
  127. Gets the property information of this source.
  128. (Optional)
  129. :return: The properties of the source
  130. .. member:: void (*obs_source_info.update)(void *data, obs_data_t *settings)
  131. Updates the settings for this source.
  132. (Optional)
  133. :param settings: New settings for this source
  134. .. member:: void (*obs_source_info.activate)(void *data)
  135. Called when the source has been activated in the main view (visible
  136. on stream/recording).
  137. (Optional)
  138. .. member:: void (*obs_source_info.deactivate)(void *data)
  139. Called when the source has been deactivated from the main view (no
  140. longer visible on stream/recording).
  141. (Optional)
  142. .. member:: void (*obs_source_info.show)(void *data)
  143. Called when the source is visible on any display and/or on the main
  144. view.
  145. (Optional)
  146. .. member:: void (*obs_source_info.hide)(void *data)
  147. Called when the source is no longer visible on any display and/or on
  148. the main view.
  149. (Optional)
  150. .. member:: void (*obs_source_info.video_tick)(void *data, float seconds)
  151. Called each video frame with the time elapsed.
  152. (Optional)
  153. :param seconds: Seconds elapsed since the last frame
  154. .. member:: void (*obs_source_info.video_render)(void *data, gs_effect_t *effect)
  155. Called when rendering the source with the graphics subsystem.
  156. If this is an input/transition source, this is called to draw the
  157. source texture with the graphics subsystem.
  158. If this is a filter source, it wraps source draw calls (for example
  159. applying a custom effect with custom parameters to a source). In
  160. this case, it's highly recommended to use the
  161. :c:func:`obs_source_process_filter_begin()` and
  162. :c:func:`obs_source_process_filter_end()` functions to automatically
  163. handle effect-based filter processing. However, you can implement
  164. custom draw handling as desired as well.
  165. If the source output capability flags do not include
  166. OBS_SOURCE_CUSTOM_DRAW, the source must use
  167. :c:func:`obs_source_draw()` to render the source's texture.
  168. :param effect: This parameter is no longer used. Instead, call
  169. :c:func:`obs_source_draw()`
  170. .. member:: struct obs_source_frame *(*obs_source_info.filter_video)(void *data, struct obs_source_frame *frame)
  171. Called to filter raw async video data. This function is only used
  172. with asynchronous video filters.
  173. :param frame: Video frame to filter
  174. :return: New video frame data. This can defer video data to
  175. be drawn later if time is needed for processing
  176. .. member:: struct obs_audio_data *(*obs_source_info.filter_audio)(void *data, struct obs_audio_data *audio)
  177. Called to filter raw audio data. This function is only used with
  178. audio filters.
  179. :param audio: Audio data to filter
  180. :return: Modified or new audio data. You can directly modify
  181. the data passed and return it, or you can defer audio
  182. data for later if time is needed for processing. If
  183. you are returning new data, that data must exist until
  184. the next call to the
  185. :c:member:`obs_source_info.filter_audio` callback or
  186. until the filter is removed/destroyed
  187. .. member:: void (*obs_source_info.enum_active_sources)(void *data, obs_source_enum_proc_t enum_callback, void *param)
  188. Called to enumerate all active sources being used within this
  189. source. If the source has children that render audio/video it must
  190. implement this callback. Only used with sources that have tha
  191. OBS_SOURCE_COMPOSITE output capability flag.
  192. :param enum_callback: Enumeration callback
  193. :param param: User data to pass to callback
  194. .. member:: void (*obs_source_info.save)(void *data, obs_data_t *settings)
  195. Called when saving custom data for a source. This is a separate
  196. function because sometimes a source needs to know when it is being
  197. saved so it doesn't always have to update the current settings until
  198. a certain point.
  199. (Optional)
  200. :param settings: Settings object to save data to
  201. .. member:: void (*obs_source_info.load)(void *data, obs_data_t *settings)
  202. Called when loading custom data from saved source data. This is
  203. called after all the loading sources have actually been created,
  204. allowing the ability to reference other sources if desired.
  205. (Optional)
  206. :param settings: Settings object to load data from
  207. .. member:: void (*obs_source_info.mouse_click)(void *data, const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count)
  208. Called when interacting with a source and a mouse-down or mouse-up
  209. occurs. Only used with sources that have the OBS_SOURCE_INTERACTION
  210. output capability flag.
  211. (Optional)
  212. :param event: Mouse event properties
  213. :param type: Mouse button pushed
  214. :param mouse_up: Mouse event type (true if mouse-up)
  215. :param click_count: Mouse click count (1 for single click, etc.)
  216. .. member:: void (*obs_source_info.mouse_move)(void *data, const struct obs_mouse_event *event, bool mouse_leave)
  217. Called when interacting with a source and a mouse-move occurs. Only
  218. used with sources that have the OBS_SOURCE_INTERACTION output
  219. capability flag.
  220. (Optional)
  221. :param event: Mouse event properties
  222. :param mouse_leave: Mouse leave state (true if mouse left source)
  223. .. member:: void (*obs_source_info.mouse_wheel)(void *data, const struct obs_mouse_event *event, int x_delta, int y_delta)
  224. Called when interacting with a source and a mouse-wheel occurs. Only
  225. used with sources that have the OBS_SOURCE_INTERACTION output
  226. capability flag.
  227. (Optional)
  228. :param event: Mouse event properties
  229. :param x_delta: Movement delta in the horizontal direction
  230. :param y_delta: Movement delta in the vertical direction
  231. .. member:: void (*obs_source_info.focus)(void *data, bool focus)
  232. Called when interacting with a source and gain focus/lost focus event
  233. occurs. Only used with sources that have the OBS_SOURCE_INTERACTION
  234. output capability flag.
  235. (Optional)
  236. :param focus: Focus state (true if focus gained)
  237. .. member:: void (*obs_source_info.key_click)(void *data, const struct obs_key_event *event, bool key_up)
  238. Called when interacting with a source and a key-up or key-down
  239. occurs. Only used with sources that have the OBS_SOURCE_INTERACTION
  240. output capability flag.
  241. (Optional)
  242. :param event: Key event properties
  243. :param focus: Key event type (true if mouse-up)
  244. .. member:: void (*obs_source_info.filter_remove)(void *data, obs_source_t *source)
  245. Called when the filter is removed from a source.
  246. (Optional)
  247. :param data: Filter data
  248. :param source: Source that the filter being removed from
  249. .. member:: void *obs_source_info.type_data
  250. void (*obs_source_info.free_type_data)(void *type_data)
  251. Private data associated with this entry. Note that this is not the
  252. same as the implementation data; this is used to differentiate
  253. between two different types if the same callbacks are used for more
  254. than one different type.
  255. .. member:: bool (*obs_source_info.audio_render)(void *data, uint64_t *ts_out, struct obs_source_audio_mix *audio_output, uint32_t mixers, size_t channels, size_t sample_rate)
  256. Called to render audio of composite sources. Only used with sources
  257. that have tha OBS_SOURCE_COMPOSITE output capability flag.
  258. .. member:: void (*obs_source_info.enum_all_sources)(void *data, obs_source_enum_proc_t enum_callback, void *param)
  259. Called to enumerate all active and inactive sources being used
  260. within this source. If this callback isn't implemented,
  261. enum_active_sources will be called instead. Only used with sources
  262. that have tha OBS_SOURCE_COMPOSITE output capability flag.
  263. This is typically used if a source can have inactive child sources.
  264. :param enum_callback: Enumeration callback
  265. :param param: User data to pass to callback
  266. .. member:: void (*obs_source_info.transition_start)(void *data)
  267. void (*obs_source_info.transition_stop)(void *data)
  268. Called on transition sources when the transition starts/stops.
  269. (Optional)
  270. .. _source_signal_handler_reference:
  271. Source Signals
  272. --------------
  273. **destroy** (ptr *source*)
  274. This signal is called when the source is about to be destroyed. Do
  275. not increment any references when using this signal.
  276. **remove** (ptr source)
  277. Called when the :c:func:`obs_source_remove()` function is called on
  278. the source.
  279. **save** (ptr source)
  280. Called when the source is being saved.
  281. **load** (ptr source)
  282. Called when the source is being loaded.
  283. **activate** (ptr source)
  284. Called when the source has been activated in the main view (visible
  285. on stream/recording).
  286. **deactivate** (ptr source)
  287. Called when the source has been deactivated from the main view (no
  288. longer visible on stream/recording).
  289. **show** (ptr source)
  290. Called when the source is visible on any display and/or on the main
  291. view.
  292. **hide** (ptr source)
  293. Called when the source is no longer visible on any display and/or on
  294. the main view.
  295. **mute** (ptr source, bool muted)
  296. Called when the source is muted/unmuted.
  297. **push_to_mute_changed** (ptr source, bool enabled)
  298. Called when push-to-mute has been enabled/disabled.
  299. **push_to_mute_delay** (ptr source, int delay)
  300. Called when the push-to-mute delay value has changed.
  301. **push_to_talk_changed** (ptr source, bool enabled)
  302. Called when push-to-talk has been enabled/disabled.
  303. **push_to_talk_delay** (ptr source, int delay)
  304. Called when the push-to-talk delay value has changed.
  305. **enable** (ptr source, bool enabled)
  306. Called when the source has been disabled/enabled.
  307. **rename** (ptr source, string new_name, string prev_name)
  308. Called when the source has been renamed.
  309. **volume** (ptr source, in out float volume)
  310. Called when the volume of the source has changed.
  311. **update_properties** (ptr source)
  312. Called when the properties of the source have been updated.
  313. **update_flags** (ptr source, int flags)
  314. Called when the flags of the source have been changed.
  315. **audio_sync** (ptr source, int out int offset)
  316. Called when the audio sync offset has changed.
  317. **audio_mixers** (ptr source, in out int mixers)
  318. Called when the audio mixers have changed.
  319. **filter_add** (ptr source, ptr filter)
  320. Called when a filter has been added to the source.
  321. **filter_remove** (ptr source, ptr filter)
  322. Called when a filter has been removed from the source.
  323. **reorder_filters** (ptr source)
  324. Called when filters have been reordered.
  325. **transition_start** (ptr source)
  326. Called when a transition is starting.
  327. **transition_video_stop** (ptr source)
  328. Called when a transition's video transitioning has stopped.
  329. **transition_stop** (ptr source)
  330. Called when a transition has stopped.
  331. General Source Functions
  332. ------------------------
  333. .. function:: void obs_register_source(struct obs_source_info *info)
  334. Registers a source type. Typically used in
  335. :c:func:`obs_module_load()` or in the program's initialization phase.
  336. ---------------------
  337. .. function:: const char *obs_source_get_display_name(const char *id)
  338. Calls the :c:member:`obs_source_info.get_name` callback to get the
  339. translated display name of a source type.
  340. :param id: The source type string identifier
  341. :return: The translated display name of a source type
  342. ---------------------
  343. .. function:: obs_source_t *obs_source_create(const char *id, const char *name, obs_data_t *settings, obs_data_t *hotkey_data)
  344. Creates a source of the specified type with the specified settings.
  345. The "source" context is used for anything related to presenting
  346. or modifying video/audio. Use obs_source_release to release it.
  347. :param id: The source type string identifier
  348. :param name: The desired name of the source. If this is
  349. not unique, it will be made to be unique
  350. :param settings: The settings for the source, or *NULL* if
  351. none
  352. :param hotkey_data: Saved hotkey data for the source, or *NULL*
  353. if none
  354. :return: A reference to the newly created source, or
  355. *NULL* if failed
  356. ---------------------
  357. .. function:: obs_source_t *obs_source_create_private(const char *id, const char *name, obs_data_t *settings)
  358. Creates a 'private' source which is not enumerated by
  359. :c:func:`obs_enum_sources()`, and is not saved by
  360. :c:func:`obs_save_sources()`.
  361. Author's Note: The existence of this function is a result of design
  362. flaw: the front-end should control saving/loading of sources, and
  363. functions like :c:func:`obs_enum_sources()` and
  364. :c:func:`obs_save_sources()` should not exist in the back-end.
  365. :param id: The source type string identifier
  366. :param name: The desired name of the source. For private
  367. sources, this does not have to be unique,
  368. and can additionally be *NULL* if desired
  369. :param settings: The settings for the source, or *NULL* if
  370. none
  371. :return: A reference to the newly created source, or
  372. *NULL* if failed
  373. ---------------------
  374. .. function:: obs_source_t *obs_source_duplicate(obs_source_t *source, const char *desired_name, bool create_private)
  375. Duplicates a source. If the source has the
  376. OBS_SOURCE_DO_NOT_DUPLICATE output flag set, this only returns a
  377. new reference to the same source.
  378. :param source: The source to duplicate
  379. :param desired_name: The desired name of the new source. If this is
  380. not a private source and the name is not unique,
  381. it will be made to be unique
  382. :param create_private: If *true*, the new source will be a private
  383. source if fully duplicated
  384. :return: A new source reference
  385. ---------------------
  386. .. function:: void obs_source_addref(obs_source_t *source)
  387. void obs_source_release(obs_source_t *source)
  388. Adds/releases a reference to a source. When the last reference is
  389. released, the source is destroyed.
  390. ---------------------
  391. .. function:: obs_weak_source_t *obs_source_get_weak_source(obs_source_t *source)
  392. obs_source_t *obs_weak_source_get_source(obs_weak_source_t *weak)
  393. These functions are used to get a weak reference from a strong source
  394. reference, or a strong source reference from a weak reference. If
  395. the source is destroyed, *obs_weak_source_get_source* will return
  396. *NULL*.
  397. ---------------------
  398. .. function:: void obs_weak_source_addref(obs_weak_source_t *weak)
  399. void obs_weak_source_release(obs_weak_source_t *weak)
  400. Adds/releases a weak reference to a source.
  401. ---------------------
  402. .. function:: void obs_source_remove(obs_source_t *source)
  403. Notifies all reference holders of the source (via
  404. :c:func:`obs_source_removed()`) that the source should be released.
  405. ---------------------
  406. .. function:: bool obs_source_removed(const obs_source_t *source)
  407. :return: *true* if the source should be released
  408. ---------------------
  409. .. function:: uint32_t obs_source_get_output_flags(const obs_source_t *source)
  410. uint32_t obs_get_source_output_flags(const char *id)
  411. :return: Capability flags of a source
  412. Author's Note: "Output flags" is poor wording in retrospect; this
  413. should have been named "Capability flags", and the OBS_SOURCE_*
  414. macros should really be OBS_SOURCE_CAP_* macros instead.
  415. See :c:member:`obs_source_info.output_flags` for more information.
  416. ---------------------
  417. .. function:: obs_data_t *obs_get_source_defaults(const char *id)
  418. Calls :c:member:`obs_source_info.get_defaults` to get the defaults
  419. settings of the source type.
  420. :return: The default settings for a source type
  421. ---------------------
  422. .. function:: obs_properties_t *obs_source_properties(const obs_source_t *source)
  423. obs_properties_t *obs_get_source_properties(const char *id)
  424. Use these functions to get the properties of a source or source type.
  425. Properties are optionally used (if desired) to automatically generate
  426. user interface widgets to allow users to update settings.
  427. :return: The properties list for a specific existing source. Free with
  428. :c:func:`obs_properties_destroy()`
  429. ---------------------
  430. .. function:: bool obs_source_configurable(const obs_source_t *source)
  431. bool obs_is_source_configurable(const char *id)
  432. :return: *true* if the the source has custom properties, *false*
  433. otherwise
  434. ---------------------
  435. .. function:: void obs_source_update(obs_source_t *source, obs_data_t *settings)
  436. Updates the settings for a source and calls the
  437. :c:member:`obs_source_info.update` callback of the source. If the
  438. source is a video source, the :c:member:`obs_source_info.update` will
  439. be not be called immediately; instead, it will be deferred to the
  440. video thread to prevent threading issues.
  441. ---------------------
  442. .. function:: void obs_source_video_render(obs_source_t *source)
  443. Renders a video source. This will call the
  444. :c:member:`obs_source_info.video_render` callback of the source.
  445. ---------------------
  446. .. function:: uint32_t obs_source_get_width(obs_source_t *source)
  447. uint32_t obs_source_get_height(obs_source_t *source)
  448. Calls the :c:member:`obs_source_info.get_width` or
  449. :c:member:`obs_source_info.get_height` of the source to get its width
  450. and/or height.
  451. Author's Note: These functions should be consolidated in to a single
  452. function/callback rather than having a function for both width and
  453. height.
  454. :return: The width or height of the source
  455. ---------------------
  456. .. function:: obs_data_t *obs_source_get_settings(const obs_source_t *source)
  457. :return: The settings string for a source. The reference counter of the
  458. returned settings data is incremented, so
  459. :c:func:`obs_data_release()` must be called when the
  460. settings are no longer used
  461. ---------------------
  462. .. function:: const char *obs_source_get_name(const obs_source_t *source)
  463. :return: The name of the source
  464. ---------------------
  465. .. function:: void obs_source_set_name(obs_source_t *source, const char *name)
  466. Sets the name of a source. If the source is not private and the name
  467. is not unique, it will automatically be given a unique name.
  468. ---------------------
  469. .. function:: enum obs_source_type obs_source_get_type(const obs_source_t *source)
  470. :return: | OBS_SOURCE_TYPE_INPUT for inputs
  471. | OBS_SOURCE_TYPE_FILTER for filters
  472. | OBS_SOURCE_TYPE_TRANSITION for transitions
  473. | OBS_SOURCE_TYPE_SCENE for scenes
  474. ---------------------
  475. .. function:: const char *obs_source_get_id(const obs_source_t *source)
  476. :return: The source's type identifier string
  477. ---------------------
  478. .. function:: signal_handler_t *obs_source_get_signal_handler(const obs_source_t *source)
  479. :return: The source's signal handler
  480. See the :ref:`source_signal_handler_reference` for more information
  481. on signals that are available for sources.
  482. ---------------------
  483. .. function:: proc_handler_t *obs_source_get_proc_handler(const obs_source_t *source)
  484. :return: The procedure handler for a source
  485. ---------------------
  486. .. function:: void obs_source_set_volume(obs_source_t *source, float volume)
  487. float obs_source_get_volume(const obs_source_t *source)
  488. Sets/gets the user volume for a source that has audio output.
  489. ---------------------
  490. .. function:: bool obs_source_muted(const obs_source_t *source)
  491. void obs_source_set_muted(obs_source_t *source, bool muted)
  492. Sets/gets whether the source's audio is muted.
  493. ---------------------
  494. .. function:: bool obs_source_push_to_mute_enabled(const obs_source_t *source)
  495. void obs_source_enable_push_to_mute(obs_source_t *source, bool enabled)
  496. Sets/gets whether push-to-mute is enabled.
  497. ---------------------
  498. .. function:: uint64_t obs_source_get_push_to_mute_delay(const obs_source_t *source)
  499. void obs_source_set_push_to_mute_delay(obs_source_t *source, uint64_t delay)
  500. Sets/gets the push-to-mute delay.
  501. ---------------------
  502. .. function:: bool obs_source_push_to_talk_enabled(const obs_source_t *source)
  503. void obs_source_enable_push_to_talk(obs_source_t *source, bool enabled)
  504. Sets/gets whether push-to-talk is enabled.
  505. ---------------------
  506. .. function:: uint64_t obs_source_get_push_to_talk_delay(const obs_source_t *source)
  507. void obs_source_set_push_to_talk_delay(obs_source_t *source, uint64_t delay)
  508. Sets/gets the push-to-talk delay.
  509. ---------------------
  510. .. function:: void obs_source_set_sync_offset(obs_source_t *source, int64_t offset)
  511. int64_t obs_source_get_sync_offset(const obs_source_t *source)
  512. Sets/gets the audio sync offset (in nanoseconds) for a source.
  513. ---------------------
  514. .. function:: void obs_source_enum_active_sources(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param)
  515. void obs_source_enum_active_tree(obs_source_t *source, obs_source_enum_proc_t enum_callback, void *param)
  516. Enumerates active child sources or source tree used by this source.
  517. Relevant data types used with this function:
  518. .. code:: cpp
  519. typedef void (*obs_source_enum_proc_t)(obs_source_t *parent,
  520. obs_source_t *child, void *param);
  521. ---------------------
  522. .. function:: bool obs_source_active(const obs_source_t *source)
  523. :return: *true* if active, *false* if not. A source is only
  524. consdiered active if it's being shown on the final mix
  525. ---------------------
  526. .. function:: bool obs_source_showing(const obs_source_t *source)
  527. :return: *true* if showing, *false* if not. A source is considered
  528. showing if it's being displayed anywhere at all, whether on
  529. a display context or on the final output
  530. ---------------------
  531. .. function:: void obs_source_inc_showing(obs_source_t *source)
  532. void obs_source_dec_showing(obs_source_t *source)
  533. Increments/decrements a source's "showing" state. Typically used
  534. when drawing a source on a display manually.
  535. ---------------------
  536. .. function:: void obs_source_set_flags(obs_source_t *source, uint32_t flags)
  537. uint32_t obs_source_get_flags(const obs_source_t *source)
  538. :param flags: OBS_SOURCE_FLAG_FORCE_MONO Forces audio to mono
  539. ---------------------
  540. .. function:: void obs_source_set_audio_mixers(obs_source_t *source, uint32_t mixers)
  541. uint32_t obs_source_get_audio_mixers(const obs_source_t *source)
  542. Sets/gets the audio mixer channels that a source outputs to
  543. (depending on what bits are set). Audio mixers allow filtering
  544. specific using multiple audio encoders to mix different sources
  545. together depending on what mixer channel they're set to.
  546. For example, to output to mixer 1 and 3, you would perform a bitwise
  547. OR on bits 0 and 2: (1<<0) | (1<<2), or 0x5.
  548. ---------------------
  549. .. function:: void obs_source_enum_filters(obs_source_t *source, obs_source_enum_proc_t callback, void *param)
  550. Enumerates active filters on a source.
  551. Relevant data types used with this function:
  552. .. code:: cpp
  553. typedef void (*obs_source_enum_proc_t)(obs_source_t *parent,
  554. obs_source_t *child, void *param);
  555. ---------------------
  556. .. function:: obs_source_t *obs_source_get_filter_by_name(obs_source_t *source, const char *name)
  557. :return: The desired filter, or *NULL* if not found. The reference
  558. of the filter is incremented
  559. ---------------------
  560. .. function:: void obs_source_copy_filters(obs_source_t *dst, obs_source_t *src)
  561. Copies filters from the source to the destination. If filters by the
  562. same name already exist in the destination source, the newer filters
  563. will be given unique names.
  564. ---------------------
  565. .. function:: bool obs_source_enabled(const obs_source_t *source)
  566. void obs_source_set_enabled(obs_source_t *source, bool enabled)
  567. Enables/disables a source, or returns the enabled state.
  568. ---------------------
  569. .. function:: void obs_source_add_audio_capture_callback(obs_source_t *source, obs_source_audio_capture_t callback, void *param)
  570. void obs_source_remove_audio_capture_callback(obs_source_t *source, obs_source_audio_capture_t callback, void *param)
  571. Adds/removes an audio capture callback for a source. This allows the
  572. ability to get the raw audio data of a source as it comes in.
  573. Relevant data types used with this function:
  574. .. code:: cpp
  575. typedef void (*obs_source_audio_capture_t)(void *param, obs_source_t *source,
  576. const struct audio_data *audio_data, bool muted);
  577. ---------------------
  578. .. function:: void obs_source_set_deinterlace_mode(obs_source_t *source, enum obs_deinterlace_mode mode)
  579. enum obs_deinterlace_mode obs_source_get_deinterlace_mode(const obs_source_t *source)
  580. Sets/gets the deinterlace mode.
  581. :param mode: | OBS_DEINTERLACE_MODE_DISABLE - Disables deinterlacing
  582. | OBS_DEINTERLACE_MODE_DISCARD - Discard
  583. | OBS_DEINTERLACE_MODE_RETRO - Retro
  584. | OBS_DEINTERLACE_MODE_BLEND - Blend
  585. | OBS_DEINTERLACE_MODE_BLEND_2X - Blend 2x
  586. | OBS_DEINTERLACE_MODE_LINEAR - Linear
  587. | OBS_DEINTERLACE_MODE_LINEAR_2X - Linear 2x
  588. | OBS_DEINTERLACE_MODE_YADIF - Yadif
  589. | OBS_DEINTERLACE_MODE_YADIF_2X - Yadif 2x
  590. ---------------------
  591. .. function:: void obs_source_set_deinterlace_field_order(obs_source_t *source, enum obs_deinterlace_field_order order)
  592. enum obs_deinterlace_field_order obs_source_get_deinterlace_field_order(const obs_source_t *source)
  593. Sets/gets the deinterlace field order.
  594. :param order: | OBS_DEINTERLACE_FIELD_ORDER_TOP - Start from top
  595. | OBS_DEINTERLACE_FIELD_ORDER_BOTTOM - Start from bottom
  596. ---------------------
  597. .. function:: obs_data_t *obs_source_get_private_settings(obs_source_t *item)
  598. Gets private front-end settings data. This data is saved/loaded
  599. automatically. Returns an incremented reference.
  600. ---------------------
  601. .. function:: void obs_source_send_mouse_click(obs_source_t *source, const struct obs_mouse_event *event, int32_t type, bool mouse_up, uint32_t click_count)
  602. Used for interacting with sources: sends a mouse down/up event to a
  603. source.
  604. ---------------------
  605. .. function:: void obs_source_send_mouse_move(obs_source_t *source, const struct obs_mouse_event *event, bool mouse_leave)
  606. Used for interacting with sources: sends a mouse move event to a
  607. source.
  608. ---------------------
  609. .. function:: void obs_source_send_mouse_wheel(obs_source_t *source, const struct obs_mouse_event *event, int x_delta, int y_delta)
  610. Used for interacting with sources: sends a mouse wheel event to a
  611. source.
  612. ---------------------
  613. .. function:: void obs_source_send_focus(obs_source_t *source, bool focus)
  614. Used for interacting with sources: sends a got-focus or lost-focus
  615. event to a source.
  616. ---------------------
  617. .. function:: void obs_source_send_key_click(obs_source_t *source, const struct obs_key_event *event, bool key_up)
  618. Used for interacting with sources: sends a key up/down event to a
  619. source.
  620. ---------------------
  621. Functions used by sources
  622. -------------------------
  623. .. function:: void obs_source_draw_set_color_matrix(const struct matrix4 *color_matrix, const struct vec3 *color_range_min, const struct vec3 *color_range_max)
  624. Helper function to set the color matrix information when drawing the
  625. source.
  626. :param color_matrix: The color matrix. Assigns to the 'color_matrix'
  627. effect variable.
  628. :param color_range_min: The minimum color range. Assigns to the
  629. 'color_range_min' effect variable. If NULL,
  630. {0.0f, 0.0f, 0.0f} is used.
  631. :param color_range_max: The maximum color range. Assigns to the
  632. 'color_range_max' effect variable. If NULL,
  633. {1.0f, 1.0f, 1.0f} is used.
  634. ---------------------
  635. .. function:: void obs_source_draw(gs_texture_t *image, int x, int y, uint32_t cx, uint32_t cy, bool flip)
  636. Helper function to draw sprites for a source (synchronous video).
  637. :param image: The sprite texture to draw. Assigns to the 'image' variable
  638. of the current effect.
  639. :param x: X position of the sprite.
  640. :param y: Y position of the sprite.
  641. :param cx: Width of the sprite. If 0, uses the texture width.
  642. :param cy: Height of the sprite. If 0, uses the texture height.
  643. :param flip: Specifies whether to flip the image vertically.
  644. ---------------------
  645. .. function:: void obs_source_output_video(obs_source_t *source, const struct obs_source_frame *frame)
  646. Outputs asynchronous video data. Set to NULL to deactivate the texture.
  647. Relevant data types used with this function:
  648. .. code:: cpp
  649. enum video_format {
  650. VIDEO_FORMAT_NONE,
  651. /* planar 420 format */
  652. VIDEO_FORMAT_I420, /* three-plane */
  653. VIDEO_FORMAT_NV12, /* two-plane, luma and packed chroma */
  654. /* packed 422 formats */
  655. VIDEO_FORMAT_YVYU,
  656. VIDEO_FORMAT_YUY2, /* YUYV */
  657. VIDEO_FORMAT_UYVY,
  658. /* packed uncompressed formats */
  659. VIDEO_FORMAT_RGBA,
  660. VIDEO_FORMAT_BGRA,
  661. VIDEO_FORMAT_BGRX,
  662. VIDEO_FORMAT_Y800, /* grayscale */
  663. /* planar 4:4:4 */
  664. VIDEO_FORMAT_I444,
  665. };
  666. struct obs_source_frame {
  667. uint8_t *data[MAX_AV_PLANES];
  668. uint32_t linesize[MAX_AV_PLANES];
  669. uint32_t width;
  670. uint32_t height;
  671. uint64_t timestamp;
  672. enum video_format format;
  673. float color_matrix[16];
  674. bool full_range;
  675. float color_range_min[3];
  676. float color_range_max[3];
  677. bool flip;
  678. };
  679. ---------------------
  680. .. function:: void obs_source_preload_video(obs_source_t *source, const struct obs_source_frame *frame)
  681. Preloads a video frame to ensure a frame is ready for playback as
  682. soon as video playback starts.
  683. ---------------------
  684. .. function:: void obs_source_show_preloaded_video(obs_source_t *source)
  685. Shows any preloaded video frame.
  686. ---------------------
  687. .. function:: void obs_source_output_audio(obs_source_t *source, const struct obs_source_audio *audio)
  688. Outputs audio data.
  689. ---------------------
  690. .. function:: void obs_source_update_properties(obs_source_t *source)
  691. Signal an update to any currently used properties.
  692. ---------------------
  693. .. function:: bool obs_source_add_active_child(obs_source_t *parent, obs_source_t *child)
  694. Adds an active child source. Must be called by parent sources on child
  695. sources when the child is added and active. This ensures that the source is
  696. properly activated if the parent is active.
  697. :return: *true* if source can be added, *false* if it causes recursion
  698. ---------------------
  699. .. function:: void obs_source_remove_active_child(obs_source_t *parent, obs_source_t *child)
  700. Removes an active child source. Must be called by parent sources on child
  701. sources when the child is removed or inactive. This ensures that the source
  702. is properly deactivated if the parent is no longer active.
  703. ---------------------
  704. Filters
  705. -------
  706. .. function:: obs_source_t *obs_filter_get_parent(const obs_source_t *filter)
  707. If the source is a filter, returns the parent source of the filter.
  708. The parent source is the source being filtered.
  709. Only guaranteed to be valid inside of the video_render, filter_audio,
  710. filter_video, and filter_remove callbacks.
  711. ---------------------
  712. .. function:: obs_source_t *obs_filter_get_target(const obs_source_t *filter)
  713. If the source is a filter, returns the target source of the filter.
  714. The target source is the next source in the filter chain.
  715. Only guaranteed to be valid inside of the video_render, filter_audio,
  716. filter_video, and filter_remove callbacks.
  717. ---------------------
  718. .. function:: void obs_source_default_render(obs_source_t *source)
  719. Can be used by filters to directly render a non-async parent source
  720. without any filter processing.
  721. ---------------------
  722. .. function:: void obs_source_filter_add(obs_source_t *source, obs_source_t *filter)
  723. void obs_source_filter_remove(obs_source_t *source, obs_source_t *filter)
  724. Adds/removes a filter to/from a source.
  725. ---------------------
  726. .. function:: void obs_source_filter_set_order(obs_source_t *source, obs_source_t *filter, enum obs_order_movement movement)
  727. Modifies the order of a specific filter.
  728. :param movement: | Can be one of the following:
  729. | OBS_ORDER_MOVE_UP
  730. | OBS_ORDER_MOVE_DOWN
  731. | OBS_ORDER_MOVE_TOP
  732. | OBS_ORDER_MOVE_BOTTOM
  733. ---------------------
  734. Functions used by filters
  735. -------------------------
  736. .. function:: bool obs_source_process_filter_begin(obs_source_t *filter, enum gs_color_format format, enum obs_allow_direct_render allow_direct)
  737. Default RGB filter handler for generic effect filters. Processes the
  738. filter chain and renders them to texture if needed, then the filter is
  739. drawn with.
  740. After calling this, set your parameters for the effect, then call
  741. obs_source_process_filter_end to draw the filter.
  742. :return: *true* if filtering should continue, *false* if the filter
  743. is bypassed for whatever reason
  744. ---------------------
  745. .. function:: void obs_source_process_filter_end(obs_source_t *filter, gs_effect_t *effect, uint32_t width, uint32_t height)
  746. Draws the filter using the effect's "Draw" technique.
  747. Before calling this function, first call obs_source_process_filter_begin and
  748. then set the effect parameters, and then call this function to finalize the
  749. filter.
  750. ---------------------
  751. .. function:: void obs_source_process_filter_tech_end(obs_source_t *filter, gs_effect_t *effect, uint32_t width, uint32_t height, const char *tech_name)
  752. Draws the filter with a specific technique in the effect.
  753. Before calling this function, first call obs_source_process_filter_begin and
  754. then set the effect parameters, and then call this function to finalize the
  755. filter.
  756. ---------------------
  757. .. function:: void obs_source_skip_video_filter(obs_source_t *filter)
  758. Skips the filter if the filter is invalid and cannot be rendered.
  759. ---------------------
  760. .. _transitions:
  761. Transitions
  762. -----------
  763. .. function:: obs_source_t *obs_transition_get_source(obs_source_t *transition, enum obs_transition_target target)
  764. :param target: | OBS_TRANSITION_SOURCE_A - Source being transitioned from, or the current source if not transitioning
  765. | OBS_TRANSITION_SOURCE_B - Source being transitioned to
  766. :return: An incremented reference to the source or destination
  767. sources of the transition
  768. ---------------------
  769. .. function:: void obs_transition_clear(obs_source_t *transition)
  770. Clears the transition.
  771. ---------------------
  772. .. function:: obs_source_t *obs_transition_get_active_source(obs_source_t *transition)
  773. :return: An incremented reference to the currently active source of
  774. the transition
  775. ---------------------
  776. .. function:: bool obs_transition_start(obs_source_t *transition, enum obs_transition_mode mode, uint32_t duration_ms, obs_source_t *dest)
  777. Starts the transition with the desired destination source.
  778. :param mode: Currently only OBS_TRANSITION_MODE_AUTO
  779. :param duration_ms: Duration in milliseconds. If the transition has
  780. a fixed duration set by
  781. :c:func:`obs_transition_enable_fixed`, this
  782. parameter will have no effect
  783. :param dest: The destination source to transition to
  784. ---------------------
  785. .. function:: void obs_transition_set_size(obs_source_t *transition, uint32_t cx, uint32_t cy)
  786. void obs_transition_get_size(const obs_source_t *transition, uint32_t *cx, uint32_t *cy)
  787. Sets/gets the dimensions of the transition.
  788. ---------------------
  789. .. function:: void obs_transition_set_scale_type(obs_source_t *transition, enum obs_transition_scale_type type)
  790. enum obs_transition_scale_type obs_transition_get_scale_type( const obs_source_t *transition)
  791. Sets/gets the scale type for sources within the transition.
  792. :param type: | OBS_TRANSITION_SCALE_MAX_ONLY - Scale to aspect ratio, but only to the maximum size of each source
  793. | OBS_TRANSITION_SCALE_ASPECT - Alwasy scale the sources, but keep aspect ratio
  794. | OBS_TRANSITION_SCALE_STRETCH - Scale and stretch the sources to the size of the transision
  795. ---------------------
  796. .. function:: void obs_transition_set_alignment(obs_source_t *transition, uint32_t alignment)
  797. uint32_t obs_transition_get_alignment(const obs_source_t *transition)
  798. Sets/gets the alignment used to draw the two sources within
  799. transition the transition.
  800. :param alignment: | Can be any bitwise OR combination of:
  801. | OBS_ALIGN_CENTER
  802. | OBS_ALIGN_LEFT
  803. | OBS_ALIGN_RIGHT
  804. | OBS_ALIGN_TOP
  805. | OBS_ALIGN_BOTTOM
  806. ---------------------
  807. Functions used by transitions
  808. -----------------------------
  809. .. function:: void obs_transition_enable_fixed(obs_source_t *transition, bool enable, uint32_t duration_ms)
  810. bool obs_transition_fixed(obs_source_t *transition)
  811. Sets/gets whether the transition uses a fixed duration. Useful for
  812. certain types of transitions such as stingers. If this is set, the
  813. *duration_ms* parameter of :c:func:`obs_transition_start()` has no
  814. effect.
  815. ---------------------
  816. .. function:: float obs_transition_get_time(obs_source_t *transition)
  817. :return: The current transition time value (0.0f..1.0f)
  818. ---------------------
  819. .. function:: void obs_transition_video_render(obs_source_t *transition, obs_transition_video_render_callback_t callback)
  820. Helper function used for rendering transitions. This function will
  821. render two distinct textures for source A and source B of the
  822. transition, allowing the ability to blend them together with a pixel
  823. shader in a desired manner.
  824. The *a* and *b* parameters of *callback* are automatically rendered
  825. textures of source A and source B, *t* is the time value
  826. (0.0f..1.0f), *cx* and *cy* are the current dimensions of the
  827. transition, and *data* is the implementation's private data.
  828. Relevant data types used with this function:
  829. .. code:: cpp
  830. typedef void (*obs_transition_video_render_callback_t)(void *data,
  831. gs_texture_t *a, gs_texture_t *b, float t,
  832. uint32_t cx, uint32_t cy);
  833. ---------------------
  834. .. function:: bool obs_transition_audio_render(obs_source_t *transition, uint64_t *ts_out, struct obs_source_audio_mix *audio, uint32_t mixers, size_t channels, size_t sample_rate, obs_transition_audio_mix_callback_t mix_a_callback, obs_transition_audio_mix_callback_t mix_b_callback)
  835. Helper function used for transitioning audio. Typically you'd call
  836. this in the obs_source_info.audio_render callback with its
  837. parameters, and use the mix_a_callback and mix_b_callback to
  838. determine the the audio fading of source A and source B.
  839. Relevant data types used with this function:
  840. .. code:: cpp
  841. typedef float (*obs_transition_audio_mix_callback_t)(void *data, float t);
  842. ---------------------
  843. .. function:: void obs_transition_swap_begin(obs_source_t *tr_dest, obs_source_t *tr_source)
  844. void obs_transition_swap_end(obs_source_t *tr_dest, obs_source_t *tr_source)
  845. Swaps two transitions. Call obs_transition_swap_begin, swap the
  846. source, then call obs_transition_swap_end when complete. This allows
  847. the ability to seamlessly swap two different transitions without it
  848. affecting the output.
  849. For example, if a transition is assigned to output channel 0, you'd
  850. call obs_transition_swap_begin, then you'd call obs_set_output_source
  851. with the new transition, then call
  852. :c:func:`obs_transition_swap_begin()`.
  853. .. ---------------------------------------------------------------------------
  854. .. _libobs/obs-source.h: https://github.com/jp9000/obs-studio/blob/master/libobs/obs-source.h