From e6d8028f7597ede030f4d7404252ccf36d212b14 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Sun, 5 Nov 2023 16:01:59 +0900 Subject: [PATCH] more AAPXS v2 pipeline implementation. --- .../src/main/cpp/android/AudioPluginInterfaceImpl.h | 3 ++- .../src/main/cpp/android/binder-client-as-plugin.cpp | 6 +++--- .../src/main/cpp/core/aapxs/aapxs-runtime.cpp | 1 + .../src/main/cpp/core/aapxs/midi-aapxs.cpp | 1 + .../src/main/cpp/core/hosting/PluginInstance.Local.cpp | 10 ++++++---- include/aap/core/host/plugin-instance.h | 8 +++++--- 6 files changed, 18 insertions(+), 11 deletions(-) diff --git a/androidaudioplugin/src/main/cpp/android/AudioPluginInterfaceImpl.h b/androidaudioplugin/src/main/cpp/android/AudioPluginInterfaceImpl.h index 990ffc90..345b3308 100644 --- a/androidaudioplugin/src/main/cpp/android/AudioPluginInterfaceImpl.h +++ b/androidaudioplugin/src/main/cpp/android/AudioPluginInterfaceImpl.h @@ -76,7 +76,7 @@ class AudioPluginInterfaceImpl : public aidl::org::androidaudioplugin::BnAudioPl int32_t *_aidl_return) override { *_aidl_return = svc->createInstance(in_pluginId, in_sampleRate); auto instance = svc->getLocalInstance(*_aidl_return); - instance->setIpcExtensionMessageSender(aapxs_host_ipc_sender_func); + instance->setIpcExtensionMessageSender(aapxs_host_ipc_sender_func, this); if (*_aidl_return < 0) return ndk::ScopedAStatus::fromServiceSpecificErrorWithMessage( AAP_BINDER_ERROR_CREATE_INSTANCE_FAILED, "failed to create AAP service instance."); @@ -137,6 +137,7 @@ class AudioPluginInterfaceImpl : public aidl::org::androidaudioplugin::BnAudioPl CHECK_INSTANCE(instance, in_instanceID) instance->completeInstantiation(); + instance->setupAAPXSInstances(); instance->startPortConfiguration(); return ndk::ScopedAStatus::ok(); } diff --git a/androidaudioplugin/src/main/cpp/android/binder-client-as-plugin.cpp b/androidaudioplugin/src/main/cpp/android/binder-client-as-plugin.cpp index 38188de2..cb4cea2e 100644 --- a/androidaudioplugin/src/main/cpp/android/binder-client-as-plugin.cpp +++ b/androidaudioplugin/src/main/cpp/android/binder-client-as-plugin.cpp @@ -218,13 +218,13 @@ AndroidAudioPlugin* aap_client_as_plugin_new( // We make use of plugin metadata that should list up required and optional extensions. if (!instance->setupAAPXSInstances(instance->getAAPXSRegistry(), [&](const char* uri, AAPXSSerializationContext *serialization) { // create asharedmem and add as an extension FD, keep it until it is destroyed. - auto fd = ASharedMemory_create(nullptr, serialization->data_size); + auto fd = ASharedMemory_create(nullptr, serialization->data_capacity); auto shm = instance->getSharedMemoryStore(); - serialization->data = shm->addExtensionFD(fd, serialization->data_size); + serialization->data = shm->addExtensionFD(fd, serialization->data_capacity); if (ctx->proxy_state != aap::PLUGIN_INSTANTIATION_STATE_ERROR) { ndk::ScopedFileDescriptor sfd{dup(fd)}; - auto stat = ctx->getProxy()->addExtension(ctx->instance_id, uri, sfd, serialization->data_size); + auto stat = ctx->getProxy()->addExtension(ctx->instance_id, uri, sfd, serialization->data_capacity); if (!stat.isOk()) { aap_bcap_log_error_with_details("addExtension() failed", stat); ctx->proxy_state = aap::PLUGIN_INSTANTIATION_STATE_ERROR; diff --git a/androidaudioplugin/src/main/cpp/core/aapxs/aapxs-runtime.cpp b/androidaudioplugin/src/main/cpp/core/aapxs/aapxs-runtime.cpp index 7f2be599..fb1f9d7a 100644 --- a/androidaudioplugin/src/main/cpp/core/aapxs/aapxs-runtime.cpp +++ b/androidaudioplugin/src/main/cpp/core/aapxs/aapxs-runtime.cpp @@ -22,6 +22,7 @@ bool aap::xs::AAPXSClientDispatcher::setupInstances(void* hostContext, int32_t urid = registry->items()->getUridMapping()->getUrid(f.uri); // allocate SerializationContext auto serialization = std::make_unique(); + serialization->data_capacity = f.data_capacity; if (!sharedMemoryAllocatingRequester(f.uri, serialization.get())) return false; // plugin extensions diff --git a/androidaudioplugin/src/main/cpp/core/aapxs/midi-aapxs.cpp b/androidaudioplugin/src/main/cpp/core/aapxs/midi-aapxs.cpp index a6511d98..e3be0d2f 100644 --- a/androidaudioplugin/src/main/cpp/core/aapxs/midi-aapxs.cpp +++ b/androidaudioplugin/src/main/cpp/core/aapxs/midi-aapxs.cpp @@ -16,6 +16,7 @@ void aap::xs::AAPXSDefinition_Midi::aapxs_midi_process_incoming_plugin_aapxs_req char *pluginId = (char *) calloc(len + 1, 1); strncpy(pluginId, (const char *) ((int32_t *) request->serialization->data + 1), len); *((int32_t *) request->serialization->data) = getMidiSettingsFromLocalConfig2(pluginId); + aapxsInstance->send_aapxs_reply(aapxsInstance, request); break; } } diff --git a/androidaudioplugin/src/main/cpp/core/hosting/PluginInstance.Local.cpp b/androidaudioplugin/src/main/cpp/core/hosting/PluginInstance.Local.cpp index 55cf386b..073d6802 100644 --- a/androidaudioplugin/src/main/cpp/core/hosting/PluginInstance.Local.cpp +++ b/androidaudioplugin/src/main/cpp/core/hosting/PluginInstance.Local.cpp @@ -210,28 +210,30 @@ void aap::LocalPluginInstance::setupAAPXS() { standards = std::make_unique(plugin); } -static inline void staticSendAAPXSReply(AAPXSInitiatorInstance* instance, AAPXSRequestContext* context) { +static inline void staticSendAAPXSReply(AAPXSRecipientInstance* instance, AAPXSRequestContext* context) { ((aap::LocalPluginInstance *) instance->host_context)->sendPluginAAPXSReply(context->uri, context->opcode, context->serialization->data, context->serialization->data_size, context->request_id); } -static inline void staticSendAAPXSRequest(AAPXSRecipientInstance* instance, AAPXSRequestContext* context) { +static inline void staticSendAAPXSRequest(AAPXSInitiatorInstance* instance, AAPXSRequestContext* context) { ((aap::LocalPluginInstance*) instance->host_context)->sendHostAAPXSRequest(context->uri, context->opcode, context->serialization->data, context->serialization->data_size, context->request_id); } void aap::LocalPluginInstance::setupAAPXSInstances() { auto store = getSharedMemoryStore(); auto func = [&](const char* uri, AAPXSSerializationContext* serialization) { + if (feature_registry->items()->getByUri(uri)->data_capacity == 0) + return; // no need to allocate serialization data auto index = store->getExtensionUriToIndexMap()[uri]; serialization->data = store->getExtensionBuffer(index); serialization->data_capacity = store->getExtensionBufferCapacity(index); }; aapxs_dispatcher.setupInstances(this, func, - staticSendAAPXSRequest, staticSendAAPXSReply, + staticSendAAPXSRequest, staticGetNewRequestId); } @@ -255,7 +257,7 @@ aap::LocalPluginInstance::sendHostAAPXSRequest(const char* uri, int32_t opcode, // This is an asynchronous function, so we do not wait for the result. } else { // the actual implementation is in AudioPluginInterfaceImpl, kicks `hostExtension()` on the callback proxy object. - ipc_send_extension_message_impl(plugin->plugin_specific, uri, getInstanceId(), opcode); + ipc_send_extension_message_func(ipc_send_extension_message_context, uri, getInstanceId(), opcode); } } #endif diff --git a/include/aap/core/host/plugin-instance.h b/include/aap/core/host/plugin-instance.h index 1c9a082a..1cf3c825 100644 --- a/include/aap/core/host/plugin-instance.h +++ b/include/aap/core/host/plugin-instance.h @@ -202,7 +202,8 @@ namespace aap { static void internalRequestProcess(AndroidAudioPluginHost *host); /** it is an unwanted exposure, but we need this internal-only member as public. You are not supposed to use it. */ - aapxs_host_ipc_sender ipc_send_extension_message_impl; + aapxs_host_ipc_sender ipc_send_extension_message_func; + void* ipc_send_extension_message_context; protected: AndroidAudioPluginHost *getHostFacadeForCompleteInstantiation() override; @@ -272,8 +273,9 @@ namespace aap { void sendPluginAAPXSReply(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId); void sendHostAAPXSRequest(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId); - void setIpcExtensionMessageSender(aapxs_host_ipc_sender sender) { - ipc_send_extension_message_impl = sender; + void setIpcExtensionMessageSender(aapxs_host_ipc_sender sender, void* context) { + ipc_send_extension_message_func = sender; + ipc_send_extension_message_context = context; } };