Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonoughe committed May 13, 2020
1 parent 135bc05 commit 9729ad8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
5 changes: 5 additions & 0 deletions src/ctsndcr.rs
Expand Up @@ -187,6 +187,11 @@ impl ICallback {
/// `IEventNotify` allows a single `ICallback` instance to be registered
/// for event notifications, but implementing `ICallback` requires a lot
/// of COM glue that we shouldn't need to worry about.
///
/// # Safety
///
/// You must call IUnknown.Release on the returned object when you are done
/// with it.
#[allow(clippy::new_ret_no_self)]
pub unsafe fn new<C>(callback: C) -> *mut Self
where
Expand Down
37 changes: 25 additions & 12 deletions src/media/mod.rs
Expand Up @@ -134,10 +134,10 @@ impl Endpoint {
.get_or_create(|| unsafe {
trace!(self.logger, "Opening PropertyStore...");
let mut property_store = MaybeUninit::uninit();
check(self.device.OpenPropertyStore(
STGM_READ,
property_store.as_mut_ptr(),
))?;
check(
self.device
.OpenPropertyStore(STGM_READ, property_store.as_mut_ptr()),
)?;
Ok(PropertyStore(
ComObject::take(property_store.assume_init()),
self.logger.clone(),
Expand Down Expand Up @@ -330,7 +330,10 @@ impl DeviceEnumerator {
enumerator.as_mut_ptr() as *mut _,
))?;
trace!(logger, "Created DeviceEnumerator");
Ok(DeviceEnumerator(ComObject::take(enumerator.assume_init()), logger))
Ok(DeviceEnumerator(
ComObject::take(enumerator.assume_init()),
logger,
))
}
}
/// Gets all active audio outputs.
Expand All @@ -339,18 +342,22 @@ impl DeviceEnumerator {
unsafe {
trace!(self.1, "Getting active endpoints...");
let mut collection = MaybeUninit::uninit();
check(
self.0
.EnumAudioEndpoints(eRender, DEVICE_STATE_ACTIVE, collection.as_mut_ptr()),
)?;
check(self.0.EnumAudioEndpoints(
eRender,
DEVICE_STATE_ACTIVE,
collection.as_mut_ptr(),
))?;
let collection = collection.assume_init();
let mut count = 0;
check((*collection).GetCount(&mut count))?;
let mut result = Vec::with_capacity(count as usize);
for i in 0..count {
let mut device = MaybeUninit::uninit();
check((*collection).Item(i, device.as_mut_ptr()))?;
result.push(Endpoint::new(ComObject::take(device.assume_init()), self.1.clone()))
result.push(Endpoint::new(
ComObject::take(device.assume_init()),
self.1.clone(),
))
}
Ok(result)
}
Expand All @@ -368,7 +375,10 @@ impl DeviceEnumerator {
self.0
.GetDefaultAudioEndpoint(eRender, eConsole, device.as_mut_ptr()),
)?;
Ok(Endpoint::new(ComObject::take(device.assume_init()), self.1.clone()))
Ok(Endpoint::new(
ComObject::take(device.assume_init()),
self.1.clone(),
))
}
}
/// Get a specific audio endpoint by its ID.
Expand All @@ -378,7 +388,10 @@ impl DeviceEnumerator {
unsafe {
let mut device = MaybeUninit::uninit();
check(self.0.GetDevice(buffer.as_ptr(), device.as_mut_ptr()))?;
Ok(Endpoint::new(ComObject::take(device.assume_init()), self.1.clone()))
Ok(Endpoint::new(
ComObject::take(device.assume_init()),
self.1.clone(),
))
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/soundcore/core.rs
Expand Up @@ -96,10 +96,10 @@ impl SoundCore {
pub(crate) fn event_stream(&self) -> Result<SoundCoreEvents, Win32Error> {
unsafe {
let mut event_notify = MaybeUninit::<*mut IEventNotify>::uninit();
check(self.sound_core.QueryInterface(
&IEventNotify::uuidof(),
event_notify.as_mut_ptr() as *mut _,
))?;
check(
self.sound_core
.QueryInterface(&IEventNotify::uuidof(), event_notify.as_mut_ptr() as *mut _),
)?;
Ok(SoundCoreEvents::new(
ComObject::take(event_notify.assume_init()),
self.sound_core.clone(),
Expand Down
2 changes: 1 addition & 1 deletion src/soundcore/parameter.rs
Expand Up @@ -153,7 +153,7 @@ impl SoundCoreParameter {
_ => panic!("tried to set parameter with nothing"),
},
value: match *value {
SoundCoreParamValue::Float(f) => mem::transmute(f),
SoundCoreParamValue::Float(f) => f.to_bits(),
SoundCoreParamValue::Bool(b) => {
if b {
0xffff_ffff
Expand Down

0 comments on commit 9729ad8

Please sign in to comment.