private void CloseRenderSession() { deckLinkInput.VideoDataArrived -= CurrentDevice_VideoDataArrived; deckLinkInput.AudioDataArrived -= CurrentDevice_AudioDataArrived; renderSession?.Close(); }
private void DeckLinkInput_CaptureChanged(bool formatChanged) { logger.Debug("DeckLinkInput_StateChanged(...) " + deckLinkInput.State + " " + formatChanged); var state = deckLinkInput.State; if (formatChanged) { if (state == DeckLink.CaptureState.Starting) {// new format... AudioRendererArgs audioArgs = GetAudioRenderArgs(); VideoRendererArgs videoArgs = GetVideoRenderArgs(); renderSession?.Setup(videoArgs, audioArgs); OnCaptureInitialized(); } else if (state == DeckLink.CaptureState.Capturing) {// new format, restart media renderers... if (renderSession != null) { renderSession.Close(); AudioRendererArgs audioArgs = GetAudioRenderArgs(); VideoRendererArgs videoArgs = GetVideoRenderArgs(); renderSession.Setup(videoArgs, audioArgs); OnCaptureInitialized(); renderSession.Start(); } } } else { if (state == DeckLink.CaptureState.Capturing) { renderSession?.Start(); OnCaptureStarted(); } else if (state == DeckLink.CaptureState.Stopped) { errorCode = deckLinkInput.ErrorCode; deckLinkInput.Shutdown(); renderSession?.Close(); OnCaptureStopped(); } } }
protected override void OnClosed(EventArgs e) { if (deckLinkInput != null) { deckLinkInput.AudioDataArrived -= CurrentDevice_AudioDataArrived; deckLinkInput.VideoDataArrived -= CurrentDevice_VideoDataArrived; deckLinkInput.StopCapture(); } if (renderSession != null) { renderSession.Close(); renderSession = null; } MediaToolkitManager.Shutdown(); base.OnClosed(e); }
public void StartCapture(int deviceIndex, long pixelFormat, long displayModeId) { logger.Debug("IDeckLinkInputControl::StartCapture(...) " + string.Join(" ", deviceIndex, pixelFormat, displayModeId)); try { DeviceIndex = deviceIndex; windowHandle = this.Handle; renderSession = new MediaRenderSession(); deckLinkInput = new DeckLinkInput(); deckLinkInput.CaptureChanged += DeckLinkInput_CaptureChanged; deckLinkInput.VideoDataArrived += CurrentDevice_VideoDataArrived; deckLinkInput.AudioDataArrived += CurrentDevice_AudioDataArrived; deckLinkInput.StartCapture(deviceIndex, pixelFormat, displayModeId); } catch (Exception ex) { logger.Error(ex); renderSession?.Close(); if (deckLinkInput != null) { deckLinkInput.VideoDataArrived -= CurrentDevice_VideoDataArrived; deckLinkInput.AudioDataArrived -= CurrentDevice_AudioDataArrived; deckLinkInput.CaptureChanged -= DeckLinkInput_CaptureChanged; deckLinkInput.Shutdown(); deckLinkInput = null; } throw; } }