Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f496130
Update copyright year
SaschaCowley Dec 17, 2024
3434c9e
Made typing information more rich
SaschaCowley Dec 17, 2024
84d16b4
Moved generation of default output device into _getOutputDevices
SaschaCowley Dec 17, 2024
a850c24
Made settings dialog use _getOutputDevices and save device IDs
SaschaCowley Dec 17, 2024
410d25f
Switch to using endpoint IDs in wasapi.cpp
SaschaCowley Dec 18, 2024
c6eed8b
Renamed deviceName to endpointId in wasapi.cpp
SaschaCowley Dec 18, 2024
9c5dc27
Update wasapi.cpp header
SaschaCowley Dec 18, 2024
e48f5a4
Removed config.conf["speech"]["outputDevice"] in favour of config.con…
SaschaCowley Dec 18, 2024
e249f1e
Pre-commit auto-fix
pre-commit-ci[bot] Dec 18, 2024
b27a8a1
Merge branch 'master' into endpointIds
SaschaCowley Dec 18, 2024
77a0d1e
Pre-commit auto-fix
pre-commit-ci[bot] Dec 18, 2024
c44c642
Changed occurances of speech.outputDevice to audio.outputDevice
SaschaCowley Dec 18, 2024
6736ecf
Merge branch 'endpointIds' of https://github.com/nvaccess/nvda into e…
SaschaCowley Dec 18, 2024
3e7763c
Scafolded test
SaschaCowley Dec 18, 2024
be22c2a
Added tests for friendlyNameToEndpointId
SaschaCowley Dec 19, 2024
95908e1
Handle case where there is no audio section in the config
SaschaCowley Dec 19, 2024
a36e43b
Add tests for config upgrade
SaschaCowley Dec 19, 2024
92f2761
Incremented config version
SaschaCowley Dec 19, 2024
f08dc94
Fixed SAPI5 (again)
SaschaCowley Dec 19, 2024
51b6698
Apply suggestions from code review
SaschaCowley Dec 19, 2024
859625c
Update copyright headers
SaschaCowley Dec 19, 2024
b548135
Apply suggestions from code review
SaschaCowley Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to using endpoint IDs in wasapi.cpp
  • Loading branch information
SaschaCowley committed Dec 18, 2024
commit 410d25ff829dc488137586d86a59bca024da2941
60 changes: 30 additions & 30 deletions nvdaHelper/local/wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const IID IID_IMMNotificationClient = __uuidof(IMMNotificationClient);
const IID IID_IAudioStreamVolume = __uuidof(IAudioStreamVolume);
const IID IID_IAudioSessionManager2 = __uuidof(IAudioSessionManager2);
const IID IID_IAudioSessionControl2 = __uuidof(IAudioSessionControl2);
const IID IID_IMMEndpoint = __uuidof(IMMEndpoint);

/**
* C++ RAII class to manage the lifecycle of a standard Windows HANDLE closed
Expand Down Expand Up @@ -491,40 +492,39 @@ HRESULT WasapiPlayer::getPreferredDevice(CComPtr<IMMDevice>& preferredDevice) {
if (FAILED(hr)) {
return hr;
}
CComPtr<IMMDeviceCollection> devices;
hr = enumerator->EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, &devices);
CComPtr<IMMDevice> device;
hr = enumerator->GetDevice(deviceName.c_str(), &device);
if (FAILED(hr)) {
return hr;
}
UINT count = 0;
devices->GetCount(&count);
for (UINT d = 0; d < count; ++d) {
CComPtr<IMMDevice> device;
hr = devices->Item(d, &device);
if (FAILED(hr)) {
return hr;
}
CComPtr<IPropertyStore> props;
hr = device->OpenPropertyStore(STGM_READ, &props);
if (FAILED(hr)) {
return hr;
}
PROPVARIANT val;
hr = props->GetValue(PKEY_Device_FriendlyName, &val);
if (FAILED(hr)) {
return hr;
}
// WinMM device names are truncated to MAXPNAMELEN characters, including the
// null terminator.
constexpr size_t MAX_CHARS = MAXPNAMELEN - 1;
if (wcsncmp(val.pwszVal, deviceName.c_str(), MAX_CHARS) == 0) {
PropVariantClear(&val);
preferredDevice = std::move(device);
return S_OK;
}
PropVariantClear(&val);

// We only want to use the device if it is plugged in and enabled.
DWORD state;
hr = device->GetState(&state);
if (FAILED(hr)) {
return hr;
} else if (state != DEVICE_STATE_ACTIVE) {
return E_NOTFOUND;
}
return E_NOTFOUND;

// We only want to use the device if it is an output device.
IMMEndpoint* endpoint;
hr = device->QueryInterface(IID_IMMEndpoint, (void**)&endpoint);
if (FAILED(hr)) {
return hr;
}
EDataFlow dataFlow;
hr = endpoint->GetDataFlow(&dataFlow);
if (FAILED(hr)) {
return hr;
} else if(dataFlow != eRender) {
Comment thread
SaschaCowley marked this conversation as resolved.
Outdated
return E_NOTFOUND;
}
preferredDevice = std::move(device);
endpoint->Release();
device.Release();
enumerator.Release();
return S_OK;
}

bool WasapiPlayer::didPreferredDeviceBecomeAvailable() {
Expand Down