I added a little serializer for size_t values and a prefix
that can be used as LMDB keys, or shared memory keys when storing
buffers.
When the python renderer has a buffer rendered it will:
- Serialize the buffer into a byte string the usual way
- Save the serialized buffer string into shared memory (or maybe with LMDB, I’m not sure of the trade-offs though) using the key generated from the same kind of counter used for voice ids
- Send the counter value / key over the buffer message queue
The thread that’s waiting for buffer messages will then:
- Use the key to look up the serialized buffer string in shared memory and get a pointer to it
- Deserialize the buffer and place it into the scheduler
- Clean up the shared memory holding the serialized copy of the buffer
As long as I only send the key over the buffer message queue once the shared memory has been released, it seems pretty safe to have the receiving thread clean up after the renderer.
Once I finish porting pippi’s SoundBuffers to be libpippi-backed rather than numpy-backed it should be possible to skip the serialization step and just put the pointer to the buffer into shared memory and hand it off without extra copies. Might make the python renderer slightly more responsive but I also never measured the latency added by serialization so who knows!