Exemplo n.º 1
0
        /// <summary>
        /// Start previewing from the camera
        /// </summary>
        private void StartPreview()
        {
            Debug.WriteLine("StartPreview");
            _selectedMediaFrameSource = _mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoPreview &&
                                                                                  source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
            if (_selectedMediaFrameSource == null)
            {
                _selectedMediaFrameSource = _mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoRecord &&
                                                                                      source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
            }

            // if no preview stream are available, bail
            if (_selectedMediaFrameSource == null)
            {
                return;
            }

            _mediaPlayer = new MediaPlayer();
            _mediaPlayer.RealTimePlayback = true;
            _mediaPlayer.AutoPlay         = true;
            _mediaPlayer.Source           = MediaSource.CreateFromMediaFrameSource(_selectedMediaFrameSource);
            UIMediaPlayerElement.SetMediaPlayer(_mediaPlayer);
            UITxtBlockPreviewProperties.Text = string.Format("{0}x{1}@{2}, {3}",
                                                             _selectedMediaFrameSource.CurrentFormat.VideoFormat.Width,
                                                             _selectedMediaFrameSource.CurrentFormat.VideoFormat.Height,
                                                             _selectedMediaFrameSource.CurrentFormat.FrameRate.Numerator + "/" + _selectedMediaFrameSource.CurrentFormat.FrameRate.Denominator,
                                                             _selectedMediaFrameSource.CurrentFormat.Subtype);

            UICameraSelectionControls.Visibility = Visibility.Visible;
            UIMediaPlayerElement.Visibility      = Visibility.Visible;
            UIResultImage.Width  = UIMediaPlayerElement.Width;
            UIResultImage.Height = UIMediaPlayerElement.Height;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the view of the virtual camera and configure available interactions
        /// </summary>
        /// <returns></returns>
        public async Task InitializeAsync()
        {
            m_mediaCapture = new MediaCapture();
            m_mediaPlayer  = new MediaPlayer();

            // We initialize the MediaCapture instance with the virtual camera in sharing mode
            // to preview its stream without blocking other app from using it
            var initSettings = new MediaCaptureInitializationSettings()
            {
                SharingMode          = MediaCaptureSharingMode.SharedReadOnly,
                VideoDeviceId        = VirtualCameraProxyInst.SymbolicLink,
                StreamingCaptureMode = StreamingCaptureMode.Video
            };

            await m_mediaCapture.InitializeAsync(initSettings);

            // Retrieve the source associated with the video preview stream.
            // On 1-pin camera, this may be the VideoRecord MediaStreamType as opposed to VideoPreview on multi-pin camera
            var frameSource = m_mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoPreview &&
                                                                         source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;

            if (frameSource == null)
            {
                frameSource = m_mediaCapture.FrameSources.FirstOrDefault(source => source.Value.Info.MediaStreamType == MediaStreamType.VideoRecord &&
                                                                         source.Value.Info.SourceKind == MediaFrameSourceKind.Color).Value;
            }

            // if no preview stream is available, bail
            if (frameSource == null)
            {
                return;
            }

            // Setup MediaPlayer with the preview source
            m_mediaPlayer.RealTimePlayback = true;
            m_mediaPlayer.AutoPlay         = true;
            m_mediaPlayer.Source           = MediaSource.CreateFromMediaFrameSource(frameSource);

            UIMediaPlayerElement.SetMediaPlayer(m_mediaPlayer);

            // Query support of custom and standard KSProperty and update UI toggle buttons accordingly
            bool isColorModeSupported         = (null != CameraKsPropertyInquiry.GetCustomControl(CustomControlKind.ColorMode, m_mediaCapture.VideoDeviceController));
            bool isEyeGazeCorrectionSupported = (null != CameraKsPropertyInquiry.GetExtendedControl(ExtendedControlKind.EyeGazeCorrection, m_mediaCapture.VideoDeviceController));

            UIColorModeControlButton.IsEnabled = isColorModeSupported;
            UIEyeGazeControlButton.IsEnabled   = isEyeGazeCorrectionSupported;
        }