There were three bugs:
1) j->state_plugged was set to PA_AVAILABLE_UNKNOWN too early. It must
be set only after we have found that the jack is shared by two ports.
The result of setting it too early was that no jack ever could have
the PA_AVAILABLE_YES status.
2) The inner jack loop iterated through p->jacks instead of p2->jacks,
so the code didn't compare jacks between two ports at all. As a result
all ports were put in the same availability group.
3) The inner jack loop checked j->state_plugged instead of
j2->state_plugged. The result was that the speaker port, which uses the
Headphone jack to toggle between unknown and unavailable, was put in the
same group with the headphone port.
There is some case that multiple ucm devices share an amixer Jack
like "Headphones", "Headset" and "Mic2" share the "Headphone Mic Jack",
When the Jack state is changed, the module-switch-on-port-available
will process them in the order they are in the jack->ucm_devices, and
the last device will decide the final setting.
But usually users put priority for those devices and expect the
final setting is based on the highest priority device if there is no
other policies like manual selection. So here do some change to store
the ucm_devices according to their priority (from low to high).
For example, we have ucm devices definition like below (ucm2):
SectionDevice."Mic2" {
Comment "Headphones Stereo Microphone"
...
Value {
CapturePriority 200
...
}
SectionDevice."Headset" {
Comment "Headset Mono Microphone"
...
Value {
CapturePriority 300
...
}
}
Without this patch, the final setting is based on Mic2, after applying
this patch, the final setting is based on the Headset (with higher
priority than Mic2).
Signed-off-by: Hui Wang <hui.wang@canonical.com>
The ALSA mixer can be opened multiple times (especially for UCM
in the probe). This adds a simple mixer cache to prevent
multiple open calls.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
It is possible that we might want to have a separate userdata to be used
for these callbacks, so let's split them out.
This is particularly needed when using an pa_rtpoll_item around pa_fdsem
since that uses its own before/after callback but will essentially have
whatever is using the fdsem set up the work callback appropriately (and
thus at least the work callback's userdata needs to be separated from
the before/after callback -- we might as well then just separate all
three).
Signed-off-by: Arun Raghavan <arun@arunraghavan.net>
Consumers are expected to use <alsa/asoundlib.h> instead of
<asoundlib.h>.
This is in preparation of an change to pkgconfig(alsa) to
not pollute CFLAGS with -I/usr/include/alsa anymore.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
It is helpful to improve reproducibility build [1] since
PA_SRCDIR/PA_BUILDDIR contains build path,
--disable-running-from-build-tree could drop these macros at
precompilation.
[1] https://reproducible-builds.org/
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
If a sound card doesn't have the "front" device defined for it, we have
to use the "hw" device for stereo. Not so long ago, the analog-stereo
mapping had "hw:%f" in its device-strings and everything worked great,
except that it caused trouble with the Intel HDMI LPE driver that uses
the first "hw" device for HDMI, and we were incorrectly detecting it as
an analog device. That problem was fixed in commit ea3ebd09, which
removed "hw:%f" from analog-stereo and added a new stereo fallback
mapping for "hw".
Now the problem is that if a sound card doesn't have the "front" device
defined for it, and it supports both mono and stereo, only the mono
mapping is used, because the stereo mapping is only a fallback. This
patch makes the mono mapping a fallback too, so the mono mapping is used
only if there's absolutely nothing else that works.
This can cause trouble at least in theory. Maybe someone actually wants
to use mono output on a card that supports both mono and stereo. But
that seems quite unlikely.
This removes the need to hardcode the ELD device index in the path
configuration. The hardcoded values don't work with the Intel HDMI LPE
driver.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100488
We have so far assumed that HDMI always uses device indexes 3, 7, 8, 9,
10, 11, 12 and 13. These values are hardcoded in the path configuration.
The Intel HDMI LPE driver, however, uses different device numbering
scheme. Since the indexes aren't always the same, we need to query the
hw device index from ALSA.
Later patches will use the queried index for HDMI jack detection and ELD
information reading.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100488
Some sound cards don't have any alsa-lib configuration, but they used to
work well enough up to PulseAudio 10. PulseAudio 11 stopped using "hw:0"
for the analog-stereo mapping, and instead defined it as a fallback
mapping without any mixer handling. As a result, switching between
headphones and speakers stopped working without changing the mixer
settings manually at least on Toshiba Chromebook 2. This patch adds the
mixer handling back to the fallback mapping.
I also renamed "unknown-stereo" to "stereo-fallback", because I like
that name more.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=102560
to_alsa_dB() returns a result rounded to two decimal places (instead of
using integer truncation) to avoid small errors when converting between
dB and volume.
Consider playback at -22 dB (which is supported by ALSA) but results in
the higher level of -21 dB plus software attenuation.
pa_sw_volume_from_dB(-22) = 28172
pa_sw_volume_to_dB(28172) = -21.9997351
to_alsa_dB(-21.9997351) = -2199
ALSA value 106 = -2200
ALSA value 107 = -2100
...
rounding = +1 /* "accurate or first above" */
snd_mixer_selem_ask_playback_dB_vol(me, -2199, rounding, &alsa_val)
alsa_val = -2100
Signed-off-by: Ian Ray <ian.ray@ge.com>
Previously, if front:x didn't work, we would try to use hw:x for analog
stereo output. There's no guarantee that hw:x is an analog output,
however. For example, the Intel HDMI LPE driver uses hw:x for HDMI
output, and PulseAudio incorrectly created analog profiles for that
card, because front:x doesn't work but hw:x does.
This patch changes things so that the analog stereo mapping doesn't any
more use hw:x as a fallback. A separate "unknown stereo" fallback
mapping is added to handle the rare case where hw:x is the only PCM
device that works.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100488
By refactoring volume probing into its own function, we can reduce
indentation a lot. Also, if an error occurs during the volume probe,
that volume element is now always skipped (instead of taking down
the entire path with it).
Also, a bug for elements with more than two channels is fixed, as
previously, the volume parsing code was continuing, potentially
referencing somewhere outside the array (which has max two channels).
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This allows a configuration scheme where after loading configuration
from "somefile", the parser loads configuration from files in
directory "somefile.d". This feature needs to be enabled on a per-file
basis, though, and this patch doesn't yet enable the feature for any
files.
When synthesized alsa path is freed there is an assert from NULL
proplist. Create empty proplist for the path to fix.
Signed-off-by: Juho Hämäläinen <juho.hamalainen@nomovok.com>
We encountered an alsa plugin a while ago (not sure if the source
can be shared) which had mixer controls, but no descriptors to
poll for changes.
Quit early to avoid latter assertion failures.
BugLink: https://bugs.launchpad.net/bugs/1092377
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
We currently only support one and two channels for volumes, and
bail out otherwise. This makes Xonar users unhappy because they
have a volume with eight channels, and bailing out means they
don't have a path/port at all.
This way they will at least have a port, which will in turn make
the gnome/unity UI behave better.
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=84983
BugLink: https://bugzilla.gnome.org/show_bug.cgi?id=745017
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Previously the UCM code created one jack object per device name (which
is not the same thing as creating one jack object per device, because
the UCM device namespace is scoped on per-verb basis, so devices in
different verbs may have the same name). I think it's conceptually
cleaner to create one jack object per alsa kcontrol. I plan to do
similar refactoring on the traditional mixer code later.
Previously module-alsa-card assigned to pa_alsa_jack.plugged_in
directly, and then did the port availability updating manually. The
idea of pa_alsa_jack_set_plugged_in() is to move the availability
updating to the mixer infrastructure, where it really belongs.
Similarly, pa_alsa_jack.has_control was previously modified directly
from several places. The has_control field affects the port
availability, and pa_alsa_jack_set_has_control() takes care of
updating the availability.
For now, pa_alsa_jack_set_plugged_in() and
pa_alsa_jack_set_has_control() only update the port availability
when using UCM. My plan is to adapt the traditional mixer code later.
These mapping names are used in sb-omni-surround-5.1.conf, which needs
to use separate mappings for input and output, since they are
associated with different alsa devices.
This makes the GUIs (e g gnome/unity-control-center) look more consistent
with other inputs/outputs that also have ports.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
This works around bug 80850: a mapping can only have one channel map,
and in case of a 6-out 10-in device, the mapping will be adjusted to
have both 10 and 6 channels, which does not work.
Reported-by: Benjamin Tegge <benjaminosm@googlemail.com>
Suggested-by: Raymond Yau <superquad.vortex2@gmail.com>
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=80850
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
FSF addresses used in PA sources are no longer valid and rpmlint
generates numerous warnings during packaging because of this.
This patch changes all FSF addresses to FSF web page according to
the GPL how-to: https://www.gnu.org/licenses/gpl-howto.en.html
Done automatically by sed-ing through sources.
get rid of the following warning when compiling with NDEBUG:
modules/alsa/alsa-mixer.c: In function 'element_is_subset':
modules/alsa/alsa-mixer.c:3125:18: warning: 'a_limit' may be used uninitialized in this function [-Wmaybe-uninitialized]
long a_limit;
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Now that we have switched to using the mixer handle only,
there is no use for sending hctl handles around.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Use the new mixer API to get callbacks, instead of using the hctl
API. Using the hctl API caused a memory leak, because alsa-lib itself
used the hctl callbacks, which we were previously overriding.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Valgrind is not correctly handling ALSA TLV syscalls, which leads
to false warnings, looking like this:
"Conditional jump or move depends on uninitialised value(s)"
Unfortunately, alsa-lib itself also uses these values which valgrind
falsely believe are uninitialized, so not all warnings are removed,
but this is what we can do from PA until the valgrind bug is fixed.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>