wasapi-notify.hpp 779 B

12345678910111213141516171819202122232425262728293031
  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)> WASAPINotifyDefaultDeviceChangedCallback;
  8. class NotificationClient;
  9. class WASAPINotify {
  10. public:
  11. WASAPINotify();
  12. ~WASAPINotify();
  13. void AddDefaultDeviceChangedCallback(void *handle, WASAPINotifyDefaultDeviceChangedCallback cb);
  14. void RemoveDefaultDeviceChangedCallback(void *handle);
  15. private:
  16. void OnDefaultDeviceChanged(EDataFlow flow, ERole role, LPCWSTR id);
  17. std::mutex mutex;
  18. ComPtr<IMMDeviceEnumerator> enumerator;
  19. ComPtr<NotificationClient> notificationClient;
  20. std::unordered_map<void *, WASAPINotifyDefaultDeviceChangedCallback> defaultDeviceChangedCallbacks;
  21. };