Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
6.4KB

  1. /*
  2. Copyright 2012-2016 David Robillard <http://drobilla.net>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. /**
  15. @defgroup worker Worker
  16. Support for non-realtime plugin operations, see
  17. <http://lv2plug.in/ns/ext/worker> for details.
  18. @{
  19. */
  20. #ifndef LV2_WORKER_H
  21. #define LV2_WORKER_H
  22. #include <stdint.h>
  23. #include "lv2.h"
  24. #define LV2_WORKER_URI "http://lv2plug.in/ns/ext/worker" ///< http://lv2plug.in/ns/ext/worker
  25. #define LV2_WORKER_PREFIX LV2_WORKER_URI "#" ///< http://lv2plug.in/ns/ext/worker#
  26. #define LV2_WORKER__interface LV2_WORKER_PREFIX "interface" ///< http://lv2plug.in/ns/ext/worker#interface
  27. #define LV2_WORKER__schedule LV2_WORKER_PREFIX "schedule" ///< http://lv2plug.in/ns/ext/worker#schedule
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /**
  32. Status code for worker functions.
  33. */
  34. typedef enum {
  35. LV2_WORKER_SUCCESS = 0, /**< Completed successfully. */
  36. LV2_WORKER_ERR_UNKNOWN = 1, /**< Unknown error. */
  37. LV2_WORKER_ERR_NO_SPACE = 2 /**< Failed due to lack of space. */
  38. } LV2_Worker_Status;
  39. /** Opaque handle for LV2_Worker_Interface::work(). */
  40. typedef void* LV2_Worker_Respond_Handle;
  41. /**
  42. A function to respond to run() from the worker method.
  43. The `data` MUST be safe for the host to copy and later pass to
  44. work_response(), and the host MUST guarantee that it will be eventually
  45. passed to work_response() if this function returns LV2_WORKER_SUCCESS.
  46. */
  47. typedef LV2_Worker_Status (*LV2_Worker_Respond_Function)(
  48. LV2_Worker_Respond_Handle handle,
  49. uint32_t size,
  50. const void* data);
  51. /**
  52. Plugin Worker Interface.
  53. This is the interface provided by the plugin to implement a worker method.
  54. The plugin's extension_data() method should return an LV2_Worker_Interface
  55. when called with LV2_WORKER__interface as its argument.
  56. */
  57. typedef struct _LV2_Worker_Interface {
  58. /**
  59. The worker method. This is called by the host in a non-realtime context
  60. as requested, possibly with an arbitrary message to handle.
  61. A response can be sent to run() using `respond`. The plugin MUST NOT
  62. make any assumptions about which thread calls this method, except that
  63. there are no real-time requirements and only one call may be executed at
  64. a time. That is, the host MAY call this method from any non-real-time
  65. thread, but MUST NOT make concurrent calls to this method from several
  66. threads.
  67. @param instance The LV2 instance this is a method on.
  68. @param respond A function for sending a response to run().
  69. @param handle Must be passed to `respond` if it is called.
  70. @param size The size of `data`.
  71. @param data Data from run(), or NULL.
  72. */
  73. LV2_Worker_Status (*work)(LV2_Handle instance,
  74. LV2_Worker_Respond_Function respond,
  75. LV2_Worker_Respond_Handle handle,
  76. uint32_t size,
  77. const void* data);
  78. /**
  79. Handle a response from the worker. This is called by the host in the
  80. run() context when a response from the worker is ready.
  81. @param instance The LV2 instance this is a method on.
  82. @param size The size of `body`.
  83. @param body Message body, or NULL.
  84. */
  85. LV2_Worker_Status (*work_response)(LV2_Handle instance,
  86. uint32_t size,
  87. const void* body);
  88. /**
  89. Called when all responses for this cycle have been delivered.
  90. Since work_response() may be called after run() finished, this provides
  91. a hook for code that must run after the cycle is completed.
  92. This field may be NULL if the plugin has no use for it. Otherwise, the
  93. host MUST call it after every run(), regardless of whether or not any
  94. responses were sent that cycle.
  95. */
  96. LV2_Worker_Status (*end_run)(LV2_Handle instance);
  97. } LV2_Worker_Interface;
  98. /** Opaque handle for LV2_Worker_Schedule. */
  99. typedef void* LV2_Worker_Schedule_Handle;
  100. /**
  101. Schedule Worker Host Feature.
  102. The host passes this feature to provide a schedule_work() function, which
  103. the plugin can use to schedule a worker call from run().
  104. */
  105. typedef struct _LV2_Worker_Schedule {
  106. /**
  107. Opaque host data.
  108. */
  109. LV2_Worker_Schedule_Handle handle;
  110. /**
  111. Request from run() that the host call the worker.
  112. This function is in the audio threading class. It should be called from
  113. run() to request that the host call the work() method in a non-realtime
  114. context with the given arguments.
  115. This function is always safe to call from run(), but it is not
  116. guaranteed that the worker is actually called from a different thread.
  117. In particular, when free-wheeling (e.g. for offline rendering), the
  118. worker may be executed immediately. This allows single-threaded
  119. processing with sample accuracy and avoids timing problems when run() is
  120. executing much faster or slower than real-time.
  121. Plugins SHOULD be written in such a way that if the worker runs
  122. immediately, and responses from the worker are delivered immediately,
  123. the effect of the work takes place immediately with sample accuracy.
  124. The `data` MUST be safe for the host to copy and later pass to work(),
  125. and the host MUST guarantee that it will be eventually passed to work()
  126. if this function returns LV2_WORKER_SUCCESS.
  127. @param handle The handle field of this struct.
  128. @param size The size of `data`.
  129. @param data Message to pass to work(), or NULL.
  130. */
  131. LV2_Worker_Status (*schedule_work)(LV2_Worker_Schedule_Handle handle,
  132. uint32_t size,
  133. const void* data);
  134. } LV2_Worker_Schedule;
  135. #ifdef __cplusplus
  136. } /* extern "C" */
  137. #endif
  138. #endif /* LV2_WORKER_H */
  139. /**
  140. @}
  141. */