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 DeckLinkInputDevice(IDeckLink deckLink) : base(deckLink) { if (!CaptureDevice) { throw new DeckLinkInputInvalidException(); } // Query input interface m_deckLinkInput = (IDeckLinkInput)deckLink; }
/// <summary> /// Construct a physical Mini-recorder device /// </summary> /// <param name="d"></param> /// <param name="channels"></param> public InputDevice(IDeckLink d, int channels) { device = d as IDeckLinkInput; if (device == null) { throw new ApplicationException("Not a Decklink input device"); } this.channels = channels; d.GetDisplayName(out name); }
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 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 DeckLinkDevice(IDeckLink deckLink) { m_deckLink = deckLink; // Get input interface try { m_deckLinkInput = (IDeckLinkInput)m_deckLink; } catch (InvalidCastException) { // No output interface found, eg in case of DeckLink Mini Monitor return; } }
protected override bool Open() { if (FDevice == null && false) { return(false); } else { try { string status; //this is a hack, we recreate the device here IDeckLinkIterator iterator = new CDeckLinkIterator(); IDeckLink device; iterator.Next(out device); FDevice = (IDeckLinkInput)device; _BMDDisplayModeSupport supported; FDevice.DoesSupportVideoMode(FVideoMode, FPixelFormat, FVideoInputFlags, out supported, out FDisplayMode); if (supported.HasFlag(_BMDDisplayModeSupport.bmdDisplayModeNotSupported)) { status = "Display mode supported"; } else if (supported.HasFlag(_BMDDisplayModeSupport.bmdDisplayModeSupportedWithConversion)) { status = "Display mode supported with conversion"; } else { throw(new Exception("Display mode not supported")); } FDevice.EnableVideoInput(FVideoMode, FPixelFormat, FVideoInputFlags); FDevice.SetCallback(this); FDevice.StartStreams(); Status = "OK : " + status; return(true); } catch (Exception e) { Status = e.Message; return(false); } } }
internal void Dispose() { if (deckLink != null) { var refCount = Marshal.ReleaseComObject(deckLink); Debug.Assert(refCount == 0, "refCount == 0"); deckLink = null; deckLinkStatus = null; deckLinkInput = null; deckLinkAttrs = null; initialized = false; } }
internal bool Init() { try { deckLinkInput = (IDeckLinkInput)deckLink; deckLinkStatus = (IDeckLinkStatus)deckLink; deckLinkAttrs = (IDeckLinkProfileAttributes)deckLink; initialized = true; } catch (InvalidCastException) { //logger.Warn(""); } return(initialized); }
public void Start() { try { var cb = new Callback(config); recorder = config.Recorder; cb.FingerprintCreated += OnFingerprintCreated; recorder.SetCallback(cb); recorder.EnableVideoInput(config.VideoMode, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault); recorder.EnableAudioInput(_BMDAudioSampleRate.bmdAudioSampleRate48kHz, _BMDAudioSampleType.bmdAudioSampleType16bitInteger, CHANNELS); recorder.StartStreams(); } catch (Exception ex) { MessageBox.Show($"Cannot start fingerprinting: {ex.Message}", "Error", MessageBoxButton.OK); Stop(false); } }
// Get IDeckLink Interface private bool GetIDeckLinkInterface() { try { deckLinkOutput = (IDeckLinkOutput)DeckLink; deckLinkInput = (IDeckLinkInput)DeckLink; deckLinkConfig = (IDeckLinkConfiguration)DeckLink; IDeckLinkDisplayModeIterator displayIterator; deckLinkInput.GetDisplayModeIterator(out displayIterator); var supportedModes = new List <IDeckLinkDisplayMode>(); deckLinkKeyer = (IDeckLinkKeyer)DeckLink; } catch { return(false); } return(true); }
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; } }
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(); } }); }
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"); }
private void StartDecklinkInput(DeckLinkAPI.IDeckLink device) { this.device = device; input = (DeckLinkAPI.IDeckLinkInput)device; input.SetCallback(this); input.EnableVideoInput(_BMDDisplayMode.bmdModeHD1080p25, _BMDPixelFormat.bmdFormat8BitYUV, _BMDVideoInputFlags.bmdVideoInputFlagDefault); input.StartStreams(); frameCount = 0; }
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); }