I have created a ReplayKit Broadcast Extension, so the maximum amount of memory I can use is 50 MB.
I am taking samples of the broadcasted stream to send those images with a CFMessagePortSendRequest call. As that function accepts only CFData type, I need to convert my multi-plane image to Data.
NSKeyedArchiver.archivedObject() seems to exceed this 50 MB. Breaking on the line before the call I can see a memory consumption of ~6 MB. Then, executing the archivedObject call, my extension crashes cause it exceeds the memory limit.
Is there a less memory-eating way to convert the CIImage of a CVPixelBuffer to Data? And then back, of course.