Skip to content
Open
Changes from all commits
Commits
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
31 changes: 6 additions & 25 deletions src/cubeb_wasapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ namespace {

const int64_t LATENCY_NOT_AVAILABLE_YET = -1;

const DWORD DEVICE_CHANGE_DEBOUNCE_MS = 250;

struct com_heap_ptr_deleter {
void operator()(void * ptr) const noexcept { CoTaskMemFree(ptr); }
};
Expand Down Expand Up @@ -754,8 +752,7 @@ class wasapi_endpoint_notification_client : public IMMNotificationClient {
}

wasapi_endpoint_notification_client(HANDLE event, ERole role)
: ref_count(1), reconfigure_event(event), role(role),
last_device_change(timeGetTime())
: ref_count(1), reconfigure_event(event), role(role)
{
}

Expand All @@ -773,25 +770,11 @@ class wasapi_endpoint_notification_client : public IMMNotificationClient {
return S_OK;
}

DWORD last_change_ms = timeGetTime() - last_device_change;
bool same_device = default_device_id && device_id &&
wcscmp(default_device_id.get(), device_id) == 0;
LOG("endpoint: Audio device default changed last_change=%lu same_device=%d",
last_change_ms, same_device);
if (last_change_ms > DEVICE_CHANGE_DEBOUNCE_MS || !same_device) {
if (device_id) {
wchar_t * new_device_id = new wchar_t[wcslen(device_id) + 1];
wcscpy(new_device_id, device_id);
default_device_id.reset(new_device_id);
} else {
default_device_id.reset();
}
BOOL ok = SetEvent(reconfigure_event);
LOG("endpoint: Audio device default changed: trigger reconfig");
if (!ok) {
LOG("endpoint: SetEvent on reconfigure_event failed: %lx",
GetLastError());
}
BOOL ok = SetEvent(reconfigure_event);
LOG("endpoint: Audio device default changed: trigger reconfig");
if (!ok) {
LOG("endpoint: SetEvent on reconfigure_event failed: %lx",
GetLastError());
}

return S_OK;
Expand Down Expand Up @@ -830,8 +813,6 @@ class wasapi_endpoint_notification_client : public IMMNotificationClient {
LONG ref_count;
HANDLE reconfigure_event;
ERole role;
std::unique_ptr<const wchar_t[]> default_device_id;
DWORD last_device_change;
};

namespace {
Expand Down
Loading