reference-services.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. Service API Reference (obs_service_t)
  2. =====================================
  3. Services are custom implementations of streaming services, which are
  4. used with outputs that stream. For example, you could have a custom
  5. implementation for streaming to Twitch, and another for YouTube to allow
  6. the ability to log in and use their APIs to do things such as get the
  7. RTMP servers or control the channel. The `libobs/obs-service.h`_ file
  8. is the dedicated header for implementing services.
  9. *(Author's note: the service API is incomplete as of this writing)*
  10. .. type:: obs_service_t
  11. A reference-counted service object.
  12. .. type:: obs_weak_service_t
  13. A weak reference to a service object.
  14. .. code:: cpp
  15. #include <obs.h>
  16. Service Definition Structure
  17. ----------------------------
  18. .. struct:: obs_service_info
  19. Service definition structure.
  20. .. member:: const char *obs_service_info.id
  21. Unique string identifier for the service (required).
  22. .. member:: const char *(*obs_service_info.get_name)(void *type_data)
  23. Get the translated name of the service type.
  24. :param type_data: The type_data variable of this structure
  25. :return: The translated name of the service type
  26. .. member:: void *(*obs_service_info.create)(obs_data_t *settings, obs_service_t *service)
  27. Creates the implementation data for the service.
  28. :param settings: Settings to initialize the service with
  29. :param service: Source that this data is associated with
  30. :return: The implementation data associated with this service
  31. .. member:: void (*obs_service_info.destroy)(void *data)
  32. Destroys the implementation data for the service.
  33. .. member:: void (*obs_service_info.get_defaults)(obs_data_t *settings)
  34. void (*obs_service_info.get_defaults2)(void *type_data, obs_data_t *settings)
  35. Sets the default settings for this service.
  36. :param settings: Default settings. Call obs_data_set_default*
  37. functions on this object to set default setting
  38. values
  39. .. member:: obs_properties_t *(*obs_service_info.get_properties)(void *data)
  40. obs_properties_t *(*obs_service_info.get_properties2)(void *data, void *type_data)
  41. Gets the property information of this service.
  42. (Optional)
  43. :return: The properties of the service
  44. .. member:: void (*obs_service_info.update)(void *data, obs_data_t *settings)
  45. Updates the settings for this service.
  46. (Optional)
  47. :param settings: New settings for this service
  48. .. member:: bool (*obs_service_info.initialize)(void *data, obs_output_t *output)
  49. Called when getting ready to start up an output, before the encoders
  50. and output are initialized.
  51. (Optional)
  52. :param output: Output context to use this service with
  53. :return: *true* to allow the output to start up,
  54. *false* to prevent output from starting up
  55. .. member:: const char *(*obs_service_info.get_url)(void *data)
  56. :return: The stream URL
  57. .. member:: const char *(*obs_service_info.get_key)(void *data)
  58. :return: The stream key
  59. .. member:: const char *(*obs_service_info.get_username)(void *data)
  60. (Optional)
  61. :return: The username
  62. .. member:: const char *(*obs_service_info.get_password)(void *data)
  63. (Optional)
  64. :return: The password
  65. .. member:: void (*obs_service_info.apply_encoder_settings)(void *data, obs_data_t *video_encoder_settings, obs_data_t *audio_encoder_settings)
  66. This function is called to apply custom encoder settings specific to
  67. this service. For example, if a service requires a specific keyframe
  68. interval, or has a bitrate limit, the settings for the video and
  69. audio encoders can be optionally modified if the front-end optionally
  70. calls :c:func:`obs_service_apply_encoder_settings()`.
  71. (Optional)
  72. :param video_encoder_settings: The audio encoder settings to change
  73. :param audio_encoder_settings: The video encoder settings to change
  74. .. member:: void *obs_service_info.type_data
  75. void (*obs_service_info.free_type_data)(void *type_data)
  76. Private data associated with this entry. Note that this is not the
  77. same as the implementation data; this is used to differentiate
  78. between two different types if the same callbacks are used for more
  79. than one different type.
  80. (Optional)
  81. .. member:: const char *(*obs_service_info.get_output_type)(void *data)
  82. (Optional)
  83. :return: The output type that should be preferred with this service
  84. .. member:: const char **(*get_supported_video_codecs)(void *data)
  85. (Optional)
  86. :return: A string pointer array of the supported video codecs, should
  87. be stored by the plugin so the caller does not need to free
  88. the data manually (typically best to use strlist_split to
  89. generate this)
  90. .. member:: const char **(*get_supported_audio_codecs)(void *data)
  91. (Optional)
  92. :return: A string pointer array of the supported audio codecs, should
  93. be stored by the plugin so the caller does not need to free
  94. the data manually (typically best to use strlist_split to
  95. generate this)
  96. .. member:: const char *(*obs_service_info.get_protocol)(void *data)
  97. :return: The protocol used by the service
  98. .. member:: const char *(*obs_service_info.get_connect_info)(void *data, uint32_t type)
  99. Output a service connection info related to a given type value:
  100. - **OBS_SERVICE_CONNECT_INFO_SERVER_URL** - Server URL (0)
  101. - **OBS_SERVICE_CONNECT_INFO_STREAM_ID** - Stream ID (2)
  102. - **OBS_SERVICE_CONNECT_INFO_STREAM_KEY** - Stream key (alias of **OBS_SERVICE_CONNECT_INFO_STREAM_ID**)
  103. - **OBS_SERVICE_CONNECT_INFO_USERNAME** - Username (4)
  104. - **OBS_SERVICE_CONNECT_INFO_PASSWORD** - Password (6)
  105. - **OBS_SERVICE_CONNECT_INFO_ENCRYPT_PASSPHRASE** - Encryption passphrase (8)
  106. - Odd values as types are reserved for third-party protocols
  107. Depending on the protocol, the service will have to provide information
  108. to the output to be able to connect.
  109. Irrelevant or unused types can return `NULL`.
  110. .. member:: bool (*obs_service_info.can_try_to_connect)(void *data)
  111. (Optional)
  112. :return: If the service has all the needed connection info to be
  113. able to connect.
  114. NOTE: If not set, :c:func:`obs_service_can_try_to_connect()`
  115. returns *true* by default.
  116. General Service Functions
  117. -------------------------
  118. .. function:: void obs_register_service(struct obs_service_info *info)
  119. Registers a service type. Typically used in
  120. :c:func:`obs_module_load()` or in the program's initialization phase.
  121. ---------------------
  122. .. function:: const char *obs_service_get_display_name(const char *id)
  123. Calls the :c:member:`obs_service_info.get_name` callback to get the
  124. translated display name of a service type.
  125. :param id: The service type string identifier
  126. :return: The translated display name of a service type
  127. ---------------------
  128. .. function:: obs_service_t *obs_service_create(const char *id, const char *name, obs_data_t *settings, obs_data_t *hotkey_data)
  129. Creates a service with the specified settings.
  130. The "service" context is used for encoding video/audio data. Use
  131. obs_service_release to release it.
  132. :param id: The service type string identifier
  133. :param name: The desired name of the service. If this is
  134. not unique, it will be made to be unique
  135. :param settings: The settings for the service, or *NULL* if
  136. none
  137. :param hotkey_data: Saved hotkey data for the service, or *NULL*
  138. if none
  139. :return: A reference to the newly created service, or
  140. *NULL* if failed
  141. ---------------------
  142. .. function:: void obs_service_addref(obs_service_t *service)
  143. Adds a reference to a service.
  144. .. deprecated:: 27.2.0
  145. Use :c:func:`obs_service_get_ref()` instead.
  146. ---------------------
  147. .. function:: obs_service_t *obs_service_get_ref(obs_service_t *service)
  148. Returns an incremented reference if still valid, otherwise returns
  149. *NULL*. Release with :c:func:`obs_service_release()`.
  150. ---------------------
  151. .. function:: void obs_service_release(obs_service_t *service)
  152. Releases a reference to a service. When the last reference is
  153. released, the service is destroyed.
  154. ---------------------
  155. .. function:: obs_weak_service_t *obs_service_get_weak_service(obs_service_t *service)
  156. obs_service_t *obs_weak_service_get_service(obs_weak_service_t *weak)
  157. These functions are used to get a weak reference from a strong service
  158. reference, or a strong service reference from a weak reference. If
  159. the service is destroyed, *obs_weak_service_get_service* will return
  160. *NULL*.
  161. ---------------------
  162. .. function:: void obs_weak_service_addref(obs_weak_service_t *weak)
  163. void obs_weak_service_release(obs_weak_service_t *weak)
  164. Adds/releases a weak reference to a service.
  165. ---------------------
  166. .. function:: const char *obs_service_get_name(const obs_service_t *service)
  167. :return: The name of the service
  168. ---------------------
  169. .. function:: obs_data_t *obs_service_defaults(const char *id)
  170. :return: An incremented reference to the service's default settings.
  171. Release with :c:func:`obs_data_release()`.
  172. ---------------------
  173. .. function:: obs_properties_t *obs_service_properties(const obs_service_t *service)
  174. obs_properties_t *obs_get_service_properties(const char *id)
  175. Use these functions to get the properties of a service or service
  176. type. Properties are optionally used (if desired) to automatically
  177. generate user interface widgets to allow users to update settings.
  178. :return: The properties list for a specific existing service. Free
  179. with :c:func:`obs_properties_destroy()`
  180. ---------------------
  181. .. function:: obs_data_t *obs_service_get_settings(const obs_service_t *service)
  182. :return: An incremented reference to the service's settings. Release with
  183. :c:func:`obs_data_release()`.
  184. ---------------------
  185. .. function:: void obs_service_update(obs_service_t *service, obs_data_t *settings)
  186. Updates the settings for this service context.
  187. ---------------------
  188. .. function:: const char *obs_service_get_url(const obs_service_t *service)
  189. :return: The URL currently used for this service
  190. .. deprecated:: 29.1.0
  191. Use :c:func:`obs_service_get_connect_info()` instead.
  192. ---------------------
  193. .. function:: const char *obs_service_get_key(const obs_service_t *service)
  194. :return: Stream key (if any) currently used for this service
  195. .. deprecated:: 29.1.0
  196. Use :c:func:`obs_service_get_connect_info()` instead.
  197. ---------------------
  198. .. function:: const char *obs_service_get_username(const obs_service_t *service)
  199. :return: User name (if any) currently used for this service
  200. .. deprecated:: 29.1.0
  201. Use :c:func:`obs_service_get_connect_info()` instead.
  202. ---------------------
  203. .. function:: const char *obs_service_get_password(const obs_service_t *service)
  204. :return: Password (if any) currently used for this service
  205. .. deprecated:: 29.1.0
  206. Use :c:func:`obs_service_get_connect_info()` instead.
  207. ---------------------
  208. .. function:: void obs_service_apply_encoder_settings(obs_service_t *service, obs_data_t *video_encoder_settings, obs_data_t *audio_encoder_settings)
  209. Applies service-specific video encoder settings.
  210. :param video_encoder_settings: Video encoder settings. Can be *NULL*
  211. :param audio_encoder_settings: Audio encoder settings. Can be *NULL*
  212. ---------------------
  213. .. function:: const char **obs_service_get_supported_video_codecs(const obs_service_t *service)
  214. :return: An array of string pointers containing the supported video
  215. codecs for the service, terminated with a *NULL* pointer.
  216. Does not need to be freed
  217. ---------------------
  218. .. function:: const char **obs_service_get_supported_audio_codecs(const obs_service_t *service)
  219. :return: An array of string pointers containing the supported audio
  220. codecs for the service, terminated with a *NULL* pointer.
  221. Does not need to be freed
  222. ---------------------
  223. .. function:: const char *obs_service_get_protocol(const obs_service_t *service)
  224. :return: Protocol currently used for this service
  225. ---------------------
  226. .. function:: const char *obs_service_get_preferred_output_type(const obs_service_t *service)
  227. :return: The output type that should be preferred with this service
  228. ---------------------
  229. .. function:: const char *obs_service_get_connect_info(const obs_service_t *service, uint32_t type)
  230. :param type: Check :c:member:`obs_service_info.get_connect_info` for
  231. type values.
  232. :return: Connection info related to the type value.
  233. ---------------------
  234. .. function:: bool obs_service_can_try_to_connect(const obs_service_t *service)
  235. :return: If the service has all the needed connection info to be
  236. able to connect. Returns `true` if
  237. :c:member:`obs_service_info.can_try_to_connect` is not set.
  238. .. ---------------------------------------------------------------------------
  239. .. _libobs/obs-service.h: https://github.com/obsproject/obs-studio/blob/master/libobs/obs-service.h