Skip to content

Commit

Permalink
add urid parameter to the anywhere it did not have it.
Browse files Browse the repository at this point in the history
  • Loading branch information
atsushieno committed Nov 14, 2023
1 parent b0520dd commit c572e57
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ size_t aap::AAPMidiEventTranslator::runThroughMidi2UmpForMidiMapping(uint8_t* by
conversion_helper_buffer_size,
0,
instance->aapxsRequestIdSerial(),
0, // FIXME: provide valid URID
AAP_PRESETS_EXTENSION_URI,
OPCODE_SET_PRESET_INDEX,
(const uint8_t *) aapxsInstance->serialization->data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ void aap_client_as_plugin_deactivate(AndroidAudioPlugin *plugin)
ctx->proxy_state = aap::PLUGIN_INSTANTIATION_STATE_INACTIVE;
}

// we do not care much about realtime safety breakage by lack of URID support here,
// because it is about Binder `extension()` call...
void* aap_client_as_plugin_get_extension(AndroidAudioPlugin *plugin, const char *uri)
{
auto ctx = (AAPClientContext*) plugin->plugin_specific;
Expand All @@ -172,6 +174,8 @@ aap_plugin_info_t aap_client_as_plugin_get_plugin_info(AndroidAudioPlugin *plugi
return hostExt->get(hostExt, &ctx->host, ctx->unique_id);
}

// we do not care much about realtime safety breakage by lack of URID support here,
// because it is about Binder `extension()` call...
void aap_client_as_plugin_send_extension_message_delegate(void* context,
const char* uri,
int32_t instanceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void aap::AAPXSMidi2InitiatorSession::addSession(
void* addMidi2EventUserData,
int32_t group,
int32_t requestId,
uint8_t urid,
const char* uri,
void* data,
int32_t dataSize,
Expand All @@ -39,6 +40,7 @@ void aap::AAPXSMidi2InitiatorSession::addSession(
midi_buffer_size,
group,
requestId,
urid,
uri,
opcode,
(uint8_t*) data,
Expand All @@ -53,6 +55,7 @@ void aap::AAPXSMidi2InitiatorSession::addSession(add_midi2_event_func addMidi2Ev
addSession(addMidi2Event, addMidi2EventUserData,
group,
request->request_id,
request->urid,
request->uri,
request->serialization->data,
request->serialization->data_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void aap::AAPXSMidi2RecipientSession::process(void* buffer) {
void aap::AAPXSMidi2RecipientSession::addReply(
void (*addMidi2Event)(AAPXSMidi2RecipientSession * processor, void *userData, int32_t messageSize),
void* addMidi2EventUserData,
uint8_t extensionUrid,
const char* extensionUri,
int32_t group,
int32_t requestId,
Expand All @@ -55,6 +56,7 @@ void aap::AAPXSMidi2RecipientSession::addReply(
AAP_MIDI2_AAPXS_DATA_MAX_SIZE,
group,
requestId,
extensionUrid,
extensionUri,
opcode,
(uint8_t*) data,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,19 @@ AndroidAudioPluginHost* aap::LocalPluginInstance::getHostFacadeForCompleteInstan
}

void *
aap::LocalPluginInstance::internalGetHostExtension(AndroidAudioPluginHost *host, const char *uri) {
auto instance = (LocalPluginInstance *) host->context;
aap::LocalPluginInstance::getHostExtension(uint8_t urid, const char *uri) {
// FIXME: in the future maybe we want to eliminate this kind of special cases.
// It is also not suitable for RT processing.
if (strcmp(uri, AAP_PLUGIN_INFO_EXTENSION_URI) == 0) {
instance->host_plugin_info.get = get_plugin_info;
return &instance->host_plugin_info;
host_plugin_info.get = get_plugin_info;
return &host_plugin_info;
}
// Look up host extension and get proxy via AAPXSDefinition.
auto definition = instance->getAAPXSRegistry()->items()->getByUri(uri);
auto registry = getAAPXSRegistry()->items();
auto definition = urid != 0 ? registry->getByUrid(urid) : registry->getByUri(uri);
if (definition && definition->get_host_extension_proxy) {
auto aapxsInstance = instance->getAAPXSDispatcher().getHostAAPXSByUri(uri);
auto& dispatcher = getAAPXSDispatcher();
auto aapxsInstance = urid != 0 ? dispatcher.getHostAAPXSByUrid(urid) : dispatcher.getHostAAPXSByUri(uri);
auto proxy = definition->get_host_extension_proxy(definition, aapxsInstance, aapxsInstance->serialization);
return proxy.as_host_extension(&proxy);
}
Expand Down Expand Up @@ -189,6 +191,7 @@ aap::LocalPluginInstance::sendPluginAAPXSReply(AAPXSRequestContext* request) {
if (instantiation_state == PLUGIN_INSTANTIATION_STATE_ACTIVE) {
aapxs_midi2_in_session.addReply(aapxsProcessorAddEventUmpOutput,
this,
request->urid,
request->uri,
// should we support MIDI 2.0 group?
0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void aap::RemotePluginInstance::configurePorts() {

AndroidAudioPluginHost* aap::RemotePluginInstance::getHostFacadeForCompleteInstantiation() {
plugin_host_facade.context = this;
plugin_host_facade.get_extension = RemotePluginInstance::internalGetHostExtension;
plugin_host_facade.get_extension = RemotePluginInstance::staticGetHostExtension;
return &plugin_host_facade;
}

Expand Down Expand Up @@ -154,15 +154,14 @@ void aap::RemotePluginInstance::process(int32_t frameCount, int32_t timeoutInNan
}

void *
aap::RemotePluginInstance::internalGetHostExtension(AndroidAudioPluginHost *host, const char *uri) {
auto instance = (RemotePluginInstance *) host->context;
aap::RemotePluginInstance::internalGetHostExtension(uint8_t urid, const char *uri) {
if (strcmp(uri, AAP_PLUGIN_INFO_EXTENSION_URI) == 0) {
instance->host_plugin_info.get = get_plugin_info;
return &instance->host_plugin_info;
host_plugin_info.get = get_plugin_info;
return &host_plugin_info;
}
// look for user-implemented host extensions
if (instance->getHostExtension)
return instance->getHostExtension(host, uri);
if (getHostExtension)
return getHostExtension(this, urid, uri);
return nullptr;
}

Expand Down Expand Up @@ -206,7 +205,8 @@ bool aap::RemotePluginInstance::setupAAPXSInstances(std::function<bool(const cha

bool
aap::RemotePluginInstance::sendPluginAAPXSRequest(uint8_t urid, const char *uri, int32_t opcode, void *data, int32_t dataSize, uint32_t newRequestId) {
auto aapxsInstance = getAAPXSDispatcher().getPluginAAPXSByUri(uri);
auto& dispatcher = getAAPXSDispatcher();
auto aapxsInstance = urid != 0 ? dispatcher.getPluginAAPXSByUrid(urid) : dispatcher.getPluginAAPXSByUri(uri);
auto serialization = aapxsInstance->serialization;
memcpy(serialization->data, data, dataSize);
serialization->data_size = dataSize;
Expand Down Expand Up @@ -254,7 +254,7 @@ aap::RemotePluginInstance::sendHostAAPXSReply(AAPXSRequestContext* request) {
// aapxsInstance already contains binary data here, so we retrieve data from there.
int32_t group = 0; // will we have to give special semantics on it?
aapxs_session.addSession(aapxsSessionAddEventUmpInput, this, group,
request->request_id, request->uri, request->serialization->data,
request->request_id, request->urid, request->uri, request->serialization->data,
request->serialization->data_size, request->opcode);
} else {
// it was done synchronously, nothing to do here
Expand All @@ -276,19 +276,21 @@ void aap::RemotePluginInstance::setupAAPXS() {
}

void aap::RemotePluginInstance::handleAAPXSReply(aap_midi2_aapxs_parse_context *context) {
auto aapxs = feature_registry->items()->getByUri(context->uri);
auto& dispatcher = getAAPXSDispatcher();
auto registry = feature_registry->items();
auto aapxs = context->urid != 0 ? registry->getByUrid(context->urid) : registry->getByUri(context->uri);
if (aapxs) {
if (context->opcode >= 0) {
// plugin AAPXS reply
auto aapxsInstance = getAAPXSDispatcher().getPluginAAPXSByUri(context->uri);
auto aapxsInstance = context->urid != 0 ? dispatcher.getPluginAAPXSByUrid(context->urid) : dispatcher.getPluginAAPXSByUri(context->uri);
AAPXSRequestContext request{nullptr, nullptr, aapxsInstance->serialization, context->urid, context->uri, context->request_id, context->opcode};
if (aapxs->process_incoming_plugin_aapxs_reply)
aapxs->process_incoming_plugin_aapxs_reply(aapxs, aapxsInstance, plugin, &request);
else
aap::a_log_f(AAP_LOG_LEVEL_WARN, LOG_TAG, "AAPXS %s does not have a reply handler (opcode: %d)", context->uri, context->opcode);
} else {
// host AAPXS request
auto aapxsInstance = getAAPXSDispatcher().getHostAAPXSByUri(context->uri);
auto aapxsInstance = context->urid != 0 ? dispatcher.getHostAAPXSByUrid(context->urid) : dispatcher.getHostAAPXSByUri(context->uri);
AAPXSRequestContext request{nullptr, nullptr, aapxsInstance->serialization, context->urid, context->uri, context->request_id, context->opcode};
if (aapxs->process_incoming_host_aapxs_request)
aapxs->process_incoming_host_aapxs_request(aapxs, aapxsInstance, &plugin_host_facade, &request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ size_t aap_midi2_generate_aapxs_sysex8(uint32_t* dst,
size_t conversionHelperBufferSize,
uint8_t group,
uint32_t requestId,
uint8_t urid,
const char* uri,
int32_t opcode,
const uint8_t* data,
Expand All @@ -53,7 +54,7 @@ size_t aap_midi2_generate_aapxs_sysex8(uint32_t* dst,
uint8_t sysexStart[] {
0x7Eu, 0x7Fu, // universal sysex
0, 1, // code
0 // extension flags
urid
};
memcpy(ptr, sysexStart, sizeof(sysexStart));
ptr += sizeof(sysexStart);
Expand Down Expand Up @@ -122,6 +123,7 @@ bool aap_midi2_parse_aapxs_sysex8(aap_midi2_aapxs_parse_context* context,
return false;

// filling in results...
context->urid = data[4];
size_t requestId = aapMidi2ExtensionHelperGetUInt32(data + 5);
context->request_id = requestId;

Expand Down
1 change: 1 addition & 0 deletions include/aap/core/AAPXSMidi2InitiatorSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace aap {
void* addMidi2EventUserData,
int32_t group,
int32_t requestId,
uint8_t urid,
const char* uri,
void* data,
int32_t dataSize,
Expand Down
1 change: 1 addition & 0 deletions include/aap/core/AAPXSMidi2RecipientSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace aap {
void
addReply(void (*addMidi2Event)(AAPXSMidi2RecipientSession *, void *, int32_t),
void* addMidi2EventUserData,
uint8_t extensionUrid,
const char* extensionUri,
int32_t group,
int32_t requestId,
Expand Down
1 change: 1 addition & 0 deletions include/aap/core/aap_midi2_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ size_t aap_midi2_generate_aapxs_sysex8(uint32_t *dst,
size_t conversionHelperBufferSize,
uint8_t group,
uint32_t requestId,
uint8_t urid,
const char *uri,
int32_t opcode,
const uint8_t *data,
Expand Down
13 changes: 10 additions & 3 deletions include/aap/core/host/plugin-instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ namespace aap {
void* aapxs_out_merge_buffer{nullptr};
int32_t aapxs_out_midi2_buffer_offset{0};

static void* internalGetHostExtension(AndroidAudioPluginHost *host, const char *uri);
static void* internalGetHostExtension(AndroidAudioPluginHost *host, const char *uri) {
return ((LocalPluginInstance*) host->context)->getHostExtension(0, uri);
}
void* getHostExtension(uint8_t urid, const char *uri);
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. */
Expand Down Expand Up @@ -260,7 +263,11 @@ namespace aap {
AAPXSMidi2InitiatorSession aapxs_session;
std::unique_ptr<RemotePluginNativeUIController> native_ui_controller{};

static void* internalGetHostExtension(AndroidAudioPluginHost* host, const char* uri);
void* internalGetHostExtension(uint8_t urid, const char *uri);

static void* staticGetHostExtension(AndroidAudioPluginHost* host, const char* uri) {
return ((RemotePluginInstance*) host->context)->internalGetHostExtension(0, uri);
}

/** it is an unwanted exposure, but we need this internal-only member as public. You are not supposed to use it. */
aapxs_client_ipc_sender ipc_send_extension_message_impl;
Expand Down Expand Up @@ -341,7 +348,7 @@ namespace aap {
void handleAAPXSReply(aap_midi2_aapxs_parse_context *context);

// Host developers can override this function to return their own extensions.
std::function<void*(AndroidAudioPluginHost *host, const char *uri)> getHostExtension;
std::function<void*(RemotePluginInstance *instance, uint8_t urid, const char *uri)> getHostExtension;
};
}

Expand Down
5 changes: 2 additions & 3 deletions include/aap/ext/midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ typedef struct AAPMidiBufferHeader {
//
// The SysEx8 UMP packets consist of multiple UMP packets, whose data part (after `5g sz si`) looks like:
//
// `7E 7F co-de ext-flag] [reqId] [uri-size] [..uri..] [opcode] [value-size] [..value..]`
// `7E 7F co-de urid] [reqId] [uri-size] [..uri..] [opcode] [value-size] [..value..]`
//
// where -
// - g : UMP group
// - sz : UMP status and size, always 1F
// - si : stream Id, always 00. AAP MIDI sysex8 does not have to support simultaneous sysex8 streams.
// - co-de : AAP sysex8 code. Always 00-01 for realtime extension controls.
// - ext-flag : extension flag, reserved as 00; it may be used once we started supporting something like
// "local extension index" (LV2 URID alike).
// - urid : 1 byte URID (LV2 URID alike).
// - reqId : request Id (32bit), assured to be unique within a connected session.
// - uri-size: string length for extension URI, in 4 bytes
// - uri: string URI in escaped ASCII format, split and padded by 13 bytes (modulo padded as 0)
Expand Down

0 comments on commit c572e57

Please sign in to comment.