Sunday, 31 March 2019

didDropSampleBuffer is called very often in iOS

I capture the video and do some analyses on it in captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer delegate. but after a short time this method is not called. then captureOutput:(AVCaptureOutput *)output didDropSampleBuffer delegate is called.

When I don't do anything in didOutputSampleBuffer, everything is okay.
I run a tensor flow model in this delegate. And this causes the problem.

Problem:
The problem is that when didDropSampleBuffer is called, didOutputSampleBuffer will not called again.

My solution:
My solution was stoping and starting avCaptureSession. but that caused extra memory usage! Which finally caused my app to crash.

 - (void)captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
    {
        // ******  do heavy work in this delegate *********
        graph = [TensorflowGraph new];
        predictions = [graph runModelOnPixelBuffer:pixelBuffer orientation: UIDeviceOrientationPortrait CardRect: _vwRect];
    }

    - (void)captureOutput:(AVCaptureOutput *)output didDropSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
    {
                CFTypeRef droppedFrameReason = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_DroppedFrameReason, NULL);
                NSLog(@"dropped frame, reason: %@", droppedFrameReason);
    }

----> dropped frame, reason: OutOfBuffers

According to [https://developer.apple.com/library/archive/technotes/tn2445/_index.html]:

This condition is typically caused by the client holding onto buffers for too long, and can be alleviated by returning buffers to the provider.

How can I return buffer to the provider?

1



from didDropSampleBuffer is called very often in iOS

No comments:

Post a Comment