MonoMac 0.0.0.0 MonoMac.Foundation.NSObject MonoMac.Foundation.Register("AVCaptureSession", true) Coordinates a recording session.

The AVCaptureSession object coordinates the recording of video or audio input and passing the recorded information to one or more output objects. An iPhone 3 for example will have two input devices, one for the camera and one for the microphone. An iPhone 4 would have three input devices, one for the microphone, one for the back camera and one for the front camera.

To record, you must create instances of the class, usually by creating instances of the concrete .

You can the configure one or more output ports for the captured data, and these can be still frames, video frames with timing information, audio samples, quicktime movie files or you can render it directly to a CoreAnimation layer.

Once you have configured the input and output components of your session, you start the actual processing by calling the method.

`void SetupCapture () / configure the capture session for low resolution, change this if your code // can cope with more data or volume session = new AVCaptureSession () { SessionPreset = AVCaptureSession.PresetMedium }; // create a device input and attach it to the session var captureDevice = AVCaptureDevice.DefaultDeviceWithMediaType (AVMediaType.Video); var input = AVCaptureDeviceInput.FromDevice (captureDevice); if (input == null){ Console.WriteLine ("No video input device"); return false; } session.AddInput (input); // create a VideoDataOutput and add it to the sesion var output = new AVCaptureVideoDataOutput () { VideoSettings = new AVVideoSettings (CVPixelFormatType.CV32BGRA), // If you want to cap the frame rate at a given speed, in this sample: 15 frames per second MinFrameDuration = new CMTime (1, 15) }; // configure the output queue = new MonoMac.CoreFoundation.DispatchQueue ("myQueue"); outputRecorder = new OutputRecorder (); output.SetSampleBufferDelegateAndQueue (outputRecorder, queue); session.AddOutput (output); session.StartRunning (); } public class OutputRecorder : AVCaptureVideoDataOutputSampleBufferDelegate { public override void DidOutputSampleBuffer (AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection) { try { var image = ImageFromSampleBuffer (sampleBuffer); // Do something with the image, we just stuff it in our main view. AppDelegate.ImageView.BeginInvokeOnMainThread (delegate { AppDelegate.ImageView.Image = image; }); // // Although this looks innocent "Oh, he is just optimizing this case away" // this is incredibly important to call on this callback, because the AVFoundation // has a fixed number of buffers and if it runs out of free buffers, it will stop // delivering frames. // sampleBuffer.Dispose (); } catch (Exception e){ Console.WriteLine (e); } } UIImage ImageFromSampleBuffer (CMSampleBuffer sampleBuffer) { // Get the CoreVideo image using (var pixelBuffer = sampleBuffer.GetImageBuffer () as CVPixelBuffer){ // Lock the base address pixelBuffer.Lock (0); // Get the number of bytes per row for the pixel buffer var baseAddress = pixelBuffer.BaseAddress; int bytesPerRow = pixelBuffer.BytesPerRow; int width = pixelBuffer.Width; int height = pixelBuffer.Height; var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little; // Create a CGImage on the RGB colorspace from the configured parameter above using (var cs = CGColorSpace.CreateDeviceRGB ()) using (var context = new CGBitmapContext (baseAddress,width, height, 8, bytesPerRow, cs, (CGImageAlphaInfo) flags)) using (var cgImage = context.ToImage ()){ pixelBuffer.Unlock (0); return UIImage.FromImage (cgImage); } } } }` avcaptureframes
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("init")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Default constructor that initializes a new instance of this class with no parameters.
- Constructor
  0.0.0.0
  MonoMac.Foundation.Export("initWithCoder:")
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  The unarchiver object.
  A constructor that initializes the object from the data stored in the unarchiver object.
  This constructor is provided to allow the class to be initialized from an unarchiver (for example, during NIB deserialization).
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Unused sentinel value, pass NSObjectFlag.Empty.
  Constructor to call on derived classes when the derived class has an [Export] constructor.

  This constructor should be called by derived classes when they are initialized using an [Export] attribute. The argument value is ignore, typically the chaining would look like this:

  public class MyClass : BaseClass { [Export ("initWithFoo:")] public MyClass (string foo) : base (NSObjectFlag.Empty) { ... }
- Constructor
  0.0.0.0
  System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)
  Pointer (handle) to the unmanaged object.
  A constructor used when creating managed representations of unmanaged objects; Called by the runtime.

  This constructor is invoked by the runtime infrastructure () to create a new managed representation for a pointer to an unmanaged Objective-C object. You should not invoke this method directly, instead you should call the GetNSObject method as it will prevent two instances of a managed object to point to the same native object.

- Method
  0.0.0.0
  MonoMac.Foundation.Export("addInput:")
  System.Void `` The AVCaptureInput to add to the session Adds an input to the Capture Session To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("addOutput:")
  System.Void `` To be added. Adds an output to the capture session. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("beginConfiguration")
  System.Void Initiates a transaction to change the configuration of the Capture Session. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("canAddInput:")
  System.Boolean `` To be added. Returns whether the given input can be added to the session. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("canAddOutput:")
  System.Boolean `` To be added. Returns whether the given input can be added to the session. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("canSetSessionPreset:")
  System.Boolean `` To be added. To be added. To be added. To be added.
- Property
  0.0.0.0
  System.IntPtr The handle for this class. The pointer to the Objective-C class. Each MonoMac class mirrors an unmanaged Objective-C class. This value contains the pointer to the Objective-C class, it is similar to calling objc_getClass with the object name.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("commitConfiguration")
  System.Void Applies atomically all the configuration changes that were made to the Capture Session since BeginConfiguration. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Notification constant for DidStartRunning NSString constant, should be used as a token to NSNotificationCenter.

  This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.

  If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.

  The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:

  `// // Lambda style // // listening notification = AVCaptureSession.Notifications.ObserveDidStartRunning ((sender, args) => { /* Access strongly typed args */ Console.WriteLine ("Notification: {0}", args.Notification); }); // To stop listening: notification.Dispose (); // // Method style // NSObject notification; void Callback (object sender, DidStartRunning args) { // Access strongly typed args Console.WriteLine ("Notification: {0}", args.Notification); } void Setup () { notification = AVCaptureSession.Notifications.ObserveDidStartRunning (Callback); } void Teardown () { notification.Dispose (); }`

  The following example shows how to use the notification with the DefaultCenter API:

  `// Lambda style NSNotificationCenter.DefaultCenter.AddObserver ( AVCaptureSession.DidStartRunningNotification, (notification) => {Console.WriteLine ("Received the notification AVCaptureSession", notification); } // Method style void Callback (NSNotification notification) { Console.WriteLine ("Received a notification AVCaptureSession", notification); } void Setup () { NSNotificationCenter.DefaultCenter.AddObserver (AVCaptureSession.DidStartRunningNotification, Callback); }`
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Notification constant for DidStopRunning NSString constant, should be used as a token to NSNotificationCenter.

  This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.

  If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.

  The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:

  `// // Lambda style // // listening notification = AVCaptureSession.Notifications.ObserveDidStopRunning ((sender, args) => { /* Access strongly typed args */ Console.WriteLine ("Notification: {0}", args.Notification); }); // To stop listening: notification.Dispose (); // // Method style // NSObject notification; void Callback (object sender, DidStopRunning args) { // Access strongly typed args Console.WriteLine ("Notification: {0}", args.Notification); } void Setup () { notification = AVCaptureSession.Notifications.ObserveDidStopRunning (Callback); } void Teardown () { notification.Dispose (); }`

  The following example shows how to use the notification with the DefaultCenter API:

  `// Lambda style NSNotificationCenter.DefaultCenter.AddObserver ( AVCaptureSession.DidStopRunningNotification, (notification) => {Console.WriteLine ("Received the notification AVCaptureSession", notification); } // Method style void Callback (NSNotification notification) { Console.WriteLine ("Received a notification AVCaptureSession", notification); } void Setup () { NSNotificationCenter.DefaultCenter.AddObserver (AVCaptureSession.DidStopRunningNotification, Callback); }`
- Method
  0.0.0.0
  System.Void ``

  If set to , the method is invoked directly and will dispose manage and unmanaged resources; If set to the method is being called by the garbage collector finalizer and should only release unmanaged resources.

  Releases the resources used by the AVCaptureSession object.

  This Dispose method releases the resources used by the AVCaptureSession class.

  This method is called by both the Dispose() method and the object finalizer (Finalize). When invoked by the Dispose method, the parameter disposting is set to and any managed object references that this object holds are also disposed or released; when invoked by the object finalizer, on the finalizer thread the value is set to .

  Calling the Dispose method when you are finished using the AVCaptureSession ensures that all external resources used by this managed object are released as soon as possible. Once you have invoked the Dispose method, the object is no longer useful and you should no longer make any calls to it.

  For more information on how to override this method and on the Dispose/IDisposable pattern, read the ``Implementing a Dispose Method'' document at http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx

- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionErrorKey To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("inputs")
  MonoMac.AVFoundation.AVCaptureInput[] Inputs to the capture session. To be added. To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("isInterrupted")
  System.Boolean Whether the session has been interrupted. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Notification constant for InterruptionEnded NSString constant, should be used as a token to NSNotificationCenter.

  This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.

  If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.

  The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:

  `// // Lambda style // // listening notification = AVCaptureSession.Notifications.ObserveInterruptionEnded ((sender, args) => { /* Access strongly typed args */ Console.WriteLine ("Notification: {0}", args.Notification); }); // To stop listening: notification.Dispose (); // // Method style // NSObject notification; void Callback (object sender, InterruptionEnded args) { // Access strongly typed args Console.WriteLine ("Notification: {0}", args.Notification); } void Setup () { notification = AVCaptureSession.Notifications.ObserveInterruptionEnded (Callback); } void Teardown () { notification.Dispose (); }`

  The following example shows how to use the notification with the DefaultCenter API:

  `// Lambda style NSNotificationCenter.DefaultCenter.AddObserver ( AVCaptureSession.InterruptionEndedNotification, (notification) => {Console.WriteLine ("Received the notification AVCaptureSession", notification); } // Method style void Callback (NSNotification notification) { Console.WriteLine ("Received a notification AVCaptureSession", notification); } void Setup () { NSNotificationCenter.DefaultCenter.AddObserver (AVCaptureSession.InterruptionEndedNotification, Callback); }`
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("outputs")
  MonoMac.AVFoundation.AVCaptureOutput[] Outputs for the capture session. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPreset1280x720 To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPreset352x288 To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPreset640x480 To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetHigh To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetiFrame1280x720 To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetiFrame960x540 To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetLow To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetMedium To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Represents the value associated with the constant AVCaptureSessionPresetPhoto To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("removeInput:")
  System.Void `` To be added. Removes the specified input source. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("removeOutput:")
  System.Void `` To be added. Removes the specified output. To be added.
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("isRunning")
  System.Boolean Whether the capture session is currently running. To be added. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Notification constant for RuntimeError NSString constant, should be used as a token to NSNotificationCenter.

  This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.

  If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.

  The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:

  `// // Lambda style // // listening notification = AVCaptureSession.Notifications.ObserveRuntimeError ((sender, args) => { /* Access strongly typed args */ Console.WriteLine ("Notification: {0}", args.Notification); Console.WriteLine ("Error", args.Error); }); // To stop listening: notification.Dispose (); // // Method style // NSObject notification; void Callback (object sender, RuntimeError args) { // Access strongly typed args Console.WriteLine ("Notification: {0}", args.Notification); Console.WriteLine ("Error", args.Error); } void Setup () { notification = AVCaptureSession.Notifications.ObserveRuntimeError (Callback); } void Teardown () { notification.Dispose (); }`

  The following example shows how to use the notification with the DefaultCenter API:

  `// Lambda style NSNotificationCenter.DefaultCenter.AddObserver ( AVCaptureSession.RuntimeErrorNotification, (notification) => {Console.WriteLine ("Received the notification AVCaptureSession", notification); } // Method style void Callback (NSNotification notification) { Console.WriteLine ("Received a notification AVCaptureSession", notification); } void Setup () { NSNotificationCenter.DefaultCenter.AddObserver (AVCaptureSession.RuntimeErrorNotification, Callback); }`
- Property
  0.0.0.0
  get: MonoMac.Foundation.Export("sessionPreset")
  set: MonoMac.Foundation.Export("setSessionPreset:")
  MonoMac.Foundation.NSString The session preset. To be added. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("startRunning")
  System.Void Starts the flow of inputs and outputs. To be added.
- Method
  0.0.0.0
  MonoMac.Foundation.Export("stopRunning")
  System.Void Stops the flow of inputs and outputs. To be added.
- Property
  0.0.0.0
  MonoMac.Foundation.NSString Notification constant for WasInterrupted NSString constant, should be used as a token to NSNotificationCenter.

  This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.

  If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.

  The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:

  `// // Lambda style // // listening notification = AVCaptureSession.Notifications.ObserveWasInterrupted ((sender, args) => { /* Access strongly typed args */ Console.WriteLine ("Notification: {0}", args.Notification); }); // To stop listening: notification.Dispose (); // // Method style // NSObject notification; void Callback (object sender, WasInterrupted args) { // Access strongly typed args Console.WriteLine ("Notification: {0}", args.Notification); } void Setup () { notification = AVCaptureSession.Notifications.ObserveWasInterrupted (Callback); } void Teardown () { notification.Dispose (); }`

  The following example shows how to use the notification with the DefaultCenter API:

  `// Lambda style NSNotificationCenter.DefaultCenter.AddObserver ( AVCaptureSession.WasInterruptedNotification, (notification) => {Console.WriteLine ("Received the notification AVCaptureSession", notification); } // Method style void Callback (NSNotification notification) { Console.WriteLine ("Received a notification AVCaptureSession", notification); } void Setup () { NSNotificationCenter.DefaultCenter.AddObserver (AVCaptureSession.WasInterruptedNotification, Callback); }`