Class DeviceEnumerator
- Namespace
- VisioForge.Core
- Assembly
- VisioForge.Core.dll
Provides specialized enumeration for Allied Vision industrial cameras using the Vimba X SDK integration.
public class DeviceEnumerator : IDisposableInheritance
Implements
Inherited Members
Remarks
This class provides unified access to a wide variety of media devices:
- Standard webcams and video capture devices
- Microphones and audio capture sources
- Audio output devices (speakers, headphones, etc.)
- IP cameras via ONVIF protocol
- NDI (Network Device Interface) sources for IP video streaming
- Blackmagic Design DeckLink professional video hardware
- Industrial cameras supporting GenICam/GigE Vision standards
- Allied Vision, Basler, and FLIR/Teledyne machine vision cameras
The class supports both synchronous and asynchronous device discovery methods with platform-specific optimizations for Windows, macOS, Linux, iOS, and Android. Real-time device change notifications are provided through events when devices are added or removed from the system.
Use the VisioForge.Core.DeviceEnumerator.Shared singleton instance for most scenarios to avoid resource duplication and ensure consistent device state across your application.
Constructors
DeviceEnumerator(ContextX)
Initializes a new instance of the VisioForge.Core.DeviceEnumerator class with an optional GStreamer context. If no context is provided, a new default context will be created for device operations.
protected DeviceEnumerator(ContextX context = null)Parameters
contextContextX-
The GStreamer context to use for device operations, or null to create a default context.
Fields
_shared
The shared singleton DeviceEnumerator instance for application-wide device management.
protected static DeviceEnumerator _sharedField Value
_videoSourcesLock
The video sources lock.
protected readonly object _videoSourcesLockField Value
_videoSourcesX
Represents a list of video capture device information objects.
protected List<VideoCaptureDeviceInfo> _videoSourcesXField Value
Properties
Shared
Gets the shared singleton VisioForge.Core.DeviceEnumerator instance that provides application-wide device enumeration.
public static DeviceEnumerator Shared { get; }Property Value
Remarks
This property provides a singleton instance that is automatically created on first access and disposed when the application exits via the ProcessExit event.
Using the shared instance is recommended for most scenarios to:
- Avoid resource duplication from multiple enumerator instances
- Maintain consistent device state across your application
- Reduce memory overhead from redundant device monitoring
Methods
AlliedVisionSourcesAsync(CancellationToken)
Asynchronously gets an array of available Allied Vision machine vision cameras.
public Task<AlliedVisionCameraInfo[]> AlliedVisionSourcesAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken-
A cancellation token to observe while waiting for the enumeration to complete.
Returns
- Task<AlliedVisionCameraInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Sources.AlliedVisionCameraInfo objects representing available Allied Vision cameras.
Remarks
This method discovers Allied Vision cameras using the Vimba X SDK, supporting GigE Vision, USB3 Vision, and Camera Link interfaces. The enumeration is performed on a background thread.
Requires the Allied Vision Vimba X SDK to be installed on the system.
AudioOutputsAsync(AudioOutputDeviceAPI?, CancellationToken)
Asynchronously gets an array of available audio output devices (speakers, headphones, etc.).
public Task<AudioOutputDeviceInfo[]> AudioOutputsAsync(AudioOutputDeviceAPI? api = null, CancellationToken cancellationToken = default)Parameters
apiAudioOutputDeviceAPI?-
Optional filter to return only devices from a specific audio API. If
null, returns devices from all available APIs. cancellationTokenCancellationToken
Returns
- Task<AudioOutputDeviceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Output.AudioOutputDeviceInfo objects representing available audio output devices.
Remarks
This method runs device enumeration on a background thread to avoid blocking the calling thread.
AudioSources(AudioCaptureDeviceAPI?)
Gets an array of available audio capture devices (microphones and audio inputs).
public AudioCaptureDeviceInfo[] AudioSources(AudioCaptureDeviceAPI? api = null)Parameters
apiAudioCaptureDeviceAPI?-
Optional filter to return only devices from a specific audio API. If
null, returns devices from all available APIs. On Linux, defaults to PulseAudio.
Returns
- AudioCaptureDeviceInfo[]
-
An array of VisioForge.Core.Types.X.Sources.AudioCaptureDeviceInfo objects representing available audio input devices.
Remarks
This method automatically performs device enumeration on first call if the internal cache is empty. Subsequent calls return cached results unless VisioForge.Core.DeviceEnumerator.Clear is called.
Supported APIs vary by platform:
- Windows: DirectSound, WASAPI
- Linux: PulseAudio, ALSA, PipeWire
- macOS: Core Audio
- iOS/Android: Platform default (single device)
AudioSourcesAsync(AudioCaptureDeviceAPI?, CancellationToken)
Asynchronously gets an array of available audio capture devices (microphones and audio inputs).
public Task<AudioCaptureDeviceInfo[]> AudioSourcesAsync(AudioCaptureDeviceAPI? api = null, CancellationToken cancellationToken = default)Parameters
apiAudioCaptureDeviceAPI?-
Optional filter to return only devices from a specific audio API. If
null, returns devices from all available APIs. cancellationTokenCancellationToken
Returns
- Task<AudioCaptureDeviceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Sources.AudioCaptureDeviceInfo objects representing available audio input devices.
Remarks
On Apple platforms (macOS, iOS), this method automatically requests microphone access permission before performing enumeration. The method runs device enumeration on a background thread.
BaslerSourcesAsync(CancellationToken)
Asynchronously gets an array of available Basler machine vision cameras.
public Task<BaslerCameraInfo[]> BaslerSourcesAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken-
A cancellation token to observe while waiting for the enumeration to complete.
Returns
- Task<BaslerCameraInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Sources.BaslerCameraInfo objects representing available Basler cameras.
Remarks
This method discovers Basler cameras using the Pylon SDK, supporting GigE Vision, USB3 Vision, and Camera Link interfaces. The enumeration provides detailed camera information including device IDs, model names, and connection details.
Requires the Basler Pylon SDK to be installed on the system. The method runs enumeration on a background thread to avoid blocking the calling thread.
Clear()
Clears all cached device lists, forcing a fresh enumeration on the next device query.
public void Clear()Remarks
This method clears all internal device caches including:
- Video capture sources
- Audio capture sources
- Audio output devices (sinks)
- DeckLink video and audio sources/sinks
- NDI sources
- GenICam cameras
Call this method when you need to force a complete re-enumeration of all devices, for example, after system configuration changes or when troubleshooting device detection issues.
DecklinkAudioSinksAsync(CancellationToken)
Asynchronously gets an array of available DeckLink audio output sinks.
public Task<DecklinkAudioSinkInfo[]> DecklinkAudioSinksAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
- Task<DecklinkAudioSinkInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Decklink.DecklinkAudioSinkInfo objects representing available DeckLink audio outputs.
Remarks
This method enumerates all DeckLink audio output connections including embedded audio channels. The enumeration is performed on a background thread.
DecklinkAudioSourcesAsync(CancellationToken)
Asynchronously gets an array of available DeckLink audio capture sources.
public Task<DecklinkAudioSourceInfo[]> DecklinkAudioSourcesAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
- Task<DecklinkAudioSourceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Decklink.DecklinkAudioSourceInfo objects representing available DeckLink audio inputs.
Remarks
This method enumerates all DeckLink audio capture inputs including embedded audio channels. The enumeration is performed on a background thread.
DecklinkVideoSinksAsync(CancellationToken)
Asynchronously gets an array of available DeckLink video output sinks.
public Task<DecklinkVideoSinkInfo[]> DecklinkVideoSinksAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
- Task<DecklinkVideoSinkInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Decklink.DecklinkVideoSinkInfo objects representing available DeckLink video outputs.
Remarks
This method enumerates all DeckLink video output connections including SDI and HDMI outputs. The enumeration is performed on a background thread.
DecklinkVideoSourcesAsync(CancellationToken)
Asynchronously gets an array of available DeckLink video capture sources.
public Task<DecklinkVideoSourceInfo[]> DecklinkVideoSourcesAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
- Task<DecklinkVideoSourceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Decklink.DecklinkVideoSourceInfo objects representing available DeckLink video inputs.
Remarks
This method enumerates all DeckLink video capture inputs including SDI, HDMI, and component connections. The enumeration is performed on a background thread.
Dispose()
Releases all resources used by the VisioForge.Core.DeviceEnumerator instance.
public void Dispose()Remarks
This method stops all active device monitors, releases GStreamer resources, and unregisters any platform-specific device notification handlers. On Windows, this also stops the WMI event watcher used for USB device change notifications.
After calling this method, the device enumerator cannot be reused. If using the VisioForge.Core.DeviceEnumerator.Shared instance, a new instance will be created automatically on the next access.
Dispose(bool)
protected virtual void Dispose(bool disposing)Parameters
disposingbool
~DeviceEnumerator()
protected ~DeviceEnumerator()FindVideoSourceByDevicePathAsync(string)
Asynchronously finds a video capture device by its device path.
public Task<VideoCaptureDeviceInfo> FindVideoSourceByDevicePathAsync(string devicePath)Parameters
devicePathstring-
The device path to search for.
Returns
- Task<VideoCaptureDeviceInfo>
-
A task that represents the asynchronous operation. The task result contains the matching VisioForge.Core.Types.X.Sources.VideoCaptureDeviceInfo or
nullif not found.
GenICamSourcesAsync()
Asynchronously gets an array of available GenICam-compliant cameras.
public Task<GenICamCamera[]> GenICamSourcesAsync()Returns
- Task<GenICamCamera[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.GenICam.GenICamCamera objects representing available GenICam cameras.
Remarks
This method discovers industrial and scientific cameras that comply with the GenICam standard, including GigE Vision and USB3 Vision devices. The enumeration provides detailed camera information including device IDs, model names, and available pixel formats.
The method includes fallback mechanisms to ensure robust camera discovery even when detailed enumeration fails.
NDISourcesAsync()
Asynchronously gets an array of available NDI video/audio sources on the network.
public Task<NDISourceInfo[]> NDISourcesAsync()Returns
- Task<NDISourceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Sources.NDISourceInfo objects representing available NDI sources.
Remarks
This method discovers NDI sources available on the local network. NDI (Network Device Interface) is a royalty-free protocol for live video streaming over IP networks, commonly used in professional broadcast and video production environments.
The enumeration includes a retry mechanism with delays to ensure all network sources are discovered, as NDI source discovery may take time depending on network conditions.
Worst-case wait budget: on Android each attempt blocks up to 3000 ms inside libndi's
find_wait_for_sources. The retry loop runs at most three attempts and inserts a 500 ms
delay between attempts when no source has been observed yet. Total worst-case ceiling is
therefore 3 * 3000 + 2 * 500 = 10000 ms on Android. On desktop the GStreamer
DeviceMonitor path is effectively synchronous, so the worst-case is dominated by the
two 500 ms inter-attempt sleeps (~1000 ms).
Use the VisioForge.Core.DeviceEnumerator.NDISourcesAsync(System.Threading.CancellationToken) overload if the caller needs to abort the worst-case wait early (e.g. when the user navigates away from a settings dialog).
NDISourcesAsync(CancellationToken)
Asynchronously gets an array of available NDI video/audio sources, with cancellation support.
public Task<NDISourceInfo[]> NDISourcesAsync(CancellationToken cancellationToken)Parameters
cancellationTokenCancellationToken-
Cancellation token observed between retry attempts and during the inter-attempt back-off. The native libndi
find_wait_for_sourcesblocking call cannot itself be interrupted mid-call; cancellation latency is therefore bounded by the per-attempt wait window (3000 ms on Android, near-instant on desktop) plus the 500 ms back-off when applicable.
Returns
- Task<NDISourceInfo[]>
-
A task that completes with the discovered sources, or faults with OperationCanceledException if cancellation fires.
ONVIF_ListSourcesAsync(TimeSpan?, CancellationTokenSource?)
Asynchronously discovers ONVIF-compliant devices on the local network.
public Task<Uri[]> ONVIF_ListSourcesAsync(TimeSpan? timeout, CancellationTokenSource? cts)Parameters
timeoutTimeSpan?-
The maximum time to wait for device responses. If
null, defaults to 2 seconds. Increase this value for larger networks or slow-responding devices. ctsCancellationTokenSource?-
Optional cancellation token source to abort the discovery operation. If
null, a new cancellation token source is created internally.
Returns
- Task<Uri[]>
-
A task that represents the asynchronous operation. The task result contains an array of Uri objects representing the service URLs of discovered ONVIF devices.
Remarks
This method uses WS-Discovery to find ONVIF devices on the network. Each returned URI represents the device service endpoint that can be used to establish a connection for camera control and streaming.
For connecting to discovered devices, use the ONVIFClientX class from VisioForge.Core.ONVIFX
namespace for full device management capabilities including PTZ control, event handling, and profile management.
StartAudioSinkMonitor()
Starts monitoring for audio output device changes on the current thread.
public void StartAudioSinkMonitor()Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnAudioSinkAdded and VisioForge.Core.DeviceEnumerator.OnAudioSinkRemoved events when audio output devices are connected or disconnected.
On Linux, this method performs a one-time enumeration instead of continuous monitoring.
StartAudioSinkMonitorAsync()
Asynchronously starts monitoring for audio output device changes.
public Task StartAudioSinkMonitorAsync()Returns
- Task
-
A task that represents the asynchronous operation.
Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnAudioSinkAdded and VisioForge.Core.DeviceEnumerator.OnAudioSinkRemoved events when audio output devices are connected or disconnected.
On Apple platforms (macOS, iOS), this method automatically requests audio access permission.
StartAudioSourceMonitor()
Starts monitoring for audio capture device changes on the current thread.
public void StartAudioSourceMonitor()Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnAudioSourceAdded and VisioForge.Core.DeviceEnumerator.OnAudioSourceRemoved events when audio input devices are connected or disconnected.
On Linux, this method performs a one-time enumeration instead of continuous monitoring.
StartAudioSourceMonitorAsync()
Asynchronously starts monitoring for audio capture device changes.
public Task StartAudioSourceMonitorAsync()Returns
- Task
-
A task that represents the asynchronous operation.
Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnAudioSourceAdded and VisioForge.Core.DeviceEnumerator.OnAudioSourceRemoved events when audio input devices are connected or disconnected.
On Apple platforms (macOS, iOS), this method automatically requests microphone access permission.
StartNDISourceWatch()
Starts the background watcher that polls libndi for NDI source changes and fires VisioForge.Core.DeviceEnumerator.NDISourcesChanged when the network set changes. Idempotent — calling twice with no intervening VisioForge.Core.DeviceEnumerator.StopNDISourceWatch is a no-op for the second call.
public void StartNDISourceWatch()Remarks
On Android the watcher reuses the persistent libndi find instance
created by VisioForge.Core.DeviceEnumerator.NDISourcesAsync, so subscribers see the
same warm mDNS state callers of the snapshot API see. The first
notification fires after the cold-start window
(NDI_FIND_INITIAL_WAIT_MS, ~5 s) if it hasn't already happened.
StartVideoSourceMonitor()
Starts monitoring for video capture device changes on the current thread.
public void StartVideoSourceMonitor()Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnVideoSourceAdded and VisioForge.Core.DeviceEnumerator.OnVideoSourceRemoved events when video capture devices are connected or disconnected.
On Linux, this method performs a one-time enumeration instead of continuous monitoring.
StartVideoSourceMonitorAsync()
Asynchronously starts monitoring for video capture device changes.
public Task StartVideoSourceMonitorAsync()Returns
- Task
-
A task that represents the asynchronous operation.
Remarks
Once started, the monitor will raise VisioForge.Core.DeviceEnumerator.OnVideoSourceAdded and VisioForge.Core.DeviceEnumerator.OnVideoSourceRemoved events when video capture devices are connected or disconnected.
On Apple platforms (macOS), this method automatically requests camera access permission.
StopNDISourceWatch()
Signals the background watcher to stop and waits briefly for it to exit. Safe to call when the watcher is not running.
public void StopNDISourceWatch()Remarks
The watcher's tightest blocking call is find_wait_for_sources
with a 10-second timeout, so worst-case Stop latency is ~10 s — but
most stops resolve far faster because the wait short-circuits as soon
as the source list moves. VisioForge.Core.DeviceEnumerator.StopNDISourceWatch is also
invoked automatically from VisioForge.Core.DeviceEnumerator.Dispose so
callers don't need to track lifetime themselves unless they want
finer control.
VideoSources()
Gets an array of available video capture devices (cameras, webcams, and capture cards).
public VideoCaptureDeviceInfo[] VideoSources()Returns
- VideoCaptureDeviceInfo[]
-
An array of VisioForge.Core.Types.X.Sources.VideoCaptureDeviceInfo objects representing available video capture devices.
Remarks
This method automatically performs device enumeration on first call if the internal cache is empty. Subsequent calls return cached results unless VisioForge.Core.DeviceEnumerator.Clear is called.
Supported video sources vary by platform:
- Windows: DirectShow, Media Foundation, UVC cameras
- Linux: V4L2, libcamera, UVC cameras
- macOS: AVFoundation cameras
- iOS: Built-in cameras via AVFoundation
- Android: Camera API devices
VideoSourcesAsync(CancellationToken)
Asynchronously gets an array of available video capture devices (cameras, webcams, and capture cards).
public Task<VideoCaptureDeviceInfo[]> VideoSourcesAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken
Returns
- Task<VideoCaptureDeviceInfo[]>
-
A task that represents the asynchronous operation. The task result contains an array of VisioForge.Core.Types.X.Sources.VideoCaptureDeviceInfo objects representing available video capture devices.
Remarks
On Apple platforms (macOS), this method automatically requests camera access permission before performing enumeration. The method runs device enumeration on a background thread.
NDISourcesChanged
Raised when the set of NDI sources visible on the network changes, after VisioForge.Core.DeviceEnumerator.StartNDISourceWatch has been called. The event carries the full current snapshot plus per-item Added / Removed diffs vs the previous notification.
public event EventHandler<NDISourcesChangedEventArgs> NDISourcesChangedEvent Type
Remarks
Threading: fired from the background watcher thread that calls
NDIlib_find_wait_for_sources. UI consumers must marshal to
their UI thread (Activity.RunOnUiThread, Dispatcher, etc.) — the SDK
does not do that for them.
Reliability: NDI sources are dropped from the internal libndi
table after ~5–10 seconds without an mDNS heartbeat, so the
Removed diff has a small detection delay vs the moment a sender
actually went off-air. This matches the behaviour of every other NDI
receiver and is not configurable per the SDK contract.
Platforms: currently implemented on Android. On other platforms
the watcher is a no-op (VisioForge.Core.DeviceEnumerator.StartNDISourceWatch succeeds
silently, no events are raised) — for desktop, use the GStreamer
DeviceMonitor change signals directly until a cross-platform
implementation lands.
OnAudioSinkAdded
Occurs when a new audio output device (speaker/headphones) is added to the system.
public event EventHandler<AudioOutputDeviceInfo> OnAudioSinkAddedEvent Type
Remarks
This event is triggered when the device monitor detects a newly connected audio output device. The event argument contains detailed information about the added device.
OnAudioSinkRemoved
Occurs when an audio output device (speaker/headphones) is removed from the system.
public event EventHandler<AudioOutputDeviceInfo> OnAudioSinkRemovedEvent Type
Remarks
This event is triggered when the device monitor detects that an audio output device has been disconnected. The event argument contains information about the removed device.
OnAudioSourceAdded
Occurs when a new audio capture device (microphone) is added to the system.
public event EventHandler<AudioCaptureDeviceInfo> OnAudioSourceAddedEvent Type
Remarks
This event is triggered when the device monitor detects a newly connected audio input device. The event argument contains detailed information about the added device including its name, API type, and internal identifier.
OnAudioSourceRemoved
Occurs when an audio capture device (microphone) is removed from the system.
public event EventHandler<AudioCaptureDeviceInfo> OnAudioSourceRemovedEvent Type
Remarks
This event is triggered when the device monitor detects that an audio input device has been disconnected. The event argument contains information about the removed device.
OnDecklinkSignalLost
Occurs when the DeckLink device loses input signal.
public event EventHandler<EventArgs> OnDecklinkSignalLostEvent Type
Remarks
This event is triggered when the DeckLink hardware detects a loss of video/audio input signal. This commonly occurs when an SDI or HDMI cable is disconnected or the source device is powered off. Applications should handle this event to notify users or switch to alternative sources.
OnVideoSourceAdded
Occurs when a new video capture device (camera/webcam) is added to the system.
public event EventHandler<VideoCaptureDeviceInfo> OnVideoSourceAddedEvent Type
Remarks
This event is triggered when the device monitor detects a newly connected video capture device. The event argument contains detailed information about the added device including its name, supported formats, resolutions, and API type.
OnVideoSourceRemoved
Occurs when a video capture device (camera/webcam) is removed from the system.
public event EventHandler<VideoCaptureDeviceInfo> OnVideoSourceRemovedEvent Type
Remarks
This event is triggered when the device monitor detects that a video capture device has been disconnected. The event argument contains information about the removed device.