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 5.7KB

12 years ago
11 years ago
12 years ago
11 years ago
12 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. @file worker.h C header for the LV2 Worker extension
  16. <http://lv2plug.in/ns/ext/worker>.
  17. */
  18. #ifndef LV2_WORKER_H
  19. #define LV2_WORKER_H
  20. #include <stdint.h>
  21. #include "lv2.h"
  22. #define LV2_WORKER_URI "http://lv2plug.in/ns/ext/worker"
  23. #define LV2_WORKER_PREFIX LV2_WORKER_URI "#"
  24. #define LV2_WORKER__interface LV2_WORKER_PREFIX "interface"
  25. #define LV2_WORKER__schedule LV2_WORKER_PREFIX "schedule"
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. /**
  30. A status code for worker functions.
  31. */
  32. typedef enum {
  33. LV2_WORKER_SUCCESS = 0, /**< Completed successfully. */
  34. LV2_WORKER_ERR_UNKNOWN = 1, /**< Unknown error. */
  35. LV2_WORKER_ERR_NO_SPACE = 2 /**< Failed due to lack of space. */
  36. } LV2_Worker_Status;
  37. typedef void* LV2_Worker_Respond_Handle;
  38. /**
  39. A function to respond to run() from the worker method.
  40. The @p data MUST be safe for the host to copy and later pass to
  41. work_response(), and the host MUST guarantee that it will be eventually
  42. passed to work_response() if this function returns LV2_WORKER_SUCCESS.
  43. */
  44. typedef LV2_Worker_Status (*LV2_Worker_Respond_Function)(
  45. LV2_Worker_Respond_Handle handle,
  46. uint32_t size,
  47. const void* data);
  48. /**
  49. LV2 Plugin Worker Interface.
  50. This is the interface provided by the plugin to implement a worker method.
  51. The plugin's extension_data() method should return an LV2_Worker_Interface
  52. when called with LV2_WORKER__interface as its argument.
  53. */
  54. typedef struct _LV2_Worker_Interface {
  55. /**
  56. The worker method. This is called by the host in a non-realtime context
  57. as requested, possibly with an arbitrary message to handle.
  58. A response can be sent to run() using @p respond. The plugin MUST NOT
  59. make any assumptions about which thread calls this method, other than
  60. the fact that there are no real-time requirements.
  61. @param instance The LV2 instance this is a method on.
  62. @param respond A function for sending a response to run().
  63. @param handle Must be passed to @p respond if it is called.
  64. @param size The size of @p data.
  65. @param data Data from run(), or NULL.
  66. */
  67. LV2_Worker_Status (*work)(LV2_Handle instance,
  68. LV2_Worker_Respond_Function respond,
  69. LV2_Worker_Respond_Handle handle,
  70. uint32_t size,
  71. const void* data);
  72. /**
  73. Handle a response from the worker. This is called by the host in the
  74. run() context when a response from the worker is ready.
  75. @param instance The LV2 instance this is a method on.
  76. @param size The size of @p body.
  77. @param body Message body, or NULL.
  78. */
  79. LV2_Worker_Status (*work_response)(LV2_Handle instance,
  80. uint32_t size,
  81. const void* body);
  82. /**
  83. Called when all responses for this cycle have been delivered.
  84. Since work_response() may be called after run() finished, this provides
  85. a hook for code that must run after the cycle is completed.
  86. This field may be NULL if the plugin has no use for it. Otherwise, the
  87. host MUST call it after every run(), regardless of whether or not any
  88. responses were sent that cycle.
  89. */
  90. LV2_Worker_Status (*end_run)(LV2_Handle instance);
  91. } LV2_Worker_Interface;
  92. typedef void* LV2_Worker_Schedule_Handle;
  93. typedef struct _LV2_Worker_Schedule {
  94. /**
  95. Opaque host data.
  96. */
  97. LV2_Worker_Schedule_Handle handle;
  98. /**
  99. Request from run() that the host call the worker.
  100. This function is in the audio threading class. It should be called from
  101. run() to request that the host call the work() method in a non-realtime
  102. context with the given arguments.
  103. This function is always safe to call from run(), but it is not
  104. guaranteed that the worker is actually called from a different thread.
  105. In particular, when free-wheeling (e.g. for offline rendering), the
  106. worker may be executed immediately. This allows single-threaded
  107. processing with sample accuracy and avoids timing problems when run() is
  108. executing much faster or slower than real-time.
  109. Plugins SHOULD be written in such a way that if the worker runs
  110. immediately, and responses from the worker are delivered immediately,
  111. the effect of the work takes place immediately with sample accuracy.
  112. The @p data MUST be safe for the host to copy and later pass to work(),
  113. and the host MUST guarantee that it will be eventually passed to work()
  114. if this function returns LV2_WORKER_SUCCESS.
  115. @param handle The handle field of this struct.
  116. @param size The size of @p data.
  117. @param data Message to pass to work(), or NULL.
  118. */
  119. LV2_Worker_Status (*schedule_work)(LV2_Worker_Schedule_Handle handle,
  120. uint32_t size,
  121. const void* data);
  122. } LV2_Worker_Schedule;
  123. #ifdef __cplusplus
  124. } /* extern "C" */
  125. #endif
  126. #endif /* LV2_WORKER_H */