Add audio thread callbacks

This commit is contained in:
Robbert van der Helm
2022-09-26 16:45:05 +02:00
parent 0d472dcd58
commit 214ba51010
2 changed files with 33 additions and 0 deletions
+22
View File
@@ -328,6 +328,28 @@ class ClapSockets final : public Sockets {
request_ref, response_ref, request_ref.get().instance_id, logging);
}
/**
* Send a message from the Wine plugin host to the native plugin to handle
* an audio thread callback. Since those functions are called from a hot
* loop we want every instance to have a dedicated socket and thread for
* handling those. These calls also always reuse buffers to minimize
* allocations.
*
* @tparam T Some object in the `ClapAudioThreadCallbackRequest` variant.
* All of these objects need to have an `owner_instance_id` field.
*/
template <typename T>
typename T::Response send_audio_thread_callback_message(
const T& object,
std::optional<std::pair<ClapLogger&, bool>> logging) {
typename T::Response response_object;
thread_local SerializationBuffer<256> audio_thread_buffer{};
return audio_thread_sockets_.at(object.owner_instance_id)
.callback_.receive_into(object, response_object, logging,
audio_thread_buffer);
}
/**
* For sending messages from the host to the plugin. After we have a better
* idea of what our communication model looks like we'll probably want to
+11
View File
@@ -246,6 +246,17 @@ class ClapBridge : public HostBridge {
object, std::nullopt);
}
/**
* Send a callback message to the host from a plugin instance's audio
* thread. This is separate from `send_message()`, which shares one socket
* for all plugin instances.
*/
template <typename T>
typename T::Response send_audio_thread_message(const T& object) {
return sockets_.send_audio_thread_callback_message(
object, std::pair<ClapLogger&, bool>(logger_, true));
}
/**
* When called from the GUI thread, spawn a new thread and call
* `send_message()` from there, and then handle functions passed by calls to