Skip to content

Commit

Permalink
more AAPXS v2 pipeline work. Now non-RT extensions are back to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Nov 5, 2023
1 parent e6d8028 commit 63e7f36
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@ void aap::AAPXSMidi2Processor::process(void* buffer) {
void aap::AAPXSMidi2Processor::addReply(
void (*addMidi2Event)(AAPXSMidi2Processor * processor, void *userData, int32_t messageSize),
void* addMidi2EventUserData,
const char* extensionUri,
int32_t group,
int32_t requestId,
AAPXSServiceInstance *aapxsInstance,
int32_t messageSize,
void* data,
int32_t dataSize,
int32_t opcode) {
size_t size = aap_midi2_generate_aapxs_sysex8((uint32_t*) midi2_aapxs_data_buffer,
AAP_MIDI2_AAPXS_DATA_MAX_SIZE / sizeof(int32_t),
(uint8_t*) midi2_aapxs_conversion_helper_buffer,
AAP_MIDI2_AAPXS_DATA_MAX_SIZE,
group,
requestId,
aapxsInstance->uri,
extensionUri,
opcode,
(uint8_t*) aapxsInstance->data,
messageSize);
(uint8_t*) data,
dataSize);
addMidi2Event(this, addMidi2EventUserData, size);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ AndroidAudioPluginHost* aap::LocalPluginInstance::getHostFacadeForCompleteInstan

void *
aap::LocalPluginInstance::internalGetHostExtension(AndroidAudioPluginHost *host, const char *uri) {
#if USE_AAPXS_V2
// FIXME: implement
assert(false);
return nullptr;
#else
if (strcmp(uri, AAP_PLUGIN_INFO_EXTENSION_URI) == 0) {
auto instance = (LocalPluginInstance *) host->context;
instance->host_plugin_info.get = get_plugin_info;
return &instance->host_plugin_info;
}
#if USE_AAPXS_V2
// FIXME: implement
assert(false);
return nullptr;
#else
if (strcmp(uri, AAP_PARAMETERS_EXTENSION_URI) == 0) {
auto instance = (LocalPluginInstance *) host->context;
instance->host_parameters_extension.notify_parameters_changed = notify_parameters_changed;
Expand Down Expand Up @@ -217,8 +217,8 @@ static inline void staticSendAAPXSReply(AAPXSRecipientInstance* instance, AAPXSR
context->serialization->data_size,
context->request_id);
}
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);
static inline bool staticSendAAPXSRequest(AAPXSInitiatorInstance* instance, AAPXSRequestContext* context) {
return ((aap::LocalPluginInstance*) instance->host_context)->sendHostAAPXSRequest(context->uri, context->opcode, context->serialization->data, context->serialization->data_size, context->request_id);
}

void aap::LocalPluginInstance::setupAAPXSInstances() {
Expand All @@ -238,12 +238,24 @@ void aap::LocalPluginInstance::setupAAPXSInstances() {
}

void
aap::LocalPluginInstance::sendPluginAAPXSReply(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
// FIXME: implement
throw std::runtime_error("FIXME: implement");
aap::LocalPluginInstance::sendPluginAAPXSReply(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t requestId) {
if (instantiation_state == PLUGIN_INSTANTIATION_STATE_ACTIVE) {
auto aapxsInstance = getAAPXSDispatcher().getPluginAAPXSByUri(uri);
aapxs_midi2_processor.addReply(aapxsProcessorAddEventUmpOutput,
this,
uri,
// should we support MIDI 2.0 group?
0,
requestId,
aapxsInstance->serialization->data,
dataSize,
opcode);
} else {
// it is synchronously handled at Binder IPC, nothing to process here.
}
}

void
bool
aap::LocalPluginInstance::sendHostAAPXSRequest(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
auto aapxsInstance = aapxs_dispatcher.getHostAAPXSByUri(uri);

Expand All @@ -255,9 +267,11 @@ aap::LocalPluginInstance::sendHostAAPXSRequest(const char* uri, int32_t opcode,
std::promise<int32_t> promise;
aapxs_host_session.addSession(aapxsSessionAddEventUmpInput, this, group, newRequestId, uri, aapxsInstance->serialization->data, dataSize, opcode, std::move(promise));
// This is an asynchronous function, so we do not wait for the result.
return true;
} else {
// the actual implementation is in AudioPluginInterfaceImpl, kicks `hostExtension()` on the callback proxy object.
ipc_send_extension_message_func(ipc_send_extension_message_context, uri, getInstanceId(), opcode);
return false;
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ aap::RemoteAAPXSManager::staticProcessExtensionReply(AAPXSClientInstance *client

// ---- AAPXS v2
#if USE_AAPXS_V2
static inline void staticSendAAPXSRequest(AAPXSInitiatorInstance* instance, AAPXSRequestContext* context) {
((aap::RemotePluginInstance *) instance->host_context)->sendPluginAAPXSRequest(context->uri,
static inline bool staticSendAAPXSRequest(AAPXSInitiatorInstance* instance, AAPXSRequestContext* context) {
return ((aap::RemotePluginInstance *) instance->host_context)->sendPluginAAPXSRequest(context->uri,
context->opcode,
context->serialization->data,
context->serialization->data_size,
Expand All @@ -284,7 +284,9 @@ bool aap::RemotePluginInstance::setupAAPXSInstances(xs::AAPXSDefinitionClientReg
}
#endif

void
// returns true if it is asynchronously invoked without waiting for result,
// or false if it is synchronously completed.
bool
aap::RemotePluginInstance::sendPluginAAPXSRequest(const char* uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
// If it is at ACTIVE state it has to switch to AAPXS SysEx8 MIDI messaging mode,
// otherwise it goes to the Binder route.
Expand All @@ -294,13 +296,15 @@ aap::RemotePluginInstance::sendPluginAAPXSRequest(const char* uri, int32_t opcod
std::promise<int32_t> promise;
aapxs_session.addSession(aapxsSessionAddEventUmpInput, this, group, newRequestId, uri, data, dataSize, opcode, std::move(promise));
// This is an asynchronous function, so we do not wait for the result.
return true;
} else {
// Here we have to get a native plugin instance and send extension message.
// It is kind af annoying because we used to implement Binder-specific part only within the
// plugin API (binder-client-as-plugin.cpp)...
// So far, instead of rewriting a lot of code to do so, we let AAPClientContext
// assign its implementation details that handle Binder messaging as a std::function.
ipc_send_extension_message_impl(plugin->plugin_specific, uri, getInstanceId(), dataSize, opcode);
return false;
}
}

Expand Down
8 changes: 6 additions & 2 deletions include/aap/core/AAPXSMidi2Processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ namespace aap {

void
addReply(void (*addMidi2Event)(AAPXSMidi2Processor *, void *, int32_t),
void *addMidi2EventUserData,
int32_t group, int32_t requestId, AAPXSServiceInstance *aapxsInstance, int32_t messageSize,
void* addMidi2EventUserData,
const char* extensionUri,
int32_t group,
int32_t requestId,
void* data,
int32_t dataSize,
int32_t opcode);
};
}
Expand Down
26 changes: 16 additions & 10 deletions include/aap/core/aapxs/aapxs-runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace aap::xs {
class AAPXSDefinitionServiceRegistry;

typedef uint32_t (*initiator_get_new_request_id_func) (AAPXSInitiatorInstance* instance);
typedef void (*aapxs_initiator_send_func) (AAPXSInitiatorInstance* instance, AAPXSRequestContext* context);
typedef bool (*aapxs_initiator_send_func) (AAPXSInitiatorInstance* instance, AAPXSRequestContext* context);
typedef void (*aapxs_recipient_send_func) (AAPXSRecipientInstance* instance, AAPXSRequestContext* context);

class AAPXSDispatcher {
Expand Down Expand Up @@ -253,6 +253,11 @@ namespace aap::xs {
callbackData->promise->set_value(result);
}

template<typename T>
static T getTypedResult(AAPXSSerializationContext* serialization) {
return *(T*) (serialization->data);
}

static void getVoidCallback(void* callbackContext, void* pluginOrHost, int32_t requestId) {
auto callbackData = (WithPromise<TypedAAPXS, int32_t>*) callbackContext;
callbackData->promise->set_value(0); // dummy result
Expand All @@ -267,12 +272,14 @@ namespace aap::xs {
uint32_t requestId = aapxs_instance->get_new_request_id(aapxs_instance);
auto future = promise.get_future();
WithPromise<TypedAAPXS, T> callbackData{this, &promise};
AAPXSRequestContext request{getTypedCallback<int32_t>, &callbackData, serialization, uri, requestId, opcode};

aapxs_instance->send_aapxs_request(aapxs_instance, &request);

future.wait();
return future.get();
AAPXSRequestContext request{getTypedCallback<T>, &callbackData, serialization, uri, requestId, opcode};

if (aapxs_instance->send_aapxs_request(aapxs_instance, &request)) {
future.wait();
return future.get();
}
else
return getTypedResult<T>(serialization);
}

// FIXME: use spinlock instead of promise<T> for RT-safe extension functions,
Expand All @@ -284,9 +291,8 @@ namespace aap::xs {
WithPromise<TypedAAPXS, int32_t> callbackData{this, &promise};
AAPXSRequestContext request{getVoidCallback, &callbackData, serialization, uri, requestId, opcode};

aapxs_instance->send_aapxs_request(aapxs_instance, &request);

future.wait();
if (aapxs_instance->send_aapxs_request(aapxs_instance, &request))
future.wait();
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions include/aap/core/host/plugin-instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ namespace aap {
void setupAAPXSInstances();
#endif
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);
bool sendHostAAPXSRequest(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId);

void setIpcExtensionMessageSender(aapxs_host_ipc_sender sender, void* context) {
ipc_send_extension_message_func = sender;
Expand Down Expand Up @@ -406,7 +406,7 @@ namespace aap {
inline xs::AAPXSClientDispatcher& getAAPXSDispatcher() { return aapxs_dispatcher; }
bool setupAAPXSInstances(xs::AAPXSDefinitionClientRegistry *registry, std::function<bool(const char*, AAPXSSerializationContext*)> sharedMemoryAllocatingRequester);
#endif
void sendPluginAAPXSRequest(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId);
bool sendPluginAAPXSRequest(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId);
void processPluginAAPXSReply(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t requestId);
void sendHostAAPXSReply(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId);
void processHostAAPXSRequest(const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t requestId);
Expand Down
2 changes: 1 addition & 1 deletion include/aap/unstable/aapxs-vnext.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct AAPXSInitiatorInstance {

// assigned by: framework reference implementation
// invoked by: AAPXS developer
void (*send_aapxs_request) (AAPXSInitiatorInstance* instance, AAPXSRequestContext* context);
bool (*send_aapxs_request) (AAPXSInitiatorInstance* instance, AAPXSRequestContext* context);
} AAPXSInitiatorInstance;

// service instance for plugin extension API, and client instance for host extension API
Expand Down

0 comments on commit 63e7f36

Please sign in to comment.