private void buttonStart_Click(object sender, EventArgs e) { logger.Debug("buttonStart_Click(...)"); var deviceIndex = 0; var item = comboBoxDevices.SelectedItem; if (item != null) { var device = item as DeckLinkDeviceDescription; if (device != null) { deviceIndex = device.DeviceIndex; } } try { OnCaputeStarted(); renderSession = new MediaRenderSession(); deckLinkInput = new DeckLinkInput(); deckLinkInput.CaptureChanged += DeckLinkInput_CaptureChanged; deckLinkInput.StartCapture(currentDevice, currentDisplayMode); } catch (Exception ex) { MessageBox.Show(ex.Message); 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; } }