Dealing with playback and capture of a single alsa mixer
I have a alsa device with only one mixer for capture and playback.
root@VZ-CVB-00000001:~ amixer -c 3
Simple mixer control 'PCM',0
Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined
Playback channels: Mono
Capture channels: Mono
Limits: Playback 0 - 100 Capture 0 - 100
Mono: Playback 100 [100%] [0.00dB] [on] Capture 100 [100%] [0.00dB] [on]
root@VZ-CVB-00000001:~ amixer -c 3 scontrols
Simple mixer control 'PCM',0
root@VZ-CVB-00000001:~ amixer -c 3 controls
numid=3,iface=MIXER,name='PCM Playback Switch'
numid=4,iface=MIXER,name='PCM Playback Volume'
numid=6,iface=MIXER,name='PCM Capture Switch'
numid=7,iface=MIXER,name='PCM Capture Volume'
numid=1,iface=PCM,name='Capture Pitch 1000000'
numid=8,iface=PCM,name='Capture Rate'
numid=2,iface=PCM,name='Playback Pitch 1000000'
numid=5,iface=PCM,name='Playback Rate'
I have made a alsa mixer profile-set
[Mapping gadget-output]
device-strings = hw:%f
channel-map = left,right,rear-left,rear-right
paths-output = foo-bar
exact-channels = false
priority = 1
direction = output
[Mapping gadget-input]
device-strings = hw:%f
fallback = yes
channel-map = front-left,front-right
paths-input = foo-bar2
priority = 1
direction = input
[Profile output:gadget-out+input:gadget-in]
output-mappings = gadget-output
input-mappings = gadget-input
priority = 5100
foo-bar and foo-bar2 have the same input
[Element PCM,0]
switch = mute
volume = merge
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Hardware volume ranges from -100.00 dB to 0.00 dB.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Fixing base volume to 0.00 dB
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Using hardware volume control. Hardware dB scale supported.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Using hardware mute control.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Activating path foo-bar
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Path foo-bar (foo-bar), direction=1, priority=0, probed=yes, supported=yes, has_mute=yes, has_volume=yes, has_dB=yes, min_volume=0, max_volume=100, min_dB=-100, max_dB=0
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Element 'PCM', direction=1, switch=1, volume=1, volume_limit=-1, enumeration=0, required=0, required_any=0, required_absent=0, mask=0x7ffffffffffff, n_channels=1, override_map=00
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Requested volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Got hardware volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Calculated software volume: 65536 (accurate-enough=yes)
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: card port changed from foo-bar to foo-bar
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Set hardware volume: min:65536 max:65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 0: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 1: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 2: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 3: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Requested volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Got hardware volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Calculated software volume: 65536 (accurate-enough=yes)
......
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 0x5595624080: 0x559561d0b0: mixer_volume_init (1258) soft: 0, path: 0x5595624540 has_vol: 1
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Hardware volume ranges from -100.00 dB to 0.00 dB.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Fixing base volume to 0.00 dB
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Using hardware volume control. Hardware dB scale supported.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Using hardware mute control.
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Activating path foo-bar2
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Path foo-bar2 (foo-bar2), direction=2, priority=0, probed=yes, supported=yes, has_mute=yes, has_volume=yes, has_dB=yes, min_volume=0, max_volume=100, min_dB=-100, max_dB=0
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Element 'PCM', direction=2, switch=1, volume=1, volume_limit=-1, enumeration=0, required=0, required_any=0, required_absent=0, mask=0x7ffffffffffff, n_channels=1, override_map=00
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Requested volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Got hardware volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Calculated software volume: 65536 (accurate-enough=yes)
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: card port changed from foo-bar to foo-bar2
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Set hardware volume: min:65536 max:65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 0: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: 1: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Requested volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Got hardware volume: 65536
Dec 01 02:39:41 VZ-CVB-00000001 wireplumber[1125]: Calculated software volume: 65536 (accurate-enough=yes)
I don't know if I understand your implementation correct but what I can see is that you can only deal with one element type of a mixer. A Capture OR playback element but no capture AND playback element.
So when you have a single mixer with capture and playback possibility. Both elements are handled but the first callback of the first handled element is overwritten by the next element callback.
When I change the volume in 'alsamixer' of the playback element. The function 'mixer_callback' in the file 'acp.c' is called but with the wrong device. In my case the capture element.