# DeviceManager

<a id="devicemanager"></a>

# DeviceManager

```cpp
#include <icy/av/devicemanager.h>

class DeviceManager
```

[Defined in src/av/include/icy/av/devicemanager.h:210](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L210)

Enumerates and manages system audio and video devices.

## Public Attributes

| Return | Name | Description |
|--------|------|-------------|
| [`NullSignal`](https://auscaster.com/icey/docs/api-reference/base.md#nullsignal) | [`DevicesChanged`](#deviceschanged)  | Signals when a system device is connected or removed. Emitted by the platform-specific [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher). |

---

<a id="deviceschanged"></a>

### DevicesChanged

```cpp
NullSignal DevicesChanged
```

Type: [`NullSignal`](https://auscaster.com/icey/docs/api-reference/base.md#nullsignal)

[Defined in src/av/include/icy/av/devicemanager.h:297](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L297)

Signals when a system device is connected or removed. Emitted by the platform-specific [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#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](#devicemanager) to enumerate. Instead, post to the main thread or set a flag.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`DeviceManager`](#devicemanager-1)  |  |
|  | [`~DeviceManager`](#devicemanager-2) `noexcept` |  |
| `bool` | [`getCameras`](#getcameras) `const` | Populate `devices` with all connected video input (camera) devices. |
| `bool` | [`getMicrophones`](#getmicrophones) `const` | Populate `devices` with all connected audio input (microphone) devices. |
| `bool` | [`getSpeakers`](#getspeakers) `const` | Populate `devices` with all connected audio output (speaker) devices. |
| `bool` | [`getDefaultCamera`](#getdefaultcamera) `const` | Return the default (or first available) camera. |
| `bool` | [`getDefaultMicrophone`](#getdefaultmicrophone) `const` | Return the default (or first available) microphone. |
| `bool` | [`getDefaultSpeaker`](#getdefaultspeaker) `const` | Return the default (or first available) speaker. |
| `bool` | [`findCamera`](#findcamera) `const` | Find a camera by display name or device id. |
| `bool` | [`findMicrophone`](#findmicrophone) `const` | Find a microphone by display name or device id. |
| `bool` | [`findSpeaker`](#findspeaker) `const` | Find a speaker by display name or device id. |
| `bool` | [`getDeviceList`](#getdevicelist-3) `const` | Populate `devices` from the platform-specific backend for the given type. |
| `int` | [`getCapabilities`](#getcapabilities) `const` |  |
| `void` | [`setWatcher`](#setwatcher)  | Replace the active device watcher. Takes ownership. |
| [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher) * | [`watcher`](#watcher) `const` |  |
| `void` | [`print`](#print-7) `const` | Print all devices to the output stream. |
| std::vector< [`HardwareCodec`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceManager-HardwareCodec.md#hardwarecodec) > | [`getHardwareCodecs`](#gethardwarecodecs) `const` | Detect available hardware-accelerated codecs via FFmpeg. |
| std::optional< std::pair< [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device), [`Device::VideoCapability`](https://auscaster.com/icey/docs/api-reference/icy-av-Device-VideoCapability.md#videocapability) > > | [`negotiateVideoCapture`](#negotiatevideocapture) `const` | Resolve the best video capture parameters for a device. |
| std::optional< std::pair< [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device), [`Device::AudioCapability`](https://auscaster.com/icey/docs/api-reference/icy-av-Device-AudioCapability.md#audiocapability) > > | [`negotiateAudioCapture`](#negotiateaudiocapture) `const` | Resolve the best audio capture parameters for a device. Returns std::nullopt if no microphone is available. |
| `const AVInputFormat *` | [`findVideoInputFormat`](#findvideoinputformat) `const` | Find base FFmpeg formats. |
| `const AVInputFormat *` | [`findAudioInputFormat`](#findaudioinputformat) `const` |  |

---

<a id="devicemanager-1"></a>

### DeviceManager

```cpp
DeviceManager()
```

[Defined in src/av/include/icy/av/devicemanager.h:213](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L213)

---

<a id="devicemanager-2"></a>

### ~DeviceManager

`noexcept`

```cpp
~DeviceManager() noexcept
```

[Defined in src/av/include/icy/av/devicemanager.h:214](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L214)

---

<a id="getcameras"></a>

### getCameras

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:219](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L219)

Populate `devices` with all connected video input (camera) devices. 
#### Returns
True if enumeration succeeded (even if the list is empty).

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `devices` | std::vector< [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) > & | Output vector to fill. |

---

<a id="getmicrophones"></a>

### getMicrophones

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:224](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L224)

Populate `devices` with all connected audio input (microphone) devices. 
#### Returns
True if enumeration succeeded.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `devices` | std::vector< [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) > & | Output vector to fill. |

---

<a id="getspeakers"></a>

### getSpeakers

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:229](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L229)

Populate `devices` with all connected audio output (speaker) devices. 
#### Returns
True if enumeration succeeded.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `devices` | std::vector< [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) > & | Output vector to fill. |

---

<a id="getdefaultcamera"></a>

### getDefaultCamera

`const`

```cpp
bool getDefaultCamera(Device & device) const
```

[Defined in src/av/include/icy/av/devicemanager.h:234](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L234)

Return the default (or first available) camera. 
#### Returns
True if a camera was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill. |

---

<a id="getdefaultmicrophone"></a>

### getDefaultMicrophone

`const`

```cpp
bool getDefaultMicrophone(Device & device) const
```

[Defined in src/av/include/icy/av/devicemanager.h:239](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L239)

Return the default (or first available) microphone. 
#### Returns
True if a microphone was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill. |

---

<a id="getdefaultspeaker"></a>

### getDefaultSpeaker

`const`

```cpp
bool getDefaultSpeaker(Device & device) const
```

[Defined in src/av/include/icy/av/devicemanager.h:244](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L244)

Return the default (or first available) speaker. 
#### Returns
True if a speaker was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill. |

---

<a id="findcamera"></a>

### findCamera

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:250](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L250)

Find a camera by display name or device id. 
#### Returns
True if a matching device was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | The name or id to search for. |
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill if found. |

---

<a id="findmicrophone"></a>

### findMicrophone

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:256](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L256)

Find a microphone by display name or device id. 
#### Returns
True if a matching device was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | The name or id to search for. |
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill if found. |

---

<a id="findspeaker"></a>

### findSpeaker

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:262](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L262)

Find a speaker by display name or device id. 
#### Returns
True if a matching device was found.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | `std::string_view` | The name or id to search for. |
| `device` | [`Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) & | Output [Device](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) to fill if found. |

---

<a id="getdevicelist-3"></a>

### getDeviceList

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:268](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L268)

Populate `devices` from the platform-specific backend for the given type. 
#### Returns
True if enumeration succeeded.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | [`Device::Type`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#type-8) | The device type to enumerate. |
| `devices` | std::vector< [`av::Device`](https://auscaster.com/icey/docs/api-reference/icy-av-Device.md#device) > & | Output vector to fill. |

---

<a id="getcapabilities"></a>

### getCapabilities

`const`

```cpp
int getCapabilities() const
```

[Defined in src/av/include/icy/av/devicemanager.h:271](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L271)

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

---

<a id="setwatcher"></a>

### setWatcher

```cpp
void setWatcher(DeviceWatcher * watcher)
```

[Defined in src/av/include/icy/av/devicemanager.h:275](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L275)

Replace the active device watcher. Takes ownership.

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `watcher` | [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher) * | The new [DeviceWatcher](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher), or nullptr to disable watching. |

---

<a id="watcher"></a>

### watcher

`const`

```cpp
DeviceWatcher * watcher() const
```

[Defined in src/av/include/icy/av/devicemanager.h:278](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L278)

#### Returns
The currently active [DeviceWatcher](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher), or nullptr if none has been set.

---

<a id="print-7"></a>

### print

`const`

```cpp
void print(std::ostream & ost) const
```

[Defined in src/av/include/icy/av/devicemanager.h:281](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L281)

Print all devices to the output stream.

---

<a id="gethardwarecodecs"></a>

### getHardwareCodecs

`const`

```cpp
std::vector< HardwareCodec > getHardwareCodecs() const
```

[Defined in src/av/include/icy/av/devicemanager.h:307](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L307)

Detect available hardware-accelerated codecs via FFmpeg.

---

<a id="negotiatevideocapture"></a>

### negotiateVideoCapture

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:321](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L321)

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); }

---

<a id="negotiateaudiocapture"></a>

### negotiateAudioCapture

`const`

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

[Defined in src/av/include/icy/av/devicemanager.h:326](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L326)

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

---

<a id="findvideoinputformat"></a>

### findVideoInputFormat

`const`

```cpp
const AVInputFormat * findVideoInputFormat() const
```

[Defined in src/av/include/icy/av/devicemanager.h:330](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L330)

Find base FFmpeg formats.

---

<a id="findaudioinputformat"></a>

### findAudioInputFormat

`const`

```cpp
const AVInputFormat * findAudioInputFormat() const
```

[Defined in src/av/include/icy/av/devicemanager.h:331](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L331)

## Public Static Methods

| Return | Name | Description |
|--------|------|-------------|
| [`DeviceManager`](#devicemanager) & | [`instance`](#instance-4) `static` | Returns the default [`DeviceManager`](#devicemanager) singleton. |
| `void` | [`shutdown`](#shutdown-2) `static` | Shuts down the `MediaFactory` and deletes the singleton instance. |

---

<a id="instance-4"></a>

### instance

`static`

```cpp
static DeviceManager & instance()
```

[Defined in src/av/include/icy/av/devicemanager.h:284](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L284)

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

---

<a id="shutdown-2"></a>

### shutdown

`static`

```cpp
static void shutdown()
```

[Defined in src/av/include/icy/av/devicemanager.h:287](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L287)

Shuts down the `MediaFactory` and deletes the singleton instance.

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| std::unique_ptr< [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher) > | [`_watcher`](#_watcher)  |  |

---

<a id="_watcher"></a>

### _watcher

```cpp
std::unique_ptr< DeviceWatcher > _watcher
```

Type: std::unique_ptr< [`DeviceWatcher`](https://auscaster.com/icey/docs/api-reference/icy-av-DeviceWatcher.md#devicewatcher) >

[Defined in src/av/include/icy/av/devicemanager.h:335](https://github.com/auscaster/icey/blob/main/src/av/include/icy/av/devicemanager.h#L335)
