Ejemplo n.º 1
0
        public async Task <VoipVideoCapture> ToggleCapturingAsync(VoipCaptureType type)
        {
            void Disable()
            {
                if (_capturer != null)
                {
                    _capturer.SetOutput(null);
                    _manager.SetVideoCapture(null);

                    _capturer.Dispose();
                    _capturer = null;
                }
            }

            if (type == VoipCaptureType.None)
            {
                Disable();
            }
            else if (type == VoipCaptureType.Video && _capturer is not VoipVideoCapture)
            {
                Disable();

                if (_manager == null)
                {
                    return(null);
                }

                _capturer = new VoipVideoCapture(await _videoWatcher.GetAndUpdateAsync());
                _manager?.SetVideoCapture(_capturer);
            }
            else if (type == VoipCaptureType.Screencast && _capturer is not VoipScreenCapture)
            {
                Disable();

                if (_manager == null || !GraphicsCaptureSession.IsSupported())
                {
                    return(null);
                }

                var picker = new GraphicsCapturePicker();
                var item   = await picker.PickSingleItemAsync();

                if (item == null || _manager == null)
                {
                    return(null);
                }

                _capturer = new VoipScreenCapture(item);
                _manager?.SetVideoCapture(_capturer);
            }

            return(_capturer);
        }
Ejemplo n.º 2
0
        public void Connect(VoipVideoCapture capturer)
        {
            if (capturer != null && _capturerWasNull)
            {
                _capturerWasNull = false;

                Video.IsChecked            = true;
                ViewfinderPanel.Visibility = Visibility.Visible;

                capturer.SetOutput(Viewfinder);
            }
            else if (capturer == null && !_capturerWasNull)
            {
                _capturerWasNull = true;

                Video.IsChecked            = false;
                ViewfinderPanel.Visibility = Visibility.Collapsed;
            }

            CheckConstraints();
        }