win-wasapi.cpp 17 KB

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