plugin-main.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "wasapi-notify.hpp"
  2. #include <obs-module.h>
  3. #include <util/windows/win-version.h>
  4. OBS_DECLARE_MODULE()
  5. OBS_MODULE_USE_DEFAULT_LOCALE("win-wasapi", "en-US")
  6. MODULE_EXPORT const char *obs_module_description(void)
  7. {
  8. return "Windows WASAPI audio input/output sources";
  9. }
  10. void RegisterWASAPIInput();
  11. void RegisterWASAPIDeviceOutput();
  12. void RegisterWASAPIProcessOutput();
  13. WASAPINotify *notify = nullptr;
  14. static void default_device_changed_callback(EDataFlow flow, ERole, LPCWSTR)
  15. {
  16. const char *id;
  17. obs_get_audio_monitoring_device(nullptr, &id);
  18. if (!id || strcmp(id, "default") != 0)
  19. return;
  20. if (flow != eRender)
  21. return;
  22. auto task = [](void *) {
  23. obs_reset_audio_monitoring();
  24. };
  25. obs_queue_task(OBS_TASK_UI, task, nullptr, false);
  26. }
  27. bool obs_module_load(void)
  28. {
  29. /* MS says 20348, but process filtering seems to work earlier */
  30. struct win_version_info ver;
  31. get_win_ver(&ver);
  32. struct win_version_info minimum;
  33. minimum.major = 10;
  34. minimum.minor = 0;
  35. minimum.build = 19041;
  36. minimum.revis = 0;
  37. const bool process_filter_supported =
  38. win_version_compare(&ver, &minimum) >= 0;
  39. RegisterWASAPIInput();
  40. RegisterWASAPIDeviceOutput();
  41. if (process_filter_supported)
  42. RegisterWASAPIProcessOutput();
  43. notify = new WASAPINotify();
  44. notify->AddDefaultDeviceChangedCallback(
  45. obs_current_module(), default_device_changed_callback);
  46. return true;
  47. }
  48. void obs_module_unload(void)
  49. {
  50. if (notify) {
  51. delete notify;
  52. notify = nullptr;
  53. }
  54. }
  55. WASAPINotify *GetNotify()
  56. {
  57. return notify;
  58. }