wasapi-notify.hpp 785 B

12345678910111213141516171819202122232425262728293031323334
  1. #pragma once
  2. #include <util/windows/ComPtr.hpp>
  3. #include <Mmdeviceapi.h>
  4. #include <unordered_map>
  5. #include <functional>
  6. #include <mutex>
  7. typedef std::function<void(EDataFlow, ERole, LPCWSTR)>
  8. WASAPINotifyDefaultDeviceChangedCallback;
  9. class NotificationClient;
  10. class WASAPINotify {
  11. public:
  12. WASAPINotify();
  13. ~WASAPINotify();
  14. void AddDefaultDeviceChangedCallback(
  15. void *handle, WASAPINotifyDefaultDeviceChangedCallback cb);
  16. void RemoveDefaultDeviceChangedCallback(void *handle);
  17. private:
  18. void OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR id);
  19. std::mutex mutex;
  20. ComPtr<IMMDeviceEnumerator> enumerator;
  21. ComPtr<NotificationClient> notificationClient;
  22. std::unordered_map<void *, WASAPINotifyDefaultDeviceChangedCallback>
  23. defaultDeviceChangedCallbacks;
  24. };