@@ -70,8 +70,6 @@ const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
7070const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
7171const IID IID_IAudioClient = __uuidof(IAudioClient);
7272const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient);
73- const static GUID IDevice_FriendlyName = { 0xa45c254e , 0xdf1c , 0x4efd , { 0x80 , 0x20 , 0x67 , 0xd1 , 0x46 , 0xa8 , 0x50 , 0xe0 } };
74- const static PROPERTYKEY PKEY_Device_FriendlyName = { IDevice_FriendlyName, 14 };
7573#pragma GCC diagnostic push
7674#pragma GCC diagnostic ignored "-Wmissing-braces" // not our issue - defined by Mingw-w64
7775const static GUID UG_KSDATAFORMAT_SUBTYPE_PCM = { STATIC_KSDATAFORMAT_SUBTYPE_PCM };
@@ -94,32 +92,13 @@ struct state_aplay_wasapi {
9492};
9593
9694string wasapi_get_default_device_id (EDataFlow dataFlow, IMMDeviceEnumerator *enumerator); // defined in WASAPI capture
95+ string wasapi_get_name (IMMDevice *pDevice); // defined in audio/playback/wasapi.cpp
9796
9897#define SAFE_RELEASE (u ) \
9998 do { if ((u) != NULL ) (u)->Release (); (u) = NULL ; } while (0 )
10099#undef THROW_IF_FAILED
101100#define THROW_IF_FAILED (cmd ) do { HRESULT hr = cmd; if (!SUCCEEDED (hr)) { ostringstream oss; oss << #cmd << " : " << hresult_to_str (hr); throw ug_runtime_error (oss.str ()); } } while (0 )
102101
103- static string get_name (IMMDevice *pDevice) {
104- wstring out;
105- IPropertyStore *pProps = NULL ;
106- PROPVARIANT varName;
107- LPWSTR pwszID = NULL ;
108- // Initialize container for property value.
109- PropVariantInit (&varName);
110- HRESULT hr = pDevice->OpenPropertyStore (STGM_READ, &pProps);
111- if (!FAILED (hr)) {
112- hr = pProps->GetValue (PKEY_Device_FriendlyName, &varName);
113- if (!FAILED (hr)) {
114- out = varName.pwszVal ;
115- }
116- }
117- SAFE_RELEASE (pProps);
118- CoTaskMemFree (pwszID);
119- PropVariantClear (&varName);
120- return win_wstr_to_str (out.c_str ());
121- }
122-
123102static void audio_play_wasapi_probe (struct device_info **available_devices, int *dev_count, void (**deleter)(void *))
124103{
125104 *deleter = free;
@@ -149,7 +128,11 @@ static void audio_play_wasapi_probe(struct device_info **available_devices, int
149128 *available_devices = (struct device_info *) realloc (*available_devices, (*dev_count + 1 ) * sizeof (struct device_info ));
150129 memset (&(*available_devices)[*dev_count], 0 , sizeof (struct device_info ));
151130 snprintf ((*available_devices)[*dev_count].dev , sizeof (*available_devices)[*dev_count].dev , " :%u" , i); // /< @todo This may be rather id than index
152- snprintf ((*available_devices)[*dev_count].name , sizeof (*available_devices)[*dev_count].name , " WASAPI %s" , get_name (pDevice).c_str ());
131+ snprintf (
132+ (*available_devices)[*dev_count].name ,
133+ sizeof (*available_devices)[*dev_count].name ,
134+ " WASAPI %s" ,
135+ wasapi_get_name (pDevice).c_str ());
153136 ++*dev_count;
154137 } catch (ug_runtime_error &e) {
155138 LOG (LOG_LEVEL_WARNING) << MOD_NAME << " Device " << i << " : " << e.what () << " \n " ;
@@ -193,7 +176,10 @@ static void audio_play_wasapi_help() {
193176 THROW_IF_FAILED (pEndpoints->Item (i, &pDevice));
194177 THROW_IF_FAILED (pDevice->GetId (&pwszID));
195178 string dev_id = win_wstr_to_str (pwszID);
196- col () << (dev_id == default_dev_id ? " (*)" : " " ) << " \t " << SBOLD (i) << " ) " << SBOLD (get_name (pDevice)) << " (ID: " << dev_id << " )\n " ;
179+ col () << (dev_id == default_dev_id ? " (*)" : " " )
180+ << " \t " << SBOLD (i) << " ) "
181+ << SBOLD (wasapi_get_name (pDevice))
182+ << " (ID: " << dev_id << " )\n " ;
197183 } catch (ug_runtime_error &e) {
198184 LOG (LOG_LEVEL_WARNING) << MOD_NAME << " Device " << i << " : " << e.what () << " \n " ;
199185 }
@@ -276,8 +262,9 @@ audio_play_wasapi_init(const struct audio_playback_opts *opts)
276262 IMMDevice *pDevice = nullptr ;
277263 pEndpoints->Item (i, &pDevice);
278264 if (pDevice != nullptr &&
279- get_name (pDevice).find (
280- req_dev_name) !=
265+ wasapi_get_name (pDevice)
266+ .find (
267+ req_dev_name) !=
281268 std::string::npos) {
282269 s->pDevice = pDevice;
283270 break ;
@@ -298,7 +285,7 @@ audio_play_wasapi_init(const struct audio_playback_opts *opts)
298285 THROW_IF_FAILED (s->pDevice ->Activate (IID_IAudioClient, CLSCTX_ALL, NULL ,
299286 (void **)&s->pAudioClient ));
300287
301- auto friendlyName = get_name (s->pDevice );
288+ auto friendlyName = wasapi_get_name (s->pDevice );
302289 if (!friendlyName.empty ()) {
303290 LOG (LOG_LEVEL_NOTICE) << MOD_NAME << " Using device: "
304291 << friendlyName << " \n " ;
0 commit comments