mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
parent
2d2e73c23c
commit
9fe82ef781
1 changed files with 7 additions and 5 deletions
|
@ -12,6 +12,7 @@ pub struct PulseAudioSink {
|
||||||
ss: pa_sample_spec,
|
ss: pa_sample_spec,
|
||||||
name: CString,
|
name: CString,
|
||||||
desc: CString,
|
desc: CString,
|
||||||
|
device: Option<CString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn call_pulseaudio<T, F, FailCheck>(
|
fn call_pulseaudio<T, F, FailCheck>(
|
||||||
|
@ -56,10 +57,6 @@ impl Open for PulseAudioSink {
|
||||||
fn open(device: Option<String>) -> PulseAudioSink {
|
fn open(device: Option<String>) -> PulseAudioSink {
|
||||||
debug!("Using PulseAudio sink");
|
debug!("Using PulseAudio sink");
|
||||||
|
|
||||||
if device.is_some() {
|
|
||||||
panic!("pulseaudio sink does not support specifying a device name");
|
|
||||||
}
|
|
||||||
|
|
||||||
let ss = pa_sample_spec {
|
let ss = pa_sample_spec {
|
||||||
format: PA_SAMPLE_S16LE,
|
format: PA_SAMPLE_S16LE,
|
||||||
channels: 2, // stereo
|
channels: 2, // stereo
|
||||||
|
@ -74,6 +71,7 @@ impl Open for PulseAudioSink {
|
||||||
ss: ss,
|
ss: ss,
|
||||||
name: name,
|
name: name,
|
||||||
desc: description,
|
desc: description,
|
||||||
|
device: device.and_then(|s| CString::new(s).ok()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,13 +79,17 @@ impl Open for PulseAudioSink {
|
||||||
impl Sink for PulseAudioSink {
|
impl Sink for PulseAudioSink {
|
||||||
fn start(&mut self) -> io::Result<()> {
|
fn start(&mut self) -> io::Result<()> {
|
||||||
if self.s == null_mut() {
|
if self.s == null_mut() {
|
||||||
|
let device = match &self.device {
|
||||||
|
None => null(),
|
||||||
|
Some(device) => device.as_ptr(),
|
||||||
|
};
|
||||||
self.s = call_pulseaudio(
|
self.s = call_pulseaudio(
|
||||||
|err| unsafe {
|
|err| unsafe {
|
||||||
pa_simple_new(
|
pa_simple_new(
|
||||||
null(), // Use the default server.
|
null(), // Use the default server.
|
||||||
self.name.as_ptr(), // Our application's name.
|
self.name.as_ptr(), // Our application's name.
|
||||||
PA_STREAM_PLAYBACK,
|
PA_STREAM_PLAYBACK,
|
||||||
null(), // Use the default device.
|
device,
|
||||||
self.desc.as_ptr(), // desc of our stream.
|
self.desc.as_ptr(), // desc of our stream.
|
||||||
&self.ss, // Our sample format.
|
&self.ss, // Our sample format.
|
||||||
null(), // Use default channel map
|
null(), // Use default channel map
|
||||||
|
|
Loading…
Reference in a new issue