Audio output switching issue when unpluging headphones

Hi,
I have the following problem:

  • Play a video
  • By default, I have sound with my PC’ speakers
  • When I plug my headphones, the sound is correctly redirected
  • When I unplug my headphones, the sound doesn’t switch back to speakers

This does not happen if I start the video after I have unplugged my headphones. In particular, every time I unplug my headphones I have to close and open again the application in order to hear the sound (this happen on every app I tested, such as: VLC, Chrome, Firefox).

It seems that headphones are correctly detected.
Environment : KDE Plasma
pulseaudio version: 15.0

These some standards commands (headphones unplugged):

$ amixer -c0

Simple mixer control 'Master',0
  Capabilities: pvolume pvolume-joined pswitch pswitch-joined
  Playback channels: Mono
  Limits: Playback 0 - 87
  Mono: Playback 87 [100%] [0.00dB] [on]
Simple mixer control 'Headphone',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 79 [91%] [-6.00dB] [off]
  Front Right: Playback 79 [91%] [-6.00dB] [off]
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 87
  Mono:
  Front Left: Playback 80 [92%] [-5.25dB] [on]
  Front Right: Playback 80 [92%] [-5.25dB] [on]
Simple mixer control 'Mic',0
  Capabilities: pvolume pswitch
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 31
  Mono:
  Front Left: Playback 0 [0%] [-34.50dB] [off]
  Front Right: Playback 0 [0%] [-34.50dB] [off]
Simple mixer control 'Mic Boost',0
  Capabilities: volume
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: 0 - 3
  Front Left: 0 [0%] [0.00dB]
  Front Right: 0 [0%] [0.00dB]
Simple mixer control 'IEC958',0
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',1
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'IEC958',2
  Capabilities: pswitch pswitch-joined
  Playback channels: Mono
  Mono: Playback [on]
Simple mixer control 'Capture',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 63
  Front Left: Capture 63 [100%] [30.00dB] [on]
  Front Right: Capture 63 [100%] [30.00dB] [on]
Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'Dmic0',0
  Capabilities: cvolume cswitch
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 70
  Front Left: Capture 55 [79%] [5.00dB] [on]
  Front Right: Capture 55 [79%] [5.00dB] [on]
Simple mixer control 'Dmic1 2nd',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 70
  Front Left: Capture 50 [71%] [0.00dB]
  Front Right: Capture 50 [71%] [0.00dB]
Simple mixer control 'Loopback Mixing',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Disabled'
Simple mixer control 'PGA1.0 1 Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 32
  Mono:
  Front Left: Playback 32 [100%] [0.00dB]
  Front Right: Playback 32 [100%] [0.00dB]
Simple mixer control 'PGA2.0 2 Master',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 80
  Front Left: Capture 50 [62%] [0.00dB]
  Front Right: Capture 50 [62%] [0.00dB]
Simple mixer control 'PGA3.0 3 Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 32
  Mono:
  Front Left: Playback 32 [100%] [0.00dB]
  Front Right: Playback 32 [100%] [0.00dB]
Simple mixer control 'PGA4.0 4 Master',0
  Capabilities: cvolume
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 80
  Front Left: Capture 50 [62%] [0.00dB]
  Front Right: Capture 50 [62%] [0.00dB]
Simple mixer control 'PGA7.0 7 Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 32
  Mono:
  Front Left: Playback 32 [100%] [0.00dB]
  Front Right: Playback 32 [100%] [0.00dB]
Simple mixer control 'PGA8.0 8 Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 32
  Mono:
  Front Left: Playback 32 [100%] [0.00dB]
  Front Right: Playback 32 [100%] [0.00dB]
Simple mixer control 'PGA9.0 9 Master',0
  Capabilities: pvolume
  Playback channels: Front Left - Front Right
  Limits: Playback 0 - 32
  Mono:
  Front Left: Playback 32 [100%] [0.00dB]
  Front Right: Playback 32 [100%] [0.00dB]
$ pacmd list-cards

1 card(s) available.
    index: 0
        name: <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
        driver: <module-alsa-card.c>
        owner module: 6
        properties:
                alsa.card = "0"
                alsa.card_name = "sof-hda-dsp"
                alsa.long_card_name = "sof-hda-dsp"
                alsa.driver_name = "snd_soc_skl_hda_dsp"
                device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
                sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "a0c8"
                device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                device.string = "0"
                device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        profiles:
                HiFi: Play HiFi quality Music (priority 40768, available: unknown)
                off: Off (priority 0, available: unknown)
        active profile: <HiFi>
        sinks:
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_5__sink/#0: Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 3 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_4__sink/#1: Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 2 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_3__sink/#2: Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 1 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink/#3: Tiger Lake-LP Smart Sound Technology Audio Controller Speaker + Headphones
        sources:
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_5__sink.monitor/#0: Monitor of Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 3 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_4__sink.monitor/#1: Monitor of Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 2 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_3__sink.monitor/#2: Monitor of Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 1 Output
                alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink.monitor/#3: Monitor of Tiger Lake-LP Smart Sound Technology Audio Controller Speaker + Headphones
                alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__source/#4: Tiger Lake-LP Smart Sound Technology Audio Controller Headphones Stereo Microphone
                alsa_input.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_6__source/#5: Tiger Lake-LP Smart Sound Technology Audio Controller Digital Microphone
        ports:
                [Out] HDMI3: HDMI / DisplayPort 3 Output (priority 700, latency offset 0 usec, available: no)
                        properties:

                [Out] HDMI2: HDMI / DisplayPort 2 Output (priority 600, latency offset 0 usec, available: no)
                        properties:

                [Out] HDMI1: HDMI / DisplayPort 1 Output (priority 500, latency offset 0 usec, available: no)
                        properties:

                [Out] Speaker: Speaker (priority 100, latency offset 0 usec, available: unknown)
                        properties:

                [Out] Headphones: Headphones (priority 200, latency offset 0 usec, available: no)
                        properties:

                [In] Mic2: Headphones Stereo Microphone (priority 200, latency offset 0 usec, available: no)
                        properties:

                [In] Mic1: Digital Microphone (priority 100, latency offset 0 usec, available: unknown)
                        properties:
$ pacmd list-sinks

4 sink(s) available.
    index: 0
        name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_5__sink>
        driver: <module-alsa-card.c>
        flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE
        priority: 9037
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 0
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 341.00 ms
        card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
        module: 6
        properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HDMI3 (*)"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "5"
                alsa.card = "0"
                alsa.card_name = "sof-hda-dsp"
                alsa.long_card_name = "sof-hda-dsp"
                alsa.driver_name = "snd_soc_skl_hda_dsp"
                device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
                sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "a0c8"
                device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                device.string = "_ucm0001.hw:sofhdadsp,5"
                device.buffering.buffer_size = "65472"
                device.buffering.fragment_size = "16320"
                device.access_mode = "mmap+timer"
                device.profile.name = "HiFi: hw:sofhdadsp,5: sink"
                device.profile.description = "HDMI / DisplayPort 3 Output"
                alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
                device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 3 Output"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        ports:
                [Out] HDMI3: HDMI / DisplayPort 3 Output (priority 700, latency offset 0 usec, available: no)
                        properties:

        active port: <[Out] HDMI3>
    index: 1
        name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_4__sink>
        driver: <module-alsa-card.c>
        flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE
        priority: 9036
        volume: front-left: 42598 /  65% / -11.23 dB,   front-right: 42598 /  65% / -11.23 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 1
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 341.00 ms
        card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
        module: 6
        properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HDMI2 (*)"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "4"
                alsa.card = "0"
                alsa.card_name = "sof-hda-dsp"
                alsa.long_card_name = "sof-hda-dsp"
                alsa.driver_name = "snd_soc_skl_hda_dsp"
                device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
                sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "a0c8"
                device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                device.string = "_ucm0001.hw:sofhdadsp,4"
                device.buffering.buffer_size = "65472"
                device.buffering.fragment_size = "16320"
                device.access_mode = "mmap+timer"
                device.profile.name = "HiFi: hw:sofhdadsp,4: sink"
                device.profile.description = "HDMI / DisplayPort 2 Output"
                alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
                device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 2 Output"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        ports:
                [Out] HDMI2: HDMI / DisplayPort 2 Output (priority 600, latency offset 0 usec, available: no)
                        properties:

        active port: <[Out] HDMI2>
    index: 2
        name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp_3__sink>
        driver: <module-alsa-card.c>
        flags: HARDWARE DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE
        priority: 9035
        volume: front-left: 65536 / 100% / 0.00 dB,   front-right: 65536 / 100% / 0.00 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 2
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 341.00 ms
        card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
        module: 6
        properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HDMI1 (*)"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "3"
                alsa.card = "0"
                alsa.card_name = "sof-hda-dsp"
                alsa.long_card_name = "sof-hda-dsp"
                alsa.driver_name = "snd_soc_skl_hda_dsp"
                device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
                sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "a0c8"
                device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                device.string = "_ucm0001.hw:sofhdadsp,3"
                device.buffering.buffer_size = "65472"
                device.buffering.fragment_size = "16320"
                device.access_mode = "mmap+timer"
                device.profile.name = "HiFi: hw:sofhdadsp,3: sink"
                device.profile.description = "HDMI / DisplayPort 1 Output"
                alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
                device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller HDMI / DisplayPort 1 Output"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        ports:
                [Out] HDMI1: HDMI / DisplayPort 1 Output (priority 500, latency offset 0 usec, available: no)
                        properties:

        active port: <[Out] HDMI1>
  * index: 3
        name: <alsa_output.pci-0000_00_1f.3-platform-skl_hda_dsp_generic.HiFi__hw_sofhdadsp__sink>
        driver: <module-alsa-card.c>
        flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
        state: SUSPENDED
        suspend cause: IDLE
        priority: 9032
        volume: front-left: 52429 /  80% / -5.81 dB,   front-right: 52429 /  80% / -5.81 dB
                balance 0.00
        base volume: 65536 / 100% / 0.00 dB
        volume steps: 65537
        muted: no
        current latency: 0.00 ms
        max request: 0 KiB
        max rewind: 0 KiB
        monitor source: 3
        sample spec: s16le 2ch 48000Hz
        channel map: front-left,front-right
                     Stereo
        used by: 0
        linked by: 0
        configured latency: 0.00 ms; range is 0.50 .. 341.00 ms
        card: 0 <alsa_card.pci-0000_00_1f.3-platform-skl_hda_dsp_generic>
        module: 6
        properties:
                alsa.resolution_bits = "16"
                device.api = "alsa"
                device.class = "sound"
                alsa.class = "generic"
                alsa.subclass = "generic-mix"
                alsa.name = ""
                alsa.id = "HDA Analog (*)"
                alsa.subdevice = "0"
                alsa.subdevice_name = "subdevice #0"
                alsa.device = "0"
                alsa.card = "0"
                alsa.card_name = "sof-hda-dsp"
                alsa.long_card_name = "sof-hda-dsp"
                alsa.driver_name = "snd_soc_skl_hda_dsp"
                device.bus_path = "pci-0000:00:1f.3-platform-skl_hda_dsp_generic"
                sysfs.path = "/devices/pci0000:00/0000:00:1f.3/skl_hda_dsp_generic/sound/card0"
                device.bus = "pci"
                device.vendor.id = "8086"
                device.vendor.name = "Intel Corporation"
                device.product.id = "a0c8"
                device.product.name = "Tiger Lake-LP Smart Sound Technology Audio Controller"
                device.string = "_ucm0001.hw:sofhdadsp"
                device.buffering.buffer_size = "65472"
                device.buffering.fragment_size = "16320"
                device.access_mode = "mmap+timer"
                device.profile.name = "HiFi: hw:sofhdadsp: sink"
                device.profile.description = "Speaker + Headphones"
                alsa.mixer_device = "_ucm0001.hw:sofhdadsp"
                device.description = "Tiger Lake-LP Smart Sound Technology Audio Controller Speaker + Headphones"
                module-udev-detect.discovered = "1"
                device.icon_name = "audio-card-pci"
        ports:
                [Out] Speaker: Speaker (priority 100, latency offset 0 usec, available: unknown)
                        properties:

                [Out] Headphones: Headphones (priority 200, latency offset 0 usec, available: no)
                        properties:

        active port: <[Out] Speaker>

ALSA data is showing Auto-Mute Mode set to Disabled

I suggest you use this command to enable it

amixer -c0 sset 'Auto-Mute Mode' enabled

PulseAudio data is showing output port Headphones not available

ports:

[Out] Headphones: Headphones (priority 200, latency offset 0 usec, available: no)

I suggest you check PulseAudio with headphones plugged in to ensure jack-detection is working in PulseAudio: The data should show headphone port as available: yes

Many thanks for your reply.
PulseAudio data is showing output port Headphones not available because headphones are not connected. If I connect them the data show available: yes.

amixer says that the command is invalid:

$ amixer -c0 sset 'Auto-Mute Mode' enabled
amixer: Invalid command!

I have change this by the graphic interface, using the command alsamixer -c0.
Now I have the following output:

amixer -c0 | grep -A3 "Simple mixer control 'Auto-Mute Mode',0"

Simple mixer control 'Auto-Mute Mode',0
  Capabilities: enum
  Items: 'Disabled' 'Enabled'
  Item0: 'Enabled'

But unfortunately this does not solve my problem.

Do you have any other ideas?
Thanks a lot,
Davide