Skip to content

Commit

Permalink
Be more consistent with some log prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Jan 27, 2025
1 parent 94d8bdc commit efdc4aa
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/enumerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ inline constexpr WCHAR primary_desc[] = L"Primary Sound Driver"; /* NOLINT(*-avo

ComPtr<IMMDevice> GetMMDevice(ComWrapper&, EDataFlow flow, const GUID &id);

#define PREFIX "enumerate_mmdev "
template<typename T>
HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)
{
Expand All @@ -30,24 +31,23 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)
IID_IMMDeviceEnumerator, ds::out_ptr(devenum))};
if(FAILED(hr))
{
ERR("enumerate_mmdev CoCreateInstance failed: {:08x}", as_unsigned(hr));
ERR(PREFIX "CoCreateInstance failed: {:08x}", as_unsigned(hr));
return hr;
}

ComPtr<IMMDeviceCollection> coll;
hr = devenum->EnumAudioEndpoints(flow, DEVICE_STATE_ACTIVE, ds::out_ptr(coll));
if(FAILED(hr))
{
WARN("enumerate_mmdev IMMDeviceEnumerator::EnumAudioEndpoints failed: {:08x}",
as_unsigned(hr));
WARN(PREFIX "IMMDeviceEnumerator::EnumAudioEndpoints failed: {:08x}", as_unsigned(hr));
return DS_OK;
}

UINT count{};
hr = coll->GetCount(&count);
if(FAILED(hr))
{
WARN("enumerate_mmdev IMMDeviceCollection::GetCount failed: {:08x}", as_unsigned(hr));
WARN(PREFIX "IMMDeviceCollection::GetCount failed: {:08x}", as_unsigned(hr));
return DS_OK;
}

Expand All @@ -56,24 +56,24 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)

std::deque<GUID>{}.swap(devlist);

TRACE("enumerate_mmdev Calling back with NULL ({})", wstr_to_utf8(std::data(primary_desc)));
bool keep_going{cb(nullptr, primary_desc, L"")};
TRACE(PREFIX "Calling back with NULL ({})", wstr_to_utf8(std::data(primary_desc)));
auto keep_going = bool{cb(nullptr, primary_desc, L"")};

auto send_device = [&devlist,&cb,&keep_going](IMMDevice *device)
{
ComPtr<IPropertyStore> ps;
HRESULT hr2{device->OpenPropertyStore(STGM_READ, ds::out_ptr(ps))};
if(FAILED(hr2))
{
WARN("send_device IMMDevice::OpenPropertyStore failed: {:08x}", as_unsigned(hr2));
WARN(PREFIX "IMMDevice::OpenPropertyStore failed: {:08x}", as_unsigned(hr2));
return;
}

PropVariant pv;
hr2 = ps->GetValue(PKEY_AudioEndpoint_GUID, pv.get());
if(FAILED(hr2) || pv.type() != VT_LPWSTR)
{
WARN("send_device IPropertyStore::GetValue(GUID) failed: {:08x}", as_unsigned(hr2));
WARN(PREFIX "IPropertyStore::GetValue(GUID) failed: {:08x}", as_unsigned(hr2));
return;
}

Expand All @@ -90,12 +90,11 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)
hr2 = ps->GetValue(std::bit_cast<PROPERTYKEY>(DEVPKEY_Device_FriendlyName), pv.get());
if(FAILED(hr2))
{
WARN("send_device IPropertyStore::GetValue(FriendlyName) failed: {:08x}",
as_unsigned(hr2));
WARN(PREFIX "IPropertyStore::GetValue(FriendlyName) failed: {:08x}", as_unsigned(hr2));
return;
}

TRACE("send_device Calling back with {} - {}", GuidPrinter{devlist.back()}.c_str(),
TRACE(PREFIX "Calling back with {} - {}", GuidPrinter{devlist.back()}.c_str(),
wstr_to_utf8(pv.value<const WCHAR*>()));
keep_going = cb(&devlist.back(), pv.value<const WCHAR*>(), std::data(aldriver_name));
};
Expand All @@ -110,7 +109,7 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)
hr = coll->Item(i, ds::out_ptr(device));
if(FAILED(hr))
{
WARN("enumerate_mmdev IMMDeviceCollection::Item failed: {:08x}", as_unsigned(hr));
WARN(PREFIX "IMMDeviceCollection::Item failed: {:08x}", as_unsigned(hr));
continue;
}

Expand All @@ -119,5 +118,6 @@ HRESULT enumerate_mmdev(const EDataFlow flow, std::deque<GUID> &devlist, T&& cb)

return keep_going ? S_OK : S_FALSE;
}
#undef PREFIX

#endif // ENUMERATE_H

0 comments on commit efdc4aa

Please sign in to comment.