Esempio n. 1
0
        public void StartCapture(int videoWidth, int videoHeight, int fps)
        {
            _fps         = fps;
            _videoWidth  = videoWidth;
            _videoHeight = videoHeight;

            var position = _usingFrontCamera ? AVCaptureDevicePosition.Back : AVCaptureDevicePosition.Front;
            var device   = FindDeviceForPosition(position);
            var format   = SelectFormatForDevice(device, videoWidth, videoHeight);

            if (format == null)
            {
                Debug.WriteLine($"CameraVideoCapturerNative -> didn't find a valid format for {device}");
                format = RTCCameraVideoCapturer.SupportedFormatsForDevice(device).FirstOrDefault();
            }

            if (format == null)
            {
                Console.WriteLine("CameraVideoCapturerNative -> no valid formats for device {0}", device);
                return;
            }

            fps = SelectFpsForFormat(format);

            _capturer.StartCaptureWithDevice(device, format, fps);
        }
Esempio n. 2
0
        private AVCaptureDeviceFormat SelectFormatForDevice(AVCaptureDevice device, int targetWidth, int targetHeight)
        {
            var formats = RTCCameraVideoCapturer.SupportedFormatsForDevice(device);

            AVCaptureDeviceFormat selectedFormat = null;

            var currentDiff = int.MaxValue;

            foreach (var format in formats)
            {
                if (!(format.FormatDescription is CMVideoFormatDescription videoFormatDescription))
                {
                    continue;
                }
                var dimension   = videoFormatDescription.Dimensions;
                var pixelFormat = videoFormatDescription.MediaSubType;
                var diff        = Math.Abs(targetWidth - dimension.Width) + Math.Abs(targetHeight - dimension.Height);
                if (diff < currentDiff)
                {
                    selectedFormat = format;
                    currentDiff    = diff;
                }
                else if (diff == currentDiff && pixelFormat == _capturer.PreferredOutputPixelFormat)
                {
                    selectedFormat = format;
                }
            }

            return(selectedFormat);
        }
Esempio n. 3
0
        public void StartCapture(int videoWidth, int videoHeight, int fps)
        {
            _videoFps    = fps;
            _videoHeight = videoHeight;
            _videoWidth  = videoWidth;

            var position = _usingFrontCamera ? AVCaptureDevicePosition.Back : AVCaptureDevicePosition.Front;
            var device   = GetDeviceByPosition(position);
            var format   = GetFormatForDevice(device, videoWidth, videoHeight);

            if (format == null)
            {
                Debug.WriteLine($"PLATFORMCAMERAVIDEOCAPTURER: not valid format for {device}");
                format = RTCCameraVideoCapturer.SupportedFormatsForDevice(device).FirstOrDefault();
                if (format == null)
                {
                    Debug.WriteLine($"PLATFORMCAMERAVIDEOCAPTURER: no valid formats for device {0} and {device}");
                    return;
                }

                fps = GetFpsByFormat(format);
                _cameraVideoCapturer.StartCaptureWithDevice(device, format, fps);
            }
        }