Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 0 additions & 39 deletions .github/workflows/platforms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,44 +351,6 @@ jobs:
- name: Build beep example
run: cargo build --example beep --target ${{ env.TARGET }}

# Windows crate version compatibility
windows-versions:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
version: ["0.59.0", "0.60.0", "0.61.3"]

name: windows-crate-v${{ matrix.version }}
steps:
- uses: actions/checkout@v5

- name: Install dependencies
run: choco install llvm

- name: Install Rust MSRV (${{ env.MSRV_WINDOWS }})
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.MSRV_WINDOWS }}

- name: Rust Cache
uses: Swatinem/rust-cache@v2
with:
key: windows-v${{ matrix.version }}

- name: Lock windows crate to specific version
shell: bash
run: |
cargo generate-lockfile
cargo update -p windows --precise ${{ matrix.version }}
echo "Locked windows crate version:"
cargo tree | grep "windows v" || echo "Windows crate not found in dependency tree"
echo "Cargo.lock entry:"
grep -A 5 "name = \"windows\"" Cargo.lock | head -10

- name: Check WASAPI with windows v${{ matrix.version }}
run: cargo check --verbose

# cpal publishing (only on cpal release events)
publish-cpal:
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')
Expand All @@ -403,7 +365,6 @@ jobs:
- wasm-bindgen
- wasm-audioworklet
- wasm-wasip1
- windows-versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
Expand Down
22 changes: 18 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ edition = "2021"
rust-version = "1.77"

[features]
default = []

# ASIO backend for Windows
# Provides low-latency audio I/O by bypassing the Windows audio stack
# Requires: ASIO drivers and LLVM/Clang for build-time bindings
Expand All @@ -19,6 +21,19 @@ asio = [
"dep:num-traits",
]

# Legacy Windows audio device activation mode. When enabled:
# - Uses IMMDevice::Activate instead of ActivateAudioInterfaceAsync
# - Audio does NOT automatically reroute when the default device changes
# - Streams will break when the default device changes (e.g., plugging in headphones)
#
# By default (without this feature), CPAL uses virtual default devices that:
# - Automatically reroute audio when the default device changes
# - Allow streams to survive device changes
# - Require Windows 8 or later
#
# Enable this feature only if supporting Windows 7 or earlier.
windows-legacy = []

# JACK Audio Connection Kit backend
# Provides low-latency connections between applications and audio hardware
# Requires: JACK server and client libraries installed on the system
Expand Down Expand Up @@ -62,11 +77,8 @@ hound = "3.5"
ringbuf = "0.4"
clap = { version = ">=4.0, <=4.5", features = ["derive"] }

# Support a range of versions in order to avoid duplication of this crate. Make sure to test all
# versions when bumping to a new release, and only increase the minimum when absolutely necessary.
# When updating this, also update the "windows-version" matrix in the CI workflow.
[target.'cfg(target_os = "windows")'.dependencies]
windows = { version = ">=0.59, <=0.62", features = [
windows = { version = "0.62.2", features = [
"Win32_Media_Audio",
"Win32_Foundation",
"Win32_Devices_Properties",
Expand All @@ -79,6 +91,8 @@ windows = { version = ">=0.59, <=0.62", features = [
"Win32_Media_Multimedia",
"Win32_UI_Shell_PropertiesSystem",
] }
# Explicitly depend on windows-core for use with the `windows::core::implement` macro.
windows-core = "0.62.2"
audio_thread_priority = { version = "0.34", optional = true }
asio-sys = { version = "0.2", path = "asio-sys", optional = true }
num-traits = { version = "0.2", optional = true }
Expand Down
12 changes: 11 additions & 1 deletion src/host/wasapi/com.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use super::IoError;
use std::marker::PhantomData;

use windows::Win32::Foundation::RPC_E_CHANGED_MODE;
use windows::Win32::System::Com::{CoInitializeEx, CoUninitialize, COINIT_APARTMENTTHREADED};
use windows::Win32::System::Com::{
CoInitializeEx, CoTaskMemFree, CoUninitialize, COINIT_APARTMENTTHREADED,
};

thread_local!(static COM_INITIALIZED: ComInitialized = {
unsafe {
Expand Down Expand Up @@ -49,6 +51,14 @@ impl Drop for ComInitialized {
}
}

/// RAII for COM-originating strings that need to be freed with `CoTaskMemFree`.
pub struct ComString(pub windows::core::PWSTR);
impl Drop for ComString {
fn drop(&mut self) {
unsafe { CoTaskMemFree(Some(self.0.as_ptr() as *mut _)) }
}
}

/// Ensures that COM is initialized in this thread.
#[inline]
pub fn com_initialized() {
Expand Down
Loading