@@ -29,8 +29,7 @@ static std::string getStringProperty(void *propertyStore, REFPROPERTYKEY key)
2929 return textString;
3030}
3131
32- audio_device_win32::audio_device_win32 (IMMDevice *device) :
33- audio_device (), _device(device)
32+ audio_device_win32::audio_device_win32 (IMMDevice *device) : audio_device(), _device(device)
3433{
3534 tt_assert (_device != nullptr );
3635 tt_hresult_check (_device->QueryInterface (&_endpoint));
@@ -63,31 +62,29 @@ std::string audio_device_win32::id() const noexcept
6362
6463std::string audio_device_win32::name () const noexcept
6564{
66- return getStringProperty (_property_store, PKEY_Device_FriendlyName);
65+ try {
66+ return getStringProperty (_property_store, PKEY_Device_FriendlyName);
67+ } catch (io_error const &) {
68+ return " <unknown name>" s;
69+ }
6770}
6871
6972tt::label audio_device_win32::label () const noexcept
7073{
7174 return {elusive_icon::Speaker, l10n (" {}" ), name ()};
7275}
7376
74-
7577audio_device_state audio_device_win32::state () const noexcept
7678{
7779 DWORD state;
7880 tt_hresult_check (_device->GetState (&state));
7981
8082 switch (state) {
81- case DEVICE_STATE_ACTIVE:
82- return audio_device_state::active;
83- case DEVICE_STATE_DISABLED:
84- return audio_device_state::disabled;
85- case DEVICE_STATE_NOTPRESENT:
86- return audio_device_state::not_present;
87- case DEVICE_STATE_UNPLUGGED:
88- return audio_device_state::unplugged;
89- default :
90- tt_no_default ();
83+ case DEVICE_STATE_ACTIVE: return audio_device_state::active;
84+ case DEVICE_STATE_DISABLED: return audio_device_state::disabled;
85+ case DEVICE_STATE_NOTPRESENT: return audio_device_state::not_present;
86+ case DEVICE_STATE_UNPLUGGED: return audio_device_state::unplugged;
87+ default : tt_no_default ();
9188 }
9289}
9390
@@ -100,19 +97,26 @@ audio_device_flow_direction audio_device_win32::direction() const noexcept
10097 case eRender: return audio_device_flow_direction::output;
10198 case eCapture: return audio_device_flow_direction::input;
10299 case eAll: return audio_device_flow_direction::bidirectional;
103- default :
104- tt_no_default ();
100+ default : tt_no_default ();
105101 }
106102}
107103
108104std::string audio_device_win32::device_name () const noexcept
109105{
110- return getStringProperty (_property_store, PKEY_DeviceInterface_FriendlyName);
106+ try {
107+ return getStringProperty (_property_store, PKEY_DeviceInterface_FriendlyName);
108+ } catch (io_error const &) {
109+ return " <unknown device name>" s;
110+ }
111111}
112112
113113std::string audio_device_win32::end_point_name () const noexcept
114114{
115- return getStringProperty (_property_store, PKEY_Device_DeviceDesc);
115+ try {
116+ return getStringProperty (_property_store, PKEY_Device_DeviceDesc);
117+ } catch (io_error const &) {
118+ return " <unknown end point name>" s;
119+ }
116120}
117121
118- }
122+ } // namespace tt
0 commit comments