obs-source.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 3 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/darray.h"
  17. #include "util/dstr.h"
  18. #include "media-io/media-io.h"
  19. /*
  20. * ===========================================
  21. * Sources
  22. * ===========================================
  23. *
  24. * A source is literally a "source" of audio and/or video.
  25. *
  26. * A module with sources needs to export these functions:
  27. * + enum_[type]
  28. *
  29. * Each individual source is then exported by it's name. For example, a
  30. * source named "mysource" would have the following exports:
  31. * + mysource_create
  32. * + mysource_destroy
  33. * + mysource_getflags
  34. *
  35. * [and optionally]
  36. * + mysource_update
  37. * + mysource_config
  38. * + mysource_video_tick
  39. * + mysource_video_render
  40. * + mysource_getparam
  41. * + mysource_setparam
  42. *
  43. * ===========================================
  44. * Primary Exports
  45. * ===========================================
  46. * const bool enum_[type](size_t idx, const char **name);
  47. * idx: index of the source.
  48. * type: pointer to variable that receives the type of the source
  49. * Return value: false when no more available.
  50. *
  51. * ===========================================
  52. * Source Exports
  53. * ===========================================
  54. * void *[name]_create(const char *settings, obs_source_t source);
  55. * Creates a source.
  56. *
  57. * settings: Settings of the source.
  58. * source: pointer to main source
  59. * Return value: Internal source pointer, or NULL if failed.
  60. *
  61. * ---------------------------------------------------------
  62. * void [name]_destroy(void *data);
  63. * Destroys the source.
  64. *
  65. * ---------------------------------------------------------
  66. * uint32_t [name]_getflags(void *data);
  67. * Returns a combination of one of the following values:
  68. * + SOURCE_VIDEO: source has video
  69. * + SOURCE_AUDIO: source has audio
  70. * + SOURCE_ASYNC: video is sent asynchronously via RAM
  71. *
  72. * ---------------------------------------------------------
  73. * int [name]_getwidth(void *data);
  74. * Returns the width of a source, or -1 for maximum width. If you render
  75. * video, this is required.
  76. *
  77. * ---------------------------------------------------------
  78. * int [name]_getheight(void *data);
  79. * Returns the height of a source, or -1 for maximum height. If you
  80. * render video, this is required.
  81. *
  82. * ===========================================
  83. * Optional Source Exports
  84. * ===========================================
  85. * void [name]_config(void *data, void *parent);
  86. * Called to configure the source.
  87. *
  88. * parent: Parent window pointer
  89. *
  90. * ---------------------------------------------------------
  91. * void [name]_video_activate(void *data);
  92. * Called when the source is being displayed.
  93. *
  94. * ---------------------------------------------------------
  95. * void [name]_video_deactivate(void *data);
  96. * Called when the source is no longer being displayed.
  97. *
  98. * ---------------------------------------------------------
  99. * void [name]_video_tick(void *data, float seconds);
  100. * Called each video frame with the time taken between the last and
  101. * current frame, in seconds.
  102. *
  103. * ---------------------------------------------------------
  104. * void [name]_video_render(void *data);
  105. * Called to render the source.
  106. *
  107. * ---------------------------------------------------------
  108. * void [name]_getparam(void *data, const char *param, void *buf,
  109. * size_t buf_size);
  110. * Gets a source parameter value.
  111. *
  112. * param: Name of parameter.
  113. * Return value: Value of parameter.
  114. *
  115. * ---------------------------------------------------------
  116. * void [name]_setparam(void *data, const char *param, const void *buf,
  117. * size_t size);
  118. * Sets a source parameter value.
  119. *
  120. * param: Name of parameter.
  121. * val: Value of parameter to set.
  122. *
  123. * ---------------------------------------------------------
  124. * bool [name]_enum_children(void *data, size_t idx, obs_source_t *child);
  125. * Enumerates child sources, if any.
  126. *
  127. * idx: Child source index.
  128. * child: Pointer to variable that receives child source.
  129. * Return value: true if sources remaining, otherwise false.
  130. *
  131. * ---------------------------------------------------------
  132. * void [name]_filter_video(void *data, struct video_frame *frame);
  133. * Filters audio data. Used with audio filters.
  134. *
  135. * frame: Video frame data.
  136. *
  137. * ---------------------------------------------------------
  138. * void [name]_filter_audio(void *data, struct audio_data *audio);
  139. * Filters video data. Used with async video data.
  140. *
  141. * audio: Audio data.
  142. */
  143. struct obs_source;
  144. struct source_info {
  145. const char *name;
  146. /* ----------------------------------------------------------------- */
  147. /* required implementations */
  148. void *(*create)(const char *settings, obs_source_t source);
  149. void (*destroy)(void *data);
  150. uint32_t (*get_output_flags)(void *data);
  151. /* ----------------------------------------------------------------- */
  152. /* optional implementations */
  153. bool (*config)(void *data, void *parent);
  154. void (*activate)(void *data);
  155. void (*deactivate)(void *data);
  156. void (*video_tick)(void *data, float seconds);
  157. void (*video_render)(void *data);
  158. int (*getwidth)(void *data);
  159. int (*getheight)(void *data);
  160. size_t (*getparam)(void *data, const char *param, void *data_out,
  161. size_t buf_size);
  162. void (*setparam)(void *data, const char *param, const void *data_in,
  163. size_t size);
  164. bool (*enum_children)(void *data, size_t idx, obs_source_t *child);
  165. void (*filter_video)(void *data, struct video_frame *frame);
  166. void (*filter_audio)(void *data, struct audio_data *audio);
  167. };
  168. struct obs_source {
  169. void *data;
  170. struct source_info callbacks;
  171. struct dstr settings;
  172. bool rendering_filter;
  173. struct obs_source *filter_target;
  174. DARRAY(struct obs_source*) filters;
  175. };
  176. extern bool get_source_info(void *module, const char *module_name,
  177. const char *source_name, struct source_info *info);
  178. extern void obs_source_init(struct obs_source *source);
  179. extern void obs_source_activate(obs_source_t source);
  180. extern void obs_source_deactivate(obs_source_t source);
  181. extern void obs_source_video_tick(obs_source_t source, float seconds);