Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pipeswitch-lib/src/pw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pub enum PipewireError {
MissingProps(u32, ObjectType, HashMap<String, String>),
#[error("direction not valid: {0}")]
InvalidDirection(String),
#[error("channel not valid: {0}")]
InvalidChannel(String),
#[error("error with core pipewire interface: {0}")]
PipewireInterfaceError(#[from] pipewire::Error),
#[error("tried to delete a global object that was not yet registered: {0}")]
Expand Down
50 changes: 17 additions & 33 deletions pipeswitch-lib/src/pw/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,26 @@ impl Direction {
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Channel {
Left,
Right,
Mono,
Aux(u32),
pub struct Channel {
short_name: String,
}

impl Channel {
fn from_channel<T: Into<String>>(input: Option<T>) -> Result<Option<Self>, PipewireError> {
if let Some(input) = input {
let input = input.into();
Ok(Some(match input.as_str() {
"FL" => Channel::Left,
"FR" => Channel::Right,
"MONO" => Channel::Mono,
i if i.starts_with("AUX") => {
let num = i.split_at("AUX".len()).1.parse()?;
match num {
0 => Channel::Left,
1 => Channel::Right,
_ => Channel::Aux(num),
}
}
_ => Err(PipewireError::InvalidChannel(input))?,
}))
} else {
Ok(None)
}
fn from_channel<T: Into<String>>(input: Option<T>) -> Option<Self> {
Some(Self {
short_name: input?.into(),
})
}

fn from_portid(input: u32) -> Result<Self, PipewireError> {
Ok(match input {
0 => Channel::Left,
1 => Channel::Right,
_ => Channel::Aux(input),
})
fn from_portid(input: u32) -> Self {
Self {
// TODO(strohel): wouldn't it be better to name them all AUX{n}?
short_name: match input {
0 => "FL".to_string(),
1 => "FR".to_string(),
_ => format!("AUX{input}"),
},
}
}
}

Expand Down Expand Up @@ -113,8 +97,8 @@ impl Port {
path: get_prop(*OBJECT_PATH),
node_id: get_prop_or(*NODE_ID)?.parse()?,
dsp: get_prop(*FORMAT_DSP),
channel: Channel::from_channel(get_prop(*AUDIO_CHANNEL))?
.unwrap_or(Channel::from_portid(local_port_id)?),
channel: Channel::from_channel(get_prop(*AUDIO_CHANNEL))
.unwrap_or(Channel::from_portid(local_port_id)),
name: get_prop_or(*PORT_NAME)?,
direction: Direction::from(get_prop_or(*PORT_DIRECTION)?)?,
alias: get_prop_or(*PORT_ALIAS)?,
Expand Down