87 Commits

Author SHA1 Message Date
pkv
d9b5addf72 win-wasapi: Add monitoring deduplication calls
For 'wasapi output capture', calls are added when devices are either
changed, started or removed.

The calls trigger checks against the monitoring device.

Signed-off-by: pkv <pkv@obsproject.com>
2025-12-12 15:21:42 -05:00
Ryan Foster
a1fbf1015f clang-format: Increase column limit from 80 to 120 2024-10-04 18:19:27 -04:00
derrod
877ddad270 win-wasapi: Remove noisy and useless debug logging 2024-07-06 16:21:21 -07:00
derrod
ebd6eec7f6 win-wasapi: Make reroute target a weak reference 2023-12-13 22:10:53 +01:00
Norihiro Kamae
70aa1e903f win-wasapi: Initialize a pointer reroute_target
The pointer `reroute_target` was never initialized if the reroute was
not set but read during processing audio.
2023-12-13 16:15:09 +01:00
derrod
48f9969df3 win-wasapi: Add procedure to reroute audio output 2023-12-12 00:05:47 +01:00
prgmitchell
0f498133a4 win-wasapi: Ignore timestamp errors
Only log packets with timestamp errors rather than resetting the device.
2023-12-04 02:25:43 -06:00
tt2468
1d5d4b29e7 win-wasapi: Handle changes to the default monitoring device
Splits the WASAPINotify class out of win-wasapi.cpp and makes it a
shared object in the plugin, then also creates a callback to reset
audio monitoring if the default output device changes.
2023-11-07 01:32:12 -06:00
prgmitchell
d017cb6718 win-wasapi: Log source name on initialization
Log the source name when a WASAPI device is initialized.
2023-10-27 14:37:46 -04:00
derrod
c2ec1fb49e win-wasapi: Handle flags set by GetBuffer 2023-10-08 02:00:58 +02:00
derrod
82f51f24ea win-wasapi: Use provided timestamp for application audio capture 2023-10-08 02:00:58 +02:00
Lain
107416193c win-wasapi: Fix arithmetic for WAVEFORMATEX::cbSize
This arithmetic used the incorrect size for WAVEFORMATEX::cbSize, which
is supposed to be sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX).
2023-09-15 10:14:10 -07:00
Penwywern
182468b373 win-wasapi: Add hook signal and proc for process output capture 2023-07-30 14:06:53 -07:00
jpark37
39183c76b5 win-wasapi: Fix Stop hang
Fix hang when audio capture is active in the background and stopped by
either closing OBS, or switching scene collections.
2022-10-01 10:36:08 -07:00
jpark37
cbb910a99c win-wasapi: Don't reconnect when inactive
Unnecessary reconnect attempts may cause noticeable hitches.
2022-10-01 07:06:56 -07:00
jpark37
f7b58f6f6e win-wasapi: Don't log if reconnect fails 2022-07-31 21:45:37 -07:00
jpark37
769a29bd1a win-wasapi: Add support for capturing a process
Use new process output API, and retrofit existing WASAPI abstractions.

Marked as "(BETA)" until we figure out the crackling at 60 minutes.
2022-07-23 17:41:34 -07:00
Richard Stanway
c7e83518e1 win-wasapi: Log source name when showing device errors
Sometimes users have a forgotten source pointing to an invalid device,
which is very difficult to locate without us showing the source name.
2022-05-17 02:47:08 -07:00
jpark37
2a991a4fa0 win-waspai: Tighten version check for RTWQ
Getting reports that it isn't working for 1607 and below.

If they continue, we should probably just pull the RTWQ path.
2022-03-13 06:07:39 -07:00
Richard Stanway
702df3cd8d win-wasapi: Fall back to old code if RTWQ fails
Fixes a crash if RTWQ is unavailable, e.g. if the mmcss service is not
running.
2022-02-24 19:28:19 -08:00
Matt Gajownik
02f80a1013 win-wasapi: Only enable work queue on Windows 10+
Fixes #5967
2022-02-19 15:37:50 -08:00
jpark37
c8d0597358 win-wasapi: Log settings 2021-10-10 19:53:27 -07:00
jpark37
ab7d370ada win-wasapi Improve default device handling
Remove lastNotifyTime throttle. Could ignore last device notification.
Will bring back if necessary, but seemed like overkill.

Make isInputDevice const for safety.

Make isDefaultDevice atomic. Allows it to be accessed simultaneously
from settings and notification callback threads. Race between setting
change in OBS and Windows is not a problem, a signal will be sent after
both to consolidate. Worst that should happen is a redundant reconnect
cycle.

Only read/write default_id from notification callback for thread safety.
2021-10-10 19:53:27 -07:00
jpark37
24d82062ae win-wasapi: Schedule work on real-time work queue
MS claims it can schedule audio better if we use their API.
2021-10-10 19:53:27 -07:00
jpark37
d1230c292e win-wasapi: Register capture thread with MMCSS
Ensure audio gets more priority to help prevent glitching.
2021-10-10 19:53:27 -07:00
jpark37
a995c305b7 win-wasapi: Remove bools and persist threads
This simplifies synchronization, and fixes several races.
2021-10-10 19:53:27 -07:00
jpark37
a504691af8 win-wasapi: Clean reset on initialization failure
Do not store IAudioClient and IAudioCaptureClient onto the source object
until initialization is almost complete, right before the capture thread
is created. We don't to retain objects from failed attempts. Also clear
them when stopping.
2021-10-10 19:53:26 -07:00
jpark37
b166b0488b win-wasapi: Remove unnecessary inline tags 2021-10-10 19:53:26 -07:00
jpark37
49aa9074f8 win-wasapi: Remove undefined function InitName 2021-10-10 19:53:26 -07:00
jpark37
88164affae win-wasapi: Rename InitRender to ClearBuffer
We no longer persist the render client.
2021-10-10 19:53:26 -07:00
jpark37
5a2e884d14 win-wasapi: Simplify sample rate logging 2021-10-10 19:53:26 -07:00
jpark37
4503c4fdac win-wasapi: Remove persistent references
Only need IMMDevice and IAudioRenderClient during initialization.
2021-10-10 19:53:26 -07:00
jpark37
15f9d37aef win-wasapi: Persist objects beyond Start/Stop
Initialize IMMNotificationClient and IMMDeviceEnumerator in constructor
to simplify cleanup and initializaiton. Both can survive a reset.
2021-10-10 19:53:26 -07:00
jpark37
12442c3e57 win-wasapi: Make InitDevice throw to log errors 2021-10-10 19:53:26 -07:00
jpark37
8f33e01b84 win-wasapi: Fix incorrect log strings 2021-10-10 19:53:26 -07:00
jpark37
8ce1bb645f win-wasapi: Remove monitor invalidation code
The previous monitor recovery logic touches the source monitoring type,
resets the monitor even if the output device hasn't been invalidated,
and was susceptible to races. Monitor invalidation should live within
the monitor abstraction.
2021-10-10 19:22:35 -07:00
jp9000
6cf22c54dc win-waspi: Make sure to unregister notification obj
Fixes a bug where the notify object existed after source deletion
2021-02-06 10:41:19 -08:00
jp9000
74e6448195 win-wasapi: Add default audio device change detection
Probably long time coming, but when the user changes their default audio
device in Windows sound settings, OBS will now detect it and change the
audio device automatically to the new device if it was set to use the
"Default" device.
2021-02-06 00:29:54 -08:00
Hans Petter Selasky
0e4ea14ba1 libobs: Implement and use better scaling function for 64-bit integers
As os_gettime_ns() gets large the current scaling methods, mostly by casting
to uint64_t, may lead to numerical overflows. Sweep the code and use
util_mul_div64() where applicable.

Signed-off-by: Hans Petter Selasky <hps@selasky.org>
2020-04-05 20:27:28 +02:00
Richard Stanway
4563e03442 win-wasapi: Fix leaking IPropertyStore 2020-03-20 17:58:14 +01:00
Richard Stanway
21737d5f7a win-wasapi: Fix crash on certain devices
Not all devices return PKEY_AudioEngine_DeviceFormat properties.

Per MSDN, if the PROPERTYKEY referenced in key is not present in
the property store, this method returns S_OK and the vt member of
the structure pointed to by pv is set to VT_EMPTY.
2020-03-20 17:53:18 +01:00
Clayton Groeneveld
82ffcdc827 UI: Add source icons 2019-11-24 20:50:42 -08:00
jpark37
7d3e086e6f win-wasapi: Verify and balance CoInitializeEx call 2019-11-24 09:43:39 -08:00
Matt Gajownik
a6a86caf21 win-wasapi: Log device sample rate when initialized 2019-10-19 21:53:08 +11:00
Michael Fabian 'Xaymar' Dirks
00298fd4f1 win-wasapi: Catch by reference 2019-07-24 18:26:44 +02:00
jp9000
f53df7da64 clang-format: Apply formatting
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
2019-06-23 23:49:10 -07:00
James Park
286e43bba8 win-wasapi: Speaker enum fixes
Remove KSAUDIO_SPEAKER_2POINT1 because it is included in the Windows
SDK. (I'm guessing it wasn't before.)

Redefine 4POINT1 as KSAUDIO_SPEAKER_SURROUND|SPEAKER_LOW_FREQUENCY
instead of KSAUDIO_SPEAKER_QUAD|SPEAKER_LOW_FREQUENCY. See definitions:

FFmpeg 4.1: FL+FR+FC+LFE+BC
WASAPI QUAD: FL+FR+BL+BR (looks wrong)
WASAPI SURROUND: FL+FR+FC+BC
WASAPI LOW_FREQUENCY: LFE
2019-05-23 21:31:18 -07:00
Igor Bochkariov
69b4df41c6 win-wasapi: Unapply/reapply audio monitoring on reconnect
Saves and disable monitoring before entering recover loop, and restores
it after recovery is complete.
2019-04-20 03:37:24 -07:00
Igor Bochkariov
041d3b4155 win-wasapi: Fix audio capture after unplugging device
This commit fixes a bug where the user would have to restart OBS when
certain types of devices are unplugged and plugged back in again
(particularly USB devices).  A wait interval is required
(RECONNECT_INTERVAL) because Windows does not send any events to
IAudioCaptureClient on device invalidation.
2019-04-20 03:37:24 -07:00
Igor Bochkariov
abe59f7187 win-wasapi: Call CoInitializeEx in reconnect thread
Fixes an issue where COM might not be available to calls within the
reconnect thread.
2019-04-20 03:37:24 -07:00