1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
|
// Copyright © 2017-2018 Mozilla Foundation
//
// This program is made available under an ISC-style license. See the
// accompanying file LICENSE for details.
use backend::*;
use cubeb_backend::{
ffi, log_enabled, Context, ContextOps, DeviceCollectionRef, DeviceId, DeviceType, Error, Ops,
Result, Stream, StreamParams, StreamParamsRef,
};
use pulse::{self, ProplistExt};
use pulse_ffi::*;
use semver;
use std::cell::RefCell;
use std::default::Default;
use std::ffi::{CStr, CString};
use std::mem;
use std::os::raw::c_void;
use std::ptr;
#[derive(Debug)]
pub struct DefaultInfo {
pub sample_spec: pulse::SampleSpec,
pub channel_map: pulse::ChannelMap,
pub flags: pulse::SinkFlags,
}
pub const PULSE_OPS: Ops = capi_new!(PulseContext, PulseStream);
#[repr(C)]
#[derive(Debug)]
pub struct PulseContext {
_ops: *const Ops,
pub mainloop: pulse::ThreadedMainloop,
pub context: Option<pulse::Context>,
pub default_sink_info: Option<DefaultInfo>,
pub context_name: Option<CString>,
pub input_collection_changed_callback: ffi::cubeb_device_collection_changed_callback,
pub input_collection_changed_user_ptr: *mut c_void,
pub output_collection_changed_callback: ffi::cubeb_device_collection_changed_callback,
pub output_collection_changed_user_ptr: *mut c_void,
pub error: bool,
pub version_2_0_0: bool,
pub version_0_9_8: bool,
#[cfg(feature = "pulse-dlopen")]
pub libpulse: LibLoader,
devids: RefCell<Intern>,
}
impl PulseContext {
#[cfg(feature = "pulse-dlopen")]
fn _new(name: Option<CString>) -> Result<Box<Self>> {
let libpulse = unsafe { open() };
if libpulse.is_none() {
cubeb_log!("libpulse not found");
return Err(Error::error());
}
let ctx = Box::new(PulseContext {
_ops: &PULSE_OPS,
libpulse: libpulse.unwrap(),
mainloop: pulse::ThreadedMainloop::new(),
context: None,
default_sink_info: None,
context_name: name,
input_collection_changed_callback: None,
input_collection_changed_user_ptr: ptr::null_mut(),
output_collection_changed_callback: None,
output_collection_changed_user_ptr: ptr::null_mut(),
error: true,
version_0_9_8: false,
version_2_0_0: false,
devids: RefCell::new(Intern::new()),
});
Ok(ctx)
}
#[cfg(not(feature = "pulse-dlopen"))]
fn _new(name: Option<CString>) -> Result<Box<Self>> {
Ok(Box::new(PulseContext {
_ops: &PULSE_OPS,
mainloop: pulse::ThreadedMainloop::new(),
context: None,
default_sink_info: None,
context_name: name,
input_collection_changed_callback: None,
input_collection_changed_user_ptr: ptr::null_mut(),
output_collection_changed_callback: None,
output_collection_changed_user_ptr: ptr::null_mut(),
error: true,
version_0_9_8: false,
version_2_0_0: false,
devids: RefCell::new(Intern::new()),
}))
}
fn server_info_cb(context: &pulse::Context, info: Option<&pulse::ServerInfo>, u: *mut c_void) {
fn sink_info_cb(_: &pulse::Context, i: *const pulse::SinkInfo, eol: i32, u: *mut c_void) {
let ctx = unsafe { &mut *(u as *mut PulseContext) };
if eol == 0 {
let info = unsafe { &*i };
let flags = pulse::SinkFlags::from_bits_truncate(info.flags);
ctx.default_sink_info = Some(DefaultInfo {
sample_spec: info.sample_spec,
channel_map: info.channel_map,
flags,
});
}
ctx.mainloop.signal();
}
if let Some(info) = info {
let _ = context.get_sink_info_by_name(
try_cstr_from(info.default_sink_name),
sink_info_cb,
u,
);
} else {
// If info is None, then an error occured.
let ctx = unsafe { &mut *(u as *mut PulseContext) };
ctx.mainloop.signal();
}
}
fn new(name: Option<&CStr>) -> Result<Box<Self>> {
let name = name.map(|s| s.to_owned());
let mut ctx = PulseContext::_new(name)?;
if ctx.mainloop.start().is_err() {
ctx.destroy();
cubeb_log!("Error: couldn't start pulse's mainloop");
return Err(Error::error());
}
if ctx.context_init().is_err() {
ctx.destroy();
cubeb_log!("Error: couldn't init pulse's context");
return Err(Error::error());
}
ctx.mainloop.lock();
/* server_info_callback performs a second async query,
* which is responsible for initializing default_sink_info
* and signalling the mainloop to end the wait. */
let user_data: *mut c_void = ctx.as_mut() as *mut _ as *mut _;
if let Some(ref context) = ctx.context {
if let Ok(o) = context.get_server_info(PulseContext::server_info_cb, user_data) {
ctx.operation_wait(None, &o);
}
}
ctx.mainloop.unlock();
/* Update `default_sink_info` when the default device changes. */
if let Err(e) = ctx.subscribe_notifications(pulse::SubscriptionMask::SERVER) {
cubeb_log!("subscribe_notifications ignored failure: {}", e);
}
// Return the result.
Ok(ctx)
}
pub fn destroy(&mut self) {
self.context_destroy();
if !self.mainloop.is_null() {
self.mainloop.stop();
}
}
fn subscribe_notifications(&mut self, mask: pulse::SubscriptionMask) -> Result<()> {
fn update_collection(
_: &pulse::Context,
event: pulse::SubscriptionEvent,
index: u32,
user_data: *mut c_void,
) {
let ctx = unsafe { &mut *(user_data as *mut PulseContext) };
let (f, t) = (event.event_facility(), event.event_type());
if (f == pulse::SubscriptionEventFacility::Source)
| (f == pulse::SubscriptionEventFacility::Sink)
{
if (t == pulse::SubscriptionEventType::Remove)
| (t == pulse::SubscriptionEventType::New)
{
if log_enabled() {
let op = if t == pulse::SubscriptionEventType::New {
"Adding"
} else {
"Removing"
};
let dev = if f == pulse::SubscriptionEventFacility::Sink {
"sink"
} else {
"source "
};
cubeb_log!("{} {} index {}", op, dev, index);
}
if f == pulse::SubscriptionEventFacility::Source {
unsafe {
ctx.input_collection_changed_callback.unwrap()(
ctx as *mut _ as *mut _,
ctx.input_collection_changed_user_ptr,
);
}
}
if f == pulse::SubscriptionEventFacility::Sink {
unsafe {
ctx.output_collection_changed_callback.unwrap()(
ctx as *mut _ as *mut _,
ctx.output_collection_changed_user_ptr,
);
}
}
}
} else if (f == pulse::SubscriptionEventFacility::Server)
&& (t == pulse::SubscriptionEventType::Change)
{
cubeb_log!("Server changed {}", index as i32);
let user_data: *mut c_void = ctx as *mut _ as *mut _;
if let Some(ref context) = ctx.context {
if let Err(e) = context.get_server_info(PulseContext::server_info_cb, user_data)
{
cubeb_log!("Error: get_server_info ignored failure: {}", e);
}
}
}
}
fn success(_: &pulse::Context, success: i32, user_data: *mut c_void) {
let ctx = unsafe { &*(user_data as *mut PulseContext) };
if success != 1 {
cubeb_log!("subscribe_success ignored failure: {}", success);
}
ctx.mainloop.signal();
}
let user_data: *mut c_void = self as *const _ as *mut _;
if let Some(ref context) = self.context {
self.mainloop.lock();
context.set_subscribe_callback(update_collection, user_data);
if let Ok(o) = context.subscribe(mask, success, self as *const _ as *mut _) {
self.operation_wait(None, &o);
} else {
self.mainloop.unlock();
cubeb_log!("Error: context subscribe failed");
return Err(Error::error());
}
self.mainloop.unlock();
}
Ok(())
}
}
impl ContextOps for PulseContext {
fn init(context_name: Option<&CStr>) -> Result<Context> {
let ctx = PulseContext::new(context_name)?;
Ok(unsafe { Context::from_ptr(Box::into_raw(ctx) as *mut _) })
}
fn backend_id(&mut self) -> &'static CStr {
unsafe { CStr::from_ptr(b"pulse-rust\0".as_ptr() as *const _) }
}
fn max_channel_count(&mut self) -> Result<u32> {
match self.default_sink_info {
Some(ref info) => Ok(u32::from(info.channel_map.channels)),
None => {
cubeb_log!("Error: couldn't get the max channel count");
Err(Error::error())
}
}
}
fn min_latency(&mut self, params: StreamParams) -> Result<u32> {
// According to PulseAudio developers, this is a safe minimum.
Ok(25 * params.rate() / 1000)
}
fn preferred_sample_rate(&mut self) -> Result<u32> {
match self.default_sink_info {
Some(ref info) => Ok(info.sample_spec.rate),
None => {
cubeb_log!("Error: Couldn't get the preferred sample rate");
Err(Error::error())
}
}
}
fn enumerate_devices(
&mut self,
devtype: DeviceType,
collection: &DeviceCollectionRef,
) -> Result<()> {
fn add_output_device(
_: &pulse::Context,
i: *const pulse::SinkInfo,
eol: i32,
user_data: *mut c_void,
) {
let list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
let ctx = list_data.context;
if eol != 0 {
ctx.mainloop.signal();
return;
}
debug_assert!(!i.is_null());
debug_assert!(!user_data.is_null());
let info = unsafe { &*i };
let group_id = match info.proplist().gets("sysfs.path") {
Some(p) => p.to_owned().into_raw(),
_ => ptr::null_mut(),
};
let vendor_name = match info.proplist().gets("device.vendor.name") {
Some(p) => p.to_owned().into_raw(),
_ => ptr::null_mut(),
};
let info_name = unsafe { CStr::from_ptr(info.name) };
let info_description = unsafe { CStr::from_ptr(info.description) }.to_owned();
let preferred = if *info_name == *list_data.default_sink_name {
ffi::CUBEB_DEVICE_PREF_ALL
} else {
ffi::CUBEB_DEVICE_PREF_NONE
};
let device_id = ctx.devids.borrow_mut().add(info_name);
let friendly_name = info_description.into_raw();
let devinfo = ffi::cubeb_device_info {
device_id,
devid: device_id as ffi::cubeb_devid,
friendly_name,
group_id,
vendor_name,
device_type: ffi::CUBEB_DEVICE_TYPE_OUTPUT,
state: ctx.state_from_port(info.active_port),
preferred,
format: ffi::CUBEB_DEVICE_FMT_ALL,
default_format: pulse_format_to_cubeb_format(info.sample_spec.format),
max_channels: u32::from(info.channel_map.channels),
min_rate: 1,
max_rate: PA_RATE_MAX,
default_rate: info.sample_spec.rate,
latency_lo: 0,
latency_hi: 0,
};
list_data.devinfo.push(devinfo);
}
fn add_input_device(
_: &pulse::Context,
i: *const pulse::SourceInfo,
eol: i32,
user_data: *mut c_void,
) {
let list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
let ctx = list_data.context;
if eol != 0 {
ctx.mainloop.signal();
return;
}
debug_assert!(!user_data.is_null());
debug_assert!(!i.is_null());
let info = unsafe { &*i };
let group_id = match info.proplist().gets("sysfs.path") {
Some(p) => p.to_owned().into_raw(),
_ => ptr::null_mut(),
};
let vendor_name = match info.proplist().gets("device.vendor.name") {
Some(p) => p.to_owned().into_raw(),
_ => ptr::null_mut(),
};
let info_name = unsafe { CStr::from_ptr(info.name) };
let info_description = unsafe { CStr::from_ptr(info.description) }.to_owned();
let preferred = if *info_name == *list_data.default_source_name {
ffi::CUBEB_DEVICE_PREF_ALL
} else {
ffi::CUBEB_DEVICE_PREF_NONE
};
let device_id = ctx.devids.borrow_mut().add(info_name);
let friendly_name = info_description.into_raw();
let devinfo = ffi::cubeb_device_info {
device_id,
devid: device_id as ffi::cubeb_devid,
friendly_name,
group_id,
vendor_name,
device_type: ffi::CUBEB_DEVICE_TYPE_INPUT,
state: ctx.state_from_port(info.active_port),
preferred,
format: ffi::CUBEB_DEVICE_FMT_ALL,
default_format: pulse_format_to_cubeb_format(info.sample_spec.format),
max_channels: u32::from(info.channel_map.channels),
min_rate: 1,
max_rate: PA_RATE_MAX,
default_rate: info.sample_spec.rate,
latency_lo: 0,
latency_hi: 0,
};
list_data.devinfo.push(devinfo);
}
fn default_device_names(
_: &pulse::Context,
info: Option<&pulse::ServerInfo>,
user_data: *mut c_void,
) {
let list_data = unsafe { &mut *(user_data as *mut PulseDevListData) };
if let Some(info) = info {
list_data.default_sink_name = super::try_cstr_from(info.default_sink_name)
.map(|s| s.to_owned())
.unwrap_or_default();
list_data.default_source_name = super::try_cstr_from(info.default_source_name)
.map(|s| s.to_owned())
.unwrap_or_default();
}
list_data.context.mainloop.signal();
}
let mut user_data = PulseDevListData::new(self);
if let Some(ref context) = self.context {
self.mainloop.lock();
if let Ok(o) =
context.get_server_info(default_device_names, &mut user_data as *mut _ as *mut _)
{
self.operation_wait(None, &o);
}
if devtype.contains(DeviceType::OUTPUT) {
if let Ok(o) = context
.get_sink_info_list(add_output_device, &mut user_data as *mut _ as *mut _)
{
self.operation_wait(None, &o);
}
}
if devtype.contains(DeviceType::INPUT) {
if let Ok(o) = context
.get_source_info_list(add_input_device, &mut user_data as *mut _ as *mut _)
{
self.operation_wait(None, &o);
}
}
self.mainloop.unlock();
}
// Extract the array of cubeb_device_info from
// PulseDevListData and convert it into C representation.
let mut tmp = Vec::new();
mem::swap(&mut user_data.devinfo, &mut tmp);
let mut devices = tmp.into_boxed_slice();
let coll = unsafe { &mut *collection.as_ptr() };
coll.device = devices.as_mut_ptr();
coll.count = devices.len();
// Giving away the memory owned by devices. Don't free it!
mem::forget(devices);
Ok(())
}
fn device_collection_destroy(&mut self, collection: &mut DeviceCollectionRef) -> Result<()> {
debug_assert!(!collection.as_ptr().is_null());
unsafe {
let coll = &mut *collection.as_ptr();
let mut devices = Vec::from_raw_parts(
coll.device as *mut ffi::cubeb_device_info,
coll.count,
coll.count,
);
for dev in &mut devices {
if !dev.group_id.is_null() {
let _ = CString::from_raw(dev.group_id as *mut _);
}
if !dev.vendor_name.is_null() {
let _ = CString::from_raw(dev.vendor_name as *mut _);
}
if !dev.friendly_name.is_null() {
let _ = CString::from_raw(dev.friendly_name as *mut _);
}
}
coll.device = ptr::null_mut();
coll.count = 0;
}
Ok(())
}
#[cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments))]
fn stream_init(
&mut self,
stream_name: Option<&CStr>,
input_device: DeviceId,
input_stream_params: Option<&StreamParamsRef>,
output_device: DeviceId,
output_stream_params: Option<&StreamParamsRef>,
latency_frames: u32,
data_callback: ffi::cubeb_data_callback,
state_callback: ffi::cubeb_state_callback,
user_ptr: *mut c_void,
) -> Result<Stream> {
if self.error {
self.context_init()?;
}
let stm = PulseStream::new(
self,
stream_name,
input_device,
input_stream_params,
output_device,
output_stream_params,
latency_frames,
data_callback,
state_callback,
user_ptr,
)?;
Ok(unsafe { Stream::from_ptr(Box::into_raw(stm) as *mut _) })
}
fn register_device_collection_changed(
&mut self,
devtype: DeviceType,
cb: ffi::cubeb_device_collection_changed_callback,
user_ptr: *mut c_void,
) -> Result<()> {
if devtype.contains(DeviceType::INPUT) {
self.input_collection_changed_callback = cb;
self.input_collection_changed_user_ptr = user_ptr;
}
if devtype.contains(DeviceType::OUTPUT) {
self.output_collection_changed_callback = cb;
self.output_collection_changed_user_ptr = user_ptr;
}
let mut mask = pulse::SubscriptionMask::empty();
if self.input_collection_changed_callback.is_some() {
mask |= pulse::SubscriptionMask::SOURCE;
}
if self.output_collection_changed_callback.is_some() {
mask |= pulse::SubscriptionMask::SINK;
}
/* Default device changed, this is always registered in order to update the
* `default_sink_info` when the default device changes. */
mask |= pulse::SubscriptionMask::SERVER;
self.subscribe_notifications(mask)
}
}
impl Drop for PulseContext {
fn drop(&mut self) {
self.destroy();
}
}
impl PulseContext {
/* Initialize PulseAudio Context */
fn context_init(&mut self) -> Result<()> {
fn error_state(c: &pulse::Context, u: *mut c_void) {
let ctx = unsafe { &mut *(u as *mut PulseContext) };
if !c.get_state().is_good() {
ctx.error = true;
}
ctx.mainloop.signal();
}
if self.context.is_some() {
debug_assert!(self.error);
self.context_destroy();
}
self.context = {
let name = self.context_name.as_ref().map(|s| s.as_ref());
pulse::Context::new(&self.mainloop.get_api(), name)
};
let context_ptr: *mut c_void = self as *mut _ as *mut _;
if self.context.is_none() {
cubeb_log!("Error: couldn't create pulse's context");
return Err(Error::error());
}
self.mainloop.lock();
let connected = if let Some(ref context) = self.context {
context.set_state_callback(error_state, context_ptr);
context
.connect(None, pulse::ContextFlags::empty(), ptr::null())
.is_ok()
} else {
false
};
if !connected || !self.wait_until_context_ready() {
self.mainloop.unlock();
self.context_destroy();
cubeb_log!("Error: error while waiting for pulse's context to be ready");
return Err(Error::error());
}
self.mainloop.unlock();
let version_str = unsafe { CStr::from_ptr(pulse::library_version()) };
if let Ok(version) = semver::Version::parse(&version_str.to_string_lossy()) {
self.version_0_9_8 =
version >= semver::Version::parse("0.9.8").expect("Failed to parse version");
self.version_2_0_0 =
version >= semver::Version::parse("2.0.0").expect("Failed to parse version");
}
self.error = false;
Ok(())
}
fn context_destroy(&mut self) {
fn drain_complete(_: &pulse::Context, u: *mut c_void) {
let ctx = unsafe { &*(u as *mut PulseContext) };
ctx.mainloop.signal();
}
let context_ptr: *mut c_void = self as *mut _ as *mut _;
if let Some(ctx) = self.context.take() {
self.mainloop.lock();
if let Ok(o) = ctx.drain(drain_complete, context_ptr) {
self.operation_wait(None, &o);
}
ctx.clear_state_callback();
ctx.disconnect();
ctx.unref();
self.mainloop.unlock();
}
}
pub fn operation_wait<'a, S>(&self, s: S, o: &pulse::Operation) -> bool
where
S: Into<Option<&'a pulse::Stream>>,
{
let stream = s.into();
while o.get_state() == PA_OPERATION_RUNNING {
self.mainloop.wait();
if let Some(ref context) = self.context {
if !context.get_state().is_good() {
return false;
}
}
if let Some(stm) = stream {
if !stm.get_state().is_good() {
return false;
}
}
}
true
}
pub fn wait_until_context_ready(&self) -> bool {
if let Some(ref context) = self.context {
loop {
let state = context.get_state();
if !state.is_good() {
return false;
}
if state == pulse::ContextState::Ready {
break;
}
self.mainloop.wait();
}
}
true
}
fn state_from_port(&self, i: *const pa_port_info) -> ffi::cubeb_device_state {
if !i.is_null() {
let info = unsafe { *i };
if self.version_2_0_0 && info.available == PA_PORT_AVAILABLE_NO {
ffi::CUBEB_DEVICE_STATE_UNPLUGGED
} else {
ffi::CUBEB_DEVICE_STATE_ENABLED
}
} else {
ffi::CUBEB_DEVICE_STATE_ENABLED
}
}
}
struct PulseDevListData<'a> {
default_sink_name: CString,
default_source_name: CString,
devinfo: Vec<ffi::cubeb_device_info>,
context: &'a PulseContext,
}
impl<'a> PulseDevListData<'a> {
pub fn new<'b>(context: &'b PulseContext) -> Self
where
'b: 'a,
{
PulseDevListData {
default_sink_name: CString::default(),
default_source_name: CString::default(),
devinfo: Vec::new(),
context,
}
}
}
impl<'a> Drop for PulseDevListData<'a> {
fn drop(&mut self) {
for elem in &mut self.devinfo {
let _ = unsafe { Box::from_raw(elem) };
}
}
}
fn pulse_format_to_cubeb_format(format: pa_sample_format_t) -> ffi::cubeb_device_fmt {
match format {
PA_SAMPLE_S16LE => ffi::CUBEB_DEVICE_FMT_S16LE,
PA_SAMPLE_S16BE => ffi::CUBEB_DEVICE_FMT_S16BE,
PA_SAMPLE_FLOAT32LE => ffi::CUBEB_DEVICE_FMT_F32LE,
PA_SAMPLE_FLOAT32BE => ffi::CUBEB_DEVICE_FMT_F32BE,
// Unsupported format, return F32NE
_ => ffi::CUBEB_DEVICE_FMT_F32NE,
}
}
|