obs-source.h 7.3 KB

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