Plugin Development
Spectrum's power lies in its extensibility. You can write custom nodes in C/C++ that integrate seamlessly into Prisma Studio graphs.
The Plugin Zoo
The Spectrum Plugins Zoo is the community hub for sharing and discovering plugins. We encourage you to contribute your plugins there!
Creating a Plugin
A Spectrum plugin is a dynamic library (.so, .dylib, .dll) that exports a specific C interface.
1. Plugin Structure
Every plugin must implement the spectrum_plugin_callbacks_t interface defined in plugin_api.h.
#include <spectrum/c/plugin_api.h>
// 1. Create
spectrum_status_e my_plugin_create(spectrum_plugin_t** plugin) {
// Allocate your plugin state
*plugin = (spectrum_plugin_t*)calloc(1, sizeof(MyPluginState));
return SPECTRUM_STATUS_SUCCESS;
}
// 2. Initialize
spectrum_status_e my_plugin_initialize(spectrum_plugin_t* plugin,
const spectrum_plugin_init_params_t* params) {
// Setup resources based on negotiated parameters
return SPECTRUM_STATUS_SUCCESS;
}
// 3. Process
spectrum_status_e my_plugin_process(spectrum_plugin_t* plugin,
const spectrum_plugin_process_request_t* request) {
// Read input packets
const spectrum_packet_t* input = request->input_packets[0];
// Write to output packets
spectrum_packet_t* output = request->output_packets[0];
// Your processing logic here...
return SPECTRUM_STATUS_SUCCESS;
}
// ... implement other callbacks (negotiate, destroy, etc.)
// Export the callbacks
const spectrum_plugin_callbacks_t* spectrum_plugin_get_callbacks(void) {
static const spectrum_plugin_callbacks_t callbacks = {
.create = my_plugin_create,
.initialize = my_plugin_initialize,
.process = my_plugin_process,
// ...
};
return &callbacks;
}
2. Lifecycle
- Discovery: Prisma Studio loads the library and calls
get_capabilitiesto understand what the plugin does. - Negotiation: When connected in a graph, the SDK calls
negotiate_input/output_descriptionto agree on formats. - Initialization:
initializeis called with the final configuration. - Processing:
processis called repeatedly with new frames. - Teardown:
stopanddestroyclean up resources.
3. Building
You can use CMake or Bazel to build your plugin. Ensure you link against the Spectrum SDK headers.
CMake Example:
add_library(my_plugin SHARED my_plugin.c)
target_include_directories(my_plugin PRIVATE path/to/spectrum/include)