feat(sound): use cosmic-settings-daemon's varlink API
This commit is contained in:
parent
3a77442dbc
commit
9155a1e902
19 changed files with 1211 additions and 3470 deletions
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright 2025 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use pipewire::device::DeviceInfoRef;
|
||||
|
||||
/// Device information
|
||||
#[must_use]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Device {
|
||||
pub id: u32,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl Device {
|
||||
/// Attains process info from a pipewire info node.
|
||||
#[must_use]
|
||||
pub fn from_device(info: &DeviceInfoRef) -> Option<Self> {
|
||||
let props = info.props()?;
|
||||
|
||||
let device = Device {
|
||||
id: props.get("object.id")?.parse::<u32>().ok()?,
|
||||
name: props.get("device.description")?.to_owned(),
|
||||
};
|
||||
|
||||
Some(device)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
// Copyright 2025 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
//! Currently unusued
|
||||
|
||||
use crate::pipewire::Direction;
|
||||
use pipewire::port::PortInfoRef;
|
||||
|
||||
#[must_use]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Port {
|
||||
pub node_id: u32,
|
||||
pub object_id: u32,
|
||||
pub port_id: u32,
|
||||
pub audio_channel: String,
|
||||
pub format_dsp: String,
|
||||
pub object_path: String,
|
||||
pub port_direction: Direction,
|
||||
pub port_group: String,
|
||||
pub port_name: String,
|
||||
pub port_alias: String,
|
||||
pub port_physical: bool,
|
||||
pub port_terminal: bool,
|
||||
pub port_monitor: bool,
|
||||
}
|
||||
|
||||
impl Port {
|
||||
/// Attains process info from a pipewire info port.
|
||||
#[must_use]
|
||||
pub fn from_port(info: &PortInfoRef) -> Option<Self> {
|
||||
let props = info.props()?;
|
||||
let object_id = info.id();
|
||||
let port_direction = match info.direction() {
|
||||
libspa::utils::Direction::Input => Direction::Input,
|
||||
libspa::utils::Direction::Output => Direction::Output,
|
||||
_ => return None,
|
||||
};
|
||||
|
||||
let mut node_id = 0;
|
||||
let mut port_id = 0;
|
||||
let mut port_monitor = false;
|
||||
let mut port_physical = false;
|
||||
let mut port_terminal = false;
|
||||
|
||||
let mut audio_channel = String::new();
|
||||
let mut format_dsp = String::new();
|
||||
let mut object_path = String::new();
|
||||
let mut port_alias = String::new();
|
||||
let mut port_group = String::new();
|
||||
let mut port_name = String::new();
|
||||
|
||||
for (entry, value) in props.iter() {
|
||||
match entry {
|
||||
// 32 bit float mono audio
|
||||
"format.dsp" => format_dsp = value.to_owned(),
|
||||
// FR
|
||||
"audio.channel" => audio_channel = value.to_owned(),
|
||||
// playback
|
||||
"port.group" => port_group = value.to_owned(),
|
||||
// 1
|
||||
"port.id" => port_id = value.parse::<u32>().ok()?,
|
||||
// false
|
||||
"port.monitor" => port_monitor = value == "true",
|
||||
// true
|
||||
"port.physical" => port_physical = value == "true",
|
||||
// true
|
||||
"port.terminal" => port_terminal = value == "true",
|
||||
// alsa:acp:Device:3:playback:playback_1
|
||||
"object.path" => object_path = value.to_owned(),
|
||||
// playback_FR
|
||||
"port.name" => port_name = value.to_owned(),
|
||||
// MosArt USB Audio Device:playback_FR
|
||||
"port.alias" => port_alias = value.to_owned(),
|
||||
// 59
|
||||
"node.id" => node_id = value.parse::<u32>().ok()?,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
let port = Port {
|
||||
format_dsp,
|
||||
audio_channel,
|
||||
port_id,
|
||||
port_direction,
|
||||
object_path,
|
||||
port_name,
|
||||
port_alias,
|
||||
port_group,
|
||||
port_monitor,
|
||||
port_physical,
|
||||
port_terminal,
|
||||
node_id,
|
||||
object_id,
|
||||
};
|
||||
|
||||
Some(port)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,150 +0,0 @@
|
|||
// Copyright 2025 System76 <info@system76.com>
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use libspa::pod::Pod;
|
||||
use std::ffi::CStr;
|
||||
|
||||
/// Read a `Pod`'s string if it contains a string.
|
||||
pub fn string_from_pod(pod: &Pod) -> Option<String> {
|
||||
if !pod.is_string() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut cstr = std::ptr::null();
|
||||
|
||||
unsafe {
|
||||
// SAFETY: Pod is checked to be a string beforehand
|
||||
if libspa_sys::spa_pod_get_string(pod.as_raw_ptr(), &mut cstr) == 0 && !cstr.is_null() {
|
||||
return Some(String::from_utf8_lossy(CStr::from_ptr(cstr).to_bytes()).into_owned());
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// SAFETY: Must be absolutely certain that the array is a compatible array.
|
||||
pub unsafe fn array_from_pod<CType: Copy>(pod: &Pod) -> Option<Vec<CType>> {
|
||||
if !pod.is_array() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut len = 0;
|
||||
|
||||
unsafe {
|
||||
let array: *mut CType = libspa_sys::spa_pod_get_array(pod.as_raw_ptr(), &mut len).cast();
|
||||
|
||||
if array.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(std::slice::from_raw_parts(array, len as usize).to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(u32)]
|
||||
#[derive(Copy, Clone, Debug, Default, Hash, Eq, PartialEq)]
|
||||
pub enum Channel {
|
||||
#[default]
|
||||
UNKNOWN = 0, // unspecified
|
||||
NA, // N/A, silent
|
||||
MONO, // mono stream
|
||||
FL, // front left
|
||||
FR, // front right
|
||||
FC, // front center
|
||||
LFE, // LFE
|
||||
SL, // side left
|
||||
SR, // side right
|
||||
FLC, // front left center
|
||||
FRC, // front right center
|
||||
RC, // rear center
|
||||
RL, // rear left
|
||||
RR, // rear right
|
||||
TC, // top center
|
||||
TFL, // top front left
|
||||
TFC, // top front center
|
||||
TFR, // top front right
|
||||
TRL, // top rear left
|
||||
TRC, // top rear center
|
||||
TRR, // top rear right
|
||||
RLC, // rear left center
|
||||
RRC, // rear right center
|
||||
FLW, // front left wide
|
||||
FRW, // front right wide
|
||||
LFE2, // LFE 2
|
||||
FLH, // front left high
|
||||
FCH, // front center high
|
||||
FRH, // front right high
|
||||
TFLC, // top front left center
|
||||
TFRC, // top front right center
|
||||
TSL, // top side left
|
||||
TSR, // top side right
|
||||
LLFE, // left LFE
|
||||
RLFE, // right LFE
|
||||
BC, // bottom center
|
||||
BLC, // bottom left center
|
||||
BRC = 37, // bottom right center
|
||||
AUX0 = 4096, // aux channels
|
||||
AUX1,
|
||||
AUX2,
|
||||
AUX3,
|
||||
AUX4,
|
||||
AUX5,
|
||||
AUX6,
|
||||
AUX7,
|
||||
AUX8,
|
||||
AUX9,
|
||||
AUX10,
|
||||
AUX11,
|
||||
AUX12,
|
||||
AUX13,
|
||||
AUX14,
|
||||
AUX15,
|
||||
AUX16,
|
||||
AUX17,
|
||||
AUX18,
|
||||
AUX19,
|
||||
AUX20,
|
||||
AUX21,
|
||||
AUX22,
|
||||
AUX23,
|
||||
AUX24,
|
||||
AUX25,
|
||||
AUX26,
|
||||
AUX27,
|
||||
AUX28,
|
||||
AUX29,
|
||||
AUX30,
|
||||
AUX31,
|
||||
AUX32,
|
||||
AUX33,
|
||||
AUX34,
|
||||
AUX35,
|
||||
AUX36,
|
||||
AUX37,
|
||||
AUX38,
|
||||
AUX39,
|
||||
AUX40,
|
||||
AUX41,
|
||||
AUX42,
|
||||
AUX43,
|
||||
AUX44,
|
||||
AUX45,
|
||||
AUX46,
|
||||
AUX47,
|
||||
AUX48,
|
||||
AUX49,
|
||||
AUX50,
|
||||
AUX51,
|
||||
AUX52,
|
||||
AUX53,
|
||||
AUX54,
|
||||
AUX55,
|
||||
AUX56,
|
||||
AUX57,
|
||||
AUX58,
|
||||
AUX59,
|
||||
AUX60,
|
||||
AUX61,
|
||||
AUX62,
|
||||
AUX63 = 4159,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue