Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added initial changes for iOS support. #69

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ env:
before_script:
- rustc --version
- cargo --version
- rustup target add aarch64-apple-ios
script:
- cargo build --verbose
- cargo test --verbose
- cargo doc --verbose
- cargo build --target aarch64-apple-ios
after_success: |
[ $TRAVIS_BRANCH = master ] &&
[ $TRAVIS_PULL_REQUEST = false ] &&
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ core_midi = ["coreaudio-sys/core_midi"]

[dependencies]
bitflags = "1.0"
coreaudio-sys = { version = "0.2", default-features = false }
coreaudio-sys = { git = "https://github.com/simlay/coreaudio-sys", branch = "add-ios-support", default-features = false }
4 changes: 2 additions & 2 deletions src/audio_unit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct InputCallback {


macro_rules! try_os_status {
($expr:expr) => (try!(Error::from_os_status($expr)))
($expr:expr) => (Error::from_os_status($expr)?)
}


Expand Down Expand Up @@ -267,7 +267,7 @@ impl AudioUnit {
/// Return the current Stream Format for the AudioUnit.
pub fn stream_format(&self, scope: Scope) -> Result<StreamFormat, Error> {
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = try!(self.get_property(id, scope, Element::Output));
let asbd = self.get_property(id, scope, Element::Output)?;
StreamFormat::from_asbd(asbd)
}

Expand Down
41 changes: 38 additions & 3 deletions src/audio_unit/render_callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub use self::data::Data;
///
/// This allows the user to provide a custom, more rust-esque callback function type that takes
/// greater advantage of rust's type safety.
pub type InputProcFn = FnMut(*mut sys::AudioUnitRenderActionFlags,
pub type InputProcFn = dyn FnMut(*mut sys::AudioUnitRenderActionFlags,
*const sys::AudioTimeStamp,
sys::UInt32,
sys::UInt32,
Expand Down Expand Up @@ -223,7 +223,8 @@ pub mod action_flags {
use std::fmt;
use sys;

bitflags!{
#[cfg(target_os = "macos")]
bitflags! {
pub struct ActionFlags: u32 {
/// Called on a render notification Proc, which is called either before or after the
/// render operation of the audio unit. If this flag is set, the proc is being called
Expand Down Expand Up @@ -279,6 +280,20 @@ pub mod action_flags {
/// **Available** in OS X v10.7 and later.
const DO_NOT_CHECK_RENDER_ARGS = sys::kAudioUnitRenderAction_DoNotCheckRenderArgs;
}

}
#[cfg(target_os = "ios")]
bitflags! {
pub struct ActionFlags: u32 {
const PRE_RENDER = sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PreRender;
const POST_RENDER = sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PostRender;
const OUTPUT_IS_SILENCE = sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_OutputIsSilence;
const OFFLINE_PREFLIGHT = sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Preflight;
const OFFLINE_RENDER = sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Render;
const OFFLINE_COMPLETE = sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Complete;
const POST_RENDER_ERROR = sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PostRenderError;
const DO_NOT_CHECK_RENDER_ARGS = sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_DoNotCheckRenderArgs;
}
}

/// A safe handle around the `AudioUnitRenderActionFlags` pointer provided by the render
Expand Down Expand Up @@ -371,6 +386,7 @@ pub mod action_flags {
unsafe impl Send for Handle {}

impl ::std::fmt::Display for ActionFlags {
#[cfg(target_os = "macos")]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{:?}", match self.bits() {
sys::kAudioUnitRenderAction_PreRender => "PRE_RENDER",
Expand All @@ -384,6 +400,21 @@ pub mod action_flags {
_ => "<Unknown ActionFlags>",
})
}
#[cfg(target_os = "ios")]
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
write!(f, "{:?}", match self.bits() {
sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PreRender => "PRE_RENDER",
sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PostRender => "POST_RENDER",
sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_OutputIsSilence => "OUTPUT_IS_SILENCE",
sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Preflight => "OFFLINE_PREFLIGHT",
sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Render => "OFFLINE_RENDER",
sys::AudioUnitRenderActionFlags_kAudioOfflineUnitRenderAction_Complete => "OFFLINE_COMPLETE",
sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_PostRenderError => "POST_RENDER_ERROR",
sys::AudioUnitRenderActionFlags_kAudioUnitRenderAction_DoNotCheckRenderArgs => "DO_NOT_CHECK_RENDER_ARGS",
_ => "<Unknown ActionFlags>",

})
}
}
}

Expand All @@ -398,7 +429,7 @@ impl AudioUnit {
// First, we'll retrieve the stream format so that we can ensure that the given callback
// format matches the audio unit's format.
let id = sys::kAudioUnitProperty_StreamFormat;
let asbd = try!(self.get_property(id, Scope::Output, Element::Output));
let asbd = self.get_property(id, Scope::Output, Element::Output)?;
let stream_format = super::StreamFormat::from_asbd(asbd)?;

// If the stream format does not match, return an error indicating this.
Expand Down Expand Up @@ -482,7 +513,11 @@ impl AudioUnit {
// Pre-allocate a buffer list for input stream.
//
// First, get the current buffer size for pre-allocating the `AudioBuffer`s.
#[cfg(target_os = "ios")]
let id = sys::kAudioSessionProperty_CurrentHardwareIOBufferDuration;
#[cfg(target_os = "macos")]
let id = sys::kAudioDevicePropertyBufferFrameSize;

let mut buffer_frame_size: u32 = self.get_property(id, Scope::Global, Element::Output)?;
let mut data: Vec<u8> = vec![];
let sample_bytes = stream_format.sample_format.size_in_bytes();
Expand Down