reference-canvases.rst 7.5 KB

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