Skip to content

Commit

Permalink
more AAPXS v2 pipeline implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Nov 5, 2023
1 parent 7367271 commit e6d8028
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AAPXSSerializationContext>();
serialization->data_capacity = f.data_capacity;
if (!sharedMemoryAllocatingRequester(f.uri, serialization.get()))
return false;
// plugin extensions
Expand Down
1 change: 1 addition & 0 deletions androidaudioplugin/src/main/cpp/core/aapxs/midi-aapxs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,28 +210,30 @@ void aap::LocalPluginInstance::setupAAPXS() {
standards = std::make_unique<xs::ServiceStandardExtensions>(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);
}

Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions include/aap/core/host/plugin-instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};

Expand Down

0 comments on commit e6d8028

Please sign in to comment.