win-wasapi.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. #include "enum-wasapi.hpp"
  2. #include <obs-module.h>
  3. #include <obs.h>
  4. #include <util/platform.h>
  5. #include <util/windows/HRError.hpp>
  6. #include <util/windows/ComPtr.hpp>
  7. #include <util/windows/WinHandle.hpp>
  8. #include <util/windows/CoTaskMemPtr.hpp>
  9. #include <util/threading.h>
  10. #include <util/util_uint64.h>
  11. #include <cinttypes>
  12. #include <thread>
  13. using namespace std;
  14. #define OPT_DEVICE_ID "device_id"
  15. #define OPT_USE_DEVICE_TIMING "use_device_timing"
  16. static void GetWASAPIDefaults(obs_data_t *settings);
  17. #define OBS_KSAUDIO_SPEAKER_4POINT1 \
  18. (KSAUDIO_SPEAKER_SURROUND | SPEAKER_LOW_FREQUENCY)
  19. class WASAPISource {
  20. ComPtr<IMMNotificationClient> notify;
  21. ComPtr<IMMDeviceEnumerator> enumerator;
  22. ComPtr<IAudioClient> client;
  23. ComPtr<IAudioCaptureClient> capture;
  24. obs_source_t *source;
  25. wstring default_id;
  26. string device_id;
  27. string device_name;
  28. uint64_t lastNotifyTime = 0;
  29. bool isInputDevice;
  30. bool useDeviceTiming = false;
  31. bool isDefaultDevice = false;
  32. bool reconnecting = false;
  33. bool previouslyFailed = false;
  34. WinHandle reconnectThread;
  35. bool active = false;
  36. WinHandle captureThread;
  37. WinHandle stopSignal;
  38. WinHandle receiveSignal;
  39. speaker_layout speakers;
  40. audio_format format;
  41. uint32_t sampleRate;
  42. static DWORD WINAPI ReconnectThread(LPVOID param);
  43. static DWORD WINAPI CaptureThread(LPVOID param);
  44. bool ProcessCaptureData();
  45. void Start();
  46. void Stop();
  47. void Reconnect();
  48. ComPtr<IMMDevice> InitDevice();
  49. void InitClient(IMMDevice *device);
  50. void ClearBuffer(IMMDevice *device);
  51. void InitFormat(WAVEFORMATEX *wfex);
  52. void InitCapture();
  53. void Initialize();
  54. bool TryInitialize();
  55. void UpdateSettings(obs_data_t *settings);
  56. public:
  57. WASAPISource(obs_data_t *settings, obs_source_t *source_, bool input);
  58. ~WASAPISource();
  59. void Update(obs_data_t *settings);
  60. void SetDefaultDevice(EDataFlow flow, ERole role, LPCWSTR id);
  61. };
  62. class WASAPINotify : public IMMNotificationClient {
  63. long refs = 0; /* auto-incremented to 1 by ComPtr */
  64. WASAPISource *source;
  65. public:
  66. WASAPINotify(WASAPISource *source_) : source(source_) {}
  67. STDMETHODIMP_(ULONG) AddRef()
  68. {
  69. return (ULONG)os_atomic_inc_long(&refs);
  70. }
  71. STDMETHODIMP_(ULONG) STDMETHODCALLTYPE Release()
  72. {
  73. long val = os_atomic_dec_long(&refs);
  74. if (val == 0)
  75. delete this;
  76. return (ULONG)val;
  77. }
  78. STDMETHODIMP QueryInterface(REFIID riid, void **ptr)
  79. {
  80. if (riid == IID_IUnknown) {
  81. *ptr = (IUnknown *)this;
  82. } else if (riid == __uuidof(IMMNotificationClient)) {
  83. *ptr = (IMMNotificationClient *)this;
  84. } else {
  85. *ptr = nullptr;
  86. return E_NOINTERFACE;
  87. }
  88. os_atomic_inc_long(&refs);
  89. return S_OK;
  90. }
  91. STDMETHODIMP OnDefaultDeviceChanged(EDataFlow flow, ERole role,
  92. LPCWSTR id)
  93. {
  94. source->SetDefaultDevice(flow, role, id);
  95. return S_OK;
  96. }
  97. STDMETHODIMP OnDeviceAdded(LPCWSTR) { return S_OK; }
  98. STDMETHODIMP OnDeviceRemoved(LPCWSTR) { return S_OK; }
  99. STDMETHODIMP OnDeviceStateChanged(LPCWSTR, DWORD) { return S_OK; }
  100. STDMETHODIMP OnPropertyValueChanged(LPCWSTR, const PROPERTYKEY)
  101. {
  102. return S_OK;
  103. }
  104. };
  105. WASAPISource::WASAPISource(obs_data_t *settings, obs_source_t *source_,
  106. bool input)
  107. : source(source_), isInputDevice(input)
  108. {
  109. UpdateSettings(settings);
  110. stopSignal = CreateEvent(nullptr, true, false, nullptr);
  111. if (!stopSignal.Valid())
  112. throw "Could not create stop signal";
  113. receiveSignal = CreateEvent(nullptr, false, false, nullptr);
  114. if (!receiveSignal.Valid())
  115. throw "Could not create receive signal";
  116. notify = new WASAPINotify(this);
  117. if (!notify)
  118. throw "Could not create WASAPINotify";
  119. HRESULT res = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr,
  120. CLSCTX_ALL,
  121. IID_PPV_ARGS(enumerator.Assign()));
  122. if (FAILED(res))
  123. throw HRError("Failed to create enumerator", res);
  124. res = enumerator->RegisterEndpointNotificationCallback(notify);
  125. if (FAILED(res))
  126. throw HRError("Failed to register endpoint callback", res);
  127. Start();
  128. }
  129. void WASAPISource::Start()
  130. {
  131. if (!TryInitialize()) {
  132. blog(LOG_INFO, "WASAPI: Device '%s' failed to start",
  133. device_id.c_str());
  134. Reconnect();
  135. }
  136. }
  137. void WASAPISource::Stop()
  138. {
  139. SetEvent(stopSignal);
  140. if (active) {
  141. blog(LOG_INFO, "WASAPI: Device '%s' Terminated",
  142. device_name.c_str());
  143. WaitForSingleObject(captureThread, INFINITE);
  144. }
  145. if (reconnecting)
  146. WaitForSingleObject(reconnectThread, INFINITE);
  147. ResetEvent(stopSignal);
  148. }
  149. WASAPISource::~WASAPISource()
  150. {
  151. enumerator->UnregisterEndpointNotificationCallback(notify);
  152. Stop();
  153. }
  154. void WASAPISource::UpdateSettings(obs_data_t *settings)
  155. {
  156. device_id = obs_data_get_string(settings, OPT_DEVICE_ID);
  157. useDeviceTiming = obs_data_get_bool(settings, OPT_USE_DEVICE_TIMING);
  158. isDefaultDevice = _strcmpi(device_id.c_str(), "default") == 0;
  159. }
  160. void WASAPISource::Update(obs_data_t *settings)
  161. {
  162. string newDevice = obs_data_get_string(settings, OPT_DEVICE_ID);
  163. bool restart = newDevice.compare(device_id) != 0;
  164. if (restart)
  165. Stop();
  166. UpdateSettings(settings);
  167. if (restart)
  168. Start();
  169. }
  170. ComPtr<IMMDevice> WASAPISource::InitDevice()
  171. {
  172. ComPtr<IMMDevice> device;
  173. if (isDefaultDevice) {
  174. HRESULT res = enumerator->GetDefaultAudioEndpoint(
  175. isInputDevice ? eCapture : eRender,
  176. isInputDevice ? eCommunications : eConsole,
  177. device.Assign());
  178. if (FAILED(res))
  179. throw HRError("Failed GetDefaultAudioEndpoint", res);
  180. CoTaskMemPtr<wchar_t> id;
  181. res = device->GetId(&id);
  182. if (FAILED(res))
  183. throw HRError("Failed to get default id", res);
  184. default_id = id;
  185. } else {
  186. wchar_t *w_id;
  187. os_utf8_to_wcs_ptr(device_id.c_str(), device_id.size(), &w_id);
  188. if (!w_id)
  189. throw "Failed to widen device id string";
  190. const HRESULT res =
  191. enumerator->GetDevice(w_id, device.Assign());
  192. bfree(w_id);
  193. if (FAILED(res))
  194. throw HRError("Failed to enumerate device", res);
  195. }
  196. return device;
  197. }
  198. #define BUFFER_TIME_100NS (5 * 10000000)
  199. void WASAPISource::InitClient(IMMDevice *device)
  200. {
  201. CoTaskMemPtr<WAVEFORMATEX> wfex;
  202. HRESULT res;
  203. DWORD flags = AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
  204. res = device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr,
  205. (void **)client.Assign());
  206. if (FAILED(res))
  207. throw HRError("Failed to activate client context", res);
  208. res = client->GetMixFormat(&wfex);
  209. if (FAILED(res))
  210. throw HRError("Failed to get mix format", res);
  211. InitFormat(wfex);
  212. if (!isInputDevice)
  213. flags |= AUDCLNT_STREAMFLAGS_LOOPBACK;
  214. res = client->Initialize(AUDCLNT_SHAREMODE_SHARED, flags,
  215. BUFFER_TIME_100NS, 0, wfex, nullptr);
  216. if (FAILED(res))
  217. throw HRError("Failed to initialize audio client", res);
  218. }
  219. void WASAPISource::ClearBuffer(IMMDevice *device)
  220. {
  221. CoTaskMemPtr<WAVEFORMATEX> wfex;
  222. HRESULT res;
  223. LPBYTE buffer;
  224. UINT32 frames;
  225. ComPtr<IAudioClient> client;
  226. res = device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, nullptr,
  227. (void **)client.Assign());
  228. if (FAILED(res))
  229. throw HRError("Failed to activate client context", res);
  230. res = client->GetMixFormat(&wfex);
  231. if (FAILED(res))
  232. throw HRError("Failed to get mix format", res);
  233. res = client->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, BUFFER_TIME_100NS,
  234. 0, wfex, nullptr);
  235. if (FAILED(res))
  236. throw HRError("Failed to initialize audio client", res);
  237. /* Silent loopback fix. Prevents audio stream from stopping and */
  238. /* messing up timestamps and other weird glitches during silence */
  239. /* by playing a silent sample all over again. */
  240. res = client->GetBufferSize(&frames);
  241. if (FAILED(res))
  242. throw HRError("Failed to get buffer size", res);
  243. ComPtr<IAudioRenderClient> render;
  244. res = client->GetService(IID_PPV_ARGS(render.Assign()));
  245. if (FAILED(res))
  246. throw HRError("Failed to get render client", res);
  247. res = render->GetBuffer(frames, &buffer);
  248. if (FAILED(res))
  249. throw HRError("Failed to get buffer", res);
  250. memset(buffer, 0, (size_t)frames * (size_t)wfex->nBlockAlign);
  251. render->ReleaseBuffer(frames, 0);
  252. }
  253. static speaker_layout ConvertSpeakerLayout(DWORD layout, WORD channels)
  254. {
  255. switch (layout) {
  256. case KSAUDIO_SPEAKER_2POINT1:
  257. return SPEAKERS_2POINT1;
  258. case KSAUDIO_SPEAKER_SURROUND:
  259. return SPEAKERS_4POINT0;
  260. case OBS_KSAUDIO_SPEAKER_4POINT1:
  261. return SPEAKERS_4POINT1;
  262. case KSAUDIO_SPEAKER_5POINT1_SURROUND:
  263. return SPEAKERS_5POINT1;
  264. case KSAUDIO_SPEAKER_7POINT1_SURROUND:
  265. return SPEAKERS_7POINT1;
  266. }
  267. return (speaker_layout)channels;
  268. }
  269. void WASAPISource::InitFormat(WAVEFORMATEX *wfex)
  270. {
  271. DWORD layout = 0;
  272. if (wfex->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
  273. WAVEFORMATEXTENSIBLE *ext = (WAVEFORMATEXTENSIBLE *)wfex;
  274. layout = ext->dwChannelMask;
  275. }
  276. /* WASAPI is always float */
  277. sampleRate = wfex->nSamplesPerSec;
  278. format = AUDIO_FORMAT_FLOAT;
  279. speakers = ConvertSpeakerLayout(layout, wfex->nChannels);
  280. }
  281. void WASAPISource::InitCapture()
  282. {
  283. HRESULT res = client->GetService(__uuidof(IAudioCaptureClient),
  284. (void **)capture.Assign());
  285. if (FAILED(res))
  286. throw HRError("Failed to create capture context", res);
  287. res = client->SetEventHandle(receiveSignal);
  288. if (FAILED(res))
  289. throw HRError("Failed to set event handle", res);
  290. captureThread = CreateThread(nullptr, 0, WASAPISource::CaptureThread,
  291. this, 0, nullptr);
  292. if (!captureThread.Valid())
  293. throw "Failed to create capture thread";
  294. client->Start();
  295. active = true;
  296. }
  297. void WASAPISource::Initialize()
  298. {
  299. ComPtr<IMMDevice> device = InitDevice();
  300. device_name = GetDeviceName(device);
  301. InitClient(device);
  302. if (!isInputDevice)
  303. ClearBuffer(device);
  304. InitCapture();
  305. blog(LOG_INFO, "WASAPI: Device '%s' [%" PRIu32 " Hz] initialized",
  306. device_name.c_str(), sampleRate);
  307. }
  308. bool WASAPISource::TryInitialize()
  309. {
  310. try {
  311. Initialize();
  312. } catch (HRError &error) {
  313. if (previouslyFailed)
  314. return active;
  315. blog(LOG_WARNING, "[WASAPISource::TryInitialize]:[%s] %s: %lX",
  316. device_name.empty() ? device_id.c_str()
  317. : device_name.c_str(),
  318. error.str, error.hr);
  319. } catch (const char *error) {
  320. if (previouslyFailed)
  321. return active;
  322. blog(LOG_WARNING, "[WASAPISource::TryInitialize]:[%s] %s",
  323. device_name.empty() ? device_id.c_str()
  324. : device_name.c_str(),
  325. error);
  326. }
  327. previouslyFailed = !active;
  328. return active;
  329. }
  330. void WASAPISource::Reconnect()
  331. {
  332. reconnecting = true;
  333. reconnectThread = CreateThread(
  334. nullptr, 0, WASAPISource::ReconnectThread, this, 0, nullptr);
  335. if (!reconnectThread.Valid())
  336. blog(LOG_WARNING,
  337. "[WASAPISource::Reconnect] "
  338. "Failed to initialize reconnect thread: %lu",
  339. GetLastError());
  340. }
  341. static inline bool WaitForSignal(HANDLE handle, DWORD time)
  342. {
  343. return WaitForSingleObject(handle, time) != WAIT_TIMEOUT;
  344. }
  345. #define RECONNECT_INTERVAL 3000
  346. DWORD WINAPI WASAPISource::ReconnectThread(LPVOID param)
  347. {
  348. WASAPISource *source = (WASAPISource *)param;
  349. os_set_thread_name("win-wasapi: reconnect thread");
  350. const HRESULT hr = CoInitializeEx(0, COINIT_MULTITHREADED);
  351. const bool com_initialized = SUCCEEDED(hr);
  352. if (!com_initialized) {
  353. blog(LOG_ERROR,
  354. "[WASAPISource::ReconnectThread]"
  355. " CoInitializeEx failed: 0x%08X",
  356. hr);
  357. }
  358. while (!WaitForSignal(source->stopSignal, RECONNECT_INTERVAL)) {
  359. if (source->TryInitialize())
  360. break;
  361. }
  362. if (com_initialized)
  363. CoUninitialize();
  364. source->reconnectThread = nullptr;
  365. source->reconnecting = false;
  366. return 0;
  367. }
  368. bool WASAPISource::ProcessCaptureData()
  369. {
  370. HRESULT res;
  371. LPBYTE buffer;
  372. UINT32 frames;
  373. DWORD flags;
  374. UINT64 pos, ts;
  375. UINT captureSize = 0;
  376. while (true) {
  377. res = capture->GetNextPacketSize(&captureSize);
  378. if (FAILED(res)) {
  379. if (res != AUDCLNT_E_DEVICE_INVALIDATED)
  380. blog(LOG_WARNING,
  381. "[WASAPISource::ProcessCaptureData]"
  382. " capture->GetNextPacketSize"
  383. " failed: %lX",
  384. res);
  385. return false;
  386. }
  387. if (!captureSize)
  388. break;
  389. res = capture->GetBuffer(&buffer, &frames, &flags, &pos, &ts);
  390. if (FAILED(res)) {
  391. if (res != AUDCLNT_E_DEVICE_INVALIDATED)
  392. blog(LOG_WARNING,
  393. "[WASAPISource::ProcessCaptureData]"
  394. " capture->GetBuffer"
  395. " failed: %lX",
  396. res);
  397. return false;
  398. }
  399. obs_source_audio data = {};
  400. data.data[0] = (const uint8_t *)buffer;
  401. data.frames = (uint32_t)frames;
  402. data.speakers = speakers;
  403. data.samples_per_sec = sampleRate;
  404. data.format = format;
  405. data.timestamp = useDeviceTiming ? ts * 100 : os_gettime_ns();
  406. if (!useDeviceTiming)
  407. data.timestamp -= util_mul_div64(frames, 1000000000ULL,
  408. sampleRate);
  409. obs_source_output_audio(source, &data);
  410. capture->ReleaseBuffer(frames);
  411. }
  412. return true;
  413. }
  414. static inline bool WaitForCaptureSignal(DWORD numSignals, const HANDLE *signals,
  415. DWORD duration)
  416. {
  417. DWORD ret;
  418. ret = WaitForMultipleObjects(numSignals, signals, false, duration);
  419. return ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT;
  420. }
  421. DWORD WINAPI WASAPISource::CaptureThread(LPVOID param)
  422. {
  423. WASAPISource *source = (WASAPISource *)param;
  424. bool reconnect = false;
  425. /* Output devices don't signal, so just make it check every 10 ms */
  426. DWORD dur = source->isInputDevice ? RECONNECT_INTERVAL : 10;
  427. HANDLE sigs[2] = {source->receiveSignal, source->stopSignal};
  428. os_set_thread_name("win-wasapi: capture thread");
  429. while (WaitForCaptureSignal(2, sigs, dur)) {
  430. if (!source->ProcessCaptureData()) {
  431. reconnect = true;
  432. break;
  433. }
  434. }
  435. source->client->Stop();
  436. source->captureThread = nullptr;
  437. source->active = false;
  438. if (reconnect) {
  439. blog(LOG_INFO, "Device '%s' invalidated. Retrying",
  440. source->device_name.c_str());
  441. source->Reconnect();
  442. }
  443. return 0;
  444. }
  445. void WASAPISource::SetDefaultDevice(EDataFlow flow, ERole role, LPCWSTR id)
  446. {
  447. if (!isDefaultDevice)
  448. return;
  449. EDataFlow expectedFlow = isInputDevice ? eCapture : eRender;
  450. ERole expectedRole = isInputDevice ? eCommunications : eConsole;
  451. if (flow != expectedFlow || role != expectedRole)
  452. return;
  453. if (id && default_id.compare(id) == 0)
  454. return;
  455. blog(LOG_INFO, "WASAPI: Default %s device changed",
  456. isInputDevice ? "input" : "output");
  457. /* reset device only once every 300ms */
  458. uint64_t t = os_gettime_ns();
  459. if (t - lastNotifyTime < 300000000)
  460. return;
  461. std::thread([this]() {
  462. Stop();
  463. Start();
  464. }).detach();
  465. lastNotifyTime = t;
  466. }
  467. /* ------------------------------------------------------------------------- */
  468. static const char *GetWASAPIInputName(void *)
  469. {
  470. return obs_module_text("AudioInput");
  471. }
  472. static const char *GetWASAPIOutputName(void *)
  473. {
  474. return obs_module_text("AudioOutput");
  475. }
  476. static void GetWASAPIDefaultsInput(obs_data_t *settings)
  477. {
  478. obs_data_set_default_string(settings, OPT_DEVICE_ID, "default");
  479. obs_data_set_default_bool(settings, OPT_USE_DEVICE_TIMING, false);
  480. }
  481. static void GetWASAPIDefaultsOutput(obs_data_t *settings)
  482. {
  483. obs_data_set_default_string(settings, OPT_DEVICE_ID, "default");
  484. obs_data_set_default_bool(settings, OPT_USE_DEVICE_TIMING, true);
  485. }
  486. static void *CreateWASAPISource(obs_data_t *settings, obs_source_t *source,
  487. bool input)
  488. {
  489. try {
  490. return new WASAPISource(settings, source, input);
  491. } catch (const char *error) {
  492. blog(LOG_ERROR, "[CreateWASAPISource] %s", error);
  493. }
  494. return nullptr;
  495. }
  496. static void *CreateWASAPIInput(obs_data_t *settings, obs_source_t *source)
  497. {
  498. return CreateWASAPISource(settings, source, true);
  499. }
  500. static void *CreateWASAPIOutput(obs_data_t *settings, obs_source_t *source)
  501. {
  502. return CreateWASAPISource(settings, source, false);
  503. }
  504. static void DestroyWASAPISource(void *obj)
  505. {
  506. delete static_cast<WASAPISource *>(obj);
  507. }
  508. static void UpdateWASAPISource(void *obj, obs_data_t *settings)
  509. {
  510. static_cast<WASAPISource *>(obj)->Update(settings);
  511. }
  512. static obs_properties_t *GetWASAPIProperties(bool input)
  513. {
  514. obs_properties_t *props = obs_properties_create();
  515. vector<AudioDeviceInfo> devices;
  516. obs_property_t *device_prop = obs_properties_add_list(
  517. props, OPT_DEVICE_ID, obs_module_text("Device"),
  518. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  519. GetWASAPIAudioDevices(devices, input);
  520. if (devices.size())
  521. obs_property_list_add_string(
  522. device_prop, obs_module_text("Default"), "default");
  523. for (size_t i = 0; i < devices.size(); i++) {
  524. AudioDeviceInfo &device = devices[i];
  525. obs_property_list_add_string(device_prop, device.name.c_str(),
  526. device.id.c_str());
  527. }
  528. obs_properties_add_bool(props, OPT_USE_DEVICE_TIMING,
  529. obs_module_text("UseDeviceTiming"));
  530. return props;
  531. }
  532. static obs_properties_t *GetWASAPIPropertiesInput(void *)
  533. {
  534. return GetWASAPIProperties(true);
  535. }
  536. static obs_properties_t *GetWASAPIPropertiesOutput(void *)
  537. {
  538. return GetWASAPIProperties(false);
  539. }
  540. void RegisterWASAPIInput()
  541. {
  542. obs_source_info info = {};
  543. info.id = "wasapi_input_capture";
  544. info.type = OBS_SOURCE_TYPE_INPUT;
  545. info.output_flags = OBS_SOURCE_AUDIO | OBS_SOURCE_DO_NOT_DUPLICATE;
  546. info.get_name = GetWASAPIInputName;
  547. info.create = CreateWASAPIInput;
  548. info.destroy = DestroyWASAPISource;
  549. info.update = UpdateWASAPISource;
  550. info.get_defaults = GetWASAPIDefaultsInput;
  551. info.get_properties = GetWASAPIPropertiesInput;
  552. info.icon_type = OBS_ICON_TYPE_AUDIO_INPUT;
  553. obs_register_source(&info);
  554. }
  555. void RegisterWASAPIOutput()
  556. {
  557. obs_source_info info = {};
  558. info.id = "wasapi_output_capture";
  559. info.type = OBS_SOURCE_TYPE_INPUT;
  560. info.output_flags = OBS_SOURCE_AUDIO | OBS_SOURCE_DO_NOT_DUPLICATE |
  561. OBS_SOURCE_DO_NOT_SELF_MONITOR;
  562. info.get_name = GetWASAPIOutputName;
  563. info.create = CreateWASAPIOutput;
  564. info.destroy = DestroyWASAPISource;
  565. info.update = UpdateWASAPISource;
  566. info.get_defaults = GetWASAPIDefaultsOutput;
  567. info.get_properties = GetWASAPIPropertiesOutput;
  568. info.icon_type = OBS_ICON_TYPE_AUDIO_OUTPUT;
  569. obs_register_source(&info);
  570. }