AVCaptureSession Not Working?

roesterroester USUniversity ✭✭

I'm creating a Mac app with video capture. I've fairly comfortable with AVCaptureSession and have used it successfully on iOS without issue. When I move the code over to a Xam.Mac project, or try the sample AVCaptureSession code directly from the docs ( https://developer.xamarin.com/api/type/MonoMac.AVFoundation.AVCaptureSession/ ), the capture session simply does not display on the Mac app window. Valid input (camera) and output (compressed video out) are added to the session, the preview layer created, sized, and assigned to the main view of the app, but nothing shows up in that main view. Also, no sample buffers are output to the AVCaptureVideoDataOutputSampleBufferDelegate.

I've already confirmed during debug sessions the input device is attached to the webcam, and other Mac OS video capture apps (not Xamarin based) are working fine with the same camera.

Is there a known issue using AVCaptureSession on Xam.Mac or should it work similarly to a Xam.iOS app?

Answers

  • roesterroester USUniversity ✭✭

    I forgot to mention I also added the video input user permission request to the info.plist so this isn't a permission issue.

    I can simplify the question...

    Has anyone successfully displayed a live camera preview from AVCaptureSession API in a Xamarin.Mac application?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    That sounds like possibly a bug, or at least an annoying platform difference.

    Could you trim down your app to a tiny sample and file it at https://github.com/xamarin/xamarin-macios/issues/new ?

  • roesterroester USUniversity ✭✭

    Thank you Chris for the reply. The most concise sample is the code in the MonoMac online documentation page for AVFoundation.AVCaptureSession class, located here:
    https://developer.xamarin.com/api/type/MonoMac.AVFoundation.AVCaptureSession/

    That "SetupCapture" code sample results in a session object that has the state "Running" but nothing shows up in the previewlayer, and no samples are output to the AVCaptureVideoDataOutputSampleBufferDelegate class.

    Will that do, or do you need me to package up the code on that documentation page and file it at GitHub?

    Thank you.

  • poupoupoupou CAMember, Xamarin Team Xamurai

    @roester the documentation sample code did not age well, it's both mentioning MonoMac. (classic era) and UIImage which is not available on macOS. I'll file internal issues on this (and you can leave feedback on the documentation site too).

    As for the issue please file an issue on GitHub and attach your (self contained) test case to it. That way we'll be sure we're looking at the same code/issue that you're experiencing (removing any guessing). Thanks!

  • roesterroester USUniversity ✭✭

    @poupou and @ChrisHamons I've created a new issue on GitHub with a simplified project as requested. I reduced all of the AVCaptureSession creation to a single method of the main ViewController class in the sample project attached to the issue.

    Issue: "AVCaptureSession not working on Xam.Mac #5390"

    I look forward to the review/feedback/solution.

    Thank you!

Sign In or Register to comment.