Update windows-rs dependency (#726)
This commit is contained in:
parent
56f54cb0b3
commit
7776c6634a
5 changed files with 41 additions and 70 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
# Unreleased
|
||||||
|
- Update `windows-rs` dependency
|
||||||
|
|
||||||
# Version 0.14.1 (2022-10-23)
|
# Version 0.14.1 (2022-10-23)
|
||||||
|
|
||||||
- Support the 0.6.1 release of `alsa-rs`
|
- Support the 0.6.1 release of `alsa-rs`
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ clap = { version = "4.0", features = ["derive"] }
|
||||||
ndk-glue = "0.7"
|
ndk-glue = "0.7"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
windows = { version = "0.37", features = ["Win32_Media_Audio", "Win32_Foundation", "Win32_System_Com", "Win32_Devices_Properties", "Win32_Media_KernelStreaming", "Win32_System_Com_StructuredStorage", "Win32_System_Ole", "Win32_System_Threading", "Win32_Security", "Win32_System_SystemServices", "Win32_System_WindowsProgramming", "Win32_Media_Multimedia", "Win32_UI_Shell_PropertiesSystem"]}
|
windows = { version = "0.43.0", features = ["Win32_Media_Audio", "Win32_Foundation", "Win32_System_Com", "Win32_Devices_Properties", "Win32_Media_KernelStreaming", "Win32_System_Com_StructuredStorage", "Win32_System_Ole", "Win32_System_Threading", "Win32_Security", "Win32_System_SystemServices", "Win32_System_WindowsProgramming", "Win32_Media_Multimedia", "Win32_UI_Shell_PropertiesSystem"]}
|
||||||
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
|
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
|
||||||
num-traits = { version = "0.2.6", optional = true }
|
num-traits = { version = "0.2.6", optional = true }
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use super::IoError;
|
use super::IoError;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ptr;
|
|
||||||
|
|
||||||
use windows::Win32::Foundation::RPC_E_CHANGED_MODE;
|
use windows::Win32::Foundation::RPC_E_CHANGED_MODE;
|
||||||
use windows::Win32::System::Com::{CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED};
|
use windows::Win32::System::Com::{CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED};
|
||||||
|
|
@ -15,7 +14,7 @@ thread_local!(static COM_INITIALIZED: ComInitialized = {
|
||||||
// This call can fail with RPC_E_CHANGED_MODE if another library initialized COM with MTA.
|
// This call can fail with RPC_E_CHANGED_MODE if another library initialized COM with MTA.
|
||||||
// That's OK though since COM ensures thread-safety/compatibility through marshalling when
|
// That's OK though since COM ensures thread-safety/compatibility through marshalling when
|
||||||
// necessary.
|
// necessary.
|
||||||
let result = CoInitializeEx(ptr::null_mut(), COINIT_APARTMENTTHREADED);
|
let result = CoInitializeEx(None, COINIT_APARTMENTTHREADED);
|
||||||
match result.clone().map_err(|e| e.code()) {
|
match result.clone().map_err(|e| e.code()) {
|
||||||
Ok(_) |
|
Ok(_) |
|
||||||
Err(RPC_E_CHANGED_MODE) => {
|
Err(RPC_E_CHANGED_MODE) => {
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ use std::time::Duration;
|
||||||
|
|
||||||
use super::com;
|
use super::com;
|
||||||
use super::{windows_err_to_cpal_err, windows_err_to_cpal_err_message};
|
use super::{windows_err_to_cpal_err, windows_err_to_cpal_err_message};
|
||||||
use std::ffi::c_void;
|
|
||||||
use windows::core::Interface;
|
use windows::core::Interface;
|
||||||
use windows::core::GUID;
|
use windows::core::GUID;
|
||||||
use windows::Win32::Devices::Properties;
|
use windows::Win32::Devices::Properties;
|
||||||
|
|
@ -26,8 +25,7 @@ use windows::Win32::Foundation;
|
||||||
use windows::Win32::Media::Audio::IAudioRenderClient;
|
use windows::Win32::Media::Audio::IAudioRenderClient;
|
||||||
use windows::Win32::Media::{Audio, KernelStreaming, Multimedia};
|
use windows::Win32::Media::{Audio, KernelStreaming, Multimedia};
|
||||||
use windows::Win32::System::Com;
|
use windows::Win32::System::Com;
|
||||||
use windows::Win32::System::Com::StructuredStorage;
|
use windows::Win32::System::Com::{StructuredStorage, STGM_READ, VT_LPWSTR};
|
||||||
use windows::Win32::System::Ole;
|
|
||||||
use windows::Win32::System::Threading;
|
use windows::Win32::System::Threading;
|
||||||
|
|
||||||
use super::stream::{AudioClientFlow, Stream, StreamInner};
|
use super::stream::{AudioClientFlow, Stream, StreamInner};
|
||||||
|
|
@ -136,7 +134,7 @@ struct WaveFormatExPtr(*mut Audio::WAVEFORMATEX);
|
||||||
impl Drop for WaveFormatExPtr {
|
impl Drop for WaveFormatExPtr {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
Com::CoTaskMemFree(self.0 as *mut _);
|
Com::CoTaskMemFree(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -201,11 +199,11 @@ pub unsafe fn is_format_supported(
|
||||||
waveformatex_ptr: *const Audio::WAVEFORMATEX,
|
waveformatex_ptr: *const Audio::WAVEFORMATEX,
|
||||||
) -> Result<bool, SupportedStreamConfigsError> {
|
) -> Result<bool, SupportedStreamConfigsError> {
|
||||||
// Check if the given format is supported.
|
// Check if the given format is supported.
|
||||||
let is_supported = |waveformatex_ptr, mut closest_waveformatex_ptr| {
|
let is_supported = |waveformatex_ptr, closest_waveformatex_ptr| {
|
||||||
let result = client.IsFormatSupported(
|
let result = client.IsFormatSupported(
|
||||||
Audio::AUDCLNT_SHAREMODE_SHARED,
|
Audio::AUDCLNT_SHAREMODE_SHARED,
|
||||||
waveformatex_ptr,
|
waveformatex_ptr,
|
||||||
&mut closest_waveformatex_ptr,
|
Some(closest_waveformatex_ptr),
|
||||||
);
|
);
|
||||||
// `IsFormatSupported` can return `S_FALSE` (which means that a compatible format
|
// `IsFormatSupported` can return `S_FALSE` (which means that a compatible format
|
||||||
// has been found, but not an exact match) so we also treat this as unsupported.
|
// has been found, but not an exact match) so we also treat this as unsupported.
|
||||||
|
|
@ -226,16 +224,16 @@ pub unsafe fn is_format_supported(
|
||||||
match (*waveformatex_ptr).wFormatTag as u32 {
|
match (*waveformatex_ptr).wFormatTag as u32 {
|
||||||
Audio::WAVE_FORMAT_PCM | Multimedia::WAVE_FORMAT_IEEE_FLOAT => {
|
Audio::WAVE_FORMAT_PCM | Multimedia::WAVE_FORMAT_IEEE_FLOAT => {
|
||||||
let mut closest_waveformatex = *waveformatex_ptr;
|
let mut closest_waveformatex = *waveformatex_ptr;
|
||||||
let closest_waveformatex_ptr = &mut closest_waveformatex as *mut _;
|
let mut closest_waveformatex_ptr = &mut closest_waveformatex as *mut _;
|
||||||
is_supported(waveformatex_ptr, closest_waveformatex_ptr)
|
is_supported(waveformatex_ptr, &mut closest_waveformatex_ptr as *mut _)
|
||||||
}
|
}
|
||||||
KernelStreaming::WAVE_FORMAT_EXTENSIBLE => {
|
KernelStreaming::WAVE_FORMAT_EXTENSIBLE => {
|
||||||
let waveformatextensible_ptr = waveformatex_ptr as *const Audio::WAVEFORMATEXTENSIBLE;
|
let waveformatextensible_ptr = waveformatex_ptr as *const Audio::WAVEFORMATEXTENSIBLE;
|
||||||
let mut closest_waveformatextensible = *waveformatextensible_ptr;
|
let mut closest_waveformatextensible = *waveformatextensible_ptr;
|
||||||
let closest_waveformatextensible_ptr = &mut closest_waveformatextensible as *mut _;
|
let closest_waveformatextensible_ptr = &mut closest_waveformatextensible as *mut _;
|
||||||
let closest_waveformatex_ptr =
|
let mut closest_waveformatex_ptr =
|
||||||
closest_waveformatextensible_ptr as *mut Audio::WAVEFORMATEX;
|
closest_waveformatextensible_ptr as *mut Audio::WAVEFORMATEX;
|
||||||
is_supported(waveformatex_ptr, closest_waveformatex_ptr)
|
is_supported(waveformatex_ptr, &mut closest_waveformatex_ptr as *mut _)
|
||||||
}
|
}
|
||||||
_ => Ok(false),
|
_ => Ok(false),
|
||||||
}
|
}
|
||||||
|
|
@ -325,7 +323,7 @@ impl Device {
|
||||||
// Open the device's property store.
|
// Open the device's property store.
|
||||||
let property_store = self
|
let property_store = self
|
||||||
.device
|
.device
|
||||||
.OpenPropertyStore(StructuredStorage::STGM_READ)
|
.OpenPropertyStore(STGM_READ)
|
||||||
.expect("could not open property store");
|
.expect("could not open property store");
|
||||||
|
|
||||||
// Get the endpoint's friendly-name property.
|
// Get the endpoint's friendly-name property.
|
||||||
|
|
@ -341,7 +339,7 @@ impl Device {
|
||||||
let prop_variant = &property_value.Anonymous.Anonymous;
|
let prop_variant = &property_value.Anonymous.Anonymous;
|
||||||
|
|
||||||
// Read the friendly-name from the union data field, expecting a *const u16.
|
// Read the friendly-name from the union data field, expecting a *const u16.
|
||||||
if prop_variant.vt != Ole::VT_LPWSTR.0 as _ {
|
if prop_variant.vt != VT_LPWSTR {
|
||||||
let description = format!(
|
let description = format!(
|
||||||
"property store produced invalid data: {:?}",
|
"property store produced invalid data: {:?}",
|
||||||
prop_variant.vt
|
prop_variant.vt
|
||||||
|
|
@ -390,21 +388,9 @@ impl Device {
|
||||||
}
|
}
|
||||||
|
|
||||||
let audio_client: Audio::IAudioClient = unsafe {
|
let audio_client: Audio::IAudioClient = unsafe {
|
||||||
let mut audio_client = ptr::null_mut();
|
|
||||||
self.device.Activate(
|
|
||||||
&Audio::IAudioClient::IID,
|
|
||||||
Com::CLSCTX_ALL,
|
|
||||||
ptr::null_mut(),
|
|
||||||
&mut audio_client,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
// can fail if the device has been disconnected since we enumerated it, or if
|
// can fail if the device has been disconnected since we enumerated it, or if
|
||||||
// the device doesn't support playback for some reason
|
// the device doesn't support playback for some reason
|
||||||
assert!(!audio_client.is_null());
|
self.device.Activate(Com::CLSCTX_ALL, None)?
|
||||||
// doing a transmute here is super nasty but the windows
|
|
||||||
// crate doesn't seem to have a native method for getting
|
|
||||||
// an interface struct from a pointer
|
|
||||||
mem::transmute::<_, Audio::IAudioClient>(audio_client as *mut _)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
*lock = Some(IAudioClientWrapper(audio_client));
|
*lock = Some(IAudioClientWrapper(audio_client));
|
||||||
|
|
@ -647,7 +633,7 @@ impl Device {
|
||||||
buffer_duration,
|
buffer_duration,
|
||||||
0,
|
0,
|
||||||
&format_attempt.Format,
|
&format_attempt.Format,
|
||||||
ptr::null(),
|
None,
|
||||||
);
|
);
|
||||||
match hresult {
|
match hresult {
|
||||||
Err(ref e) if e.code() == Audio::AUDCLNT_E_DEVICE_INVALIDATED => {
|
Err(ref e) if e.code() == Audio::AUDCLNT_E_DEVICE_INVALIDATED => {
|
||||||
|
|
@ -671,17 +657,13 @@ impl Device {
|
||||||
|
|
||||||
// Creating the event that will be signalled whenever we need to submit some samples.
|
// Creating the event that will be signalled whenever we need to submit some samples.
|
||||||
let event = {
|
let event = {
|
||||||
let event = Threading::CreateEventA(
|
let event =
|
||||||
ptr::null_mut(),
|
Threading::CreateEventA(None, false, false, windows::core::PCSTR(ptr::null()))
|
||||||
false,
|
.map_err(|e| {
|
||||||
false,
|
let description = format!("failed to create event: {}", e);
|
||||||
windows::core::PCSTR(ptr::null()),
|
let err = BackendSpecificError { description };
|
||||||
)
|
BuildStreamError::from(err)
|
||||||
.map_err(|e| {
|
})?;
|
||||||
let description = format!("failed to create event: {}", e);
|
|
||||||
let err = BackendSpecificError { description };
|
|
||||||
BuildStreamError::from(err)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if let Err(e) = audio_client.SetEventHandle(event) {
|
if let Err(e) = audio_client.SetEventHandle(event) {
|
||||||
let description = format!("failed to call SetEventHandle: {}", e);
|
let description = format!("failed to call SetEventHandle: {}", e);
|
||||||
|
|
@ -761,7 +743,7 @@ impl Device {
|
||||||
buffer_duration,
|
buffer_duration,
|
||||||
0,
|
0,
|
||||||
&format_attempt.Format,
|
&format_attempt.Format,
|
||||||
ptr::null(),
|
None,
|
||||||
)
|
)
|
||||||
.map_err(windows_err_to_cpal_err::<BuildStreamError>)?;
|
.map_err(windows_err_to_cpal_err::<BuildStreamError>)?;
|
||||||
|
|
||||||
|
|
@ -770,17 +752,13 @@ impl Device {
|
||||||
|
|
||||||
// Creating the event that will be signalled whenever we need to submit some samples.
|
// Creating the event that will be signalled whenever we need to submit some samples.
|
||||||
let event = {
|
let event = {
|
||||||
let event = Threading::CreateEventA(
|
let event =
|
||||||
ptr::null_mut(),
|
Threading::CreateEventA(None, false, false, windows::core::PCSTR(ptr::null()))
|
||||||
false,
|
.map_err(|e| {
|
||||||
false,
|
let description = format!("failed to create event: {}", e);
|
||||||
windows::core::PCSTR(ptr::null()),
|
let err = BackendSpecificError { description };
|
||||||
)
|
BuildStreamError::from(err)
|
||||||
.map_err(|e| {
|
})?;
|
||||||
let description = format!("failed to create event: {}", e);
|
|
||||||
let err = BackendSpecificError { description };
|
|
||||||
BuildStreamError::from(err)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
if let Err(e) = audio_client.SetEventHandle(event) {
|
if let Err(e) = audio_client.SetEventHandle(event) {
|
||||||
let description = format!("failed to call SetEventHandle: {}", e);
|
let description = format!("failed to call SetEventHandle: {}", e);
|
||||||
|
|
@ -845,7 +823,7 @@ impl PartialEq for Device {
|
||||||
/// RAII for device IDs.
|
/// RAII for device IDs.
|
||||||
impl Drop for IdRAII {
|
impl Drop for IdRAII {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
unsafe { Com::CoTaskMemFree(self.0 .0 as *mut c_void) }
|
unsafe { Com::CoTaskMemFree(None) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// GetId only fails with E_OUTOFMEMORY and if it does, we're probably dead already.
|
// GetId only fails with E_OUTOFMEMORY and if it does, we're probably dead already.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use std::ptr;
|
||||||
use std::sync::mpsc::{channel, Receiver, Sender};
|
use std::sync::mpsc::{channel, Receiver, Sender};
|
||||||
use std::thread::{self, JoinHandle};
|
use std::thread::{self, JoinHandle};
|
||||||
use windows::Win32::Foundation;
|
use windows::Win32::Foundation;
|
||||||
|
use windows::Win32::Foundation::WAIT_OBJECT_0;
|
||||||
use windows::Win32::Media::Audio;
|
use windows::Win32::Media::Audio;
|
||||||
use windows::Win32::System::SystemServices;
|
use windows::Win32::System::SystemServices;
|
||||||
use windows::Win32::System::Threading;
|
use windows::Win32::System::Threading;
|
||||||
|
|
@ -89,12 +90,7 @@ impl Stream {
|
||||||
E: FnMut(StreamError) + Send + 'static,
|
E: FnMut(StreamError) + Send + 'static,
|
||||||
{
|
{
|
||||||
let pending_scheduled_event = unsafe {
|
let pending_scheduled_event = unsafe {
|
||||||
Threading::CreateEventA(
|
Threading::CreateEventA(None, false, false, windows::core::PCSTR(ptr::null()))
|
||||||
ptr::null_mut(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
windows::core::PCSTR(ptr::null()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.expect("cpal: could not create input stream event");
|
.expect("cpal: could not create input stream event");
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
@ -127,12 +123,7 @@ impl Stream {
|
||||||
E: FnMut(StreamError) + Send + 'static,
|
E: FnMut(StreamError) + Send + 'static,
|
||||||
{
|
{
|
||||||
let pending_scheduled_event = unsafe {
|
let pending_scheduled_event = unsafe {
|
||||||
Threading::CreateEventA(
|
Threading::CreateEventA(None, false, false, windows::core::PCSTR(ptr::null()))
|
||||||
ptr::null_mut(),
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
windows::core::PCSTR(ptr::null()),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.expect("cpal: could not create output stream event");
|
.expect("cpal: could not create output stream event");
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
|
|
@ -249,14 +240,14 @@ fn wait_for_handle_signal(handles: &[Foundation::HANDLE]) -> Result<usize, Backe
|
||||||
false, // irrelevant parameter here
|
false, // irrelevant parameter here
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if result == Foundation::WAIT_FAILED.0 {
|
if result == Foundation::WAIT_FAILED {
|
||||||
let err = unsafe { Foundation::GetLastError() };
|
let err = unsafe { Foundation::GetLastError() };
|
||||||
let description = format!("`WaitForMultipleObjectsEx failed: {}", err.0);
|
let description = format!("`WaitForMultipleObjectsEx failed: {}", err.0);
|
||||||
let err = BackendSpecificError { description };
|
let err = BackendSpecificError { description };
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
// Notifying the corresponding task handler.
|
// Notifying the corresponding task handler.
|
||||||
let handle_idx = (result - Threading::WAIT_OBJECT_0) as usize;
|
let handle_idx = (result.0 - WAIT_OBJECT_0.0) as usize;
|
||||||
Ok(handle_idx)
|
Ok(handle_idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -387,8 +378,8 @@ fn process_input(
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
&mut frames_available,
|
&mut frames_available,
|
||||||
flags.as_mut_ptr(),
|
flags.as_mut_ptr(),
|
||||||
ptr::null_mut(),
|
None,
|
||||||
&mut qpc_position,
|
Some(&mut qpc_position),
|
||||||
);
|
);
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
|
@ -500,7 +491,7 @@ fn stream_instant(stream: &StreamInner) -> Result<crate::StreamInstant, StreamEr
|
||||||
unsafe {
|
unsafe {
|
||||||
stream
|
stream
|
||||||
.audio_clock
|
.audio_clock
|
||||||
.GetPosition(&mut position, &mut qpc_position)
|
.GetPosition(&mut position, Some(&mut qpc_position))
|
||||||
.map_err(windows_err_to_cpal_err::<StreamError>)?;
|
.map_err(windows_err_to_cpal_err::<StreamError>)?;
|
||||||
};
|
};
|
||||||
// The `qpc_position` is in 100 nanosecond units. Convert it to nanoseconds.
|
// The `qpc_position` is in 100 nanosecond units. Convert it to nanoseconds.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue