Skip to content

Commit

Permalink
chore(blink): use new errors for play and pause
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwoodbury committed Nov 2, 2023
1 parent b83dec4 commit d5ba221
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
24 changes: 13 additions & 11 deletions extensions/warp-blink-wrtc/src/host_media/audio/opus/sink/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,18 @@ impl SinkTrack for OpusSink {

fn play(&self) -> Result<(), Error> {
*self.muted.write() = false;
self.stream
.play()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
Ok(())
self.stream.play().map_err(|err| match err {
cpal::PlayStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})
}

fn pause(&self) -> Result<(), Error> {
*self.muted.write() = true;
self.stream
.pause()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
Ok(())
self.stream.pause().map_err(|err| match err {
cpal::PauseStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})
}
fn change_output_device(
&mut self,
Expand All @@ -219,9 +220,10 @@ impl SinkTrack for OpusSink {
)?;
*self = new_sink;
if !*self.muted.read() {
self.stream
.play()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
self.stream.play().map_err(|err| match err {
cpal::PlayStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})?;
}

Ok(())
Expand Down
21 changes: 12 additions & 9 deletions extensions/warp-blink-wrtc/src/host_media/audio/opus/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,18 @@ impl SourceTrack for OpusSource {
}

fn play(&self) -> Result<(), Error> {
self.stream
.play()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
self.stream.play().map_err(|err| match err {
cpal::PlayStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})?;
*self.muted.write() = false;
Ok(())
}
fn pause(&self) -> Result<(), Error> {
self.stream
.pause()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
self.stream.pause().map_err(|err| match err {
cpal::PauseStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})?;
*self.muted.write() = true;
Ok(())
}
Expand All @@ -118,9 +120,10 @@ impl SourceTrack for OpusSource {
self.stream = stream;
self.packetizer_handle = handle;
if !*self.muted.read() {
self.stream
.play()
.map_err(|x| Error::OtherWithContext(x.to_string()))?;
self.stream.play().map_err(|err| match err {
cpal::PlayStreamError::DeviceNotAvailable => Error::AudioDeviceDisconnected,
_ => Error::OtherWithContext(err.to_string()),
})?;
}
Ok(())
}
Expand Down
4 changes: 3 additions & 1 deletion warp/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ pub enum Error {
InvalidDataType,

//Blink Errors
#[error("Device not found")]
#[error("Audio device not found")]
AudioDeviceNotFound,
#[error("AudioDeviceDisconnected")]
AudioDeviceDisconnected,
// indicates a problem enumerating audio I/O devices
#[error("AudioHostError: {_0}")]
AudioHostError(String),
Expand Down

0 comments on commit d5ba221

Please sign in to comment.