Skip to content

Commit

Permalink
Initial changes for adding visionOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
simlay committed Jun 7, 2024
1 parent f3620f6 commit ea5c36b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/coreaudio-rs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ jobs:
- name: Build iphonesimulator feedback example
run: cd examples/ios && xcodebuild ONLY_ACTIVE_ARCH=NO ARCHS=x86_64 -scheme coreaudio-ios-example -configuration Debug -derivedDataPath build -sdk iphonesimulator

apple-tier-3-check:
runs-on: macOS-14
strategy:
matrix:
target: [
aarch64-apple-visionos,
aarch64-apple-visionos-sim,
]
steps:
- uses: actions/checkout@v4

- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly
components: rust-src

- name: Install Xcode Command Line Tools
# TODO: Remove this when xcode 15.2 or later is the default in
# https://github.com/actions/runner-images/blob/main/images/macos/macos-14-arm64-Readme.md#xcode
run: sudo xcode-select --switch /Applications/Xcode_15.4.app/Contents/Developer

- name: Build for visionOS target ${{matrix.target}}
run: cargo +nightly build -Z build-std --target=${{matrix.target}}

# Build the docs with all features to make sure docs.rs will work.
macos-docs:
runs-on: macOS-latest
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "coreaudio-rs"
version = "0.12.0"
authors = ["mitchmindtree <mitchell.nordine@gmail.com>", "yupferris <jake@fusetools.com>"]
description = "A friendly rust interface for Apple's CoreAudio API."
keywords = ["core", "audio", "unit", "osx", "ios"]
keywords = ["core", "audio", "unit", "osx", "ios", "visionos"]
readme = "README.md"
license = "MIT/Apache-2.0"
edition = '2018'
Expand All @@ -30,3 +30,6 @@ core-foundation-sys = "0.8.3"
all-features = true
default-target = "x86_64-apple-darwin"
targets = ["x86_64-apple-darwin", "x86_64-apple-ios"]

[patch.crates-io]
coreaudio-sys = { git = "https://github.com/simlay/coreaudio-sys.git", branch = "tier-3-more-apple-targets"}
2 changes: 1 addition & 1 deletion src/audio_unit/macos_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// This is a collection of helper functions for performing common tasks on macOS.
/// These functions are only implemented for macOS, not iOS.
/// These functions are only implemented for macOS, not iOS or visionOS.
use crate::error::Error;
use std::collections::VecDeque;
use std::ffi::CStr;
Expand Down
4 changes: 3 additions & 1 deletion src/audio_unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ pub fn set_property<T>(
/// Gets the value of an **AudioUnit** property.
///
/// **Available** in iOS 2.0 and later.
/// **Available** in visionOS 1.0 and later.
///
/// Parameters
/// ----------
Expand Down Expand Up @@ -414,12 +415,13 @@ pub fn get_property<T>(
/// Gets the value of a specified audio session property.
///
/// **Available** in iOS 2.0 and later.
/// **Available** in visionOS 1.0 and later.
///
/// Parameters
/// ----------
///
/// - **id**: The identifier of the property.
#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "visionos"))]
pub fn audio_session_get_property<T>(id: u32) -> Result<T, Error> {
let mut size = ::std::mem::size_of::<T>() as u32;
unsafe {
Expand Down
5 changes: 4 additions & 1 deletion src/audio_unit/render_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ impl AudioUnit {
let buffer_frame_size: u32 = self.get_property(id, Scope::Global, Element::Output)?;
buffer_frame_size
};
#[cfg(target_os = "ios")]

// TODO: watchOS and tvOS. It's unclear how to get the frame buffer size on watchOS or
// tvOS.
#[cfg(any(target_os = "ios", target_os = "visionos"))]
let mut buffer_frame_size: u32 = {
let id = sys::kAudioSessionProperty_CurrentHardwareIOBufferDuration;
let seconds: f32 = super::audio_session_get_property(id)?;
Expand Down

0 comments on commit ea5c36b

Please sign in to comment.