Implement BufferSize::Fixed in wasapi, and migrate wasapi to officially-supported Windows crate (#669)
I migrated to `windows-rs` in this PR since exposing the buffer size range for hardware-offloaded audio processing requires `IAudioClient2`, which isn't exposed in the `winapi` crate, and `winapi` seems to be more or less unmaintained at this point. * Basic type conversion * Make everything compile! * Fix warnings * Implement buffer sizing for wasapi * Convert tabs to spaces * Run cargo fmt * Remove winapi from Cargo.toml * Remove unused commented code from wasapi, and fix lingering TODOs * Fix compile error * Update to windows 0.37.0 * Run rustfmt * Work around rustfmt nested tuple issues * Improve readability of guid comparison code
This commit is contained in:
parent
493a0904f3
commit
417b7fff6f
5 changed files with 478 additions and 649 deletions
|
|
@ -4,9 +4,8 @@ use super::IoError;
|
|||
use std::marker::PhantomData;
|
||||
use std::ptr;
|
||||
|
||||
use super::winapi::shared::winerror::{HRESULT, RPC_E_CHANGED_MODE, SUCCEEDED};
|
||||
use super::winapi::um::combaseapi::{CoInitializeEx, CoUninitialize};
|
||||
use super::winapi::um::objbase::COINIT_APARTMENTTHREADED;
|
||||
use windows::Win32::Foundation::RPC_E_CHANGED_MODE;
|
||||
use windows::Win32::System::Com::{CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED};
|
||||
|
||||
thread_local!(static COM_INITIALIZED: ComInitialized = {
|
||||
unsafe {
|
||||
|
|
@ -17,14 +16,18 @@ thread_local!(static COM_INITIALIZED: ComInitialized = {
|
|||
// That's OK though since COM ensures thread-safety/compatibility through marshalling when
|
||||
// necessary.
|
||||
let result = CoInitializeEx(ptr::null_mut(), COINIT_APARTMENTTHREADED);
|
||||
if SUCCEEDED(result) || result == RPC_E_CHANGED_MODE {
|
||||
ComInitialized {
|
||||
result,
|
||||
_ptr: PhantomData,
|
||||
match result.clone().map_err(|e| e.code()) {
|
||||
Ok(_) |
|
||||
Err(RPC_E_CHANGED_MODE) => {
|
||||
ComInitialized {
|
||||
result,
|
||||
_ptr: PhantomData,
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
// COM initialization failed in another way, something is really wrong.
|
||||
panic!("Failed to initialize COM: {}", IoError::from_raw_os_error(e.0));
|
||||
}
|
||||
} else {
|
||||
// COM initialization failed in another way, something is really wrong.
|
||||
panic!("Failed to initialize COM: {}", IoError::from_raw_os_error(result));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -34,7 +37,7 @@ thread_local!(static COM_INITIALIZED: ComInitialized = {
|
|||
// We store a raw pointer because it's the only way at the moment to remove `Send`/`Sync` from the
|
||||
// object.
|
||||
struct ComInitialized {
|
||||
result: HRESULT,
|
||||
result: windows::core::Result<()>,
|
||||
_ptr: PhantomData<*mut ()>,
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +46,7 @@ impl Drop for ComInitialized {
|
|||
fn drop(&mut self) {
|
||||
// Need to avoid calling CoUninitialize() if CoInitializeEx failed since it may have
|
||||
// returned RPC_E_MODE_CHANGED - which is OK, see above.
|
||||
if SUCCEEDED(self.result) {
|
||||
if self.result.is_ok() {
|
||||
unsafe { CoUninitialize() };
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue