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(); } }); }
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 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(); } }); }
void IDeckLinkInputCallback.VideoInputFormatChanged(_BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode newDisplayMode, _BMDDetectedVideoInputFormatFlags detectedSignalFlags) { logger.Debug("IDeckLinkInputCallback.VideoInputFormatChanged(...) " + notificationEvents); // Restart capture with the new video mode if told to if (!applyDetectedInputMode) { return; } //var pixelFormat = _BMDPixelFormat.bmdFormat10BitYUV; //if ((detectedSignalFlags & _BMDDetectedVideoInputFormatFlags.bmdDetectedVideoInputRGB444) != 0) //{ // pixelFormat = _BMDPixelFormat.bmdFormat10BitRGB; //} var pixelFormat = _BMDPixelFormat.bmdFormat8BitYUV;//bmdFormat8BitYUV; //!!!!!!!!!! var dispMode = newDisplayMode.GetDisplayMode(); deckLinkInput.DoesSupportVideoMode(_BMDVideoConnection.bmdVideoConnectionHDMI, dispMode, pixelFormat, _BMDSupportedVideoModeFlags.bmdSupportedVideoModeDefault, out int supported); logger.Debug(pixelFormat + " " + supported); // Stop the capture deckLinkInput.StopStreams(); // Set the video input mode deckLinkInput.EnableVideoInput(dispMode, pixelFormat, _BMDVideoInputFlags.bmdVideoInputEnableFormatDetection); // Start the capture deckLinkInput.StartStreams(); logger.Debug("NewDisplayMode: " + newDisplayMode.GetDisplayMode()); InputFormatChanged?.Invoke(newDisplayMode); }
public DeckLinkDevice(IDeckLink deckLink) { this.deckLink = deckLink; // Get input interface try { deckLinkInput = (IDeckLinkInput)this.deckLink; deckLinkStatus = (IDeckLinkStatus)this.deckLink; bool videoInputSignalLocked = false; deckLinkStatus.GetFlag(_BMDDeckLinkStatusID.bmdDeckLinkStatusVideoInputSignalLocked, out int videoInputSignalLockedFlag); videoInputSignalLocked = (videoInputSignalLockedFlag != 0); if (videoInputSignalLocked) { throw new Exception("Video input locked"); } this.deckLink.GetDisplayName(out deviceName); this.deckLink.GetModelName(out modelName); var deckLinkAttributes = (IDeckLinkProfileAttributes)deckLink; deckLinkAttributes.GetFlag(_BMDDeckLinkAttributeID.BMDDeckLinkSupportsInputFormatDetection, out int supportsFormatDetectionFlag); supportsFormatDetection = (supportsFormatDetectionFlag != 0); logger.Debug("------------------------- " + deviceName + " -------------------------"); IDeckLinkDisplayModeIterator iterator = null; deckLinkInput.GetDisplayModeIterator(out iterator); IDeckLinkDisplayMode displayMode = null; do { if (iterator != null) { iterator.Next(out displayMode); if (displayMode != null) { displayMode.GetName(out string displayName); displayMode.GetFrameRate(out long frameDuration, out long timeScale); int width = displayMode.GetWidth(); int height = displayMode.GetHeight(); var bdmDisplayMode = displayMode.GetDisplayMode(); var displayModeFlags = displayMode.GetFlags(); var fieldDominance = displayMode.GetFieldDominance(); var resolution = width + "x" + height; // var log = string.Join(", " , displayName, resolution, bdmDisplayMode, displayModeFlags, frameDuration, timeScale, fieldDominance); var videoModeFlags = _BMDSupportedVideoModeFlags.bmdSupportedVideoModeDefault; //var allPixelFormats = Enum.GetValues(typeof(_BMDPixelFormat)); var formatLog = ""; foreach (var fmtObj in pixelFormats) { var pixelFormat = (_BMDPixelFormat)fmtObj; deckLinkInput.DoesSupportVideoMode(_BMDVideoConnection.bmdVideoConnectionHDMI, bdmDisplayMode, pixelFormat, videoModeFlags, out int supported); if (supported != 0) { formatLog += " " + pixelFormat; } } var log = string.Join(", ", displayName, resolution); logger.Debug(displayName + " " + resolution + " (" + formatLog + ")"); } else { break; } } }while (displayMode != null); logger.Debug("-----------------------------------------------------"); } catch (InvalidCastException) { // No output interface found, eg in case of DeckLink Mini Monitor return; } }