iOS Development

ios – AVCaptureVideoDataOutputSampleBufferDelegate runs for a short while, then stops

Spread the love

I am making an attempt to do some realtime picture processing utilizing Xamarin.iOS C#, however looks as if the AVCaptureVideoDataOutputSampleBufferDelegate is hanging after a couple of dozen samples. If I contact the display screen, it should startup for one more dozen samples and stops once more.

The premise for this code is a Swift instance right here: which I transformed to a Xamarin undertaking.

public class UICameraPreview : UIView, IAVCaptureVideoDataOutputSampleBufferDelegate
        public AVCaptureSession captureSession = new AVCaptureSession();
        non-public AVCaptureVideoPreviewLayer previewLayer;
        non-public AVCaptureVideoDataOutput videoOutput;
        public UICameraPreview(CameraOptions choices)
            AddPreviewLayer(); ;

            Process.Run(() =>
        public override void LayoutSubviews()
            previewLayer.Body = Bounds;

        public void DidOutputSampleBuffer(AVCaptureOutput output, CMSampleBuffer sampleBuffer, AVCaptureConnection connection)
            var body = sampleBuffer.GetImageBuffer();
            if (body == null)
                Console.WriteLine("unable to get picture from pattern buffer");
            Console.WriteLine("did obtain picture body");

            // course of picture right here


        non-public void AddCameraInput()

        non-public void AddPreviewLayer()
            previewLayer = new AVCaptureVideoPreviewLayer(captureSession)
                VideoGravity = AVLayerVideoGravity.ResizeAspect

        non-public void AddVideoOutput()
            videoOutput = new AVCaptureVideoDataOutput();
            var videoSettings = new NSDictionary<NSString, NSObject>(new NSString("PixelFormatType"), new NSNumber((int)CVPixelFormatType.CV420YpCbCr8BiPlanarFullRange));
            videoOutput.WeakVideoSettings = videoSettings;
            videoOutput.SetSampleBufferDelegateQueue(this, DispatchQueue.MainQueue);


sampleBuffer.GetImageBuffer() works as anticipated...I simply want it to run with out hanging.

I've tried sampleBuffer.Dispose() as properly however I am pondering some useful resource needs to be launched someplace.

Nothing I've tried works besides including a delay of three seconds or extra within the delegate. I consider it some type reminiscence leak, I'm at a loss as to how discover a answer.

Leave a Reply

Your email address will not be published. Required fields are marked *