@@ -113,12 +113,16 @@ impl Iterator for Devices {
113
113
}
114
114
}
115
115
116
+ struct SioHdl ( * mut sndio_sys:: sio_hdl ) ;
117
+
118
+ unsafe impl Send for SioHdl { }
119
+
116
120
/// The shared state between Device and Stream. Responsible for closing handle when dropped.
117
121
struct InnerState {
118
122
/// If device has been open with sio_open, contains a handle. Note that even though this is a
119
123
/// pointer type and so doesn't follow Rust's borrowing rules, we should be careful not to copy
120
124
/// it out because that may render Mutex<InnerState> ineffective in enforcing exclusive access.
121
- hdl : Option < * mut sndio_sys :: sio_hdl > ,
125
+ hdl : Option < SioHdl > ,
122
126
123
127
/// Buffer overrun/underrun behavior -- ignore/sync/error?
124
128
behavior : BufferXrunBehavior ,
@@ -159,8 +163,6 @@ struct OutputCallbacks {
159
163
error_callback : Box < dyn FnMut ( StreamError ) + Send + ' static > ,
160
164
}
161
165
162
- unsafe impl Send for InnerState { }
163
-
164
166
#[ derive( Debug , Copy , Clone , Eq , PartialEq ) ]
165
167
enum Status {
166
168
/// Initial state. No thread running. Device/Stream methods will start thread and change this
@@ -205,7 +207,7 @@ impl InnerState {
205
207
if hdl. is_null ( ) {
206
208
return Err ( SndioError :: DeviceNotAvailable ) ;
207
209
}
208
- self . hdl = Some ( hdl) ;
210
+ self . hdl = Some ( SioHdl ( hdl) ) ;
209
211
210
212
let mut sample_rate_to_par = HashMap :: new ( ) ;
211
213
for rate in SUPPORTED_SAMPLE_RATES {
@@ -267,7 +269,7 @@ impl InnerState {
267
269
// will wait for playback data to be provided (using the sio_write()
268
270
// function). Once enough data is queued to ensure that play buffers will
269
271
// not underrun, actual playback is started automatically."
270
- sndio_sys:: sio_start ( self . hdl . unwrap ( ) ) // Unwrap OK because of check above
272
+ sndio_sys:: sio_start ( self . hdl . as_ref ( ) . unwrap ( ) . 0 ) // Unwrap OK because of check above
271
273
} ;
272
274
if status != 1 {
273
275
return Err ( backend_specific_error ( "failed to start stream" ) ) ;
@@ -286,7 +288,7 @@ impl InnerState {
286
288
// playback. If samples to play are queued but playback hasn't started yet then
287
289
// playback is forced immediately; playback will actually stop once the buffer is
288
290
// drained. In no case are samples in the play buffer discarded.
289
- sndio_sys:: sio_stop ( self . hdl . unwrap ( ) ) // Unwrap OK because of check above
291
+ sndio_sys:: sio_stop ( self . hdl . as_ref ( ) . unwrap ( ) . 0 ) // Unwrap OK because of check above
290
292
} ;
291
293
if status != 1 {
292
294
return Err ( backend_specific_error ( "error calling sio_stop" ) ) ;
@@ -385,7 +387,7 @@ impl InnerState {
385
387
386
388
let status = unsafe {
387
389
// Retrieve the actual parameters of the device.
388
- sndio_sys:: sio_getpar ( self . hdl . unwrap ( ) , par as * mut _ )
390
+ sndio_sys:: sio_getpar ( self . hdl . as_ref ( ) . unwrap ( ) . 0 , par as * mut _ )
389
391
} ;
390
392
if status != 1 {
391
393
return Err ( backend_specific_error (
@@ -439,7 +441,7 @@ impl InnerState {
439
441
let status = unsafe {
440
442
// Request the device using our parameters
441
443
// unwrap OK because of the check at the top of this function.
442
- sndio_sys:: sio_setpar ( self . hdl . unwrap ( ) , & mut newpar as * mut _ )
444
+ sndio_sys:: sio_setpar ( self . hdl . as_ref ( ) . unwrap ( ) . 0 , & mut newpar as * mut _ )
443
445
} ;
444
446
if status != 1 {
445
447
return Err ( backend_specific_error ( "failed to set parameters with sio_setpar" ) . into ( ) ) ;
@@ -452,7 +454,7 @@ impl Drop for InnerState {
452
454
fn drop ( & mut self ) {
453
455
if let Some ( hdl) = self . hdl . take ( ) {
454
456
unsafe {
455
- sndio_sys:: sio_close ( hdl) ;
457
+ sndio_sys:: sio_close ( hdl. 0 ) ;
456
458
}
457
459
}
458
460
}
0 commit comments