public DLDirect(IDeckLink deckLink, IDeckLinkDisplayMode displayMode) { PreRollFrameCount = 4; this.displayMode = displayMode; this.m_deckLink = deckLink; DisplayWidth = displayMode.GetWidth(); DisplayHeight = displayMode.GetHeight(); m_running = false; // Get the IDeckLinkOutput interface m_deckLinkOutput = (IDeckLinkOutput)m_deckLink; // Provide this class as a delegate to the audio and video output interfaces m_deckLinkOutput.SetScheduledFrameCompletionCallback(this); m_frameWidth = displayMode.GetWidth(); m_frameHeight = displayMode.GetHeight(); displayMode.GetFrameRate(out m_frameDuration, out m_frameTimescale); // Calculate the number of frames per second, rounded up to the nearest integer. For example, for NTSC (29.97 FPS), framesPerSecond == 30. m_framesPerSecond = (uint)((m_frameTimescale + (m_frameDuration - 1)) / m_frameDuration); FPS = (int)m_framesPerSecond; // Set the video output mode m_deckLinkOutput.EnableVideoOutput(displayMode.GetDisplayMode(), _BMDVideoOutputFlags.bmdVideoOutputFlagDefault); // Generate the frame used for playback m_deckLinkOutput.CreateVideoFrame(m_frameWidth, m_frameHeight, m_frameWidth * 4, _BMDPixelFormat.bmdFormat8BitBGRA, _BMDFrameFlags.bmdFrameFlagDefault, out m_videoFramePlayback); m_totalFramesScheduled = 0; }
private void DisplayModeChanged(IDeckLinkDisplayMode newDisplayMode) { foreach (DisplayModeEntry item in comboBoxVideoFormat.Items) { if (item.displayMode.GetDisplayMode() == newDisplayMode.GetDisplayMode()) { comboBoxVideoFormat.SelectedItem = item; } } }
private void comboBoxVideoFormat_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxVideoFormat.SelectedIndex < 0) { return; } m_selectedDisplayMode = ((DisplayModeEntry)comboBoxVideoFormat.SelectedItem).displayMode; RefreshPixelFormatList(); }
public void ConfigureDeckLinks(int DLIdx, int DLDisplayModeIdx) { IDeckLink dl = DLHelper.GetDeckLinks()[DLIdx]; IDeckLinkDisplayMode dl1DisplayMode = DLHelper.GetDisplayModes(dl)[DLDisplayModeIdx]; output = new DLDirect(dl, dl1DisplayMode); output.FrameDrawnCallback = NextFrame; DisplayWidth = output.DisplayWidth; DisplayHeight = output.DisplayHeight; }
private void DisplayModeChanged(IDeckLinkDisplayMode newDisplayMode) { foreach (DisplayModeEntry item in comboBoxVideoFormat.Items) { if (item.displayMode.GetDisplayMode() == newDisplayMode.GetDisplayMode()) { comboBoxVideoFormat.SelectedItem = item; } if (m_selectedDevice != null) { labelPixelFormat.Text = m_selectedDevice.pxFormat; } } }
public DeckLinkRenderer(IDeckLinkOutput newDeckLinkOutput, IDeckLinkDisplayMode newDisplayMode) { running = false; deckLinkOutput = newDeckLinkOutput; displayMode = newDisplayMode; frameWidth = displayMode.GetWidth(); frameHeight = displayMode.GetHeight(); displayMode.GetFrameRate(out frameDuration, out frameTimescale); framesPerSecond = (uint)((frameTimescale + (frameDuration - 1)) / frameDuration); deckLinkOutput.SetScreenPreviewCallback(this); deckLinkOutput.SetScheduledFrameCompletionCallback(this); deckLinkOutput.SetAudioCallback(this); }
public void ConfigureDeckLinks(int DL1Idx, int DL2Idx, int DL1DisplayModeIdx, int DL2DisplayModeIdx) { IDeckLink dl1 = DLHelper.GetDeckLinks()[DL1Idx]; IDeckLink dl2 = DLHelper.GetDeckLinks()[DL2Idx]; IDeckLinkDisplayMode dl1DisplayMode = DLHelper.GetDisplayModes(dl1)[DL1DisplayModeIdx]; IDeckLinkDisplayMode dl2DisplayMode = DLHelper.GetDisplayModes(dl2)[DL2DisplayModeIdx]; output_A = new DLDirect(dl1, dl1DisplayMode); output_B = new DLDirect(dl2, dl2DisplayMode); output_A.FrameDrawnCallback = NextFrame; DisplayWidth = output_A.DisplayWidth; DisplayHeight = output_A.DisplayHeight; }
public Form1() { InitializeComponent(); captureVideo(); Decklink decklink = new Decklink(); IDeckLinkOutput device = (IDeckLinkOutput)decklink.GetAvailableDeckLinks()[0]; IDeckLinkDisplayMode mode = (IDeckLinkDisplayMode)decklink.GetAvailableDisplayModes(device)[0]; DeckLinkRenderer renderer = new DeckLinkRenderer(device, mode); renderer.Start(); Thread.Sleep(3000); renderer.Stop(); }
public static string LogDisplayMode(IDeckLinkDisplayMode deckLinkDisplayMode) { string log = ""; if (deckLinkDisplayMode != null) { var displayMode = deckLinkDisplayMode.GetDisplayMode(); int width = deckLinkDisplayMode.GetWidth(); int height = deckLinkDisplayMode.GetHeight(); deckLinkDisplayMode.GetName(out string name); var fieldDominance = deckLinkDisplayMode.GetFieldDominance(); deckLinkDisplayMode.GetFrameRate(out long frameDuration, out long timeScale); var fps = ((double)timeScale / frameDuration); log = displayMode + " " + width + "x" + height + " " + fps.ToString("0.00") + "fps " + fieldDominance; } return(log); }
/// <summary> /// SetCallback /// </summary> public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { if (newDisplayMode == null) { return; } Run(() => notifications.Text = string.Format("Video format changed: mode={0}", newDisplayMode.GetDisplayMode())); Marshal.ReleaseComObject(newDisplayMode); }
public DisplayModeEntry(IDeckLinkDisplayMode displayMode) { this.displayMode = displayMode; }
void IDeckLinkInputCallback.VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { }
public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { Reinitialise = true; }
private Decklink(IDeckLink cDevice) { (new Logger()).WriteDebug3("in"); try { nAudioQueueLength = nAudioQueueLengthPrevious = 0; nBTLAudioQueueLengthPrevious = nBTLVideoQueueLengthPrevious = nVideoQueueLengthPrevious = 0; _iDLDevice = cDevice; if(Preferences.bDeviceInput) _iDLInput = (IDeckLinkInput)_iDLDevice; else _iDLOutput = (IDeckLinkOutput)_iDLDevice; IDeckLinkDisplayModeIterator cDisplayModeIterator; IDeckLinkDisplayMode cNextDLDisplayMode; string sDisplayModeName = ""; string sMessage = "decklink supported modes:<br>"; if (Preferences.bDeviceInput) { _iDLInputDisplayMode = null; _iDLInput.GetDisplayModeIterator(out cDisplayModeIterator); while (true) { cDisplayModeIterator.Next(out cNextDLDisplayMode); if (cNextDLDisplayMode == null) break; cNextDLDisplayMode.GetName(out sDisplayModeName); if (null == _iDLInputDisplayMode && sDisplayModeName.ToLower().Contains(Preferences.sVideoFormat)) { sMessage += "selected:"; _iDLInputDisplayMode = cNextDLDisplayMode; } else sMessage += "\t"; sMessage += sDisplayModeName + "<br>"; } (new Logger()).WriteNotice(sMessage); if (null == _iDLInputDisplayMode) throw new Exception("can't find " + Preferences.sVideoFormat + " mode within specified device for input"); } else { _nFramesAudioDropped = 0; _iDLOutputDisplayMode = null; _iDLOutput.GetDisplayModeIterator(out cDisplayModeIterator); while (true) { cDisplayModeIterator.Next(out cNextDLDisplayMode); if (cNextDLDisplayMode == null) break; cNextDLDisplayMode.GetName(out sDisplayModeName); if (null == _iDLOutputDisplayMode && sDisplayModeName.ToLower().Contains(Preferences.sVideoFormat)) { sMessage += "selected:"; _iDLOutputDisplayMode = cNextDLDisplayMode; } else sMessage += "\t"; sMessage += sDisplayModeName + "<br>"; } (new Logger()).WriteNotice(sMessage); if (null == _iDLOutputDisplayMode) throw new Exception("can't find " + Preferences.sVideoFormat + " mode within specified device for output"); stArea = new Area(0, 0, (ushort)_iDLOutputDisplayMode.GetWidth(), (ushort)_iDLOutputDisplayMode.GetHeight()); long nFrameDuration, nFrameTimescale; _iDLOutputDisplayMode.GetFrameRate(out nFrameDuration, out nFrameTimescale); _nFPS = (ushort)((nFrameTimescale + (nFrameDuration - 1)) / nFrameDuration); //до ближайшего целого - взято из примера деклинка _bDoWritingFrames = false; _aqWritingFrames = new Queue<byte[]>(); _cThreadWritingFramesWorker = new System.Threading.Thread(WritingFramesWorker); _cThreadWritingFramesWorker.IsBackground = true; _cThreadWritingFramesWorker.Priority = System.Threading.ThreadPriority.Normal; _cThreadWritingFramesWorker.Start(); if (Preferences.bAudio) { switch (Preferences.nAudioBitDepth) { case 32: _eAudioSampleDepth = _BMDAudioSampleType.bmdAudioSampleType32bitInteger; break; case 16: default: _eAudioSampleDepth = _BMDAudioSampleType.bmdAudioSampleType16bitInteger; break; } switch (Preferences.nAudioSamplesRate) { case 48000: _eAudioSampleRate = _BMDAudioSampleRate.bmdAudioSampleRate48kHz; break; default: throw new Exception("unsupported audio sample rate [" + Preferences.nAudioSamplesRate + "]"); } //_pAudioSamplesBuffer = Marshal.AllocCoTaskMem((int)_nAudioFrameSize_InBytes); _cAudioBuffer = new AudioBuffer(); _nAudioBufferCapacity_InSamples = Preferences.nAudioSamplesPerFrame * Preferences.nQueueDeviceLength; //for (int nIndx = 0; _nAudioFrameSize_InBytes > nIndx; nIndx++) // Marshal.WriteByte(_pAudioSamplesBuffer, nIndx, 0); _nTimescale = (ushort)_eAudioSampleRate; _nFrameDuration = (ushort)(_nTimescale / _nFPS); } if (null != Preferences.cDownStreamKeyer) _iDeckLinkKeyer = (IDeckLinkKeyer)_iDLDevice; } } catch (Exception ex) { (new Logger()).WriteError(ex); throw; } (new Logger()).WriteDebug4("return"); }
// Video Input Format Changed public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { }
public DisplayModeItem(IDeckLinkDisplayMode displayMode) { this.displayMode = displayMode; }
public void VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { MessageBox.Show("format changed"); }
public static List <DeckLinkDisplayModeDescription> GetDisplayDescriptions(IDeckLinkInput deckLinkInput, List <_BMDPixelFormat> pixelFormats, _BMDVideoConnection connection = _BMDVideoConnection.bmdVideoConnectionHDMI, _BMDSupportedVideoModeFlags videoModeFlags = _BMDSupportedVideoModeFlags.bmdSupportedVideoModeDefault) { List <DeckLinkDisplayModeDescription> displayDescriptions = new List <DeckLinkDisplayModeDescription>(); IDeckLinkDisplayModeIterator iterator = null; try { deckLinkInput.GetDisplayModeIterator(out iterator); while (true) { IDeckLinkDisplayMode displayMode = null; try { iterator.Next(out displayMode); if (displayMode == null) { break; } var displayModeId = displayMode.GetDisplayMode(); displayMode.GetName(out string displayName); displayMode.GetFrameRate(out long frameDuration, out long timeScale); var fps = (double)timeScale / frameDuration; int width = displayMode.GetWidth(); int height = displayMode.GetHeight(); var resolution = width + "x" + height; var displayModeFlags = displayMode.GetFlags(); var fieldDominance = displayMode.GetFieldDominance(); foreach (var pixFmt in pixelFormats) { deckLinkInput.DoesSupportVideoMode(connection, displayModeId, pixFmt, videoModeFlags, out int supported); if (supported != 0) { displayDescriptions.Add(new DeckLinkDisplayModeDescription { ModeId = (long)displayModeId, Width = width, Height = height, Fps = fps, PixFmt = (long)pixFmt, Description = displayName + " (" + resolution + " " + fps.ToString("0.##") + " fps " + GetFourCCStr(pixFmt) + ")", }); } else { //Console.WriteLine("Display mode not supported: "+ displayModeId + " " + pixFmt); } } } finally { if (displayMode != null) { Marshal.ReleaseComObject(displayMode); displayMode = null; } } } } finally { if (iterator != null) { Marshal.ReleaseComObject(iterator); iterator = null; } } return(displayDescriptions); }
internal DeckLinkDeviceDescription GetDeviceDescription() { if (!initialized) { return(null); } DeckLinkDeviceDescription deviceDescription = null; deckLink.GetDisplayName(out string deviceName); deckLinkAttrs.GetString(_BMDDeckLinkAttributeID.BMDDeckLinkDeviceHandle, out string deviceHandle); deckLinkStatus.GetFlag(_BMDDeckLinkStatusID.bmdDeckLinkStatusVideoInputSignalLocked, out int videoInputSignalLockedFlag); bool available = (videoInputSignalLockedFlag != 0); deckLinkStatus.GetInt(_BMDDeckLinkStatusID.bmdDeckLinkStatusBusy, out long deviceBusyStateFlag); _BMDDeviceBusyState deviceBusyState = (_BMDDeviceBusyState)deviceBusyStateFlag; bool isBusy = (deviceBusyState == _BMDDeviceBusyState.bmdDeviceCaptureBusy); deckLinkStatus.GetInt(_BMDDeckLinkStatusID.bmdDeckLinkStatusCurrentVideoInputMode, out long bmdDeckLinkStatusCurrentVideoInputModeFlag); _BMDDisplayMode displayModeId = (_BMDDisplayMode)bmdDeckLinkStatusCurrentVideoInputModeFlag; deckLinkStatus.GetInt(_BMDDeckLinkStatusID.bmdDeckLinkStatusCurrentVideoInputPixelFormat, out long currentVideoInputPixelFormatFlag); _BMDPixelFormat pixelFormat = (_BMDPixelFormat)currentVideoInputPixelFormatFlag; DeckLinkDisplayModeDescription displayDescription = null; IDeckLinkDisplayMode displayMode = null; try { deckLinkInput.GetDisplayMode(displayModeId, out displayMode); int width = displayMode.GetWidth(); int height = displayMode.GetHeight(); displayMode.GetFrameRate(out long duration, out long scale); displayMode.GetName(out string displayName); displayDescription = new DeckLinkDisplayModeDescription { Width = width, Height = height, PixFmt = (long)pixelFormat, Fps = ((double)scale / duration), Description = displayName, }; } finally { if (displayMode != null) { Marshal.ReleaseComObject(displayMode); } } deviceDescription = new DeckLinkDeviceDescription { DeviceHandle = deviceHandle, DeviceName = deviceName, Available = available, IsBusy = isBusy, DisplayModeIds = new List <DeckLinkDisplayModeDescription> { displayDescription }, }; return(deviceDescription); }