From b6912a3d8746eb6a015685b3d0c3e26ae474dc68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Mon, 21 Sep 2020 17:38:54 +0200 Subject: [PATCH] dde_bsd: query initial head-phone state Account for the situation where the driver is started while the HP is already plugged in and configure the mixer accordingly. Thanks to Peter for the patch. Issue #3929. --- repos/dde_bsd/src/lib/audio/driver.cc | 37 ++++++++++++++++++- .../dde_bsd/src/lib/audio/include/bsd_emul.h | 3 +- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/repos/dde_bsd/src/lib/audio/driver.cc b/repos/dde_bsd/src/lib/audio/driver.cc index d323867e0d..bf8311fef3 100644 --- a/repos/dde_bsd/src/lib/audio/driver.cc +++ b/repos/dde_bsd/src/lib/audio/driver.cc @@ -216,7 +216,7 @@ static bool set_mixer_value(Mixer &mixer, char const * const field, } -static char const *get_mixer_value(mixer_devinfo_t *info) +static char const *get_mixer_value(mixer_devinfo_t const *info) { static char buffer[128]; @@ -272,6 +272,33 @@ static char const *get_mixer_value(mixer_devinfo_t *info) } +static bool headphone_plugged() +{ + for (unsigned i = 0; i < mixer.num; i++) { + mixer_devinfo_t const &info = mixer.info[i]; + + if (info.type == AUDIO_MIXER_CLASS) { + continue; + } + + unsigned const mixer_class = info.mixer_class; + char const * const class_name = mixer.info[mixer_class].label.name; + char const * const name = info.label.name; + + Genode::String<64> const control { class_name, ".", name }; + if (control != "outputs.hp_sense") { + continue; + } + + auto const result = get_mixer_value(&info); + + return Genode::strcmp("plugged", result) == 0; + } + + return false; +} + + static void dump_mixer(Mixer const &mixer) { Genode::log("--- mixer information ---"); @@ -406,6 +433,8 @@ static bool configure_audio_device(Genode::Env &env, dev_t dev, Genode::Xml_node configure_mixer(env, mixer, config); + notify_hp_sense(headphone_plugged() ? 1: 0); + return true; } @@ -561,6 +590,12 @@ extern "C" void notify_record() } +extern "C" void notify_hp_sense(int const sense) +{ + set_mixer_value(mixer, "record.adc-0:1_source", sense ? "mic2" : "mic"); +} + + /***************************** ** private Audio namespace ** *****************************/ diff --git a/repos/dde_bsd/src/lib/audio/include/bsd_emul.h b/repos/dde_bsd/src/lib/audio/include/bsd_emul.h index adfee55321..379ed9afeb 100644 --- a/repos/dde_bsd/src/lib/audio/include/bsd_emul.h +++ b/repos/dde_bsd/src/lib/audio/include/bsd_emul.h @@ -8,7 +8,7 @@ */ /* - * Copyright (C) 2014-2017 Genode Labs GmbH + * Copyright (C) 2014-2020 Genode Labs GmbH * * This file is part of the Genode OS framework, which is distributed * under the terms of the GNU Affero General Public License version 3. @@ -28,6 +28,7 @@ void notify_play(); void notify_record(); +void notify_hp_sense(int const); /*****************