hal: Select output device dynamically
If handset and speaker use different interfaces, then they can't be enabled simultaneously. On veux, this causes top speaker to be disabled during ultrasound emitting. This matches stock audio HAL from veux. Change-Id: Id5afafbce56f2192bde9729e4c5c1349b37c390e
This commit is contained in:
parent
1da52220dd
commit
4c033c02d8
|
@ -28,6 +28,7 @@
|
|||
#define ULTRASOUND_CALIBRATION_FILE "/mnt/vendor/persist/audio/us_cal"
|
||||
#define ULTRASOUND_CALIBRATION_MIXER "Ultrasound Calibration Data"
|
||||
#define ULTRASOUND_RAMPDOWN_MIXER "Ultrasound RampDown"
|
||||
#define ULTRASOUND_SUSPEND_MIXER "Ultrasound Suspend"
|
||||
|
||||
enum {
|
||||
ULTRASOUND_STATUS_DEFAULT,
|
||||
|
@ -109,6 +110,32 @@ exit:
|
|||
ALOGD("%s: exit", __func__);
|
||||
}
|
||||
|
||||
void us_suspend(int val)
|
||||
{
|
||||
struct mixer_ctl *ctl;
|
||||
int rc;
|
||||
|
||||
ALOGD("%s: enter", __func__);
|
||||
ALOGD("%s: suspend: %d", __func__, val);
|
||||
|
||||
ctl = mixer_get_ctl_by_name(us->adev->mixer, ULTRASOUND_SUSPEND_MIXER);
|
||||
if (!ctl) {
|
||||
ALOGD("%s: Could not get ctl for mixer cmd - %s",
|
||||
__func__, ULTRASOUND_SUSPEND_MIXER);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (val)
|
||||
us_ramp_down();
|
||||
|
||||
rc = mixer_ctl_set_value(ctl, 0, val);
|
||||
if (rc < 0)
|
||||
ALOGE("%s: Could not set ctl, error:%d ", __func__, rc);
|
||||
|
||||
exit:
|
||||
ALOGD("%s: exit", __func__);
|
||||
}
|
||||
|
||||
int us_init(struct audio_device *adev)
|
||||
{
|
||||
int rc = 0;
|
||||
|
@ -198,6 +225,32 @@ static int stop_us(void)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static snd_device_t us_get_output_snd_device(void)
|
||||
{
|
||||
snd_device_t snd_device;
|
||||
|
||||
snd_device = platform_get_output_snd_device(us->adev->platform,
|
||||
us->adev->primary_output,
|
||||
USECASE_TYPE_MAX);
|
||||
switch (snd_device) {
|
||||
case SND_DEVICE_OUT_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HANDSET_TMUS:
|
||||
case SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HAC_HANDSET:
|
||||
case SND_DEVICE_OUT_ANC_HANDSET:
|
||||
case SND_DEVICE_OUT_VOIP_HANDSET:
|
||||
break;
|
||||
default:
|
||||
snd_device = SND_DEVICE_OUT_SPEAKER;
|
||||
break;
|
||||
}
|
||||
|
||||
ALOGD("%s: %s", __func__, platform_get_snd_device_name(snd_device));
|
||||
|
||||
return snd_device;
|
||||
}
|
||||
|
||||
int us_start(void)
|
||||
{
|
||||
int rc = 0, rx_device_id, tx_device_id;
|
||||
|
@ -228,14 +281,14 @@ int us_start(void)
|
|||
}
|
||||
|
||||
rx_usecase->type = PCM_PLAYBACK;
|
||||
rx_usecase->out_snd_device = SND_DEVICE_OUT_VOICE_HANDSET;
|
||||
rx_usecase->out_snd_device = us_get_output_snd_device();
|
||||
rx_usecase->id = USECASE_AUDIO_ULTRASOUND_RX;
|
||||
rx_usecase->stream.out = us->adev->primary_output;
|
||||
list_init(&rx_usecase->device_list);
|
||||
assign_devices(&rx_usecase->device_list, &us->adev->primary_output->device_list);
|
||||
list_add_tail(&us->adev->usecase_list, &rx_usecase->list);
|
||||
|
||||
enable_snd_device(us->adev, SND_DEVICE_OUT_VOICE_HANDSET);
|
||||
enable_snd_device(us->adev, rx_usecase->out_snd_device);
|
||||
enable_audio_route(us->adev, rx_usecase);
|
||||
ALOGV("%s: Opening PCM playback device card_id(%d) device_id(%d)",
|
||||
__func__, us->adev->snd_card, rx_device_id);
|
||||
|
|
|
@ -23,11 +23,13 @@
|
|||
#define us_deinit() (0)
|
||||
#define us_start() (0)
|
||||
#define us_stop() (0)
|
||||
#define us_suspend() (0)
|
||||
#else
|
||||
int us_init(struct audio_device *adev);
|
||||
void us_deinit(void);
|
||||
int us_start(void);
|
||||
int us_stop(void);
|
||||
void us_suspend(int val);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2131,11 +2131,6 @@ static void check_usecases_codec_backend(struct audio_device *adev,
|
|||
platform_get_snd_device_name(usecase->out_snd_device),
|
||||
platform_check_backends_match(snd_device, usecase->out_snd_device));
|
||||
|
||||
#ifdef ELLIPTIC_ULTRASOUND_ENABLED
|
||||
if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX)
|
||||
continue;
|
||||
#endif
|
||||
|
||||
if ((usecase->type != PCM_CAPTURE) && (usecase != uc_info) &&
|
||||
(usecase->type != PCM_PASSTHROUGH)) {
|
||||
uc_derive_snd_device = derive_playback_snd_device(adev->platform,
|
||||
|
@ -2152,11 +2147,33 @@ static void check_usecases_codec_backend(struct audio_device *adev,
|
|||
ALOGD("%s:becf: check_usecases (%s) is active on (%s) - disabling ..",
|
||||
__func__, use_case_table[usecase->id],
|
||||
platform_get_snd_device_name(usecase->out_snd_device));
|
||||
#ifdef ELLIPTIC_ULTRASOUND_ENABLED
|
||||
if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX)
|
||||
us_suspend(1);
|
||||
#endif
|
||||
disable_audio_route(adev, usecase);
|
||||
switch_device[usecase->id] = true;
|
||||
/* Enable existing usecase on derived playback device */
|
||||
derive_snd_device[usecase->id] = uc_derive_snd_device;
|
||||
num_uc_to_switch++;
|
||||
#ifdef ELLIPTIC_ULTRASOUND_ENABLED
|
||||
if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX) {
|
||||
switch (snd_device) {
|
||||
case SND_DEVICE_OUT_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HANDSET_TMUS:
|
||||
case SND_DEVICE_OUT_VOICE_TTY_HCO_HANDSET:
|
||||
case SND_DEVICE_OUT_VOICE_HAC_HANDSET:
|
||||
case SND_DEVICE_OUT_ANC_HANDSET:
|
||||
case SND_DEVICE_OUT_VOIP_HANDSET:
|
||||
derive_snd_device[usecase->id] = snd_device;
|
||||
break;
|
||||
default:
|
||||
derive_snd_device[usecase->id] = SND_DEVICE_OUT_SPEAKER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2208,6 +2225,10 @@ static void check_usecases_codec_backend(struct audio_device *adev,
|
|||
} else {
|
||||
enable_snd_device(adev, derive_snd_device[usecase->id]);
|
||||
}
|
||||
#ifdef ELLIPTIC_ULTRASOUND_ENABLED
|
||||
if (usecase->id == USECASE_AUDIO_ULTRASOUND_RX)
|
||||
us_suspend(0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue