Add log statements in failure paths
I'm having a hard time debugging in the field without this.
This commit is contained in:
Родитель
f0cd31f450
Коммит
f2456201db
|
@ -52,6 +52,7 @@ impl PulseContext {
|
|||
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());
|
||||
}
|
||||
|
||||
|
@ -128,11 +129,13 @@ impl PulseContext {
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -220,7 +223,7 @@ impl PulseContext {
|
|||
if let Some(ref context) = ctx.context {
|
||||
if let Err(e) = context.get_server_info(PulseContext::server_info_cb, user_data)
|
||||
{
|
||||
cubeb_log!("get_server_info ignored failure: {}", e);
|
||||
cubeb_log!("Error: get_server_info ignored failure: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +247,7 @@ impl PulseContext {
|
|||
self.operation_wait(None, &o);
|
||||
} else {
|
||||
self.mainloop.unlock();
|
||||
cubeb_log!("Context subscribe failed");
|
||||
cubeb_log!("Error: context subscribe failed");
|
||||
return Err(Error::error());
|
||||
}
|
||||
|
||||
|
@ -268,7 +271,10 @@ impl ContextOps for PulseContext {
|
|||
fn max_channel_count(&mut self) -> Result<u32> {
|
||||
match self.default_sink_info {
|
||||
Some(ref info) => Ok(u32::from(info.channel_map.channels)),
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: couldn't get the max channel count");
|
||||
Err(Error::error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +286,10 @@ impl ContextOps for PulseContext {
|
|||
fn preferred_sample_rate(&mut self) -> Result<u32> {
|
||||
match self.default_sink_info {
|
||||
Some(ref info) => Ok(info.sample_spec.rate),
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: Couldn't get the preferred sample rate");
|
||||
Err(Error::error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -592,6 +601,7 @@ impl PulseContext {
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -608,6 +618,7 @@ impl PulseContext {
|
|||
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());
|
||||
}
|
||||
|
||||
|
|
|
@ -300,6 +300,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
fn check_error(s: &pulse::Stream, u: *mut c_void) {
|
||||
let stm = unsafe { &mut *(u as *mut PulseStream) };
|
||||
if !s.get_state().is_good() {
|
||||
cubeb_log!("Calling error callback");
|
||||
stm.state_change_callback(ffi::CUBEB_STATE_ERROR);
|
||||
}
|
||||
stm.context.mainloop.signal();
|
||||
|
@ -313,6 +314,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
) -> i32 {
|
||||
let readable_size = s.readable_size().map(|s| s as i32).unwrap_or(-1);
|
||||
if readable_size > 0 && unsafe { s.peek(buffer, size).is_err() } {
|
||||
cubeb_logv!("Error while peeking the input stream");
|
||||
return -1;
|
||||
}
|
||||
readable_size
|
||||
|
@ -460,6 +462,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
stm.output_stream = Some(s);
|
||||
}
|
||||
Err(e) => {
|
||||
cubeb_log!("Output stream initialization error");
|
||||
stm.context.mainloop.unlock();
|
||||
stm.destroy();
|
||||
return Err(e);
|
||||
|
@ -502,6 +505,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
stm.input_stream = Some(s);
|
||||
}
|
||||
Err(e) => {
|
||||
cubeb_log!("Input stream initialization error");
|
||||
stm.context.mainloop.unlock();
|
||||
stm.destroy();
|
||||
return Err(e);
|
||||
|
@ -532,6 +536,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
|
||||
if !r {
|
||||
stm.destroy();
|
||||
cubeb_log!("Error while waiting for the stream to be ready");
|
||||
return Err(Error::error());
|
||||
}
|
||||
|
||||
|
@ -637,11 +642,11 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
self.context.mainloop.lock();
|
||||
self.shutdown = true;
|
||||
// If draining is taking place wait to finish
|
||||
cubeb_log!("Stream stop: waiting for drain.");
|
||||
cubeb_log!("Stream stop: waiting for drain");
|
||||
while !self.drain_timer.load(Ordering::Acquire).is_null() {
|
||||
self.context.mainloop.wait();
|
||||
}
|
||||
cubeb_log!("Stream stop: waited for drain.");
|
||||
cubeb_log!("Stream stop: waited for drain");
|
||||
self.context.mainloop.unlock();
|
||||
}
|
||||
self.cork(CorkState::cork() | CorkState::notify());
|
||||
|
@ -657,6 +662,7 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
}
|
||||
|
||||
if self.output_stream.is_none() {
|
||||
cubeb_log!("Calling position() on an input-only stream");
|
||||
return Err(Error::error());
|
||||
}
|
||||
|
||||
|
@ -666,7 +672,10 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
let bytes = USecExt::to_bytes(r_usec, &self.output_sample_spec);
|
||||
Ok((bytes / self.output_sample_spec.frame_size()) as u64)
|
||||
}
|
||||
Err(_) => Err(Error::error()),
|
||||
Err(_) => {
|
||||
cubeb_log!("Error: stm.get_time failed");
|
||||
Err(Error::error())
|
||||
}
|
||||
};
|
||||
|
||||
if !in_thread {
|
||||
|
@ -678,7 +687,10 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
|
||||
fn latency(&mut self) -> Result<u32> {
|
||||
match self.output_stream {
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: calling latency() on an input-only stream");
|
||||
Err(Error::error())
|
||||
}
|
||||
Some(ref stm) => match stm.get_latency() {
|
||||
Ok(StreamLatency::Positive(r_usec)) => {
|
||||
let latency = (r_usec * pa_usec_t::from(self.output_sample_spec.rate)
|
||||
|
@ -688,14 +700,20 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
Ok(_) => {
|
||||
panic!("Can not handle negative latency values.");
|
||||
}
|
||||
Err(_) => Err(Error::error()),
|
||||
Err(_) => {
|
||||
cubeb_log!("Error: get_latency() failed for an output stream");
|
||||
Err(Error::error())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn input_latency(&mut self) -> Result<u32> {
|
||||
match self.input_stream {
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: calling input_latency() on an output-only stream");
|
||||
Err(Error::error())
|
||||
}
|
||||
Some(ref stm) => match stm.get_latency() {
|
||||
Ok(StreamLatency::Positive(w_usec)) => {
|
||||
let latency = (w_usec * pa_usec_t::from(self.input_sample_spec.rate)
|
||||
|
@ -705,14 +723,20 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
// Input stream can be negative only if it is attached to a
|
||||
// monitor source device
|
||||
Ok(StreamLatency::Negative(_)) => Ok(0),
|
||||
Err(_) => Err(Error::error()),
|
||||
Err(_) => {
|
||||
cubeb_log!("Error: stm.get_latency() failed for an input stream");
|
||||
Err(Error::error())
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn set_volume(&mut self, volume: f32) -> Result<()> {
|
||||
match self.output_stream {
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: can't set volume on an input-only stream");
|
||||
Err(Error::error())
|
||||
}
|
||||
Some(ref stm) => {
|
||||
if let Some(ref context) = self.context.context {
|
||||
self.context.mainloop.lock();
|
||||
|
@ -752,6 +776,7 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
self.context.mainloop.unlock();
|
||||
Ok(())
|
||||
} else {
|
||||
cubeb_log!("Error: set_volume: no context?");
|
||||
Err(Error::error())
|
||||
}
|
||||
}
|
||||
|
@ -760,7 +785,10 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
|
||||
fn set_name(&mut self, name: &CStr) -> Result<()> {
|
||||
match self.output_stream {
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: can't set the name on a input-only stream.");
|
||||
Err(Error::error())
|
||||
}
|
||||
Some(ref stm) => {
|
||||
self.context.mainloop.lock();
|
||||
if let Ok(o) = stm.set_name(name, stream_success, self as *const _ as *mut _) {
|
||||
|
@ -780,6 +808,7 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
dev.input_name = match stm.get_device_name() {
|
||||
Ok(name) => name.to_owned().into_raw(),
|
||||
Err(_) => {
|
||||
cubeb_log!("Error: couldn't get the input stream's device name");
|
||||
return Err(Error::error());
|
||||
}
|
||||
}
|
||||
|
@ -789,6 +818,7 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
dev.output_name = match stm.get_device_name() {
|
||||
Ok(name) => name.to_owned().into_raw(),
|
||||
Err(_) => {
|
||||
cubeb_log!("Error: couldn't get the output stream's device name");
|
||||
return Err(Error::error());
|
||||
}
|
||||
}
|
||||
|
@ -796,12 +826,14 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
|
||||
Ok(unsafe { DeviceRef::from_ptr(Box::into_raw(dev) as *mut _) })
|
||||
} else {
|
||||
cubeb_log!("Error: PulseAudio context too old");
|
||||
Err(not_supported())
|
||||
}
|
||||
}
|
||||
|
||||
fn device_destroy(&mut self, device: &DeviceRef) -> Result<()> {
|
||||
if device.as_ptr().is_null() {
|
||||
cubeb_log!("Error: can't destroy null device");
|
||||
Err(Error::error())
|
||||
} else {
|
||||
unsafe {
|
||||
|
@ -815,6 +847,7 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
|
|||
&mut self,
|
||||
_: ffi::cubeb_device_changed_callback,
|
||||
) -> Result<()> {
|
||||
cubeb_log!("Error: register_device_change_callback unimplemented");
|
||||
Err(Error::error())
|
||||
}
|
||||
}
|
||||
|
@ -826,6 +859,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
stream_name: Option<&CStr>,
|
||||
) -> Result<pulse::Stream> {
|
||||
if stream_params.prefs() == StreamPrefs::LOOPBACK {
|
||||
cubeb_log!("Error: StreamPref::LOOPBACK unimplemented");
|
||||
return Err(not_supported());
|
||||
}
|
||||
|
||||
|
@ -841,6 +875,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
|
||||
let fmt = to_pulse_format(stream_params.format());
|
||||
if fmt == pulse::SampleFormat::Invalid {
|
||||
cubeb_log!("Error: invalid sample format");
|
||||
return Err(invalid_format());
|
||||
}
|
||||
|
||||
|
@ -874,7 +909,10 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
let stream = pulse::Stream::new(context, stream_name.unwrap(), &ss, cm.as_ref());
|
||||
|
||||
match stream {
|
||||
None => Err(Error::error()),
|
||||
None => {
|
||||
cubeb_log!("Error: pulse::Stream::new failure");
|
||||
Err(Error::error())
|
||||
}
|
||||
Some(stm) => Ok(stm),
|
||||
}
|
||||
}
|
||||
|
@ -1007,6 +1045,7 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
while towrite > 0 {
|
||||
match stm.begin_write(towrite) {
|
||||
Err(e) => {
|
||||
cubeb_logv!("Error: failure to write data");
|
||||
panic!("Failed to write data: {}", e);
|
||||
}
|
||||
Ok((buffer, size)) => {
|
||||
|
@ -1081,7 +1120,9 @@ impl<'ctx> PulseStream<'ctx> {
|
|||
got += (padding_bytes / frame_size) as i64;
|
||||
}
|
||||
} else {
|
||||
cubeb_log!("Not enough room to pad up to prebuf when prebuffering.")
|
||||
cubeb_logv!(
|
||||
"Not enough room to pad up to prebuf when prebuffering."
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче