A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hi @Siu Pang ,
Thank you for reaching out.
I recommend make ProcessSampleBuffer() return immediately. We should not do heavy work inside it.
Because Apple’s ReplayKit calls this method in a real-time pipeline. It must stay fast. (Base on this official document).
While this is a non-Microsoft link, it’s official Apple Developer documentation and is safe to visit.
I suggest doing minimal work inside ProcessSampleBuffer(), don't do heavy processing on Main Thread. Furthermore, remember to always release buffers.
This is code example you can refer to:
public override void ProcessSampleBuffer(CMSampleBuffer sampleBuffer, RPSampleBufferType sampleBufferType)
{
if (sampleBufferType == RPSampleBufferType.Video)
{
sampleBuffer.Retain();
// Process asynchronously - DON'T WAIT!
Task.Run(() => ProcessVideoFrameAsync(sampleBuffer));
// Return immediately!
}
}
private async Task ProcessVideoFrameAsync(CMSampleBuffer sampleBuffer)
{
try
{
// Do your heavy work here
var image = GetImageFromBuffer(sampleBuffer);
await ProcessImageAsync(image);
await UploadToServerAsync(image);
}
finally
{
// Release when done
sampleBuffer.Release();
}
}
Hope this helps. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance provide feedback. Thank you.