AV module

DeviceManager

Enumerates and manages system audio and video devices.

DeviceManager

#include <icy/av/devicemanager.h>

Enumerates and manages system audio and video devices.

Public Attributes

ReturnNameDescription
NullSignalDevicesChangedSignals when a system device is connected or removed. Emitted by the platform-specific [DeviceWatcher](icy-av-DeviceWatcher.html#devicewatcher).

DevicesChanged

NullSignal DevicesChanged

Signals when a system device is connected or removed. Emitted by the platform-specific [DeviceWatcher](icy-av-DeviceWatcher.html#devicewatcher).

NOTE: This signal may be emitted from a background thread (e.g. inotify thread on Linux, COM callback on Windows, CoreAudio listener on macOS). Handlers must be thread-safe and should NOT call back into DeviceManager to enumerate. Instead, post to the main thread or set a flag.

Public Methods

ReturnNameDescription
DeviceManager
boolgetCameras constPopulate devices with all connected video input (camera) devices.
boolgetMicrophones constPopulate devices with all connected audio input (microphone) devices.
boolgetSpeakers constPopulate devices with all connected audio output (speaker) devices.
boolgetDefaultCamera constReturn the default (or first available) camera.
boolgetDefaultMicrophone constReturn the default (or first available) microphone.
boolgetDefaultSpeaker constReturn the default (or first available) speaker.
boolfindCamera constFind a camera by display name or device id.
boolfindMicrophone constFind a microphone by display name or device id.
boolfindSpeaker constFind a speaker by display name or device id.
boolgetDeviceList constPopulate devices from the platform-specific backend for the given type.
intgetCapabilities const#### Returns
voidsetWatcherReplace the active device watcher. Takes ownership.
DeviceWatcher *watcher const#### Returns
voidprint constPrint all devices to the output stream.
std::vector< HardwareCodec >getHardwareCodecs constDetect available hardware-accelerated codecs via FFmpeg.
std::optional< std::pair< Device, Device::VideoCapability > >negotiateVideoCapture constResolve the best video capture parameters for a device.
std::optional< std::pair< Device, Device::AudioCapability > >negotiateAudioCapture constResolve the best audio capture parameters for a device. Returns std::nullopt if no microphone is available.
const AVInputFormat *findVideoInputFormat constFind base FFmpeg formats.
const AVInputFormat *findAudioInputFormat const

DeviceManager

DeviceManager()

getCameras

const

bool getCameras(std::vector< Device > & devices) const

Populate devices with all connected video input (camera) devices.

Parameters

  • devices Output vector to fill.

Returns

True if enumeration succeeded (even if the list is empty).


getMicrophones

const

bool getMicrophones(std::vector< Device > & devices) const

Populate devices with all connected audio input (microphone) devices.

Parameters

  • devices Output vector to fill.

Returns

True if enumeration succeeded.


getSpeakers

const

bool getSpeakers(std::vector< Device > & devices) const

Populate devices with all connected audio output (speaker) devices.

Parameters

  • devices Output vector to fill.

Returns

True if enumeration succeeded.


getDefaultCamera

const

bool getDefaultCamera(Device & device) const

Return the default (or first available) camera.

Parameters

  • device Output Device to fill.

Returns

True if a camera was found.


getDefaultMicrophone

const

bool getDefaultMicrophone(Device & device) const

Return the default (or first available) microphone.

Parameters

  • device Output Device to fill.

Returns

True if a microphone was found.


getDefaultSpeaker

const

bool getDefaultSpeaker(Device & device) const

Return the default (or first available) speaker.

Parameters

  • device Output Device to fill.

Returns

True if a speaker was found.


findCamera

const

bool findCamera(std::string_view name, Device & device) const

Find a camera by display name or device id.

Parameters

  • name The name or id to search for.

  • device Output Device to fill if found.

Returns

True if a matching device was found.


findMicrophone

const

bool findMicrophone(std::string_view name, Device & device) const

Find a microphone by display name or device id.

Parameters

  • name The name or id to search for.

  • device Output Device to fill if found.

Returns

True if a matching device was found.


findSpeaker

const

bool findSpeaker(std::string_view name, Device & device) const

Find a speaker by display name or device id.

Parameters

  • name The name or id to search for.

  • device Output Device to fill if found.

Returns

True if a matching device was found.


getDeviceList

const

bool getDeviceList(Device::Type type, std::vector< av::Device > & devices) const

Populate devices from the platform-specific backend for the given type.

Parameters

  • type The device type to enumerate.

  • devices Output vector to fill.

Returns

True if enumeration succeeded.


getCapabilities

const

int getCapabilities() const

Returns

A bitmask of MediaCapabilities flags indicating which capture/render types are available.


setWatcher

void setWatcher(DeviceWatcher * watcher)

Replace the active device watcher. Takes ownership.

Parameters


watcher

const

DeviceWatcher * watcher() const

Returns

The currently active DeviceWatcher, or nullptr if none has been set.


print

const

void print(std::ostream & ost) const

Print all devices to the output stream.


getHardwareCodecs

const

std::vector< HardwareCodec > getHardwareCodecs() const

Detect available hardware-accelerated codecs via FFmpeg.


negotiateVideoCapture

const

std::optional< std::pair< Device, Device::VideoCapability > > negotiateVideoCapture(std::string_view deviceName, int width, int height, double fps) const

Resolve the best video capture parameters for a device.

Looks up the device by name/id (or default camera if empty), queries its capabilities, and returns the closest match. Returns std::nullopt if no camera is available.

Usage: if (auto result = devman.negotiateVideoCapture("", 1280, 720, 30)) { auto& [dev, cap] = *result; capture.openVideo(dev.id, cap.width, cap.height, cap.maxFps, cap.pixelFormat); }


negotiateAudioCapture

const

std::optional< std::pair< Device, Device::AudioCapability > > negotiateAudioCapture(std::string_view deviceName, int sampleRate, int channels) const

Resolve the best audio capture parameters for a device. Returns std::nullopt if no microphone is available.


findVideoInputFormat

const

const AVInputFormat * findVideoInputFormat() const

Find base FFmpeg formats.


findAudioInputFormat

const

const AVInputFormat * findAudioInputFormat() const

Public Static Methods

ReturnNameDescription
DeviceManager &instance staticReturns the default [DeviceManager](#devicemanager) singleton.
voidshutdown staticShuts down the MediaFactory and deletes the singleton instance.

instance

static

static DeviceManager & instance()

Returns the default [DeviceManager](#devicemanager) singleton.


shutdown

static

static void shutdown()

Shuts down the MediaFactory and deletes the singleton instance.

Protected Attributes

ReturnNameDescription
std::unique_ptr< DeviceWatcher >_watcher

_watcher

std::unique_ptr< DeviceWatcher > _watcher