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); }
public void DidCreateLocalCapturer(RTCCameraVideoCapturer localCapturer) { _videoCallView.LocalVideoView.CaptureSession = localCapturer.CaptureSession; _captureController = new ARDCaptureController(localCapturer, new ARDSettingsModel()); _captureController.StartCapture(); }
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); }
public ICameraVideoCapturer CreateCameraCapturer(IVideoSource videoSource, bool frontCamera) { var capturer = new RTCCameraVideoCapturer(); capturer.WeakDelegate = videoSource.ToPlatformNative <RTCVideoSource>(); return(new PlatformCameraVideoCapturer(capturer, frontCamera)); }
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); } }
public CameraVideoCapturerNative(RTCCameraVideoCapturer capturer, bool frontCamera) : base(capturer) { _capturer = capturer; _usingFrontCamera = frontCamera; }
public ICameraVideoCapturer CreateCameraCapturer(IVideoSource videoSource, bool frontCamera) { var capturer = new RTCCameraVideoCapturer(videoSource.ToNative <RTCVideoSource>()); return(new CameraVideoCapturerNative(capturer, frontCamera)); }
public PlatformCameraVideoCapturer(RTCCameraVideoCapturer cameraVideoCapturer, bool usingFrontCamera = true) : base(cameraVideoCapturer) { _cameraVideoCapturer = cameraVideoCapturer; _usingFrontCamera = usingFrontCamera; }
public CameraVideoCapturerNative(RTCCameraVideoCapturer capturer, RTCCameraDevice cameraDevice) : base(capturer) { _capturer = capturer; _deviceName = cameraDevice.DeviceId; }
public void DidCreateLocalCapturer(RTCCameraVideoCapturer localCapturer) { }
public ARDCaptureController(RTCCameraVideoCapturer capturer, ARDSettingsModel settings) { _capturer = capturer; _settings = settings; _usingFrontCamera = true; }
public ICameraVideoCapturer CreateCameraCapturer(IVideoSource videoSource, RTCCameraDevice cameraDevice) { var capturer = new RTCCameraVideoCapturer(videoSource.ToNative <RTCVideoSource>()); return(new CameraVideoCapturerNative(capturer, cameraDevice)); }