diff --git a/src/host/wasapi/device.rs b/src/host/wasapi/device.rs index f57ba04..3093b10 100644 --- a/src/host/wasapi/device.rs +++ b/src/host/wasapi/device.rs @@ -552,7 +552,7 @@ impl Device { } } - fn data_flow(&self) -> EDataFlow { + pub(crate) fn data_flow(&self) -> EDataFlow { let endpoint = Endpoint::from(self.device as *const _); endpoint.data_flow() } diff --git a/src/host/wasapi/mod.rs b/src/host/wasapi/mod.rs index eadeb95..239adbf 100644 --- a/src/host/wasapi/mod.rs +++ b/src/host/wasapi/mod.rs @@ -21,6 +21,10 @@ mod device; mod stream; /// The WASAPI host, the default windows host type. +/// +/// Note: If you use a WASAPI output device as an input device it will +/// transparently enable loopback mode (see +/// https://docs.microsoft.com/en-us/windows/win32/coreaudio/loopback-recording). #[derive(Debug)] pub struct Host; diff --git a/src/host/wasapi/stream.rs b/src/host/wasapi/stream.rs index 15382a0..bd20ba8 100644 --- a/src/host/wasapi/stream.rs +++ b/src/host/wasapi/stream.rs @@ -6,7 +6,8 @@ use super::winapi::shared::ksmedia; use super::winapi::shared::minwindef::{BYTE, DWORD, FALSE, WORD}; use super::winapi::shared::mmreg; use super::winapi::um::audioclient::{self, AUDCLNT_E_DEVICE_INVALIDATED, AUDCLNT_S_BUFFER_EMPTY}; -use super::winapi::um::audiosessiontypes::{AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK}; +use super::winapi::um::audiosessiontypes::{AUDCLNT_SHAREMODE_SHARED, AUDCLNT_STREAMFLAGS_EVENTCALLBACK, AUDCLNT_STREAMFLAGS_LOOPBACK}; +use super::winapi::um::mmdeviceapi::eRender; use super::winapi::um::handleapi; use super::winapi::um::synchapi; use super::winapi::um::winbase; @@ -151,10 +152,16 @@ impl EventLoop { _ => (), } + // Support capturing output devices. + let mut stream_flags: DWORD = AUDCLNT_STREAMFLAGS_EVENTCALLBACK; + if device.data_flow() == eRender { + stream_flags |= AUDCLNT_STREAMFLAGS_LOOPBACK; + } + // finally initializing the audio client let hresult = (*audio_client).Initialize( share_mode, - AUDCLNT_STREAMFLAGS_EVENTCALLBACK, + stream_flags, 0, 0, &format_attempt.Format,