diwic / alsa-rs

Thin but safe ALSA wrappers for Rust
Apache License 2.0
138 stars 64 forks source link

Allow to pass flags to snd_pcm_open #120

Open abique opened 1 week ago

abique commented 1 week ago

We'd need to be able to pass additionnal flags for scanning pcm. There's an undocumented ALSA flag: 256 that will allow to open the pcm for scanning info (ignore EBUSY).

diwic commented 1 week ago

Apparently this flag is call SND_PCM_APPEND in alsa-lib. Never heard of it before.

Could you either ask the ALSA people to document it, or maybe give an explanation of how it works and what you can and can't do if this flag is enabled? I'd rather support it properly than just allow undocumented flags.

abique commented 1 week ago

This is useful for scanning device capabilities even if the devices is busy.

abique commented 1 week ago

Even if you don't document it, you could allow an arbitrary int for the flags.

diwic commented 1 week ago

This is useful for scanning device capabilities even if the devices is busy.

So what things can you not do if this flag is set? Can you still set hwparams? Start a direct mmap transfer? Start/stop the stream? Etc etc.

Being able to open more than one PCM object to the same device could cause unsafety or undefined behaviour if not done correctly.

Even if you don't document it, you could allow an arbitrary int for the flags.

As some kind of fallback I could potentially allow unsafe fn PCM::from_handle(*mut snd_pcm_t), I guess, then you could call snd_pcm_open yourself and then use alsa-rs for the rest, but as I said, one of the main things these bindings provide is safety, and I'm hesitant to risk that.

abique commented 1 week ago

You can have a method 'open_forscanning()' which will prevent starting and stopping the stream and every `set*()`.

You could also have a method that just collects the PCM capabilities.

diwic commented 1 week ago

You can have a method 'open_forscanning()' which will prevent starting and stopping the stream and every set*(). You could also have a method that just collects the PCM capabilities.

And you could do some research and come back with answers to my questions ;-)

I'm quite hesitant to just add support for undocumented features that could potentially make the library unsafe.

abique commented 1 week ago

Sorry I can't do research I've no time for it. I told already everything I know.