public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Initialize the class responsible for managing AV capture session and asset writer
            videoProcessor = new RosyWriterVideoProcessor();

            // Keep track of changes to the device orientation so we can update the video processor
            var notificationCenter = NSNotificationCenter.DefaultCenter;

            notificationCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange);

            UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications();

            // Setup and start the capture session
            videoProcessor.SetupAndStartCaptureSession();
            Console.WriteLine("Finished Setting up AV");

            notificationCenter.AddObserver(UIApplication.DidBecomeActiveNotification, On_ApplicationDidBecomeActive);

            oglView = new RosyWriterPreviewWindow(RectangleF.Empty);

            // Our interface is always in portrait
            oglView.Transform = videoProcessor.TransformFromCurrentVideoOrientationToOrientation(AVCaptureVideoOrientation.Portrait);

            RectangleF bounds = viewPreview.ConvertRectToView(viewPreview.Bounds, oglView);

            oglView.Bounds = bounds;
            oglView.Center = new PointF(viewPreview.Bounds.Size.Width / 2.0F, viewPreview.Bounds.Size.Height / 2.0F);

            viewPreview.AddSubview(oglView);

            Console.WriteLine("Added OGL View");

            // Set up labels
            shouldShowStats = true;

            frameRateLabel = LabelWithText(string.Empty, 10.0F);
            viewPreview.AddSubview(frameRateLabel);

            dimensionsLabel = LabelWithText(string.Empty, 54.0F);
            viewPreview.AddSubview(dimensionsLabel);

            typeLabel = LabelWithText(string.Empty, 90F);
            viewPreview.Add(typeLabel);

            // btnRecord Event Handler
            btnRecord.Clicked += On_ToggleRecording;

            // Video Processor Event Handlers
            videoProcessor.RecordingDidStart          += On_RecordingDidStart;
            videoProcessor.RecordingDidStop           += On_RecordingDidStop;
            videoProcessor.RecordingWillStart         += On_RecordingWillStart;
            videoProcessor.RecordingWillStop          += On_RecordingWillStop;
            videoProcessor.PixelBufferReadyForDisplay += On_PixelBufferReadyForDisplay;

            Console.WriteLine("Finished OnDidLoad");
        }
Пример #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            statisticView.Layer.CornerRadius = 4f;

            // Initialize the class responsible for managing AV capture session and asset writer
            videoProcessor = new RosyWriterVideoProcessor();

            // Setup and start the capture session
            var isSupported = videoProcessor.SetupAndStartCaptureSession();

            if (isSupported)
            {
                // Our interface is always in portrait
                previewView.Transform = videoProcessor.TransformFromCurrentVideoOrientationToOrientation(AVCaptureVideoOrientation.Portrait);
                previewView.Bounds    = View.ConvertRectToView(View.Bounds, previewView);
                previewView.Center    = new CGPoint(View.Bounds.Size.Width / 2f, View.Bounds.Size.Height / 2f);

                UIApplication.Notifications.ObserveDidBecomeActive(OnApplicationDidBecomeActive);

                // Set up labels
                shouldShowStats = true;

                // Video Processor Event Handlers
                videoProcessor.RecordingDidStart          += OnRecordingDidStart;
                videoProcessor.RecordingDidStop           += OnRecordingDidStop;
                videoProcessor.RecordingWillStart         += OnRecordingWillStart;
                videoProcessor.RecordingWillStop          += OnRecordingWillStop;
                videoProcessor.PixelBufferReadyForDisplay += OnPixelBufferReadyForDisplay;
            }
            else
            {
                errorLabel.Hidden = false;

                previewView.Hidden   = true;
                recordButton.Enabled = false;
            }
        }
Пример #3
0
            public bool SetupAssetWriterVideoInput(CMFormatDescription currentFormatDescription)
            {
                Console.WriteLine("Setting up Video Asset Writer");
                float bitsPerPixel;
                var   dimensions = currentFormatDescription.VideoDimensions;
                int   numPixels  = dimensions.Width * dimensions.Height;
                int   bitsPerSecond;

                // Assume that lower-than-SD resolution are intended for streaming, and use a lower bitrate
                if (numPixels < (640 * 480))
                {
                    bitsPerPixel = 4.05F;                     // This bitrate matches the quality produced by AVCaptureSessionPresetMedium or Low.
                }
                else
                {
                    bitsPerPixel = 11.4F;                     // This bitrate matches the quality produced by AVCaptureSessionPresetHigh.
                }
                bitsPerSecond = Convert.ToInt32((float)numPixels * bitsPerPixel);

                NSDictionary videoCompressionSettings = NSDictionary.FromObjectsAndKeys(
                    new NSObject[]
                {                           // The Compression Settings Values
                    AVVideo.CodecH264,
                    NSNumber.FromInt32(dimensions.Width),
                    NSNumber.FromInt32(dimensions.Height),
                    NSDictionary.FromObjectsAndKeys(
                        new object[]
                    {                                           // Compression Property Values
                        NSNumber.FromInt32(bitsPerSecond),
                        NSNumber.FromInt32(30)
                    },
                        new object[]
                    {                                           // Compression Property Keys
                        AVVideo.AverageBitRateKey,
                        AVVideo.MaxKeyFrameIntervalKey
                    })
                },
                    new NSObject[]
                {                               // The Compression Settings Keys
                    AVVideo.CodecKey,
                    AVVideo.WidthKey,
                    AVVideo.HeightKey,
                    AVVideo.CompressionPropertiesKey
                }
                    );

                if (processor.assetWriter.CanApplyOutputSettings(videoCompressionSettings, AVMediaType.Video))
                {
                    processor.assetWriterVideoIn = new AVAssetWriterInput(AVMediaType.Video, videoCompressionSettings);
                    processor.assetWriterVideoIn.ExpectsMediaDataInRealTime = true;
                    processor.assetWriterVideoIn.Transform = processor.TransformFromCurrentVideoOrientationToOrientation(processor.ReferenceOrientation);

                    if (processor.assetWriter.CanAddInput(processor.assetWriterVideoIn))
                    {
                        processor.assetWriter.AddInput(processor.assetWriterVideoIn);
                    }
                    else
                    {
                        Console.WriteLine("Couldn't add asset writer video input.");
                        return(false);
                    }
                }
                else
                {
                    Console.WriteLine("Couldn't apply video output settings.");
                }

                return(true);
            }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // Initialize the class responsible for managing AV capture session and asset writer
            videoProcessor = new RosyWriterVideoProcessor ();

            // Keep track of changes to the device orientation so we can update the video processor
            var notificationCenter = NSNotificationCenter.DefaultCenter;
            notificationCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange);

            UIDevice.CurrentDevice.BeginGeneratingDeviceOrientationNotifications ();

            // Setup and start the capture session
            videoProcessor.SetupAndStartCaptureSession ();

            notificationCenter.AddObserver (UIApplication.DidBecomeActiveNotification, OnApplicationDidBecomeActive);

            oglView = new RosyWriterPreviewWindow(CGRect.Empty);

            // Our interface is always in portrait
            oglView.Transform = videoProcessor.TransformFromCurrentVideoOrientationToOrientation(AVCaptureVideoOrientation.Portrait);

            CGRect bounds = previewView.ConvertRectToView(previewView.Bounds, oglView);
            oglView.Bounds = bounds;
            oglView.Center = new CGPoint(previewView.Bounds.Size.Width / 2.0F, previewView.Bounds.Size.Height / 2.0F);

            previewView.AddSubview(oglView);

            // Set up labels
            shouldShowStats = true;

            frameRateLabel = LabelWithText (string.Empty, 10.0F);
            previewView.AddSubview (frameRateLabel);

            dimensionsLabel = LabelWithText (string.Empty, 54.0F);
            previewView.AddSubview (dimensionsLabel);

            typeLabel = LabelWithText (string.Empty, 90F);
            previewView.Add (typeLabel);

            // btnRecord Event Handler
            btnRecord.Clicked += OnToggleRecording;

            // Video Processor Event Handlers
            videoProcessor.RecordingDidStart += OnRecordingDidStart;
            videoProcessor.RecordingDidStop += OnRecordingDidStop;
            videoProcessor.RecordingWillStart += OnRecordingWillStart;
            videoProcessor.RecordingWillStop += OnRecordingWillStop;
            videoProcessor.PixelBufferReadyForDisplay += OnPixelBufferReadyForDisplay;
        }