| 1 |
// Copyright © 2017 Mozilla Foundation |
| 2 |
// |
| 3 |
// This program is made available under an ISC-style license. See the |
| 4 |
// accompanying file LICENSE for details. |
| 5 |
|
| 6 |
#[macro_use] |
| 7 |
extern crate bitflags; |
| 8 |
extern crate pulse_ffi as ffi; |
| 9 |
|
| 10 |
#[macro_use] |
| 11 |
mod error; |
| 12 |
mod context; |
| 13 |
mod mainloop_api; |
| 14 |
mod operation; |
| 15 |
mod proplist; |
| 16 |
mod stream; |
| 17 |
mod threaded_mainloop; |
| 18 |
mod util; |
| 19 |
|
| 20 |
pub use context::Context; |
| 21 |
pub use error::ErrorCode; |
| 22 |
pub use ffi::pa_buffer_attr as BufferAttr; |
| 23 |
pub use ffi::pa_channel_map as ChannelMap; |
| 24 |
pub use ffi::pa_cvolume as CVolume; |
| 25 |
pub use ffi::pa_sample_spec as SampleSpec; |
| 26 |
pub use ffi::pa_server_info as ServerInfo; |
| 27 |
pub use ffi::pa_sink_info as SinkInfo; |
| 28 |
pub use ffi::pa_sink_input_info as SinkInputInfo; |
| 29 |
pub use ffi::pa_source_info as SourceInfo; |
| 30 |
pub use ffi::pa_usec_t as USec; |
| 31 |
pub use ffi::pa_volume_t as Volume; |
| 32 |
pub use ffi::timeval as TimeVal; |
| 33 |
pub use mainloop_api::MainloopApi; |
| 34 |
pub use operation::Operation; |
| 35 |
pub use proplist::Proplist; |
| 36 |
use std::os::raw::{c_char, c_uint}; |
| 37 |
pub use stream::Stream; |
| 38 |
pub use threaded_mainloop::ThreadedMainloop; |
| 39 |
|
| 40 |
#[allow(non_camel_case_types)] |
| 41 |
#[repr(i32)] |
| 42 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 43 |
pub enum SampleFormat { |
| 44 |
Invalid = ffi::PA_SAMPLE_INVALID, |
| 45 |
U8 = ffi::PA_SAMPLE_U8, |
| 46 |
Alaw = ffi::PA_SAMPLE_ALAW, |
| 47 |
Ulaw = ffi::PA_SAMPLE_ULAW, |
| 48 |
Signed16LE = ffi::PA_SAMPLE_S16LE, |
| 49 |
Signed16BE = ffi::PA_SAMPLE_S16BE, |
| 50 |
Float32LE = ffi::PA_SAMPLE_FLOAT32LE, |
| 51 |
Float32BE = ffi::PA_SAMPLE_FLOAT32BE, |
| 52 |
Signed32LE = ffi::PA_SAMPLE_S32LE, |
| 53 |
Signed32BE = ffi::PA_SAMPLE_S32BE, |
| 54 |
Signed24LE = ffi::PA_SAMPLE_S24LE, |
| 55 |
Signed24BE = ffi::PA_SAMPLE_S24BE, |
| 56 |
Signed24_32LE = ffi::PA_SAMPLE_S24_32LE, |
| 57 |
Signed23_32BE = ffi::PA_SAMPLE_S24_32BE, |
| 58 |
} |
| 59 |
|
| 60 |
impl Default for SampleFormat { |
| 61 |
fn default() -> Self { |
| 62 |
SampleFormat::Invalid |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
impl Into<ffi::pa_sample_format_t> for SampleFormat { |
| 67 |
fn into(self) -> ffi::pa_sample_format_t { |
| 68 |
self as ffi::pa_sample_format_t |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
#[repr(i32)] |
| 73 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 74 |
pub enum ContextState { |
| 75 |
Unconnected = ffi::PA_CONTEXT_UNCONNECTED, |
| 76 |
Connecting = ffi::PA_CONTEXT_CONNECTING, |
| 77 |
Authorizing = ffi::PA_CONTEXT_AUTHORIZING, |
| 78 |
SettingName = ffi::PA_CONTEXT_SETTING_NAME, |
| 79 |
Ready = ffi::PA_CONTEXT_READY, |
| 80 |
Failed = ffi::PA_CONTEXT_FAILED, |
| 81 |
Terminated = ffi::PA_CONTEXT_TERMINATED, |
| 82 |
} |
| 83 |
|
| 84 |
impl ContextState { |
| 85 |
// This function implements the PA_CONTENT_IS_GOOD macro from pulse/def.h |
| 86 |
// It must match the version from PA headers. |
| 87 |
pub fn is_good(self) -> bool { |
| 88 |
match self { |
| 89 |
ContextState::Connecting |
| 90 |
| ContextState::Authorizing |
| 91 |
| ContextState::SettingName |
| 92 |
| ContextState::Ready => true, |
| 93 |
_ => false, |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
pub fn try_from(x: ffi::pa_context_state_t) -> Option<Self> { |
| 98 |
if x >= ffi::PA_CONTEXT_UNCONNECTED && x <= ffi::PA_CONTEXT_TERMINATED { |
| 99 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 100 |
} else { |
| 101 |
None |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
impl Default for ContextState { |
| 107 |
fn default() -> Self { |
| 108 |
ContextState::Unconnected |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
impl Into<ffi::pa_context_state_t> for ContextState { |
| 113 |
fn into(self) -> ffi::pa_context_state_t { |
| 114 |
self as ffi::pa_context_state_t |
| 115 |
} |
| 116 |
} |
| 117 |
|
| 118 |
#[repr(i32)] |
| 119 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 120 |
pub enum StreamState { |
| 121 |
Unconnected = ffi::PA_STREAM_UNCONNECTED, |
| 122 |
Creating = ffi::PA_STREAM_CREATING, |
| 123 |
Ready = ffi::PA_STREAM_READY, |
| 124 |
Failed = ffi::PA_STREAM_FAILED, |
| 125 |
Terminated = ffi::PA_STREAM_TERMINATED, |
| 126 |
} |
| 127 |
|
| 128 |
impl StreamState { |
| 129 |
// This function implements the PA_STREAM_IS_GOOD macro from pulse/def.h |
| 130 |
// It must match the version from PA headers. |
| 131 |
pub fn is_good(self) -> bool { |
| 132 |
match self { |
| 133 |
StreamState::Creating | StreamState::Ready => true, |
| 134 |
_ => false, |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
pub fn try_from(x: ffi::pa_stream_state_t) -> Option<Self> { |
| 139 |
if x >= ffi::PA_STREAM_UNCONNECTED && x <= ffi::PA_STREAM_TERMINATED { |
| 140 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 141 |
} else { |
| 142 |
None |
| 143 |
} |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
impl Default for StreamState { |
| 148 |
fn default() -> Self { |
| 149 |
StreamState::Unconnected |
| 150 |
} |
| 151 |
} |
| 152 |
|
| 153 |
impl Into<ffi::pa_stream_state_t> for StreamState { |
| 154 |
fn into(self) -> ffi::pa_stream_state_t { |
| 155 |
self as ffi::pa_stream_state_t |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
#[repr(i32)] |
| 160 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 161 |
pub enum OperationState { |
| 162 |
Running = ffi::PA_OPERATION_RUNNING, |
| 163 |
Done = ffi::PA_OPERATION_DONE, |
| 164 |
Cancelled = ffi::PA_OPERATION_CANCELLED, |
| 165 |
} |
| 166 |
|
| 167 |
impl OperationState { |
| 168 |
pub fn try_from(x: ffi::pa_operation_state_t) -> Option<Self> { |
| 169 |
if x >= ffi::PA_OPERATION_RUNNING && x <= ffi::PA_OPERATION_CANCELLED { |
| 170 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 171 |
} else { |
| 172 |
None |
| 173 |
} |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
impl Into<ffi::pa_operation_state_t> for OperationState { |
| 178 |
fn into(self) -> ffi::pa_operation_state_t { |
| 179 |
self as ffi::pa_operation_state_t |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
bitflags! { |
| 184 |
pub struct ContextFlags: u32 { |
| 185 |
const NOAUTOSPAWN = ffi::PA_CONTEXT_NOAUTOSPAWN; |
| 186 |
const NOFAIL = ffi::PA_CONTEXT_NOFAIL; |
| 187 |
} |
| 188 |
} |
| 189 |
|
| 190 |
impl Into<ffi::pa_context_flags_t> for ContextFlags { |
| 191 |
fn into(self) -> ffi::pa_context_flags_t { |
| 192 |
self.bits() as ffi::pa_context_flags_t |
| 193 |
} |
| 194 |
} |
| 195 |
|
| 196 |
#[repr(i32)] |
| 197 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 198 |
pub enum DeviceType { |
| 199 |
Sink = ffi::PA_DEVICE_TYPE_SINK, |
| 200 |
Source = ffi::PA_DEVICE_TYPE_SOURCE, |
| 201 |
} |
| 202 |
|
| 203 |
impl DeviceType { |
| 204 |
pub fn try_from(x: ffi::pa_device_type_t) -> Option<Self> { |
| 205 |
if x >= ffi::PA_DEVICE_TYPE_SINK && x <= ffi::PA_DEVICE_TYPE_SOURCE { |
| 206 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 207 |
} else { |
| 208 |
None |
| 209 |
} |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
impl Into<ffi::pa_device_type_t> for DeviceType { |
| 214 |
fn into(self) -> ffi::pa_device_type_t { |
| 215 |
self as ffi::pa_device_type_t |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
#[repr(i32)] |
| 220 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 221 |
pub enum StreamDirection { |
| 222 |
NoDirection = ffi::PA_STREAM_NODIRECTION, |
| 223 |
Playback = ffi::PA_STREAM_PLAYBACK, |
| 224 |
Record = ffi::PA_STREAM_RECORD, |
| 225 |
StreamUpload = ffi::PA_STREAM_UPLOAD, |
| 226 |
} |
| 227 |
|
| 228 |
impl StreamDirection { |
| 229 |
pub fn try_from(x: ffi::pa_stream_direction_t) -> Option<Self> { |
| 230 |
if x >= ffi::PA_STREAM_NODIRECTION && x <= ffi::PA_STREAM_UPLOAD { |
| 231 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 232 |
} else { |
| 233 |
None |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
|
| 238 |
impl Into<ffi::pa_stream_direction_t> for StreamDirection { |
| 239 |
fn into(self) -> ffi::pa_stream_direction_t { |
| 240 |
self as ffi::pa_stream_direction_t |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
bitflags! { |
| 245 |
pub struct StreamFlags : u32 { |
| 246 |
const START_CORKED = ffi::PA_STREAM_START_CORKED; |
| 247 |
const INTERPOLATE_TIMING = ffi::PA_STREAM_INTERPOLATE_TIMING; |
| 248 |
const NOT_MONOTONIC = ffi::PA_STREAM_NOT_MONOTONIC; |
| 249 |
const AUTO_TIMING_UPDATE = ffi::PA_STREAM_AUTO_TIMING_UPDATE; |
| 250 |
const NO_REMAP_CHANNELS = ffi::PA_STREAM_NO_REMAP_CHANNELS; |
| 251 |
const NO_REMIX_CHANNELS = ffi::PA_STREAM_NO_REMIX_CHANNELS; |
| 252 |
const FIX_FORMAT = ffi::PA_STREAM_FIX_FORMAT; |
| 253 |
const FIX_RATE = ffi::PA_STREAM_FIX_RATE; |
| 254 |
const FIX_CHANNELS = ffi::PA_STREAM_FIX_CHANNELS; |
| 255 |
const DONT_MOVE = ffi::PA_STREAM_DONT_MOVE; |
| 256 |
const VARIABLE_RATE = ffi::PA_STREAM_VARIABLE_RATE; |
| 257 |
const PEAK_DETECT = ffi::PA_STREAM_PEAK_DETECT; |
| 258 |
const START_MUTED = ffi::PA_STREAM_START_MUTED; |
| 259 |
const ADJUST_LATENCY = ffi::PA_STREAM_ADJUST_LATENCY; |
| 260 |
const EARLY_REQUESTS = ffi::PA_STREAM_EARLY_REQUESTS; |
| 261 |
const DONT_INHIBIT_AUTO_SUSPEND = ffi::PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND; |
| 262 |
const START_UNMUTED = ffi::PA_STREAM_START_UNMUTED; |
| 263 |
const FAIL_ON_SUSPEND = ffi::PA_STREAM_FAIL_ON_SUSPEND; |
| 264 |
const RELATIVE_VOLUME = ffi::PA_STREAM_RELATIVE_VOLUME; |
| 265 |
const PASSTHROUGH = ffi::PA_STREAM_PASSTHROUGH; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
impl StreamFlags { |
| 270 |
pub fn try_from(x: ffi::pa_stream_flags_t) -> Option<Self> { |
| 271 |
if (x & !(ffi::PA_STREAM_NOFLAGS |
| 272 |
| ffi::PA_STREAM_START_CORKED |
| 273 |
| ffi::PA_STREAM_INTERPOLATE_TIMING |
| 274 |
| ffi::PA_STREAM_NOT_MONOTONIC |
| 275 |
| ffi::PA_STREAM_AUTO_TIMING_UPDATE |
| 276 |
| ffi::PA_STREAM_NO_REMAP_CHANNELS |
| 277 |
| ffi::PA_STREAM_NO_REMIX_CHANNELS |
| 278 |
| ffi::PA_STREAM_FIX_FORMAT |
| 279 |
| ffi::PA_STREAM_FIX_RATE |
| 280 |
| ffi::PA_STREAM_FIX_CHANNELS |
| 281 |
| ffi::PA_STREAM_DONT_MOVE |
| 282 |
| ffi::PA_STREAM_VARIABLE_RATE |
| 283 |
| ffi::PA_STREAM_PEAK_DETECT |
| 284 |
| ffi::PA_STREAM_START_MUTED |
| 285 |
| ffi::PA_STREAM_ADJUST_LATENCY |
| 286 |
| ffi::PA_STREAM_EARLY_REQUESTS |
| 287 |
| ffi::PA_STREAM_DONT_INHIBIT_AUTO_SUSPEND |
| 288 |
| ffi::PA_STREAM_START_UNMUTED |
| 289 |
| ffi::PA_STREAM_FAIL_ON_SUSPEND |
| 290 |
| ffi::PA_STREAM_RELATIVE_VOLUME |
| 291 |
| ffi::PA_STREAM_PASSTHROUGH)) |
| 292 |
== 0 |
| 293 |
{ |
| 294 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 295 |
} else { |
| 296 |
None |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
impl Into<ffi::pa_stream_flags_t> for StreamFlags { |
| 302 |
fn into(self) -> ffi::pa_stream_flags_t { |
| 303 |
self.bits() as ffi::pa_stream_flags_t |
| 304 |
} |
| 305 |
} |
| 306 |
|
| 307 |
pub enum StreamLatency { |
| 308 |
Positive(u64), |
| 309 |
Negative(u64), |
| 310 |
} |
| 311 |
|
| 312 |
bitflags! { |
| 313 |
pub struct SubscriptionMask : u32 { |
| 314 |
const SINK = ffi::PA_SUBSCRIPTION_MASK_SINK; |
| 315 |
const SOURCE = ffi::PA_SUBSCRIPTION_MASK_SOURCE; |
| 316 |
const SINK_INPUT = ffi::PA_SUBSCRIPTION_MASK_SINK_INPUT; |
| 317 |
const SOURCE_OUTPUT = ffi::PA_SUBSCRIPTION_MASK_SOURCE_OUTPUT; |
| 318 |
const MODULE = ffi::PA_SUBSCRIPTION_MASK_MODULE; |
| 319 |
const CLIENT = ffi::PA_SUBSCRIPTION_MASK_CLIENT; |
| 320 |
const SAMPLE_CACHE = ffi::PA_SUBSCRIPTION_MASK_SAMPLE_CACHE; |
| 321 |
const SERVER = ffi::PA_SUBSCRIPTION_MASK_SERVER; |
| 322 |
const AUTOLOAD = ffi::PA_SUBSCRIPTION_MASK_AUTOLOAD; |
| 323 |
const CARD = ffi::PA_SUBSCRIPTION_MASK_CARD; |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
impl SubscriptionMask { |
| 328 |
pub fn try_from(x: ffi::pa_subscription_mask_t) -> Option<Self> { |
| 329 |
if (x & !ffi::PA_SUBSCRIPTION_MASK_ALL) == 0 { |
| 330 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 331 |
} else { |
| 332 |
None |
| 333 |
} |
| 334 |
} |
| 335 |
} |
| 336 |
|
| 337 |
impl Into<ffi::pa_subscription_mask_t> for SubscriptionMask { |
| 338 |
fn into(self) -> ffi::pa_subscription_mask_t { |
| 339 |
self.bits() as ffi::pa_subscription_mask_t |
| 340 |
} |
| 341 |
} |
| 342 |
|
| 343 |
#[repr(i32)] |
| 344 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 345 |
pub enum SubscriptionEventFacility { |
| 346 |
Sink = ffi::PA_SUBSCRIPTION_EVENT_SINK, |
| 347 |
Source = ffi::PA_SUBSCRIPTION_EVENT_SOURCE, |
| 348 |
SinkInput = ffi::PA_SUBSCRIPTION_EVENT_SINK_INPUT, |
| 349 |
SourceOutput = ffi::PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT, |
| 350 |
Module = ffi::PA_SUBSCRIPTION_EVENT_MODULE, |
| 351 |
Client = ffi::PA_SUBSCRIPTION_EVENT_CLIENT, |
| 352 |
SampleCache = ffi::PA_SUBSCRIPTION_EVENT_SAMPLE_CACHE, |
| 353 |
Server = ffi::PA_SUBSCRIPTION_EVENT_SERVER, |
| 354 |
Autoload = ffi::PA_SUBSCRIPTION_EVENT_AUTOLOAD, |
| 355 |
Card = ffi::PA_SUBSCRIPTION_EVENT_CARD, |
| 356 |
} |
| 357 |
|
| 358 |
#[repr(C)] |
| 359 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 360 |
pub enum SubscriptionEventType { |
| 361 |
New, |
| 362 |
Change, |
| 363 |
Remove, |
| 364 |
} |
| 365 |
|
| 366 |
#[repr(C)] |
| 367 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 368 |
pub struct SubscriptionEvent(ffi::pa_subscription_event_type_t); |
| 369 |
impl SubscriptionEvent { |
| 370 |
pub fn try_from(x: ffi::pa_subscription_event_type_t) -> Option<Self> { |
| 371 |
if (x & !(ffi::PA_SUBSCRIPTION_EVENT_TYPE_MASK | ffi::PA_SUBSCRIPTION_EVENT_FACILITY_MASK)) |
| 372 |
== 0 |
| 373 |
{ |
| 374 |
Some(SubscriptionEvent(x)) |
| 375 |
} else { |
| 376 |
None |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
pub fn event_facility(self) -> SubscriptionEventFacility { |
| 381 |
unsafe { ::std::mem::transmute(self.0 & ffi::PA_SUBSCRIPTION_EVENT_FACILITY_MASK) } |
| 382 |
} |
| 383 |
|
| 384 |
pub fn event_type(self) -> SubscriptionEventType { |
| 385 |
unsafe { ::std::mem::transmute((self.0 & ffi::PA_SUBSCRIPTION_EVENT_TYPE_MASK) >> 4) } |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
#[repr(i32)] |
| 390 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 391 |
pub enum SeekMode { |
| 392 |
Relative = ffi::PA_SEEK_RELATIVE, |
| 393 |
Absolute = ffi::PA_SEEK_ABSOLUTE, |
| 394 |
RelativeOnRead = ffi::PA_SEEK_RELATIVE_ON_READ, |
| 395 |
RelativeEnd = ffi::PA_SEEK_RELATIVE_END, |
| 396 |
} |
| 397 |
|
| 398 |
impl SeekMode { |
| 399 |
pub fn try_from(x: ffi::pa_seek_mode_t) -> Option<Self> { |
| 400 |
if x >= ffi::PA_SEEK_RELATIVE && x <= ffi::PA_SEEK_RELATIVE_END { |
| 401 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 402 |
} else { |
| 403 |
None |
| 404 |
} |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
impl Into<ffi::pa_seek_mode_t> for SeekMode { |
| 409 |
fn into(self) -> ffi::pa_seek_mode_t { |
| 410 |
self as ffi::pa_seek_mode_t |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
bitflags! { |
| 415 |
#[derive(Debug, Clone, Copy)] |
| 416 |
pub struct SinkFlags: u32 { |
| 417 |
const HW_VOLUME_CTRL = ffi::PA_SINK_HW_VOLUME_CTRL; |
| 418 |
const LATENCY = ffi::PA_SINK_LATENCY; |
| 419 |
const HARDWARE = ffi::PA_SINK_HARDWARE; |
| 420 |
const NETWORK = ffi::PA_SINK_NETWORK; |
| 421 |
const HW_MUTE_CTRL = ffi::PA_SINK_HW_MUTE_CTRL; |
| 422 |
const DECIBEL_VOLUME = ffi::PA_SINK_DECIBEL_VOLUME; |
| 423 |
const FLAT_VOLUME = ffi::PA_SINK_FLAT_VOLUME; |
| 424 |
const DYNAMIC_LATENCY = ffi::PA_SINK_DYNAMIC_LATENCY; |
| 425 |
const SET_FORMATS = ffi::PA_SINK_SET_FORMATS; |
| 426 |
} |
| 427 |
} |
| 428 |
|
| 429 |
impl SinkFlags { |
| 430 |
pub fn try_from(x: ffi::pa_sink_flags_t) -> Option<SinkFlags> { |
| 431 |
if (x & !(ffi::PA_SINK_NOFLAGS |
| 432 |
| ffi::PA_SINK_HW_VOLUME_CTRL |
| 433 |
| ffi::PA_SINK_LATENCY |
| 434 |
| ffi::PA_SINK_HARDWARE |
| 435 |
| ffi::PA_SINK_NETWORK |
| 436 |
| ffi::PA_SINK_HW_MUTE_CTRL |
| 437 |
| ffi::PA_SINK_DECIBEL_VOLUME |
| 438 |
| ffi::PA_SINK_DYNAMIC_LATENCY |
| 439 |
| ffi::PA_SINK_FLAT_VOLUME |
| 440 |
| ffi::PA_SINK_SET_FORMATS)) |
| 441 |
== 0 |
| 442 |
{ |
| 443 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 444 |
} else { |
| 445 |
None |
| 446 |
} |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
#[repr(i32)] |
| 451 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 452 |
pub enum SinkState { |
| 453 |
InvalidState = ffi::PA_SINK_INVALID_STATE, |
| 454 |
Running = ffi::PA_SINK_RUNNING, |
| 455 |
Idle = ffi::PA_SINK_IDLE, |
| 456 |
Suspended = ffi::PA_SINK_SUSPENDED, |
| 457 |
Init = ffi::PA_SINK_INIT, |
| 458 |
Unlinked = ffi::PA_SINK_UNLINKED, |
| 459 |
} |
| 460 |
|
| 461 |
bitflags! { |
| 462 |
pub struct SourceFlags: u32 { |
| 463 |
const HW_VOLUME_CTRL = ffi::PA_SOURCE_HW_VOLUME_CTRL; |
| 464 |
const LATENCY = ffi::PA_SOURCE_LATENCY; |
| 465 |
const HARDWARE = ffi::PA_SOURCE_HARDWARE; |
| 466 |
const NETWORK = ffi::PA_SOURCE_NETWORK; |
| 467 |
const HW_MUTE_CTRL = ffi::PA_SOURCE_HW_MUTE_CTRL; |
| 468 |
const DECIBEL_VOLUME = ffi::PA_SOURCE_DECIBEL_VOLUME; |
| 469 |
const DYNAMIC_LATENCY = ffi::PA_SOURCE_DYNAMIC_LATENCY; |
| 470 |
const FLAT_VOLUME = ffi::PA_SOURCE_FLAT_VOLUME; |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
impl Into<ffi::pa_source_flags_t> for SourceFlags { |
| 475 |
fn into(self) -> ffi::pa_source_flags_t { |
| 476 |
self.bits() as ffi::pa_source_flags_t |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
#[repr(i32)] |
| 481 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 482 |
pub enum SourceState { |
| 483 |
InvalidState = ffi::PA_SOURCE_INVALID_STATE, |
| 484 |
Running = ffi::PA_SOURCE_RUNNING, |
| 485 |
Idle = ffi::PA_SOURCE_IDLE, |
| 486 |
Suspended = ffi::PA_SOURCE_SUSPENDED, |
| 487 |
Init = ffi::PA_SOURCE_INIT, |
| 488 |
Unlinked = ffi::PA_SOURCE_UNLINKED, |
| 489 |
} |
| 490 |
|
| 491 |
#[repr(i32)] |
| 492 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 493 |
pub enum PortAvailable { |
| 494 |
Unknown = ffi::PA_PORT_AVAILABLE_UNKNOWN, |
| 495 |
No = ffi::PA_PORT_AVAILABLE_NO, |
| 496 |
Yes = ffi::PA_PORT_AVAILABLE_YES, |
| 497 |
} |
| 498 |
|
| 499 |
impl PortAvailable { |
| 500 |
pub fn try_from(x: ffi::pa_port_available_t) -> Option<Self> { |
| 501 |
if x >= ffi::PA_PORT_AVAILABLE_UNKNOWN && x <= ffi::PA_PORT_AVAILABLE_YES { |
| 502 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 503 |
} else { |
| 504 |
None |
| 505 |
} |
| 506 |
} |
| 507 |
} |
| 508 |
|
| 509 |
impl Into<ffi::pa_port_available_t> for PortAvailable { |
| 510 |
fn into(self) -> ffi::pa_port_available_t { |
| 511 |
self as ffi::pa_port_available_t |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
#[repr(i32)] |
| 516 |
#[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| 517 |
pub enum ChannelPosition { |
| 518 |
Invalid = ffi::PA_CHANNEL_POSITION_INVALID, |
| 519 |
Mono = ffi::PA_CHANNEL_POSITION_MONO, |
| 520 |
FrontLeft = ffi::PA_CHANNEL_POSITION_FRONT_LEFT, |
| 521 |
FrontRight = ffi::PA_CHANNEL_POSITION_FRONT_RIGHT, |
| 522 |
FrontCenter = ffi::PA_CHANNEL_POSITION_FRONT_CENTER, |
| 523 |
RearCenter = ffi::PA_CHANNEL_POSITION_REAR_CENTER, |
| 524 |
RearLeft = ffi::PA_CHANNEL_POSITION_REAR_LEFT, |
| 525 |
RearRight = ffi::PA_CHANNEL_POSITION_REAR_RIGHT, |
| 526 |
LowFreqEffects = ffi::PA_CHANNEL_POSITION_LFE, |
| 527 |
FrontLeftOfCenter = ffi::PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, |
| 528 |
FrontRightOfCenter = ffi::PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, |
| 529 |
SideLeft = ffi::PA_CHANNEL_POSITION_SIDE_LEFT, |
| 530 |
SideRight = ffi::PA_CHANNEL_POSITION_SIDE_RIGHT, |
| 531 |
Aux0 = ffi::PA_CHANNEL_POSITION_AUX0, |
| 532 |
Aux1 = ffi::PA_CHANNEL_POSITION_AUX1, |
| 533 |
Aux2 = ffi::PA_CHANNEL_POSITION_AUX2, |
| 534 |
Aux3 = ffi::PA_CHANNEL_POSITION_AUX3, |
| 535 |
Aux4 = ffi::PA_CHANNEL_POSITION_AUX4, |
| 536 |
Aux5 = ffi::PA_CHANNEL_POSITION_AUX5, |
| 537 |
Aux6 = ffi::PA_CHANNEL_POSITION_AUX6, |
| 538 |
Aux7 = ffi::PA_CHANNEL_POSITION_AUX7, |
| 539 |
Aux8 = ffi::PA_CHANNEL_POSITION_AUX8, |
| 540 |
Aux9 = ffi::PA_CHANNEL_POSITION_AUX9, |
| 541 |
Aux10 = ffi::PA_CHANNEL_POSITION_AUX10, |
| 542 |
Aux11 = ffi::PA_CHANNEL_POSITION_AUX11, |
| 543 |
Aux12 = ffi::PA_CHANNEL_POSITION_AUX12, |
| 544 |
Aux13 = ffi::PA_CHANNEL_POSITION_AUX13, |
| 545 |
Aux14 = ffi::PA_CHANNEL_POSITION_AUX14, |
| 546 |
Aux15 = ffi::PA_CHANNEL_POSITION_AUX15, |
| 547 |
Aux16 = ffi::PA_CHANNEL_POSITION_AUX16, |
| 548 |
Aux17 = ffi::PA_CHANNEL_POSITION_AUX17, |
| 549 |
Aux18 = ffi::PA_CHANNEL_POSITION_AUX18, |
| 550 |
Aux19 = ffi::PA_CHANNEL_POSITION_AUX19, |
| 551 |
Aux20 = ffi::PA_CHANNEL_POSITION_AUX20, |
| 552 |
Aux21 = ffi::PA_CHANNEL_POSITION_AUX21, |
| 553 |
Aux22 = ffi::PA_CHANNEL_POSITION_AUX22, |
| 554 |
Aux23 = ffi::PA_CHANNEL_POSITION_AUX23, |
| 555 |
Aux24 = ffi::PA_CHANNEL_POSITION_AUX24, |
| 556 |
Aux25 = ffi::PA_CHANNEL_POSITION_AUX25, |
| 557 |
Aux26 = ffi::PA_CHANNEL_POSITION_AUX26, |
| 558 |
Aux27 = ffi::PA_CHANNEL_POSITION_AUX27, |
| 559 |
Aux28 = ffi::PA_CHANNEL_POSITION_AUX28, |
| 560 |
Aux29 = ffi::PA_CHANNEL_POSITION_AUX29, |
| 561 |
Aux30 = ffi::PA_CHANNEL_POSITION_AUX30, |
| 562 |
Aux31 = ffi::PA_CHANNEL_POSITION_AUX31, |
| 563 |
TopCenter = ffi::PA_CHANNEL_POSITION_TOP_CENTER, |
| 564 |
TopFrontLeft = ffi::PA_CHANNEL_POSITION_TOP_FRONT_LEFT, |
| 565 |
TopFrontRight = ffi::PA_CHANNEL_POSITION_TOP_FRONT_RIGHT, |
| 566 |
TopFrontCenter = ffi::PA_CHANNEL_POSITION_TOP_FRONT_CENTER, |
| 567 |
TopRearLeft = ffi::PA_CHANNEL_POSITION_TOP_REAR_LEFT, |
| 568 |
TopRearRight = ffi::PA_CHANNEL_POSITION_TOP_REAR_RIGHT, |
| 569 |
TopRearCenter = ffi::PA_CHANNEL_POSITION_TOP_REAR_CENTER, |
| 570 |
} |
| 571 |
|
| 572 |
impl ChannelPosition { |
| 573 |
pub fn try_from(x: ffi::pa_channel_position_t) -> Option<Self> { |
| 574 |
if x >= ffi::PA_CHANNEL_POSITION_INVALID && x < ffi::PA_CHANNEL_POSITION_MAX { |
| 575 |
Some(unsafe { ::std::mem::transmute(x) }) |
| 576 |
} else { |
| 577 |
None |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
impl Default for ChannelPosition { |
| 583 |
fn default() -> Self { |
| 584 |
ChannelPosition::Invalid |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
impl Into<ffi::pa_channel_position_t> for ChannelPosition { |
| 589 |
fn into(self) -> ffi::pa_channel_position_t { |
| 590 |
self as ffi::pa_channel_position_t |
| 591 |
} |
| 592 |
} |
| 593 |
pub type Result<T> = ::std::result::Result<T, error::ErrorCode>; |
| 594 |
|
| 595 |
pub trait CVolumeExt { |
| 596 |
fn set(&mut self, channels: c_uint, v: Volume); |
| 597 |
fn set_balance(&mut self, map: &ChannelMap, new_balance: f32); |
| 598 |
} |
| 599 |
|
| 600 |
impl CVolumeExt for CVolume { |
| 601 |
fn set(&mut self, channels: c_uint, v: Volume) { |
| 602 |
unsafe { |
| 603 |
ffi::pa_cvolume_set(self, channels, v); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
fn set_balance(&mut self, map: &ChannelMap, new_balance: f32) { |
| 608 |
unsafe { |
| 609 |
ffi::pa_cvolume_set_balance(self, map, new_balance); |
| 610 |
} |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
pub trait ChannelMapExt { |
| 615 |
fn init() -> ChannelMap; |
| 616 |
fn init_auto(ch: u32, def: ffi::pa_channel_map_def_t) -> Option<ChannelMap>; |
| 617 |
fn can_balance(&self) -> bool; |
| 618 |
} |
| 619 |
|
| 620 |
impl ChannelMapExt for ChannelMap { |
| 621 |
fn init() -> ChannelMap { |
| 622 |
let mut cm = ChannelMap::default(); |
| 623 |
unsafe { |
| 624 |
ffi::pa_channel_map_init(&mut cm); |
| 625 |
} |
| 626 |
cm |
| 627 |
} |
| 628 |
fn init_auto(ch: u32, def: ffi::pa_channel_map_def_t) -> Option<ChannelMap> { |
| 629 |
let mut cm = ChannelMap::default(); |
| 630 |
let r: *mut ffi::pa_channel_map = |
| 631 |
unsafe { ffi::pa_channel_map_init_auto(&mut cm, ch, def) }; |
| 632 |
if r.is_null() { |
| 633 |
None |
| 634 |
} else { |
| 635 |
Some(cm) |
| 636 |
} |
| 637 |
} |
| 638 |
fn can_balance(&self) -> bool { |
| 639 |
unsafe { ffi::pa_channel_map_can_balance(self) > 0 } |
| 640 |
} |
| 641 |
} |
| 642 |
|
| 643 |
pub trait ProplistExt { |
| 644 |
fn proplist(&self) -> Proplist; |
| 645 |
} |
| 646 |
|
| 647 |
impl ProplistExt for SinkInfo { |
| 648 |
fn proplist(&self) -> Proplist { |
| 649 |
unsafe { proplist::from_raw_ptr(self.proplist) } |
| 650 |
} |
| 651 |
} |
| 652 |
|
| 653 |
impl ProplistExt for SourceInfo { |
| 654 |
fn proplist(&self) -> Proplist { |
| 655 |
unsafe { proplist::from_raw_ptr(self.proplist) } |
| 656 |
} |
| 657 |
} |
| 658 |
|
| 659 |
pub trait SampleSpecExt { |
| 660 |
fn frame_size(&self) -> usize; |
| 661 |
fn sample_size(&self) -> usize; |
| 662 |
} |
| 663 |
|
| 664 |
impl SampleSpecExt for SampleSpec { |
| 665 |
fn frame_size(&self) -> usize { |
| 666 |
unsafe { ffi::pa_frame_size(self) } |
| 667 |
} |
| 668 |
fn sample_size(&self) -> usize { |
| 669 |
unsafe { ffi::pa_sample_size(self) } |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
pub trait USecExt { |
| 674 |
fn to_bytes(self, spec: &SampleSpec) -> usize; |
| 675 |
} |
| 676 |
|
| 677 |
impl USecExt for USec { |
| 678 |
fn to_bytes(self, spec: &SampleSpec) -> usize { |
| 679 |
unsafe { ffi::pa_usec_to_bytes(self, spec) } |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
pub fn library_version() -> *const c_char { |
| 684 |
unsafe { ffi::pa_get_library_version() } |
| 685 |
} |
| 686 |
|
| 687 |
pub fn sw_volume_from_linear(vol: f64) -> Volume { |
| 688 |
unsafe { ffi::pa_sw_volume_from_linear(vol) } |
| 689 |
} |
| 690 |
|
| 691 |
pub fn rtclock_now() -> USec { |
| 692 |
unsafe { ffi::pa_rtclock_now() } |
| 693 |
} |