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.

worker.h 6.0KB

12 years ago
9 years ago
12 years ago
11 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
9 years ago
12 years ago
11 years ago
11 years ago
11 years ago
12 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. Copyright 2012 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"
  25. #define LV2_WORKER_PREFIX LV2_WORKER_URI "#"
  26. #define LV2_WORKER__interface LV2_WORKER_PREFIX "interface"
  27. #define LV2_WORKER__schedule LV2_WORKER_PREFIX "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, other than
  63. the fact that there are no real-time requirements.
  64. @param instance The LV2 instance this is a method on.
  65. @param respond A function for sending a response to run().
  66. @param handle Must be passed to `respond` if it is called.
  67. @param size The size of `data`.
  68. @param data Data from run(), or NULL.
  69. */
  70. LV2_Worker_Status (*work)(LV2_Handle instance,
  71. LV2_Worker_Respond_Function respond,
  72. LV2_Worker_Respond_Handle handle,
  73. uint32_t size,
  74. const void* data);
  75. /**
  76. Handle a response from the worker. This is called by the host in the
  77. run() context when a response from the worker is ready.
  78. @param instance The LV2 instance this is a method on.
  79. @param size The size of `body`.
  80. @param body Message body, or NULL.
  81. */
  82. LV2_Worker_Status (*work_response)(LV2_Handle instance,
  83. uint32_t size,
  84. const void* body);
  85. /**
  86. Called when all responses for this cycle have been delivered.
  87. Since work_response() may be called after run() finished, this provides
  88. a hook for code that must run after the cycle is completed.
  89. This field may be NULL if the plugin has no use for it. Otherwise, the
  90. host MUST call it after every run(), regardless of whether or not any
  91. responses were sent that cycle.
  92. */
  93. LV2_Worker_Status (*end_run)(LV2_Handle instance);
  94. } LV2_Worker_Interface;
  95. /** Opaque handle for LV2_Worker_Schedule. */
  96. typedef void* LV2_Worker_Schedule_Handle;
  97. /**
  98. Schedule Worker Host Feature.
  99. The host passes this feature to provide a schedule_work() function, which
  100. the plugin can use to schedule a worker call from run().
  101. */
  102. typedef struct _LV2_Worker_Schedule {
  103. /**
  104. Opaque host data.
  105. */
  106. LV2_Worker_Schedule_Handle handle;
  107. /**
  108. Request from run() that the host call the worker.
  109. This function is in the audio threading class. It should be called from
  110. run() to request that the host call the work() method in a non-realtime
  111. context with the given arguments.
  112. This function is always safe to call from run(), but it is not
  113. guaranteed that the worker is actually called from a different thread.
  114. In particular, when free-wheeling (e.g. for offline rendering), the
  115. worker may be executed immediately. This allows single-threaded
  116. processing with sample accuracy and avoids timing problems when run() is
  117. executing much faster or slower than real-time.
  118. Plugins SHOULD be written in such a way that if the worker runs
  119. immediately, and responses from the worker are delivered immediately,
  120. the effect of the work takes place immediately with sample accuracy.
  121. The `data` MUST be safe for the host to copy and later pass to work(),
  122. and the host MUST guarantee that it will be eventually passed to work()
  123. if this function returns LV2_WORKER_SUCCESS.
  124. @param handle The handle field of this struct.
  125. @param size The size of `data`.
  126. @param data Message to pass to work(), or NULL.
  127. */
  128. LV2_Worker_Status (*schedule_work)(LV2_Worker_Schedule_Handle handle,
  129. uint32_t size,
  130. const void* data);
  131. } LV2_Worker_Schedule;
  132. #ifdef __cplusplus
  133. } /* extern "C" */
  134. #endif
  135. #endif /* LV2_WORKER_H */
  136. /**
  137. @}
  138. */