[pulseaudio-commits] [Git][pulseaudio/pulseaudio][master] alsa-mixer: store the ucm_device with the order of their priority
Tanu Kaskinen
gitlab at gitlab.freedesktop.org
Wed Jun 10 06:18:28 UTC 2020
Tanu Kaskinen pushed to branch master at PulseAudio / pulseaudio
Commits:
3549a4d9 by Hui Wang at 2020-06-10T08:46:51+03:00
alsa-mixer: store the ucm_device with the order of their priority
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 at canonical.com>
- - - - -
3 changed files:
- src/modules/alsa/alsa-mixer.c
- src/pulsecore/dynarray.c
- src/pulsecore/dynarray.h
Changes:
=====================================
src/modules/alsa/alsa-mixer.c
=====================================
@@ -249,10 +249,23 @@ void pa_alsa_jack_set_plugged_in(pa_alsa_jack *jack, bool plugged_in) {
}
void pa_alsa_jack_add_ucm_device(pa_alsa_jack *jack, pa_alsa_ucm_device *device) {
+ pa_alsa_ucm_device *idevice;
+ unsigned idx, prio, iprio;
+
pa_assert(jack);
pa_assert(device);
- pa_dynarray_append(jack->ucm_devices, device);
+ /* store the ucm device with the sequence of priority from low to high. this
+ * could guarantee when the jack state is changed, the device with highest
+ * priority will send to the module-switch-on-port-available last */
+ prio = device->playback_priority ? device->playback_priority : device->capture_priority;
+
+ PA_DYNARRAY_FOREACH(idevice, jack->ucm_devices, idx) {
+ iprio = idevice->playback_priority ? idevice->playback_priority : idevice->capture_priority;
+ if (iprio > prio)
+ break;
+ }
+ pa_dynarray_insert_by_index(jack->ucm_devices, device, idx);
}
void pa_alsa_jack_add_ucm_hw_mute_device(pa_alsa_jack *jack, pa_alsa_ucm_device *device) {
=====================================
src/pulsecore/dynarray.c
=====================================
@@ -140,3 +140,26 @@ unsigned pa_dynarray_size(pa_dynarray *array) {
return array->n_entries;
}
+
+int pa_dynarray_insert_by_index(pa_dynarray *array, void *p, unsigned i) {
+ void *entry;
+ unsigned j;
+
+ pa_assert(array);
+
+ if (i > array->n_entries)
+ return -PA_ERR_NOENTITY;
+
+ if (i == array->n_entries)
+ pa_dynarray_append(array, p);
+ else {
+ entry = pa_dynarray_last(array);
+ pa_dynarray_append(array, entry);
+ j = array->n_entries - 2;
+ for (;j > i; j--)
+ array->data[j] = array->data[j-1];
+ array->data[i] = p;
+ }
+
+ return 0;
+}
=====================================
src/pulsecore/dynarray.h
=====================================
@@ -63,6 +63,10 @@ void *pa_dynarray_steal_last(pa_dynarray *array);
unsigned pa_dynarray_size(pa_dynarray *array);
+/* Returns -PA_ERR_NOENTITY if i is out of bounds, and zero otherwise.
+ * Here i is the location index in the array like 0, ..., array->entries */
+int pa_dynarray_insert_by_index(pa_dynarray *array, void *p, unsigned i);
+
#define PA_DYNARRAY_FOREACH(elem, array, idx) \
for ((idx) = 0; ((elem) = pa_dynarray_get(array, idx)); (idx)++)
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/3549a4d926c9505f3600a8eb7941dc27a9039b3f
--
View it on GitLab: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/commit/3549a4d926c9505f3600a8eb7941dc27a9039b3f
You're receiving this email because of your account on gitlab.freedesktop.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-commits/attachments/20200610/459e5046/attachment-0001.htm>
More information about the pulseaudio-commits
mailing list