Esempio n. 1
0
        private async Task AddEffectsAsync()
        {
            UpdateConfiguration();

            var videoEffectDefinition = new Windows.Media.Effects.VideoEffectDefinition("Lumia.Imaging.VideoEffect", m_configurationPropertySet);

            await m_mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            await m_mediaCapture.ClearEffectsAsync(MediaStreamType.VideoRecord);

            await m_mediaCapture.ClearEffectsAsync(MediaStreamType.Photo);

            await m_mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.VideoPreview);

            switch (m_mediaCapture.MediaCaptureSettings.VideoDeviceCharacteristic)
            {
            case VideoDeviceCharacteristic.AllStreamsIndependent:
                await m_mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.VideoRecord);

                await m_mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.Photo);

                break;

            case VideoDeviceCharacteristic.PreviewPhotoStreamsIdentical:
            case VideoDeviceCharacteristic.RecordPhotoStreamsIdentical:
                await m_mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.VideoRecord);

                break;

            case VideoDeviceCharacteristic.PreviewRecordStreamsIdentical:
                await m_mediaCapture.AddVideoEffectAsync(videoEffectDefinition, MediaStreamType.Photo);

                break;
            }
        }
        private async Task CloseCamera()
        {
            if (faceDetectionEffect != null && faceDetectionEffect.Enabled)
            {
                faceDetectionEffect.Enabled       = false;
                faceDetectionEffect.FaceDetected -= FaceDetected;
                await capture.ClearEffectsAsync(MediaStreamType.VideoPreview);

                faceDetectionEffect = null;
                facesCanvas.Children.Clear();
            }

            if (capture != null)
            {
                if (isPreviewing)
                {
                    await capture.StopPreviewAsync();

                    isPreviewing = false;
                }
                capture.Dispose();
                capture = null;
            }

            //if (photoFile != null)
            //{
            //    await photoFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
            //    photoFile = null;
            //}
        }
 private async Task ResetEffectsAsync()
 {
     if (mediaCapture.CameraStreamState == CameraStreamState.Streaming)
     {
         await mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);
     }
 }
        /// <summary>
        ///  Disables and removes the video stabilization effect, and unregisters the event handler for the EnabledChanged event of the effect
        /// </summary>
        /// <returns></returns>
        private async Task CleanUpVideoStabilizationEffectAsync()
        {
            // No work to be done if there is no effect
            if (_videoStabilizationEffect == null)
            {
                return;
            }

            // Disable the effect
            _videoStabilizationEffect.Enabled = false;

            _videoStabilizationEffect.EnabledChanged -= VideoStabilizationEffect_EnabledChanged;

            // Remove the effect from the record stream
            await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoRecord);

            Debug.WriteLine("VS effect removed from pipeline");

            // If backed up settings (stream properties and encoding profile) exist, restore them and clear the backups
            if (_inputPropertiesBackup != null)
            {
                await _mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoRecord, _inputPropertiesBackup);

                _inputPropertiesBackup = null;
            }

            if (_outputPropertiesBackup != null)
            {
                _encodingProfile.Video  = _outputPropertiesBackup;
                _outputPropertiesBackup = null;
            }

            // Clear the member variable that held the effect instance
            _videoStabilizationEffect = null;
        }
Esempio n. 5
0
        public async Task StopEverything()
        {
            if (Preview.Previewing)
            {
                await Preview.StopAsync();
            }

            if (Video.Capturing)
            {
                await Video.StopAsync();
            }

            if (FaceDetection != null)
            {
                FaceDetection.Enabled       = false;
                FaceDetection.FaceDetected -= FaceDetection_FaceDetected;
            }

            if (DefaultManager != null)
            {
                DefaultManager.RecordLimitationExceeded -= DefaultManager_RecordLimitationExceeded;
                await DefaultManager.ClearEffectsAsync(MediaStreamType.VideoPreview);

                DefaultManager.Dispose();
                DefaultManager = null;
            }
        }
Esempio n. 6
0
        private async void CoreApplication_EnteredBackground(object sender, EnteredBackgroundEventArgs e)
        {
            var Deferral = e.GetDeferral();

            await Capture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            await Capture.StopPreviewAsync();

            Capture = null;
            MediaCaptureProvider.Dispose();

            CaptureControl.Source = null;

            StayAwake.RequestRelease();

            Deferral.Complete();
        }
Esempio n. 7
0
        private async void FaceStopDetect()
        {
            _faceDetectionEffect.Enabled       = false;
            _faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected;
            await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            _faceDetectionEffect = null; this.cvsFaceOverlay.Children.Clear();
            this.cvsFaceOverlay.Children.Clear();
        }
Esempio n. 8
0
        private async void btnStopDetection_Click(object sender, RoutedEventArgs e)
        {
            this.cvsFaceOverlay.Children.Clear();
            _faceDetectionEffect.Enabled       = false;
            _faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected;
            await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            _faceDetectionEffect = null;
        }
Esempio n. 9
0
        private async void getWebcam2()
        {
            MediaCapture capture = new MediaCapture();
            await capture.InitializeAsync();

            await capture.ClearEffectsAsync(MediaStreamType.VideoRecord);

            cap_CaptureElement.Source = capture;
            await capture.StartPreviewAsync();
        }
Esempio n. 10
0
        private async Task CleanupCameraAsync()
        {
            await mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            await mediaCapture.StopPreviewAsync();

            PreviewControl.Source = null;
            mediaCapture.Dispose();
            mediaCapture = null;
        }
Esempio n. 11
0
        /// <summary>
        /// Asynchronously stop face detection
        /// </summary>
        public async Task StopFaceDetectionAsync()
        {
            if (FaceDetectionEffect != null)
            {
                FaceDetectionEffect.Enabled = false;
                await MediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

                FaceDetectionEffect = null;
            }
        }
Esempio n. 12
0
        private async void OnStateChanged(VideoEffectState newState, VideoEffectState oldState)
        {
            switch (newState)
            {
            case VideoEffectState.Idle:
                await MediaCapture.ClearEffectsAsync(PreviewMediaStreamType);

                break;

            case VideoEffectState.Locked:
            case VideoEffectState.PostProcess:
                break;
            }
        }
        /// <summary>
        ///  Disables and removes the face detection effect, and unregisters the event handler for face detection
        /// </summary>
        /// <returns></returns>
        private async Task CleanUpFaceDetectionEffectAsync()
        {
            // Disable detection
            _faceDetectionEffect.Enabled = false;

            // Unregister the event handler
            _faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected;

            // Remove the effect from the preview stream
            await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            // Clear the member variable that held the effect instance
            _faceDetectionEffect = null;
        }
        /// <summary>
        ///  Disables and removes the scene analysis effect, and unregisters the event handler for the SceneAnalyzed event of the effect
        /// </summary>
        /// <returns></returns>
        private async Task CleanSceneAnalysisEffectAsync()
        {
            // Disable detection
            _sceneAnalysisEffect.HighDynamicRangeAnalyzer.Enabled = false;

            _sceneAnalysisEffect.SceneAnalyzed -= SceneAnalysisEffect_SceneAnalyzed;

            // Remove the effect from the preview stream
            await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            Debug.WriteLine("SA effect removed from pipeline");

            // Clear the member variable that held the effect instance
            _sceneAnalysisEffect = null;
        }
        private async Task StopMediaCaptureSession()
        {
            if (isRecording)
            {
                faceDetectionEffect.Enabled       = false;
                faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected;
                await mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

                await mediaCapture.StopPreviewAsync();

                await mediaCapture.StopRecordAsync();

                isRecording         = false;
                faceDetectionEffect = null;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Record button tapped for either starting or stopping video recording
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void RecordButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            if (_isRecording)
            {
                RecordSymbol.Symbol = Symbol.Target;
                await StopVideoRecordingAsync();

                await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoRecord);

                if (_sphericalProjectionEffect != null)
                {
                    if (_sphericalProjectionEffect.SphericalProjection.IsEnabled)
                    {
                        _mediaPlayerProjection.IsEnabled   = (_mediaPlayerProjection.FrameFormat == SphericalVideoFrameFormat.Equirectangular) || (ToggleForceSpherical.IsChecked == true);
                        _mediaPlayerProjection.FrameFormat = _sphericalProjectionEffect.SphericalProjection.FrameFormat;
                        _mediaPlayerProjection.HorizontalFieldOfViewInDegrees = _sphericalProjectionEffect.SphericalProjection.HorizontalFieldOfViewInDegrees;
                        _mediaPlayerProjection.ProjectionMode  = _sphericalProjectionEffect.SphericalProjection.ProjectionMode;
                        _mediaPlayerProjection.ViewOrientation = _sphericalProjectionEffect.SphericalProjection.ViewOrientation;
                    }
                    _sphericalProjectionEffect = null;
                }
            }
            else
            {
                RecordSymbol.Symbol = Symbol.Stop;
                if (ToggleRecordProjection.IsChecked == true)
                {
                    _sphericalProjectionEffect = new Windows.Media.Effects.VideoTransformEffectDefinition();
                    _sphericalProjectionEffect.SphericalProjection.IsEnabled   = _mediaPlayerProjection.IsEnabled;
                    _sphericalProjectionEffect.SphericalProjection.FrameFormat = _mediaPlayerProjection.FrameFormat;
                    _sphericalProjectionEffect.SphericalProjection.HorizontalFieldOfViewInDegrees = _mediaPlayerProjection.HorizontalFieldOfViewInDegrees;
                    _sphericalProjectionEffect.SphericalProjection.ProjectionMode  = _mediaPlayerProjection.ProjectionMode;
                    _sphericalProjectionEffect.SphericalProjection.ViewOrientation = _mediaPlayerProjection.ViewOrientation;
                    _mediaPlayerProjection.IsEnabled = false;
                    await _mediaCapture.AddVideoEffectAsync(_sphericalProjectionEffect, MediaStreamType.VideoRecord);
                }
                await StartVideoRecordingAsync();
            }
            _isRecording = !_isRecording;
            await EnableDisableCameraControlsOnUI(!_isRecording);
        }
Esempio n. 17
0
        /// <summary>
        /// Stops the camera preview and releases all resources
        /// </summary>
        /// <returns></returns>
        public async Task CleanupCameraAsync()
        {
            if (_mediaCapture != null)
            {
                if (_isDetecting)
                {
                    // Disable detection
                    _faceDetectionEffect.Enabled = false;

                    // Unregister the event handler
                    _faceDetectionEffect.FaceDetected -= FaceDetectionEffect_FaceDetected;

                    // Remove the effect from the preview stream
                    await _mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

                    // Clear the member variable that held the effect instance
                    _faceDetectionEffect = null;

                    _isDetecting = false;
                }

                if (IsPreviewing)
                {
                    await _mediaCapture.StopPreviewAsync();

                    IsPreviewing = false;
                }

                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    CameraPreview.Source = null;
                    if (_displayRequest != null)
                    {
                        _displayRequest.RequestRelease();
                    }

                    _mediaCapture.Dispose();
                    _mediaCapture = null;
                });
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Starts/stops the effect.
        /// </summary>
        /// <returns>True, if the effect was set on. False, if it was turned off.</returns>
        public async Task <bool> ToggleEffectAsync()
        {
            if (Started)
            {
                if (EffectSet)
                {
                    await MediaCapture.ClearEffectsAsync(PreviewMediaStreamType);

                    StateManager.State = VideoEffectState.Idle;
                }
                else
                {
                    Messenger.SettingsChangedFlag = true;
                    Messenger.ModeChangedFlag     = true;
                    await MediaCapture.AddEffectAsync(PreviewMediaStreamType, RealtimeTransformActivationId, Properties);

                    StateManager.State = VideoEffectState.Locking;
                }
            }

            return(EffectSet);
        }
        //</SnippetStartRecordWithRotation>


        async void AddEffectCapture(MediaCapture captureMgrReal)
        {
            // <SnippetCaptureAddEffect>
            MediaCapture captureMgr = new MediaCapture();
            await captureMgr.InitializeAsync();

            await captureMgr.AddEffectAsync(
                MediaStreamType.VideoRecord,
                Windows.Media.VideoEffects.VideoStabilization,
                null);

            // </SnippetCaptureAddEffect>

            // For Testing snippet.  Don't include in snippet.
            captureMgrReal        = captureMgr;
            capturePreview.Source = captureMgrReal;
            await captureMgr.StartPreviewAsync();

            // <SnippetCaptureRemoveEffect>
            // captureMgr is of type MediaCapture.
            await captureMgr.ClearEffectsAsync(MediaStreamType.VideoRecord);

            // </SnippetCaptureRemoveEffect>
        }
        private async Task ClearVideoEffectsAsync()
        {
            await mediaCapture.ClearEffectsAsync(MediaStreamType.VideoPreview);

            previewEffect = null;
        }
Esempio n. 21
0
 async private void removeEffects()
 {
     await mediaCapture.ClearEffectsAsync(
         MediaStreamType.VideoPreview
         );
 }
 async void ClearEffectsCapture(MediaCapture captureMgr)
 {
     await captureMgr.ClearEffectsAsync(MediaStreamType.VideoRecord);
 }