Skip to content

Fix deprecation warnings #74

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

Merged
Merged
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
14 changes: 8 additions & 6 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 @@ -156,10 +156,11 @@ impl AudioUnit {
}

// Create an instance of the default audio unit using the component.
let mut instance: sys::AudioUnit = mem::uninitialized();
let mut instance_uninit = mem::MaybeUninit::<sys::AudioUnit>::uninit();
try_os_status!(
sys::AudioComponentInstanceNew(component, &mut instance as *mut sys::AudioUnit)
sys::AudioComponentInstanceNew(component, instance_uninit.as_mut_ptr() as *mut sys::AudioUnit)
);
let instance: sys::AudioUnit = instance_uninit.assume_init();

// Initialise the audio unit!
try_os_status!(sys::AudioUnitInitialize(instance));
Expand Down Expand Up @@ -290,7 +291,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 Expand Up @@ -391,12 +392,13 @@ pub fn get_property<T>(
let elem = elem as c_uint;
let mut size = ::std::mem::size_of::<T>() as u32;
unsafe {
let mut data: T = ::std::mem::uninitialized();
let data_ptr = &mut data as *mut _ as *mut c_void;
let mut data_uninit = ::std::mem::MaybeUninit::<T>::uninit();
let data_ptr = data_uninit.as_mut_ptr() as *mut _ as *mut c_void;
let size_ptr = &mut size as *mut _;
try_os_status!(
sys::AudioUnitGetProperty(au, id, scope, elem, data_ptr, size_ptr)
);
let data: T = data_uninit.assume_init();
Ok(data)
}
}
Expand Down
4 changes: 2 additions & 2 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 @@ -398,7 +398,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::Input, Element::Output));
let asbd = self.get_property(id, Scope::Input, Element::Output)?;
let stream_format = super::StreamFormat::from_asbd(asbd)?;

// If the stream format does not match, return an error indicating this.
Expand Down
71 changes: 22 additions & 49 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ pub mod audio {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
let description = match *self {
Error::Unimplemented => "Unimplemented",
Error::FileNotFound => "File not found",
Error::FilePermission => "File permission",
Expand All @@ -60,7 +54,8 @@ pub mod audio {
Error::Param => "Param",
Error::MemFull => "Memory full",
Error::Unknown => "An unknown error occurred",
}
};
write!(f, "{}", description)
}
}

Expand Down Expand Up @@ -106,13 +101,7 @@ pub mod audio_codec {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
let description = match *self {
Error::Unspecified => "Unspecified",
Error::UnknownProperty => "Unknown property",
Error::BadPropertySize => "Bad property size",
Expand All @@ -121,7 +110,8 @@ pub mod audio_codec {
Error::State => "State",
Error::NotEnoughBufferSpace => "Not enough buffer space",
Error::Unknown => "Unknown error occurred",
}
};
write!(f, "{}", description)
}
}

Expand Down Expand Up @@ -161,21 +151,16 @@ pub mod audio_format {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
let description = match *self {
Error::Unspecified => "An unspecified error",
Error::UnsupportedProperty => "The specified property is not supported",
Error::BadPropertySize => "Bad property size",
Error::BadSpecifierSize => "Bad specifier size",
Error::UnsupportedDataFormat => "The specified data format is not supported",
Error::UnknownFormat => "The specified data format is not a known format",
Error::Unknown => "Unknown error occurred",
}
};
write!(f, "{}", description)
}
}
}
Expand Down Expand Up @@ -239,13 +224,7 @@ pub mod audio_unit {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
let description = match *self {
Error::InvalidProperty => "Invalid property",
Error::InvalidParameter => "Invalid parameter",
Error::InvalidElement => "Invalid element",
Expand All @@ -264,7 +243,8 @@ pub mod audio_unit {
Error::InvalidOfflineRender => "Invalid offline render",
Error::Unauthorized => "Unauthorized",
Error::Unknown => "Unknown error occurred",
}
};
write!(f, "{}", description)
}
}

Expand Down Expand Up @@ -338,25 +318,18 @@ impl Error {

impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
write!(f, "{:?}", self)
}
}

impl ::std::error::Error for Error {
fn description(&self) -> &str {
match *self {
Error::Unspecified => "An unspecified error has occurred",
Error::NoMatchingDefaultAudioUnitFound => "No matching default audio unit found",
Error::Unspecified => write!(f, "An unspecified error has occurred"),
Error::NoMatchingDefaultAudioUnitFound => write!(f, "No matching default audio unit found"),
Error::RenderCallbackBufferFormatDoesNotMatchAudioUnitStreamFormat =>
"The given render callback buffer format does not match the `AudioUnit` `StreamFormat`",
Error::SystemSoundClientMessageTimedOut => "The system sound client message timed out",
Error::NoKnownSubtype => "The type has no known subtypes",
Error::Audio(ref err) => err.description(),
Error::AudioCodec(ref err) => err.description(),
Error::AudioFormat(ref err) => err.description(),
Error::AudioUnit(ref err) => err.description(),
Error::Unknown(_) => "An unknown error unknown to the coreaudio-rs API occurred",
write!(f, "The given render callback buffer format does not match the `AudioUnit` `StreamFormat`"),
Error::SystemSoundClientMessageTimedOut => write!(f, "The system sound client message timed out"),
Error::NoKnownSubtype => write!(f, "The type has no known subtypes"),
Error::Audio(ref err) => write!(f, "{}", err),
Error::AudioCodec(ref err) => write!(f, "{}", err),
Error::AudioFormat(ref err) => write!(f, "{}", err),
Error::AudioUnit(ref err) => write!(f, "{}", err),
Error::Unknown(_) => write!(f, "An unknown error unknown to the coreaudio-rs API occurred"),
}
}
}