protected async void FrameReaderOnFrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args) { try { //MediaFrameReference mediaFrameReference = sender.TryAcquireLatestFrame( ); //if (mediaFrameReference != null) //{ // var imageDataFrame = mediaFrameReference.BufferMediaFrame; // var imageDataBuffer = imageDataFrame.Buffer; // var imageData = imageDataBuffer.ToArray( ); // mediaFrameReference.Dispose( ); //} using (var frame = sender.TryAcquireLatestFrame()) { if (frame != null) { frameQueue.Add(frame.VideoMediaFrame?.SoftwareBitmap); } } //frameReader?.Dispose( ); } catch (Exception e) { await frameReader.StopAsync( ); } }
public Task PauseVideo() { if (_mediaFrameReader != null) { return(_mediaFrameReader.StopAsync().AsTask()); } else { return(Task.CompletedTask); } }
/// <summary> /// Stops the video pipeline and frame reading. /// </summary> /// <returns>Whether the video frame reader is successfully stopped</returns> private async Task <bool> StopFrameReaderAsyncTask() { await _frameReader.StopAsync(); _logger.Log("Stopped frame reader"); return(true); }
/// <summary> /// Stop the camera. This will release resources and /// </summary> public async void Stop() { #if CAN_USE_UWP_TYPES bool isStopping = false; lock (stateLock) { if (State == CameraState.CapturingContinuous || State == CameraState.CapturingSingle || State == CameraState.Ready || State == CameraState.Starting) { // TODO: may have to do something about being in the starting state. i.e. wait until started, or perhaps cancel remaining starting operations. State = CameraState.Stopping; isStopping = true; } } if (isStopping) { frameReader.FrameArrived -= OnMediaFrameArrived; await frameReader.StopAsync(); } #else await Task.CompletedTask; #endif }
private async void StopCamera() { await mediaFrameReader.StopAsync(); mediaFrameReader.FrameArrived -= ColorFrameReader_FrameArrived; mediaCapture.Dispose(); mediaCapture = null; }
async void CleanerAsync() { await mediaFrameReader.StopAsync(); mediaFrameReader.FrameArrived -= ColorFrameReader_FrameArrived; mediaCapture.Dispose(); mediaCapture = null; }
public override async Task Stop() { await this.StopRecognition(); await frameReader.StopAsync(); await FileUtils.Save(messageStream, this.FileName); }
//############################################################################################# /// <summary> /// Stop the video capture. After this call, frame could be get with <see cref="GetFrame"/> but keep in mind that it returns the last available frame if exist. /// </summary> public async Task Stop() { if (_running) { await _mediaFrameReader.StopAsync(); _running = false; } }
public override async Task DisposeAsync() { FrameReader.FrameArrived -= FrameArrived; await FrameReader.StopAsync(); FrameReader.Dispose(); MediaCapture.Dispose(); Logger.Log($"Disposed {nameof(ColorCameraProcessor)}."); }
public IAsyncAction CloseAsync() { return(Task.Run(async() => { _depthReader.FrameArrived -= DepthReader_FrameArrived; await _depthReader.StopAsync(); _isStarted = false; }).AsAsyncAction()); }
// </SnippetFrameArrived> private async Task Cleanup() { // <SnippetCleanup> await mediaFrameReader.StopAsync(); mediaFrameReader.FrameArrived -= ColorFrameReader_FrameArrived; mediaCapture.Dispose(); mediaCapture = null; // </SnippetCleanup> }
private async void StopCapture() { System.Diagnostics.Debug.WriteLine("Stopping capture."); await mediaFrameReader.StopAsync(); mediaFrameReader.FrameArrived -= MediaFrameReader_FrameArrived; mediaCapture.Dispose(); mediaCapture = null; System.Diagnostics.Debug.WriteLine("Capture stopped."); }
public async Task Stop() { _stopThreads = true; SpinWait.SpinUntil(() => { return(_threadsCount == _stoppedThreads); }); await _mediaFrameReader.StopAsync(); _stopThreads = false; }
public async Task Cleanup() { if (_mediaCapture != null) { await _reader.StopAsync(); _reader.FrameArrived -= ColorFrameReader_FrameArrivedAsync; _reader.Dispose(); _mediaCapture = null; } }
/// <summary> /// Unregisters FrameArrived event handlers, stops and disposes frame readers /// and disposes the MediaCapture object. /// </summary> private async Task CleanupMediaCaptureAsync() { if (mediaCapture != null) { await reader.StopAsync(); reader.FrameArrived -= ColorFrameReader_FrameArrivedAsync; reader.Dispose(); mediaCapture = null; } }
private async Task CleanupMediaCaptureAsync() { if (_mediaCapture != null) { await _reader.StopAsync(); _reader.FrameArrived -= HandleFrameArrive; _reader.Dispose(); _mediaCapture = null; } }
public async Task Stop() { _isStopping = true; while (!_isStopped) { await Task.Delay(10); } _isStopping = false; await _mediaFrameReader.StopAsync(); }
public async Task StopCapturing() { #if ENABLE_WINMD_SUPPORT if (_captureManager != null && _captureManager.CameraStreamState != CameraStreamState.Shutdown) { await _frameReader.StopAsync(); _frameReader.Dispose(); _captureManager.Dispose(); _captureManager = null; } #endif }
private async Task <bool> StopFrameReaderAsync() { if (captureStatus != CaptureStatus.Running) { Debug.Log(TAG + ": StopFrameReaderAsync() fails because of incorrect status"); return(false); } await frameReader.StopAsync(); captureStatus = CaptureStatus.Initialized; Debug.Log(TAG + ": StopFrameReaderAsync() is successful"); return(true); }
/// <summary> /// The task to asynchronously stops the video pipeline and frame reading. The task should /// be executed when the ARUWPController status is ARUWP_STATUS_RUNNING, and will change it /// to ARUWP_STATUS_CTRL_INITIALIZED when the task is successful. Note that the frame reader /// can be restarted after stop. It is more pause-resume instead of stop-start, because the /// video pipeline does not need to be configured again. The task is wrapped up in the /// ARUWPController.Pause() function. [internal use] /// </summary> /// <returns>Whether the video frame reader is successfully stopped</returns> public async Task <bool> StopFrameReaderAsyncTask() { if (controller.status != ARUWP.ARUWP_STATUS_RUNNING) { Debug.Log(TAG + ": StopFrameReaderAsyncTask() fails because of incorrect status"); return(false); } await frameReader.StopAsync(); controller.status = ARUWP.ARUWP_STATUS_CTRL_INITIALIZED; Debug.Log(TAG + ": StopFrameReaderAsyncTask() is successful"); return(true); }
/// <summary> /// Asynchronously stop media capture and dispose of resources /// </summary> /// <returns></returns> public async Task StopMediaFrameReaderAsync() { #if ENABLE_WINMD_SUPPORT if (_mediaCapture != null && _mediaCapture.CameraStreamState != CameraStreamState.Shutdown) { await _mediaFrameReader.StopAsync(); _mediaFrameReader.Dispose(); _mediaCapture.Dispose(); _mediaCapture = null; } IsCapturing = false; #endif }
public override void StartStream() { paused = false; if (!Streaming) { Streaming = true; Reader.FrameArrived += NewFrameArrived; var task = Reader.StartAsync(); while (task.Status == AsyncStatus.Started) { Thread.Sleep(50); } CaptureElement captureElement = null; bool waiting = true; Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() => { captureElement = new CaptureElement { Source = NativeDevice }; waiting = false; }); NativeDevice.Failed += OnFail; while (waiting) { Thread.Sleep(50); } Task.Run(() => { while (Streaming) { if (StreamFaultTimer.ElapsedMilliseconds > 1000) { Debug.WriteLine("Been a second without frames. forcing a call"); var Task = Reader.StopAsync(); while (Task.Status == AsyncStatus.Started) { Thread.Sleep(50); } var taskt = Reader.StartAsync(); while (taskt.Status == AsyncStatus.Started) { Thread.Sleep(50); } StreamFaultTimer.Reset(); } } }); } }
/// <summary> /// Stops reading from the frame reader, disposes of the reader and updates the button state. /// </summary> private async Task StopReaderAsync() { _streaming = false; if (_reader != null) { await _reader.StopAsync(); _reader.FrameArrived -= Reader_FrameArrived; _reader.Dispose(); _reader = null; _logger.Log("Reader stopped."); } }
/// <summary> /// カメラプレビューを停止する /// </summary> /// <param name="onVideoModeStoppedCallback"></param> public async Task <bool> StopVideoModeAsync() { if (IsStreaming == false) { // すでにプレビューを停止している場合は何もしない return(false); } _frameReader.FrameArrived -= HandleFrameArrived; await _frameReader.StopAsync(); _frameReader.Dispose(); _frameReader = null; return(true); }
/// <summary> /// Asynchronously stops video mode. /// </summary> /// <param name="onVideoModeStoppedCallback">This callback will be invoked once video mode has been deactivated.</param> public async void StopVideoModeAsync(OnVideoModeStoppedCallback onVideoModeStoppedCallback) { if (IsStreaming == false) { onVideoModeStoppedCallback?.Invoke(new VideoCaptureResult(1, ResultType.InappropriateState, false)); return; } _frameReader.FrameArrived -= HandleFrameArrived; await _frameReader.StopAsync(); _frameReader.Dispose(); _frameReader = null; onVideoModeStoppedCallback?.Invoke(new VideoCaptureResult(0, ResultType.Success, true)); }
/// <summary> /// Dispose of camera pipeline resources. /// </summary> /// <returns></returns> public async Task CleanupAsync() { if (m_frameReader != null) { m_frameReader.FrameArrived -= FrameArrivedHandler; await m_frameReader.StopAsync(); m_frameReader.Dispose(); m_frameReader = null; } if (m_mediaCapture != null) { m_mediaCapture.Failed -= MediaCapture_Failed; m_mediaCapture.Dispose(); } m_mediaCapture = null; }
public IAsyncAction CloseAsync() { return(Task.Run(async() => { if (_depthReader != null) { _depthReader.FrameArrived -= DepthReader_FrameArrived; await _depthReader.StopAsync(); } else { _networkClient.DepthFrameArrived -= NetworkClient_DepthFrameArrived; await _networkClient.SendCommandAsync(new CloseReader(ReaderType.Depth)); } _isStarted = false; }).AsAsyncAction()); }
private async void SettingSensorData(int deviceNum, int cameraNum) { if (mediaFrameReader != null) { await mediaFrameReader.StopAsync(); mediaFrameReader.FrameArrived -= FrameArrived; mediaFrameReader.Dispose(); mediaFrameReader = null; } var mediaFrameSourceGroupList = await MediaFrameSourceGroup.FindAllAsync(); var mediaFrameSourceGroup = mediaFrameSourceGroupList[deviceNum]; var mediaFrameSourceInfo = mediaFrameSourceGroup.SourceInfos[cameraNum]; MediaFrameSourceKind kind = mediaFrameSourceInfo.SourceKind; var mediaCapture = new MediaCapture(); var settings = new MediaCaptureInitializationSettings() { SourceGroup = mediaFrameSourceGroup, SharingMode = MediaCaptureSharingMode.SharedReadOnly, StreamingCaptureMode = StreamingCaptureMode.Video, MemoryPreference = MediaCaptureMemoryPreference.Cpu, }; try { await mediaCapture.InitializeAsync(settings); var mediaFrameSource = mediaCapture.FrameSources[mediaFrameSourceInfo.Id]; if (kind == MediaFrameSourceKind.Color) { mediaFrameReader = await mediaCapture.CreateFrameReaderAsync(mediaFrameSource, MediaEncodingSubtypes.Argb32); } else { mediaFrameReader = await mediaCapture.CreateFrameReaderAsync(mediaFrameSource, mediaFrameSource.CurrentFormat.Subtype); } mediaFrameReader.FrameArrived += FrameArrived; await mediaFrameReader.StartAsync(); } catch (Exception) { throw; } }
async Task OnDestroy() { await audioFrameReader.StopAsync(); await videoFrameReader.StopAsync(); audioFrameReader.FrameArrived -= AudioFrameArrived; audioStream.FlushAsync(); audioStream.Dispose(); audioStream = null; videoFrameReader.FrameArrived -= VideoFrameArrived; videoStream.FlushAsync(); videoStream.Dispose(); videoStream = null; mediaCapture.Dispose(); }
private async Task StopReaderAsync2() { _streaming2 = false; if (_reader2 != null) { await _reader2.StopAsync(); _reader2.FrameArrived -= Reader_FrameArrived2; _reader2.Dispose(); _reader2 = null; _logger2.Log("Reader stopped."); } await UpdateButtonStateAsync2(); }