Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux pipewire integration (Audio + Microphone) #1973

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Meister1593
Copy link
Collaborator

This is not done by any means, just put up for anyone to see how things are progressing
So far: main flow (pipewire source, getting data from one place to another) is kinda done, but i've yet to determine why only thing i get is pops into mic, it might be a multiple issues at once (buffer overload + trying to push all at once)
Other issues are listed in TODO's

@Meister1593 Meister1593 marked this pull request as draft February 4, 2024 20:12
@zarik5
Copy link
Member

zarik5 commented Feb 5, 2024

I haven't reviewed completely. But linux specific code should go in crates/audio/src/linux.rs

@Meister1593
Copy link
Collaborator Author

Meister1593 commented Feb 5, 2024

I haven't reviewed completely. But linux specific code should go in crates/audio/src/linux.rs

Please don't review it completely yet, its just in barely compilable state, not ready for any serious review of the code itself.

@guysoft
Copy link

guysoft commented Feb 26, 2024

Cool! Any way to help?

@Vixea
Copy link
Collaborator

Vixea commented Feb 26, 2024

Cool! Any way to help?

no not really unless you wanna pull a night of just reading documentation on oboe(not the rust crate but the google software one) oh and you somehow figure out what we're doing wrong so you have to know Rust too

@Meister1593 Meister1593 force-pushed the pipewire-microphone branch 3 times, most recently from 69a43ad to 725909f Compare March 17, 2024 18:17
@zarik5 zarik5 force-pushed the master branch 2 times, most recently from d01478e to 005c4c7 Compare March 22, 2024 09:18
Changed chan size to proper, as well as audio format to f32

Uncommitted older changes

Updated pipewire libs, adapted code to new pipewire lib version, issue with moving threads for pipewire

Sink creation done, pipewire-rs and alvr compiled, no buffer copying yet

Dropped unnecessary custom pw-rs, tokio. Code cleanup and move to single mainloop thread.

Cfg cleanup

Changed cfgs to not linux for android client compatibility

Removed unnecessary pipewire code from client

Renamed microphone output for linux pipewire, removed Audio Type

Updated Cargo.lock

Started implementing channels for pipewire to handle buffers

Implemented basic buffer, almost completely non functional, code related to actual bufferring needs to be re-added

Refactored flow, experimenting with byte types, order, etc

Added comment about graceful shutdown

Fixed steamvr shutdown. Experimenting with alternative ways to process streamed data
@Meister1593
Copy link
Collaborator Author

Current progress: Both audio sink and microphone source are being created and working correctly!
What's left to do: Refactor platform-specific code, overalll cleanup code and make UI edits to allow for native pipewire, make it default with fallback to cpal in case pipewire is missing or outdated (this specifically - unlikely scenario? code needs at least 0.3.49 pipewire).

@Meister1593 Meister1593 self-assigned this Jun 5, 2024
@zarik5
Copy link
Member

zarik5 commented Jun 5, 2024

I would say that the pipewire audio code can replace cpal for linux.

@The-personified-devil
Copy link
Collaborator

I think a fair amount of people still run pulseaudio and for them audio would not work at all. So either we make pipewire a hard requirement or we keep the cpal code around for the time being.

@Meister1593
Copy link
Collaborator Author

I've considered removing cpal, but i know that linux mint is still on pulse

That said, they won't have microphone and they can technically switch to pipewire (and they should really)

I'm 50/50 about this, but inclined to removing cpal from linux and going pipewire all the way, and point people to install pipewire.

@The-personified-devil
Copy link
Collaborator

I looked at it and basically all big distros (arch, debian, ubuntu, fedora, centos) have been shipping pipewire as default for at least a year, and every other sane distro has support for it. Even Mint will ship it as default in the upcoming release. So I think forcing pipewire should be the thing.

@Meister1593
Copy link
Collaborator Author

I looked at it and basically all big distros (arch, debian, ubuntu, fedora, centos) have been shipping pipewire as default for at least a year, and every other sane distro has support for it. Even Mint will ship it as default in the upcoming release. So I think forcing pipewire should be the thing.

Then i think that settles it, i would remove cpal from linux completely
Would need to adjust ui with that as well, probably gonna make conditionals for audio section to remove parts of it on linux

@infidelus
Copy link

infidelus commented Jun 6, 2024

I've considered removing cpal, but i know that linux mint is still on pulse

Linux Mint will be moving to PipeWire from the next release - https://blog.linuxmint.com/?p=4660. Obviously there will still be those on earlier versions of LM that are still on PulseAudio though, although maybe it'll be the nudge those users need to upgrade (or install PipeWire separately). :)

@Meister1593 Meister1593 changed the title Draft: Linux pipewire integration Linux pipewire integration (Sink + Microphone) Jun 9, 2024
@Meister1593 Meister1593 marked this pull request as ready for review June 9, 2024 17:40
@Meister1593
Copy link
Collaborator Author

Meister1593 commented Jun 9, 2024

In current state:
Creates sink (ALVR Audio) and microphone (ALVR Microphone), they are working as a regular device (no different to others)
image
Replaced audio presets to just toggles
image
Advanced audio will be changed to hide older cpal device list for linux (not in this PR)

Only thing left to do is remove on connect script from setup guide, maybe even make a migration so that it will be removed to not interfere with pipewire from this PR

Opened PR for review, for suggestions, and will use it for the time being to find any inconsistencies or issues if there will be any

@Meister1593 Meister1593 changed the title Linux pipewire integration (Sink + Microphone) Linux pipewire integration (Audio + Microphone) Jun 9, 2024
Copy link
Collaborator

@The-personified-devil The-personified-devil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't really review the actual linux pipewire code yet because I don't have enough time rn

@@ -231,7 +232,7 @@ impl DataSources {
match ws.read() {
Ok(tungstenite::Message::Text(json_string)) => {
if let Ok(event) = serde_json::from_str(&json_string) {
debug!("Server event received: {:?}", event);
// debug!("Server event received: {:?}", event);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not want to keep this? Cleaning up the logging is a different issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unintentional, it was spamming into logs too much, couldn't see anything else because of it, just commented for the dev time

};
}

#[cfg(target_os = "android")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to move this out into it's own file if it's android only

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus as far as I can tell this code is also invoked on the non-android clients

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/alvr-org/ALVR/blob/master/alvr/client_core/src/connection.rs#L327
As far as I can tell this code is relevant for all clients, not just android. If that's actually the case then you should rename that file from android to client and feature gate it as "not windows and not linux"

alvr/audio/src/lib.rs Outdated Show resolved Hide resolved
alvr/audio/src/lib.rs Outdated Show resolved Hide resolved
alvr/client_core/src/audio.rs Outdated Show resolved Hide resolved
alvr/server/src/connection.rs Show resolved Hide resolved
}

// returns (sink, source)
pub fn new_virtual_microphone_pair(config: MicrophoneDevicesConfig) -> Result<(Self, Self)> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do here, since this isn't needed on the client so it could just always return an error, but idk if it wouldn't be used in a potential future macos port

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i'm kind of divivded about this as well, it's never used and i don't know what to do with it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

6 participants