Skip to content

Commit

Permalink
more AAPXS v2 work [WIP].
Browse files Browse the repository at this point in the history
- partially go back to implementation in PluginInstance classes.
- AAPXSFeatureVNext -> AAPXSDefinition
  • Loading branch information
atsushieno committed Oct 30, 2023
1 parent 98dc58c commit 9b9cb05
Show file tree
Hide file tree
Showing 12 changed files with 301 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ Java_org_androidaudioplugin_hosting_NativeRemotePluginInstance_00024Companion_se
jboolean isCopy{false};
auto uriChars = env->GetStringUTFChars(uri, &isCopy);
auto src = (uint8_t*) env->GetDirectBufferAddress(buffer);
instance->getAAPXSDispatcher().sendExtensionRequest(uriChars, opcode, src + offset, length, instance->aapxsRequestIdSerial());
instance->sendAAPXSRequest(uriChars, opcode, src + offset, length, instance->aapxsRequestIdSerial());
if (isCopy)
env->ReleaseStringChars(uri, (const jchar*) uriChars);
}
Expand Down
150 changes: 51 additions & 99 deletions androidaudioplugin/src/main/cpp/core/aapxs/aapxs-runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,148 +3,100 @@
#include "aap/core/aapxs/aapxs-runtime.h"

aap::AAPXSClientDispatcher::AAPXSClientDispatcher(
aap::AAPXSClientFeatureRegistry *registry) /*: registry(registry)*/ {
aap::AAPXSDefinitionClientRegistry *registry) /*: registry(registry)*/ {
}

aap::AAPXSServiceDispatcher::AAPXSServiceDispatcher(
aap::AAPXSServiceFeatureRegistry *registry) {
aap::AAPXSDefinitionServiceRegistry *registry) {
}

// Client setup
void aap::AAPXSClientDispatcher::setupInstances(aap::AAPXSClientFeatureRegistry *registry,

void aap::AAPXSClientDispatcher::setupInstances(aap::AAPXSDefinitionClientRegistry *registry,
AAPXSSerializationContext *serialization,
initiator_get_new_request_id_func initiatorGetNewRequestId,
recipient_get_new_request_id_func recipientGetNewRequestId) {
std::for_each(registry->begin(), registry->end(), [&](AAPXSFeatureVNext* f) {
aap::aapxs_initiator_send_func sendAAPXSRequest,
aap::aapxs_initiator_receive_func processIncomingAAPXSReply,
aap::aapxs_recipient_receive_func processIncomingAAPXSRequest,
aap::aapxs_recipient_send_func sendAAPXSReply,
aap::initiator_get_new_request_id_func initiatorGetNewRequestId,
aap::recipient_get_new_request_id_func recipientGetNewRequestId) {
std::for_each(registry->begin(), registry->end(), [&](AAPXSDefinition* f) {
// plugin extensions
addInitiator(populateAAPXSInitiatorInstance(serialization, initiatorGetNewRequestId), f->uri);
addInitiator(populateAAPXSInitiatorInstance(serialization, sendAAPXSRequest, processIncomingAAPXSReply, initiatorGetNewRequestId), f->uri);
// host extensions
addRecipient(populateAAPXSRecipientInstance(serialization, recipientGetNewRequestId), f->uri);
addRecipient(populateAAPXSRecipientInstance(serialization, processIncomingAAPXSRequest, sendAAPXSReply, recipientGetNewRequestId), f->uri);
});
}

AAPXSInitiatorInstance aap::AAPXSClientDispatcher::populateAAPXSInitiatorInstance(AAPXSSerializationContext* serialization, initiator_get_new_request_id_func getNewRequestId) {
AAPXSInitiatorInstance aap::AAPXSClientDispatcher::populateAAPXSInitiatorInstance(
AAPXSSerializationContext* serialization,
aap::aapxs_initiator_send_func sendAAPXSRequest,
aap::aapxs_initiator_receive_func processIncomingAAPXSReply,
initiator_get_new_request_id_func getNewRequestId) {
AAPXSInitiatorInstance instance{this,
serialization,
getNewRequestId,
staticSendAAPXSRequest,
staticProcessIncomingAAPXSReply};
sendAAPXSRequest,
processIncomingAAPXSReply};
return instance;
}

AAPXSRecipientInstance aap::AAPXSClientDispatcher::populateAAPXSRecipientInstance(
AAPXSSerializationContext *serialization, recipient_get_new_request_id_func getNewRequestId) {
AAPXSRecipientInstance
aap::AAPXSClientDispatcher::populateAAPXSRecipientInstance(
AAPXSSerializationContext *serialization,
aap::aapxs_recipient_receive_func processIncomingAapxsRequest,
aap::aapxs_recipient_send_func sendAapxsReply,
aap::recipient_get_new_request_id_func getNewRequestId) {
AAPXSRecipientInstance instance{this,
serialization,
getNewRequestId,
staticProcessIncomingAAPXSRequest,
staticSendAAPXSReply};
processIncomingAapxsRequest,
sendAapxsReply};
return instance;
}

// Client send/receive
void
aap::AAPXSClientDispatcher::sendExtensionRequest(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
auto aapxs = getPluginAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, newRequestId, opcode};
assert(aapxs.serialization->data_capacity >= dataSize);
memcpy(aapxs.serialization->data, data, dataSize);
aapxs.serialization->data_size = dataSize;
aapxs.send_aapxs_request(&aapxs, &context);
}

void
aap::AAPXSClientDispatcher::processExtensionReply(const char *uri, int32_t opcode, void* data, int32_t dataSize, uint32_t requestId) {
auto aapxs = getPluginAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
aapxs.process_incoming_aapxs_reply(&aapxs, &context);
}

void
aap::AAPXSClientDispatcher::processHostExtensionRequest(const char *uri, int32_t opcode, void* data, int32_t dataSize, uint32_t requestId) {
auto aapxs = getHostAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
aapxs.process_incoming_aapxs_request(&aapxs, &context);
}

void
aap::AAPXSClientDispatcher::sendHostExtensionReply(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t requestId) {
auto aapxs = getHostAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
assert(aapxs.serialization->data_capacity >= dataSize);
memcpy(aapxs.serialization->data, data, dataSize);
aapxs.serialization->data_size = dataSize;
aapxs.send_aapxs_reply(&aapxs, &context);
}

// Service send/receive
// Service setup

// setup
void aap::AAPXSServiceDispatcher::setupInstances(aap::AAPXSServiceFeatureRegistry *registry,
void aap::AAPXSServiceDispatcher::setupInstances(aap::AAPXSDefinitionServiceRegistry *registry,
AAPXSSerializationContext *serialization,
initiator_get_new_request_id_func initiatorGetNewRequestId,
recipient_get_new_request_id_func recipientGetNewRequestId) {
std::for_each(registry->begin(), registry->end(), [&](AAPXSFeatureVNext* f) {
aap::aapxs_initiator_send_func sendAAPXSRequest,
aap::aapxs_initiator_receive_func processIncomingAAPXSReply,
aap::aapxs_recipient_receive_func processIncomingAapxsRequest,
aap::aapxs_recipient_send_func sendAapxsReply,
aap::initiator_get_new_request_id_func initiatorGetNewRequestId,
aap::recipient_get_new_request_id_func recipientGetNewRequestId) {
std::for_each(registry->begin(), registry->end(), [&](AAPXSDefinition* f) {
// host extensions
addInitiator(populateAAPXSInitiatorInstance(serialization, initiatorGetNewRequestId), f->uri);
addInitiator(populateAAPXSInitiatorInstance(serialization, sendAAPXSRequest, processIncomingAAPXSReply, initiatorGetNewRequestId), f->uri);
// plugin extensions
addRecipient(populateAAPXSRecipientInstance(serialization, recipientGetNewRequestId), f->uri);
addRecipient(populateAAPXSRecipientInstance(serialization, processIncomingAapxsRequest, sendAapxsReply, recipientGetNewRequestId), f->uri);
});
}


AAPXSRecipientInstance
aap::AAPXSServiceDispatcher::populateAAPXSRecipientInstance(
AAPXSSerializationContext *serialization, recipient_get_new_request_id_func getNewRequestId) {
AAPXSSerializationContext *serialization,
aap::aapxs_recipient_receive_func processIncomingAAPXSRequest,
aap::aapxs_recipient_send_func sendAAPXSReply,
recipient_get_new_request_id_func getNewRequestId) {
AAPXSRecipientInstance instance{this,
serialization,
getNewRequestId,
staticProcessIncomingAAPXSRequest,
staticSendAAPXSReply};
processIncomingAAPXSRequest,
sendAAPXSReply};
return instance;
}

AAPXSInitiatorInstance
aap::AAPXSServiceDispatcher::populateAAPXSInitiatorInstance(
AAPXSSerializationContext *serialization, initiator_get_new_request_id_func getNewRequestId) {
AAPXSSerializationContext *serialization,
aapxs_initiator_send_func sendHostAAPXSRequest,
aapxs_initiator_receive_func processIncomingHostAAPXSReply,
initiator_get_new_request_id_func getNewRequestId) {
AAPXSInitiatorInstance instance{this,
serialization,
getNewRequestId,
staticSendHostAAPXSRequest,
staticProcessIncomingHostAAPXSReply};
sendHostAAPXSRequest,
processIncomingHostAAPXSReply};
return instance;
}

// send/receive
void
aap::AAPXSServiceDispatcher::processExtensionRequest(const char *uri, int32_t opcode, uint32_t requestId) {
auto aapxs = getPluginAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
aapxs.process_incoming_aapxs_request(&aapxs, &context);
}

void
aap::AAPXSServiceDispatcher::sendExtensionReply(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t requestId) {
auto aapxs = getPluginAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
assert(aapxs.serialization->data_capacity >= dataSize);
memcpy(aapxs.serialization->data, data, dataSize);
aapxs.serialization->data_size = dataSize;
aapxs.send_aapxs_reply(&aapxs, &context);
}

void
aap::AAPXSServiceDispatcher::sendHostExtensionRequest(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
auto aapxs = getHostAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, newRequestId, opcode};
assert(aapxs.serialization->data_capacity >= dataSize);
memcpy(aapxs.serialization->data, data, dataSize);
aapxs.serialization->data_size = dataSize;
aapxs.send_aapxs_request(&aapxs, &context);
}

void aap::AAPXSServiceDispatcher::processHostExtensionReply(const char *uri, int32_t opcode, uint32_t requestId) {
auto aapxs = getHostAAPXSByUri(uri);
AAPXSRequestContext context{nullptr, nullptr, aapxs.serialization, uri, requestId, opcode};
aapxs.process_incoming_aapxs_reply(&aapxs, &context);
}
21 changes: 11 additions & 10 deletions androidaudioplugin/src/main/cpp/core/aapxs/presets-aapxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "aap/core/aapxs/aapxs-runtime.h"

void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_plugin_aapxs_request(
struct AAPXSFeatureVNext *feature, AAPXSRecipientInstance *aapxsInstance,
struct AAPXSDefinition *feature, AAPXSRecipientInstance *aapxsInstance,
AndroidAudioPlugin *plugin, AAPXSRequestContext *context) {
auto ext = (aap_presets_extension_t*) plugin->get_extension(plugin, AAP_PRESETS_EXTENSION_URI);
switch(context->opcode) {
Expand Down Expand Up @@ -57,7 +57,7 @@ void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_plugin_aapxs_reque
}

void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_host_aapxs_request(
struct AAPXSFeatureVNext *feature, AAPXSRecipientInstance *aapxsInstance,
struct AAPXSDefinition *feature, AAPXSRecipientInstance *aapxsInstance,
AndroidAudioPluginHost *host, AAPXSRequestContext *context) {
auto ext = (aap_presets_host_extension_t*) host->get_extension(host, AAP_PRESETS_EXTENSION_URI);
switch(context->opcode) {
Expand All @@ -75,14 +75,14 @@ void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_host_aapxs_request
}

void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_plugin_aapxs_reply(
struct AAPXSFeatureVNext *feature, AAPXSInitiatorInstance *aapxsInstance,
struct AAPXSDefinition *feature, AAPXSInitiatorInstance *aapxsInstance,
AndroidAudioPlugin *plugin, AAPXSRequestContext *request) {
if (request->callback != nullptr)
request->callback(request->callback_user_data, plugin, request->request_id);
}

void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_host_aapxs_reply(
struct AAPXSFeatureVNext *feature, AAPXSInitiatorInstance *aapxsInstance,
struct AAPXSDefinition *feature, AAPXSInitiatorInstance *aapxsInstance,
AndroidAudioPluginHost *host, AAPXSRequestContext *context) {
//auto ext = (aap_presets_host_extension_t*) host->get_extension(host, AAP_PRESETS_EXTENSION_URI);
switch(context->opcode) {
Expand All @@ -95,7 +95,7 @@ void aap::AAPXSFeaturePresets::aapxs_presets_process_incoming_host_aapxs_reply(
}
}

// Strongly-typed client implementation
// Strongly-typed client implementation (plugin extension functions)

void aap::PresetsClientAAPXS::getPresetIntCallback(void* callbackContext, AndroidAudioPlugin* plugin, int32_t requestId) {
auto callbackData = (WithPromise<aap::PresetsClientAAPXS, int32_t>*) callbackContext;
Expand Down Expand Up @@ -134,6 +134,7 @@ void aap::PresetsClientAAPXS::getPresetCallback(void* callbackContext, AndroidAu
}

void aap::PresetsClientAAPXS::getPreset(int32_t index, aap_preset_t &preset) {
// FIXME: use spinlock instead of std::promise and std::future, as getPresetCount() and getPresetIndex() must be RT_SAFE.
std::promise<int32_t> promise{};
uint32_t requestId = initiatorInstance->get_new_request_id(initiatorInstance);
auto future = promise.get_future();
Expand Down Expand Up @@ -161,16 +162,16 @@ void aap::PresetsClientAAPXS::setPresetIndex(int32_t index) {
initiatorInstance->send_aapxs_request(initiatorInstance, &request);
}

// Strongly-typed service implementation
// Strongly-typed service implementation (host extension functions)

void aap::PresetsServiceAAPXS::notifyPresetLoaded() {
uint32_t requestId = recipientInstance->get_new_request_id(recipientInstance);
uint32_t requestId = initiatorInstance->get_new_request_id(initiatorInstance);
AAPXSRequestContext context{nullptr, nullptr, serialization, AAP_PRESETS_EXTENSION_URI, requestId, OPCODE_NOTIFY_PRESET_LOADED};
recipientInstance->process_incoming_aapxs_request(recipientInstance, &context);
initiatorInstance->send_aapxs_request(initiatorInstance, &context);
}

void aap::PresetsServiceAAPXS::notifyPresetsUpdated() {
uint32_t requestId = recipientInstance->get_new_request_id(recipientInstance);
uint32_t requestId = initiatorInstance->get_new_request_id(initiatorInstance);
AAPXSRequestContext context{nullptr, nullptr, serialization, AAP_PRESETS_EXTENSION_URI, requestId, OPCODE_NOTIFY_PRESET_UPDATED};
recipientInstance->process_incoming_aapxs_request(recipientInstance, &context);
initiatorInstance->send_aapxs_request(initiatorInstance, &context);
}
32 changes: 16 additions & 16 deletions androidaudioplugin/src/main/cpp/core/aapxs/presets-aapxs.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace aap {
protected:
AAPXSFeatureImpl() {}
public:
virtual AAPXSFeatureVNext* asPublic() = 0;
virtual AAPXSDefinition* asPublic() = 0;

template<typename T>
static T correlate(AAPXSRequestContext request, std::function<std::future<T>(std::promise<T> promiseInner)> registerCallback, std::function<T()> getResult) {
Expand All @@ -41,37 +41,37 @@ namespace aap {
: public AAPXSFeatureImpl {

static void aapxs_presets_process_incoming_plugin_aapxs_request(
struct AAPXSFeatureVNext* feature,
struct AAPXSDefinition* feature,
AAPXSRecipientInstance* aapxsInstance,
AndroidAudioPlugin* plugin,
AAPXSRequestContext* context);
static void aapxs_presets_process_incoming_host_aapxs_request(
struct AAPXSFeatureVNext* feature,
struct AAPXSDefinition* feature,
AAPXSRecipientInstance* aapxsInstance,
AndroidAudioPluginHost* host,
AAPXSRequestContext* context);
static void aapxs_presets_process_incoming_plugin_aapxs_reply(
struct AAPXSFeatureVNext* feature,
struct AAPXSDefinition* feature,
AAPXSInitiatorInstance* aapxsInstance,
AndroidAudioPlugin* plugin,
AAPXSRequestContext* context);
static void aapxs_presets_process_incoming_host_aapxs_reply(
struct AAPXSFeatureVNext* feature,
struct AAPXSDefinition* feature,
AAPXSInitiatorInstance* aapxsInstance,
AndroidAudioPluginHost* host,
AAPXSRequestContext* context);

AAPXSFeatureVNext aapxs_presets{AAP_PRESETS_EXTENSION_URI,
nullptr,
PRESETS_SHARED_MEMORY_SIZE,
aapxs_presets_process_incoming_plugin_aapxs_request,
aapxs_presets_process_incoming_host_aapxs_request,
aapxs_presets_process_incoming_plugin_aapxs_reply,
aapxs_presets_process_incoming_host_aapxs_reply
AAPXSDefinition aapxs_presets{AAP_PRESETS_EXTENSION_URI,
nullptr,
PRESETS_SHARED_MEMORY_SIZE,
aapxs_presets_process_incoming_plugin_aapxs_request,
aapxs_presets_process_incoming_host_aapxs_request,
aapxs_presets_process_incoming_plugin_aapxs_reply,
aapxs_presets_process_incoming_host_aapxs_reply
};

public:
AAPXSFeatureVNext * asPublic() override {
AAPXSDefinition * asPublic() override {
return &aapxs_presets;
}
};
Expand All @@ -96,12 +96,12 @@ namespace aap {
};

class PresetsServiceAAPXS {
AAPXSRecipientInstance *recipientInstance;
AAPXSInitiatorInstance *initiatorInstance;
AAPXSSerializationContext *serialization;

public:
PresetsServiceAAPXS(AAPXSRecipientInstance* instance, AAPXSSerializationContext* serialization)
: recipientInstance(instance), serialization(serialization) {
PresetsServiceAAPXS(AAPXSInitiatorInstance* instance, AAPXSSerializationContext* serialization)
: initiatorInstance(instance), serialization(serialization) {
}

void notifyPresetLoaded();
Expand Down
Loading

0 comments on commit 9b9cb05

Please sign in to comment.