From 28b6363050d3fdf616840a983d6d497908b3cb19 Mon Sep 17 00:00:00 2001 From: atsushieno Date: Thu, 18 Feb 2021 01:09:10 +0900 Subject: [PATCH] Reorganized port properties. part of https://github.com/atsushieno/android-audio-plugin-framework/issues/32 - default, minimum, maximum have namespace with pp: prefix. - introduced pp:type and pp:enumeration. --- docs/DESIGN_NOTES.md | 13 +++++++++++++ docs/DEVELOPERS.md | 4 ++-- .../androidaudioplugin/AudioPluginHostHelper.kt | 14 ++++++++------ .../src/main/res/xml/aap_metadata.xml | 2 +- .../core/include/aap/port-properties.h | 15 ++++++++------- 5 files changed, 32 insertions(+), 16 deletions(-) diff --git a/docs/DESIGN_NOTES.md b/docs/DESIGN_NOTES.md index 2fd9c1d8..1a66182a 100644 --- a/docs/DESIGN_NOTES.md +++ b/docs/DESIGN_NOTES.md @@ -20,6 +20,19 @@ A better alternative is obviously JSON, but for AAP there is a constraining reas They are important in that if they are not met then hosts will have to cache plugin metadata list like VST hosts. LV2 design is clever in this aspect. +On a related note, the actual parameter names were designed like: + +``` +#define AAP_PORT_BASE "org.androidaudioplugin.port" +#define AAP_PORT_DEFAULT AAP_PORT_BASE ":default" +``` + +which were like that it can be directly used as XML namespace prefix (because BASE does not contain a ':') while keeping things pseudo-globally-unique, or JSON object keys. +Since we were using an XML parser that does not support XML Namespaces (tinyxml2), it could work like a hacky solution. +But since we cannot switch to JSON anyways, we rather went back to the basics and eliminated any XML parsing bits from native code on Android, and used authentic XML parser (libxml2) on desktop. + +At that stage, there is no point of avoiding standard URI format for port property identifiers, so we simply use "urn:" for the parameters. (It can be "http:", but I guess it would be weird if the protocol without 's' will stay forever and if it matches "cool URLs don't change." concept...) + ### out-process model Unlike in-host-process plugin processing, switching process context is important. Considering the performance loss and limited resources on mobile devices, it is best if we can avoid that. However it is inevitable. It will be handled via [NdkBinder](https://developer.android.com/ndk/reference/group/ndk-binder). diff --git a/docs/DEVELOPERS.md b/docs/DEVELOPERS.md index cfe1461f..3dfbf7ef 100644 --- a/docs/DEVELOPERS.md +++ b/docs/DEVELOPERS.md @@ -64,12 +64,12 @@ external fun initialize(lv2Path: String, assets: AssetManager) The other one with `org.androidaudioplugin.AudioPluginService#Plugins` is to specify an additional XML resource for the service. The `android:resource` attribute indicates that there is `res/xml/aap_metadata.xml` in the project. The file content looks like this: ``` - + - + diff --git a/java/androidaudioplugin/src/main/java/org/androidaudioplugin/AudioPluginHostHelper.kt b/java/androidaudioplugin/src/main/java/org/androidaudioplugin/AudioPluginHostHelper.kt index 22be49e2..30b4469e 100644 --- a/java/androidaudioplugin/src/main/java/org/androidaudioplugin/AudioPluginHostHelper.kt +++ b/java/androidaudioplugin/src/main/java/org/androidaudioplugin/AudioPluginHostHelper.kt @@ -15,6 +15,8 @@ class AudioPluginHostHelper { const val AAP_ACTION_NAME = "org.androidaudioplugin.AudioPluginService" const val AAP_METADATA_NAME_PLUGINS = "org.androidaudioplugin.AudioPluginService#Plugins" const val AAP_METADATA_NAME_EXTENSIONS = "org.androidaudioplugin.AudioPluginService#Extensions" + const val AAP_METADATA_CORE_NS = "urn:org.androidaudioplugin.core" + const val AAP_METADATA_PORT_PROPERTIES_NS = "urn:org.androidaudioplugin.port" private fun parseAapMetadata(isOutProcess: Boolean, label: String, packageName: String, className: String, xp: XmlPullParser) : AudioPluginServiceInformation { // TODO: this XML parsing is super hacky so far. @@ -28,7 +30,7 @@ class AudioPluginHostHelper { if (eventType == XmlPullParser.IGNORABLE_WHITESPACE) continue if (eventType == XmlPullParser.START_TAG) { - if (xp.name == "plugin") { + if (xp.name == "plugin" && (xp.namespace == "" || xp.namespace == AAP_METADATA_CORE_NS)) { val name = xp.getAttributeValue(null, "name") val backend = xp.getAttributeValue(null, "backend") val version = xp.getAttributeValue(null, "version") @@ -59,14 +61,14 @@ class AudioPluginHostHelper { isOutProcess ) aapServiceInfo.plugins.add(currentPlugin) - } else if (xp.name == "port") { + } else if (xp.name == "port" && (xp.namespace == "" || xp.namespace == AAP_METADATA_CORE_NS)) { if (currentPlugin != null) { val name = xp.getAttributeValue(null, "name") val direction = xp.getAttributeValue(null, "direction") val content = xp.getAttributeValue(null, "content") - val default = xp.getAttributeValue(null, "default") - val minimum = xp.getAttributeValue(null, "minimum") - val maximum = xp.getAttributeValue(null, "maximum") + val default = xp.getAttributeValue(AAP_METADATA_PORT_PROPERTIES_NS, "default") + val minimum = xp.getAttributeValue(AAP_METADATA_PORT_PROPERTIES_NS, "minimum") + val maximum = xp.getAttributeValue(AAP_METADATA_PORT_PROPERTIES_NS, "maximum") val port = PortInformation( name, if (direction == "input") PortInformation.PORT_DIRECTION_INPUT else PortInformation.PORT_DIRECTION_OUTPUT, @@ -83,7 +85,7 @@ class AudioPluginHostHelper { } } if (eventType == XmlPullParser.END_TAG) { - if (xp.name == "plugin") + if (xp.name == "plugin" && (xp.namespace == "" || xp.namespace == AAP_METADATA_CORE_NS)) currentPlugin = null } } diff --git a/java/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml b/java/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml index bdbdbce1..a4194b95 100644 --- a/java/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml +++ b/java/samples/aapbarebonepluginsample/src/main/res/xml/aap_metadata.xml @@ -1,4 +1,4 @@ - + diff --git a/native/androidaudioplugin/core/include/aap/port-properties.h b/native/androidaudioplugin/core/include/aap/port-properties.h index 03938c7e..2a1b09dd 100644 --- a/native/androidaudioplugin/core/include/aap/port-properties.h +++ b/native/androidaudioplugin/core/include/aap/port-properties.h @@ -1,9 +1,10 @@ -#define AAP_PORT_BASE "org.androidaudioplugin.port" -#define AAP_PORT_DEFAULT AAP_PORT_BASE ":default" -#define AAP_PORT_MAXIMUM AAP_PORT_BASE ":maximum" -#define AAP_PORT_MINIMUM AAP_PORT_BASE ":minimum" -#define AAP_PORT_OPTIONAL AAP_PORT_BASE ":optional" -#define AAP_PORT_ENUMERATION AAP_PORT_BASE ":enumeration" -#define AAP_PORT_PRIMITIVE_TYPE AAP_PORT_BASE ":primitive-type" +#define AAP_PORT_URL "urn:org.androidaudioplugin.port" +#define AAP_PORT_BASE AAP_PORT_URL "#" +#define AAP_PORT_DEFAULT AAP_PORT_BASE "default" +#define AAP_PORT_MAXIMUM AAP_PORT_BASE "maximum" +#define AAP_PORT_MINIMUM AAP_PORT_BASE "minimum" +#define AAP_PORT_OPTIONAL AAP_PORT_BASE "optional" +#define AAP_PORT_ENUMERATION AAP_PORT_BASE "enumeration" +#define AAP_PORT_TYPE AAP_PORT_BASE "type"