reference-canvases.rst 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. Canvas API Reference (obs_canvas_t)
  2. ===================================
  3. .. danger::
  4. Canvases are still in their early stages of implementation and the API will evolve as they are gradually integrated
  5. across OBS Studio.
  6. The Canvas API should be considered **unstable** and may be changed without warning. This documentation serves to aid
  7. in their iterative development within OBS Studio.
  8. **If you are developing a plugin that utilizes canvases, proceed with great caution.**
  9. Canvases are reference-counted objects that contain scenes and define how those are rendered.
  10. They provide a video object which can be used with encoders or raw outputs.
  11. libobs maintains a main canvas that exists at all times and is used for the default video outputs.
  12. .. type:: obs_canvas_t
  13. A reference-counted canvas.
  14. .. type:: obs_weak_canvas_t
  15. A weak reference to a canvas.
  16. .. code:: cpp
  17. #include <obs.h>
  18. .. _canvas_signal_handler_reference:
  19. Canvas Signals
  20. --------------
  21. The following signals are defined for canvases:
  22. **remove** (ptr canvas)
  23. Called when the :c:func:`obs_canvas_remove()` function is called on the canvas.
  24. **destroy** (ptr canvas)
  25. Called when a canvas is about to be destroyed.
  26. **video_reset** (ptr canvas)
  27. Called when the canvas's video mix has been reset after a call to
  28. :c:func:`obs_reset_video()` or :c:func:`obs_canvas_reset_video()`.
  29. **source_add** (ptr canvas, ptr source)
  30. Called when a source has been added to the canvas.
  31. **source_remove** (ptr canvas, ptr source)
  32. Called when a source has been removed from the canvas.
  33. **rename** (ptr canvas, string new_name, string prev_name)
  34. Called when the canvas has been renamed.
  35. **channel_change** (ptr canvas, int channel, in out ptr source, ptr prev_source)
  36. Called when a channel source has been changed.
  37. Canvas Flags
  38. ------------
  39. Canvases can have different behaviors, these can be controlled via the **flags** parameter when creating a canvas.
  40. Flags may be `0` or a bitwise `OR` combination of the following values:
  41. - **MAIN** - Main canvas, cannot be renamed or reset, cannot be set by user
  42. - **ACTIVATE** - Canvas's sources will become active when they are visible
  43. - **MIX_AUDIO** - Audio from channels in this canvas will be mixed into the audio output
  44. - **SCENE_REF** - Canvas will hold references for scene sources
  45. - **EPHEMERAL** - Indicates this canvas is not supposed to be saved
  46. Additionally, the following preset combinations of flags are defined:
  47. - **PROGRAM** which equals `ACTIVATE | MIX_AUDIO | SCENE_REF`
  48. - **PREVIEW** which equals `EPHEMERAL`
  49. - **DEVICE** which equals `ACTIVATE | EPHEMERAL`
  50. General Canvas Functions
  51. ------------------------
  52. .. function:: obs_canvas_t *obs_get_main_canvas()
  53. Get a strong reference to the main OBS canvas.
  54. ---------------------
  55. .. function:: obs_canvas_t *obs_canvas_create(const char *name, struct obs_video_info *ovi, uint32_t flags)
  56. Creates a new canvas.
  57. :param name: Name, will be deduplicated if necessary
  58. :param ovi: Video configuration to use for this canvas's video output
  59. :param flags: Canvas flags
  60. :return: Canvas object
  61. ---------------------
  62. .. function:: obs_canvas_t *obs_canvas_create_private(const char *name, struct obs_video_info *ovi, uint32_t flags)
  63. Creates a new private canvas.
  64. :param name: Name, will **not** be deduplicated
  65. :param ovi: Video configuration to use for this canvas's video output
  66. :param flags: Canvas flags
  67. :return: Canvas object
  68. ---------------------
  69. .. function:: void obs_canvas_remove(obs_canvas_t *canvas)
  70. Signal that references to canvas should be released and mark the canvas as removed.
  71. ---------------------
  72. .. function:: bool obs_canvas_removed(obs_canvas_t *canvas)
  73. Returns if a canvas is marked as removed (i.e., should no longer be used).
  74. ---------------------
  75. .. function:: void obs_canvas_set_name(obs_canvas_t *canvas, const char *name)
  76. Set canvas name
  77. ---------------------
  78. .. function:: const char *obs_canvas_get_name(const obs_canvas_t *canvas)
  79. Get canvas name
  80. ---------------------
  81. .. function:: const char *obs_canvas_get_uuid(const obs_canvas_t *canvas)
  82. Get canvas UUID
  83. ---------------------
  84. .. function:: uint32_t obs_canvas_get_flags(const obs_canvas_t *canvas)
  85. Gets flags set on a canvas
  86. ---------------------
  87. Saving/Loading Functions
  88. ------------------------
  89. .. function:: obs_data_t *obs_save_canvas(obs_canvas_t *source)
  90. Saves a canvas to settings data
  91. ---------------------
  92. .. function:: obs_canvas_t *obs_load_canvas(obs_data_t *data)
  93. Loads a canvas from settings data
  94. ---------------------
  95. Reference Counting Functions
  96. ----------------------------
  97. .. function:: obs_canvas_t *obs_canvas_get_ref(obs_canvas_t *canvas)
  98. Add strong reference to a canvas
  99. ---------------------
  100. .. function:: void obs_canvas_release(obs_canvas_t *canvas)
  101. Release strong reference
  102. ---------------------
  103. .. function:: void obs_weak_canvas_addref(obs_weak_canvas_t *weak)
  104. Add weak reference
  105. ---------------------
  106. .. function:: void obs_weak_canvas_release(obs_weak_canvas_t *weak)
  107. Release weak reference
  108. ---------------------
  109. .. function:: obs_weak_canvas_t *obs_canvas_get_weak_canvas(obs_canvas_t *canvas)
  110. Get weak reference from strong reference
  111. ---------------------
  112. .. function:: obs_canvas_t *obs_weak_canvas_get_canvas(obs_weak_canvas_t *weak)
  113. Get strong reference from weak reference
  114. ---------------------
  115. Canvas Channel Functions
  116. ------------------------
  117. .. function:: void obs_canvas_set_channel(obs_canvas_t *canvas, uint32_t channel, obs_source_t *source)
  118. Sets the source to be used for a canvas channel.
  119. ---------------------
  120. .. function:: obs_source_t *obs_canvas_get_channel(obs_canvas_t *canvas, uint32_t channel)
  121. Gets the source currently in use for a canvas channel.
  122. ---------------------
  123. Canvas Source List Functions
  124. ----------------------------
  125. .. function:: obs_scene_t *obs_canvas_scene_create(obs_canvas_t *canvas, const char *name)
  126. Create scene attached to a canvas.
  127. ---------------------
  128. .. function:: void obs_canvas_scene_remove(obs_scene_t *scene)
  129. Remove a scene from a canvas.
  130. ---------------------
  131. .. function:: void obs_canvas_move_scene(obs_scene_t *scene, obs_canvas_t *dst)
  132. Move scene to another canvas, detaching it from the previous one and deduplicating the name if needed.
  133. ---------------------
  134. .. function:: void obs_canvas_enum_scenes(obs_canvas_t *canvas, bool (*enum_proc)(void *, obs_source_t *), void *param)
  135. Enumerates scenes belonging to a canvas.
  136. Callback function returns true to continue enumeration, or false to end enumeration.
  137. ---------------------
  138. .. function:: obs_source_t *obs_canvas_get_source_by_name(const char *name)
  139. Gets a canvas source by its name.
  140. Increments the source reference counter, use
  141. :c:func:`obs_source_release()` to release it when complete.
  142. ---------------------
  143. .. function:: obs_scene_t *obs_canvas_get_scene_by_name(const char *name)
  144. Gets a canvas scene by its name.
  145. Increments the source reference counter, use
  146. :c:func:`obs_scene_release()` to release it when complete.
  147. ---------------------
  148. Canvas Video Functions
  149. ----------------------
  150. .. function:: bool obs_canvas_reset_video(obs_canvas_t *canvas, struct obs_video_info *ovi)
  151. Reset a canvas's video configuration.
  152. Note that the frame rate property is ignored and the global rendering frame rate is used instead.
  153. ---------------------
  154. .. function:: bool obs_canvas_has_video(obs_canvas_t *canvas)
  155. Returns true if the canvas video is configured.
  156. ---------------------
  157. .. function:: video_t *obs_canvas_get_video(const obs_canvas_t *canvas)
  158. Get canvas video output
  159. ---------------------
  160. .. function:: bool obs_canvas_get_video_info(const obs_canvas_t *canvas, struct obs_video_info *ovi)
  161. Get canvas video info (if any)
  162. ---------------------
  163. .. function:: void obs_canvas_render(obs_canvas_t *canvas)
  164. Render the canvas's view. Must be called on the graphics thread.
  165. ---------------------