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; }
public override string ToString() { string strn; displayMode.GetName(out strn); string str = String.Format("{0},{1} : {2}", displayMode.GetWidth(), displayMode.GetHeight(), strn); return(str); }
public void Open(DeviceRegister.DeviceIndex device, _BMDDisplayMode mode, _BMDVideoInputFlags flags) { if (Ready) { Close(); } WorkerThread.Singleton.PerformBlocking(() => { this.Lock.AcquireWriterLock(10000); try { if (device == null) { throw (new Exception("No device selected")); } IDeckLink rawDevice = DeviceRegister.Singleton.GetDeviceHandle(device.Index); FDevice = rawDevice as IDeckLinkInput; FMode = mode; FFlags = flags; if (FDevice == null) { throw (new Exception("No input device connected")); } _BMDDisplayModeSupport displayModeSupported; FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode); Width = FDisplayMode.GetWidth(); Height = FDisplayMode.GetHeight(); FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags); FDevice.SetCallback(this); FDevice.StartStreams(); Reinitialise = true; Ready = true; FreshData = false; } catch (Exception e) { Ready = false; Reinitialise = false; FreshData = false; throw; } finally { this.Lock.ReleaseWriterLock(); } }); }
public void Open(IDeckLink device, _BMDDisplayMode mode, _BMDVideoInputFlags flags) { if (Ready) { Close(); } try { this.Lock.AcquireWriterLock(10000); } catch { } try { FDevice = device as IDeckLinkInput; FMode = mode; FFlags = flags; if (FDevice == null) { throw (new Exception("No input device connected")); } _BMDDisplayModeSupport displayModeSupported; FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode); Width = FDisplayMode.GetWidth(); Height = FDisplayMode.GetHeight(); FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags); FDevice.SetCallback(this); FDevice.StartStreams(); Reinitialise = true; Ready = true; FreshData = false; } catch (Exception e) { Ready = false; Reinitialise = false; FreshData = false; throw (e); } finally { this.Lock.ReleaseWriterLock(); } }
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 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); }
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); }
public override void Allocate() { FOutput.Image.Initialise(new Size(FDisplayMode.GetWidth(), FDisplayMode.GetHeight()), TColorFormat.RGBA8); }
public void Open(DeviceRegister.DeviceIndex device, _BMDDisplayMode mode, _BMDVideoInputFlags flags) { if (Ready) { Close(); } WorkerThread.Singleton.PerformBlocking(() => { this.Lock.AcquireWriterLock(10000); try { if (device == null) { throw (new Exception("No device selected")); } IDeckLink rawDevice = DeviceRegister.Singleton.GetDeviceHandle(device.Index); FDevice = rawDevice as IDeckLinkInput; FOutDevice = rawDevice as IDeckLinkOutput; FMode = mode; FFlags = flags; FConverter = new CDeckLinkVideoConversion(); if (FDevice == null) { throw (new Exception("No input device connected")); } _BMDDisplayModeSupport displayModeSupported; FDevice.DoesSupportVideoMode(FMode, FPixelFormat, flags, out displayModeSupported, out FDisplayMode); Width = FDisplayMode.GetWidth(); Height = FDisplayMode.GetHeight(); // inspiration http://dviz.googlecode.com/svn/trunk/src/livemix/CameraThread.cpp FOutDevice.CreateVideoFrame(Width, Height, Width * 4, _BMDPixelFormat.bmdFormat8BitBGRA, _BMDFrameFlags.bmdFrameFlagDefault, out rgbFrame); FDevice.EnableVideoInput(FMode, FPixelFormat, FFlags); FDevice.SetCallback(this); FDevice.StartStreams(); Reinitialise = true; Ready = true; FreshData = false; } catch (Exception e) { Ready = false; Reinitialise = false; FreshData = false; throw; } finally { this.Lock.ReleaseWriterLock(); } }); }
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); }