public DecklinkDevices() { _deviceList = new List <Device>(); try { _iterator = new CDeckLinkIterator(); if (_iterator == null) { throw new Exception("Please check DeckLink drivers are installed."); } _deviceList.Clear(); /* * Now Iterate through available hardware */ while (true) { IDeckLink deckLink; _iterator.Next(out deckLink); string displayName, modelName; //Not valid device Skip if (deckLink == null) { break; } deckLink.GetDisplayName(out displayName); deckLink.GetModelName(out modelName); Console.WriteLine("Found:" + modelName); _deviceList.Add(new Device() { Card = deckLink, DisplayName = displayName, ModelName = modelName, }); } if (!_deviceList.Any()) { throw new Exception("No Decklink Cards found"); } } catch (Exception e) { Console.WriteLine("Failed to access Decklink Hardware:" + Environment.NewLine + e.Message); } finally { //Clear COM objects Marshal.ReleaseComObject(_iterator); } }
// Private methods /// <summary> /// Gets the detected DeckLink API version /// </summary> /// <returns>Returns the version as a string in the following format: major.minor.point</returns> private static string GetDeckLinkAPIVersion(IDeckLinkIterator deckLinkIterator) { IDeckLinkAPIInformation deckLinkAPIInformation = (IDeckLinkAPIInformation)deckLinkIterator; long deckLinkVersion; deckLinkAPIInformation.GetInt(_BMDDeckLinkAPIInformationID.BMDDeckLinkAPIVersion, out deckLinkVersion); int dlVerMajor = (int)((deckLinkVersion & 0xFF000000) >> 24); int dlVerMinor = (int)((deckLinkVersion & 0x00FF0000) >> 16); int dlVerPoint = (int)((deckLinkVersion & 0x0000FF00) >> 8); return(String.Format("{0}.{1}.{2}", dlVerMajor, dlVerMinor, dlVerPoint)); }
public static bool GetDeviceByHandle(string deviceHandle, out IDeckLink deckLink) { logger.Verb("GetDeviceByName(...) " + deviceHandle); bool Success = false; deckLink = null; IDeckLinkIterator deckLinkIterator = null; try { deckLinkIterator = new CDeckLinkIterator(); int index = 0; do { if (deckLink != null) { Marshal.ReleaseComObject(deckLink); deckLink = null; } deckLinkIterator.Next(out deckLink); if (deckLink != null) { ((IDeckLinkProfileAttributes)deckLink).GetString(_BMDDeckLinkAttributeID.BMDDeckLinkDeviceHandle, out string handle); if (deviceHandle == handle) { break; } } index++; }while (deckLink != null); } catch (Exception ex) { logger.Error(ex); } finally { if (deckLinkIterator != null) { Marshal.ReleaseComObject(deckLinkIterator); deckLinkIterator = null; } } return(Success); }
public static bool GetDeviceByIndex(int inputIndex, out IDeckLink deckLink) { logger.Verb("GetDeviceByIndex(...) " + inputIndex); bool Success = false; deckLink = null; IDeckLinkIterator deckLinkIterator = null; try { deckLinkIterator = new CDeckLinkIterator(); int index = 0; do { if (deckLink != null) { Marshal.ReleaseComObject(deckLink); deckLink = null; } deckLinkIterator.Next(out deckLink); if (index == inputIndex) { Success = true; break; } index++; }while (deckLink != null); } catch (Exception ex) { logger.Error(ex); } finally { if (deckLinkIterator != null) { Marshal.ReleaseComObject(deckLinkIterator); deckLinkIterator = null; } } return(Success); }
/// <summary> /// Tries to initialise the DeckLink Streaming API /// </summary> /// <returns>Returns true on success, false on failure.</returns> public bool TryInitializeAPI() { // Initialise Blackmagic API try { deckLinkIterator = new CDeckLinkIterator(); if (deckLinkIterator == null) { throw new COMException(); } } catch (COMException) { return(false); } _deckLinkAPIVersion = GetDeckLinkAPIVersion(deckLinkIterator); Debug.WriteLine("DeckLink API v" + DeckLinkAPIVersion); // Initialise Blackmagic Streaming API try { streamingDiscovery = new CBMDStreamingDiscovery(); if (streamingDiscovery == null) { throw new COMException(); } } catch (COMException) { return(false); } // Note: at this point you may get device notification messages! streamingDiscovery.InstallDeviceNotifications(this); Debug.WriteLine("Device notifications installed"); return(true); }
public static List <DeckLinkDeviceDescription> GetDeckLinkInputDevices() { List <DeckLinkDeviceDescription> devices = new List <DeckLinkDeviceDescription>(); IDeckLinkIterator deckLinkIterator = null; try { deckLinkIterator = new CDeckLinkIterator(); int index = 0; IDeckLink deckLink = null; do { if (deckLink != null) { Marshal.ReleaseComObject(deckLink); deckLink = null; } deckLinkIterator.Next(out deckLink); if (deckLink == null) { break; } deckLink.GetDisplayName(out string deviceName); try { var deckLinkInput = (IDeckLinkInput)deckLink; var deckLinkStatus = (IDeckLinkStatus)deckLink; var deckLinkAttrs = (IDeckLinkProfileAttributes)deckLink; deckLinkAttrs.GetString(_BMDDeckLinkAttributeID.BMDDeckLinkDeviceHandle, out string deviceHandle); deckLinkStatus.GetFlag(_BMDDeckLinkStatusID.bmdDeckLinkStatusVideoInputSignalLocked, out int videoInputSignalLockedFlag); bool available = (videoInputSignalLockedFlag != 0); var pixelFormats = SupportedPixelFormats.Keys.ToList(); var displayModeIds = GetDisplayDescriptions(deckLinkInput, pixelFormats); DeckLinkDeviceDescription deviceDescription = new DeckLinkDeviceDescription { DeviceHandle = deviceHandle, DeviceIndex = index, DeviceName = deviceName, Available = available, DisplayModeIds = displayModeIds, }; devices.Add(deviceDescription); //Marshal.ReleaseComObject(deckLinkInput); //Marshal.ReleaseComObject(deckLinkStatus); } catch (InvalidCastException) { } index++; }while (deckLink != null); } catch (Exception ex) { if (deckLinkIterator == null) { throw new Exception("This application requires the DeckLink drivers installed.\n" + "Please install the Blackmagic DeckLink drivers to use the features of this application"); } throw; } return(devices); }
public List <DeckLinkDeviceDescription> FindInputs() { logger.Debug("DeckLinkDeviceManager::GetDeckLinkInputs()"); List <DeckLinkDeviceDescription> devices = new List <DeckLinkDeviceDescription>(); IDeckLinkIterator deckLinkIterator = null; try { deckLinkIterator = new CDeckLinkIterator(); int index = 0; IDeckLink deckLink = null; do { if (deckLink != null) { Marshal.ReleaseComObject(deckLink); deckLink = null; } deckLinkIterator.Next(out deckLink); if (deckLink == null) { break; } var inputDevice = new DeckLinkInput(deckLink); if (inputDevice.Init()) { DeckLinkDeviceDescription deviceDescription = inputDevice.GetDeviceDescription(); if (deviceDescription != null) { deviceDescription.DeviceIndex = index; devices.Add(deviceDescription); index++; } } if (inputDevice != null) { inputDevice.Dispose(); inputDevice = null; } }while (deckLink != null); } catch (Exception ex) { logger.Error(ex); } finally { if (deckLinkIterator != null) { Marshal.ReleaseComObject(deckLinkIterator); deckLinkIterator = null; } } return(devices); }