Skip to content

Commit 2aaf419

Browse files
committed
Update to windows crate v0.32
1 parent 4bdb045 commit 2aaf419

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "wasapi"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
edition = "2018"
55
authors = ["HEnquist <henrik.enquist@gmail.com>"]
66
description = "Bindings for the Wasapi API on Windows"
@@ -12,8 +12,9 @@ readme = "README.md"
1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1313

1414
[dependencies.windows]
15-
version = "0.30.0"
15+
version = "0.32.0"
1616
features = ["Foundation",
17+
"implement",
1718
"Win32_Media_Audio",
1819
"Win32_Foundation",
1920
"Win32_Devices_Properties",
@@ -28,7 +29,6 @@ features = ["Foundation",
2829
[dependencies]
2930
widestring = "0.5.1"
3031
log = "0.4.14"
31-
windows_macros = "0.30.0"
3232

3333
[dev-dependencies]
3434
simplelog = "0.11.2"

src/api.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl Device {
193193

194194
/// Read the FriendlyName of an IMMDevice
195195
pub fn get_friendlyname(&self) -> WasapiRes<String> {
196-
let store = unsafe { self.device.OpenPropertyStore(STGM_READ as u32)? };
196+
let store = unsafe { self.device.OpenPropertyStore(STGM_READ)? };
197197
let prop = unsafe { store.GetValue(&DEVPKEY_Device_FriendlyName)? };
198198
let propstr = unsafe { PropVariantToStringAlloc(&prop)? };
199199
let wide_name = unsafe { U16CString::from_ptr_str(propstr.0) };
@@ -204,7 +204,7 @@ impl Device {
204204

205205
/// Read the Description of an IMMDevice
206206
pub fn get_description(&self) -> WasapiRes<String> {
207-
let store = unsafe { self.device.OpenPropertyStore(STGM_READ as u32)? };
207+
let store = unsafe { self.device.OpenPropertyStore(STGM_READ)? };
208208
let prop = unsafe { store.GetValue(&DEVPKEY_Device_DeviceDesc)? };
209209
let propstr = unsafe { PropVariantToStringAlloc(&prop)? };
210210
let wide_desc = unsafe { U16CString::from_ptr_str(propstr.0) };
@@ -625,23 +625,23 @@ impl BufferFlags {
625625
/// Create a new BufferFlags struct from a u32 value.
626626
pub fn new(flags: u32) -> Self {
627627
BufferFlags {
628-
data_discontinuity: flags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY as u32 > 0,
629-
silent: flags & AUDCLNT_BUFFERFLAGS_SILENT as u32 > 0,
630-
timestamp_error: flags & AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR as u32 > 0,
628+
data_discontinuity: flags & AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY.0 as u32 > 0,
629+
silent: flags & AUDCLNT_BUFFERFLAGS_SILENT.0 as u32 > 0,
630+
timestamp_error: flags & AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR.0 as u32 > 0,
631631
}
632632
}
633633

634634
/// Convert a BufferFlags struct to a u32 value.
635635
pub fn to_u32(&self) -> u32 {
636636
let mut value = 0;
637637
if self.data_discontinuity {
638-
value += AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY as u32;
638+
value += AUDCLNT_BUFFERFLAGS_DATA_DISCONTINUITY.0 as u32;
639639
}
640640
if self.silent {
641-
value += AUDCLNT_BUFFERFLAGS_SILENT as u32;
641+
value += AUDCLNT_BUFFERFLAGS_SILENT.0 as u32;
642642
}
643643
if self.timestamp_error {
644-
value += AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR as u32;
644+
value += AUDCLNT_BUFFERFLAGS_TIMESTAMP_ERROR.0 as u32;
645645
}
646646
value
647647
}

src/events.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ use std::rc::Weak;
22
use std::slice;
33
use widestring::U16CString;
44
use windows::{
5-
core::{GUID, HRESULT},
6-
Win32::Foundation::{BOOL, PWSTR, S_OK},
5+
core::{implement, Result, GUID},
6+
Win32::Foundation::{BOOL, PWSTR},
77
Win32::Media::Audio::{
88
AudioSessionDisconnectReason, AudioSessionState, AudioSessionStateActive,
99
AudioSessionStateExpired, AudioSessionStateInactive, DisconnectReasonDeviceRemoval,
1010
DisconnectReasonExclusiveModeOverride, DisconnectReasonFormatChanged,
1111
DisconnectReasonServerShutdown, DisconnectReasonSessionDisconnected,
12-
DisconnectReasonSessionLogoff,
12+
DisconnectReasonSessionLogoff, IAudioSessionEvents, IAudioSessionEvents_Impl,
1313
},
1414
};
15-
use windows_macros::implement;
16-
// Workaround for implement macro
17-
use windows as Windows;
1815

1916
use crate::SessionState;
2017

@@ -128,20 +125,20 @@ pub enum DisconnectReason {
128125
}
129126

130127
/// Wrapper for [IAudioSessionEvents](https://docs.microsoft.com/en-us/windows/win32/api/audiopolicy/nn-audiopolicy-iaudiosessionevents).
131-
#[implement(Windows::Win32::Media::Audio::IAudioSessionEvents)]
128+
#[implement(IAudioSessionEvents)]
132129
pub(crate) struct AudioSessionEvents {
133130
callbacks: Weak<EventCallbacks>,
134131
}
135132

136-
#[allow(non_snake_case)]
137133
impl AudioSessionEvents {
138134
/// Create a new AudioSessionEvents instance, returned as a IAudioSessionEvent.
139-
#[allow(clippy::new_ret_no_self)]
140135
pub fn new(callbacks: Weak<EventCallbacks>) -> Self {
141136
Self { callbacks }
142137
}
138+
}
143139

144-
fn OnStateChanged(&mut self, newstate: AudioSessionState) -> HRESULT {
140+
impl IAudioSessionEvents_Impl for AudioSessionEvents {
141+
fn OnStateChanged(&mut self, newstate: AudioSessionState) -> Result<()> {
145142
#[allow(non_upper_case_globals)]
146143
let state_name = match newstate {
147144
AudioSessionStateActive => "Active",
@@ -155,17 +152,20 @@ impl AudioSessionEvents {
155152
AudioSessionStateActive => SessionState::Active,
156153
AudioSessionStateInactive => SessionState::Inactive,
157154
AudioSessionStateExpired => SessionState::Expired,
158-
_ => return S_OK,
155+
_ => return Ok(()),
159156
};
160157
if let Some(callbacks) = &mut self.callbacks.upgrade() {
161158
if let Some(callback) = &callbacks.state {
162159
callback(sessionstate);
163160
}
164161
}
165-
S_OK
162+
Ok(())
166163
}
167164

168-
fn OnSessionDisconnected(&mut self, disconnectreason: AudioSessionDisconnectReason) -> HRESULT {
165+
fn OnSessionDisconnected(
166+
&mut self,
167+
disconnectreason: AudioSessionDisconnectReason,
168+
) -> Result<()> {
169169
trace!("Disconnected");
170170
#[allow(non_upper_case_globals)]
171171
let reason = match disconnectreason {
@@ -183,14 +183,14 @@ impl AudioSessionEvents {
183183
callback(reason);
184184
}
185185
}
186-
S_OK
186+
Ok(())
187187
}
188188

189189
fn OnDisplayNameChanged(
190190
&mut self,
191191
newdisplayname: PWSTR,
192192
eventcontext: *const GUID,
193-
) -> HRESULT {
193+
) -> Result<()> {
194194
let wide_name = unsafe { U16CString::from_ptr_str(newdisplayname.0) };
195195
let name = wide_name.to_string_lossy();
196196
trace!("New display name: {}", name);
@@ -200,10 +200,10 @@ impl AudioSessionEvents {
200200
callback(name, context);
201201
}
202202
}
203-
S_OK
203+
Ok(())
204204
}
205205

206-
fn OnIconPathChanged(&mut self, newiconpath: PWSTR, eventcontext: *const GUID) -> HRESULT {
206+
fn OnIconPathChanged(&mut self, newiconpath: PWSTR, eventcontext: *const GUID) -> Result<()> {
207207
let wide_path = unsafe { U16CString::from_ptr_str(newiconpath.0) };
208208
let path = wide_path.to_string_lossy();
209209
trace!("New icon path: {}", path);
@@ -213,23 +213,23 @@ impl AudioSessionEvents {
213213
callback(path, context);
214214
}
215215
}
216-
S_OK
216+
Ok(())
217217
}
218218

219219
fn OnSimpleVolumeChanged(
220220
&mut self,
221221
newvolume: f32,
222222
newmute: BOOL,
223223
eventcontext: *const GUID,
224-
) -> HRESULT {
224+
) -> Result<()> {
225225
trace!("New volume: {}, mute: {:?}", newvolume, newmute);
226226
if let Some(callbacks) = &mut self.callbacks.upgrade() {
227227
if let Some(callback) = &callbacks.simple_volume {
228228
let context = unsafe { *eventcontext };
229229
callback(newvolume, bool::from(newmute), context);
230230
}
231231
}
232-
S_OK
232+
Ok(())
233233
}
234234

235235
fn OnChannelVolumeChanged(
@@ -238,7 +238,7 @@ impl AudioSessionEvents {
238238
newchannelvolumearray: *const f32,
239239
changedchannel: u32,
240240
eventcontext: *const GUID,
241-
) -> HRESULT {
241+
) -> Result<()> {
242242
trace!("New channel volume for channel: {}", changedchannel);
243243
let volslice =
244244
unsafe { slice::from_raw_parts(newchannelvolumearray, channelcount as usize) };
@@ -249,14 +249,14 @@ impl AudioSessionEvents {
249249
callback(changedchannel as usize, newvol, context);
250250
}
251251
}
252-
S_OK
252+
Ok(())
253253
}
254254

255255
fn OnGroupingParamChanged(
256256
&mut self,
257257
newgroupingparam: *const GUID,
258258
eventcontext: *const GUID,
259-
) -> HRESULT {
259+
) -> Result<()> {
260260
trace!("Grouping changed");
261261
if let Some(callbacks) = &mut self.callbacks.upgrade() {
262262
if let Some(callback) = &callbacks.groupingparam {
@@ -265,6 +265,6 @@ impl AudioSessionEvents {
265265
callback(grouping, context);
266266
}
267267
}
268-
S_OK
268+
Ok(())
269269
}
270270
}

0 commit comments

Comments
 (0)