コード例 #1
0
		public override void WindowControllerDidLoadNib (NSWindowController windowController)
		{
			base.WindowControllerDidLoadNib (windowController);

			// A reference to the window controller must be kept on the managed side
			// to keep the object from being GC'd so that the delegates below resolve.
			// Don't remove unless the framework is updated to track the reference.
			this.windowController = windowController;

			NSError err;
			
			windowController.Window.WillClose += delegate {
				if (captureSession != null)
					captureSession.StopRunning ();
				var dev = captureInput.Device;
				if (dev.IsOpen)
					dev.Close ();
			};
			
			// Create a movie, and store the information in memory on an NSMutableData
			movie = new QTMovie (new NSMutableData (1), out err);
			if (movie == null){
				NSAlert.WithError (err).RunModal ();
				return;
			}
			movieView.Movie = movie;
			
			// Find video device
			captureSession = new QTCaptureSession ();
			var device = QTCaptureDevice.GetDefaultInputDevice (QTMediaType.Video);
			if (!device.Open (out err)){
				NSAlert.WithError (err).RunModal ();
				return;
			}
			
			// Add device input
			captureInput = new QTCaptureDeviceInput (device);
			if (!captureSession.AddInput (captureInput, out err)){
				NSAlert.WithError (err).RunModal ();
				return;
			}
			
			// Create decompressor for video output, to get raw frames
			decompressedVideo = new QTCaptureDecompressedVideoOutput ();
			decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
				lock (this){
					currentImage = e.VideoFrame;
				}
			};
			if (!captureSession.AddOutput (decompressedVideo, out err)){
				NSAlert.WithError (err).RunModal ();
				return;
			}
			
			// Activate preview
			captureView.CaptureSession = captureSession;
			
			// Start running.
			captureSession.StartRunning ();
		}
コード例 #2
0
ファイル: MyDocument.cs プロジェクト: chamons/mac-samples-1
        public override void WindowControllerDidLoadNib(NSWindowController windowController)
        {
            NSError err;

            // Create a movie, and store the information in memory on an NSMutableData
            movie = new QTMovie(new NSMutableData(1), out err);
            if (movie == null)
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            movieView.Movie = movie;

            // Find video device
            captureSession = new QTCaptureSession();
            var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video);

            if (device == null)
            {
                new NSAlert {
                    MessageText = "You do not have a camera connected."
                }.BeginSheet(windowController.Window);
                return;
            }
            else if (!device.Open(out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Add device input
            captureInput = new QTCaptureDeviceInput(device);
            if (!captureSession.AddInput(captureInput, out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Create decompressor for video output, to get raw frames
            decompressedVideo = new QTCaptureDecompressedVideoOutput();
            decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
                lock (this) {
                    currentImage = e.VideoFrame;
                }
            };
            if (!captureSession.AddOutput(decompressedVideo, out err))
            {
                NSAlert.WithError(err).BeginSheet(windowController.Window);
                return;
            }

            // Activate preview
            captureView.CaptureSession = captureSession;

            // Start running.
            captureSession.StartRunning();
        }
コード例 #3
0
ファイル: MyDocument.cs プロジェクト: RangoLee/mac-samples
		public override void WindowControllerDidLoadNib (NSWindowController windowController)
		{
			NSError err;

			// Create a movie, and store the information in memory on an NSMutableData
			movie = new QTMovie (new NSMutableData (1), out err);
			if (movie == null) {
				NSAlert.WithError (err).RunModal ();
				return;
			}

			movieView.Movie = movie;

			// Find video device
			captureSession = new QTCaptureSession ();
			var device = QTCaptureDevice.GetDefaultInputDevice (QTMediaType.Video);
			if (device == null) {
				new NSAlert { MessageText = "You do not have a camera connected." }.BeginSheet (windowController.Window);
				return;
			} else if (!device.Open (out err)) {
				NSAlert.WithError (err).BeginSheet (windowController.Window);
				return;
			}

			// Add device input
			captureInput = new QTCaptureDeviceInput (device);
			if (!captureSession.AddInput (captureInput, out err)) {
				NSAlert.WithError (err).BeginSheet (windowController.Window);
				return;
			}

			// Create decompressor for video output, to get raw frames
			decompressedVideo = new QTCaptureDecompressedVideoOutput ();
			decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
				lock (this) {
					currentImage = e.VideoFrame;
				}
			};
			if (!captureSession.AddOutput (decompressedVideo, out err)) {
				NSAlert.WithError (err).BeginSheet (windowController.Window);
				return;
			}

			// Activate preview
			captureView.CaptureSession = captureSession;

			// Start running.
			captureSession.StartRunning ();
		}
コード例 #4
0
        public override void WindowControllerDidLoadNib(NSWindowController windowController)
        {
            base.WindowControllerDidLoadNib(windowController);

            // A reference to the window controller must be kept on the managed side
            // to keep the object from being GC'd so that the delegates below resolve.
            // Don't remove unless the framework is updated to track the reference.
            this.windowController = windowController;

            NSError err;

            windowController.Window.WillClose += delegate {
                if (captureSession != null)
                {
                    captureSession.StopRunning();
                }
                var dev = captureInput.Device;
                if (dev.IsOpen)
                {
                    dev.Close();
                }
            };

            // Create a movie, and store the information in memory on an NSMutableData
            movie = new QTMovie(new NSMutableData(1), out err);
            if (movie == null)
            {
                NSAlert.WithError(err).RunModal();
                return;
            }
            movieView.Movie = movie;

            // Find video device
            captureSession = new QTCaptureSession();
            var device = QTCaptureDevice.GetDefaultInputDevice(QTMediaType.Video);

            if (!device.Open(out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Add device input
            captureInput = new QTCaptureDeviceInput(device);
            if (!captureSession.AddInput(captureInput, out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Create decompressor for video output, to get raw frames
            decompressedVideo = new QTCaptureDecompressedVideoOutput();
            decompressedVideo.DidOutputVideoFrame += delegate(object sender, QTCaptureVideoFrameEventArgs e) {
                lock (this){
                    currentImage = e.VideoFrame;
                }
            };
            if (!captureSession.AddOutput(decompressedVideo, out err))
            {
                NSAlert.WithError(err).RunModal();
                return;
            }

            // Activate preview
            captureView.CaptureSession = captureSession;

            // Start running.
            captureSession.StartRunning();
        }
コード例 #5
0
        public void AwakeFromNib()
        {
            // Create the capture session
            this.mCaptureSession = new QTCaptureSession();

            // Connect inputs and outputs to the session
            bool success;
            NSError error;

            // Find a video device
            QTCaptureDevice videoDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeVideo);
            if (videoDevice != null)
            {
                success = videoDevice.Open(out error);
            }
            else
            {
                success = false;
            }

            // If a video input device can't be found or opened, try to find and open a muxed input device
            if (!success)
            {
                videoDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeMuxed);
            }

            if (videoDevice != null)
            {
                success = videoDevice.Open(out error);
            }
            else
            {
                success = false;
            }

            if (!success)
            {
                videoDevice = null;
                // Handle error
            }

            if (videoDevice != null)
            {
                //Add the video device to the session as a device input
                this.mCaptureVideoDeviceInput = new QTCaptureDeviceInput(videoDevice);
                success = this.mCaptureSession.AddInputError(this.mCaptureVideoDeviceInput, out error);
                if (!success)
                {
                    // Handle error
                }

                // If the video device doesn't also supply audio, add an audio device input to the session
                if (!videoDevice.HasMediaType(QTMedia.QTMediaTypeSound) && !videoDevice.HasMediaType(QTMedia.QTMediaTypeMuxed))
                {
                    QTCaptureDevice audioDevice = QTCaptureDevice.DefaultInputDeviceWithMediaType(QTMedia.QTMediaTypeSound);
                    success = audioDevice.Open(out error);

                    if (!success)
                    {
                        audioDevice = null;
                        // Handle error
                    }

                    if (audioDevice != null)
                    {
                        this.mCaptureAudioDeviceInput = new QTCaptureDeviceInput(audioDevice);

                        success = this.mCaptureSession.AddInputError(this.mCaptureAudioDeviceInput, out error);
                        if (!success)
                        {
                            // Handle error
                        }
                    }
                }

                // Create the movie file output and add it to the session
                this.mCaptureMovieFileOutput = new QTCaptureMovieFileOutput();
                success = this.mCaptureSession.AddOutputError(this.mCaptureMovieFileOutput, out error);
                if (!success)
                {
                    // Handle error
                }

                this.mCaptureMovieFileOutput.Delegate = this;

                // Set the compression for the audio/video that is recorded to the hard disk.
                foreach (QTCaptureConnection connection in this.mCaptureMovieFileOutput.Connections.GetEnumerator<QTCaptureConnection>())
                {
                    NSString mediaType = connection.MediaType;
                    QTCompressionOptions compressionOptions = null;

                    // specify the video compression options
                    // (note: a list of other valid compression types can be found in the QTCompressionOptions.h interface file)
                    if (mediaType.IsEqualToString(QTMedia.QTMediaTypeVideo))
                    {
                        // use H.264
                        compressionOptions = QTCompressionOptions.CompressionOptionsWithIdentifier("QTCompressionOptions240SizeH264Video");
                        // specify the audio compression options
                    }
                    else if (mediaType.IsEqualToString(QTMedia.QTMediaTypeSound))
                    {
                        // use AAC Audio
                        compressionOptions = QTCompressionOptions.CompressionOptionsWithIdentifier("QTCompressionOptionsHighQualityAACAudio");
                    }

                    // set the compression options for the movie file output
                    this.mCaptureMovieFileOutput.SetCompressionOptionsForConnection(compressionOptions, connection);
                }

                // Associate the capture view in the UI with the session
                this.mCaptureView.CaptureSession = this.mCaptureSession;
                this.mCaptureSession.StartRunning();
            }
        }