aboutsummaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorcodeworkx <codeworkx@cyanogenmod.org>2012-11-24 08:12:58 +0100
committercodeworkx <codeworkx@cyanogenmod.org>2012-11-24 08:12:58 +0100
commitdb9fbaf5f1c5ceb1f75dfc66e3b04dec0b030a0f (patch)
treeb1993ec5c07777c846b9960d23dc8c339d17baa3 /audio
parentaeeb94d3bd1b06b6357e9e5937c0ea3f70b3331e (diff)
downloaddevice_samsung_espresso3g-db9fbaf5f1c5ceb1f75dfc66e3b04dec0b030a0f.tar.gz
device_samsung_espresso3g-db9fbaf5f1c5ceb1f75dfc66e3b04dec0b030a0f.tar.bz2
device_samsung_espresso3g-db9fbaf5f1c5ceb1f75dfc66e3b04dec0b030a0f.zip
common: update audio hal for mr1
Change-Id: I4d9c51c427e9ca175f0879e494f2205e52c17a5c
Diffstat (limited to 'audio')
-rwxr-xr-xaudio/audio_hw.c129
1 files changed, 63 insertions, 66 deletions
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 18fa2bd..678d673 100755
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -89,8 +89,10 @@ struct espresso_audio_device {
int num_dev_cfgs;
struct mixer *mixer;
audio_mode_t mode;
- int active_devices;
- int devices;
+ int active_out_device;
+ int out_device;
+ int active_in_device;
+ int in_device;
struct pcm *pcm_modem_dl;
struct pcm *pcm_modem_ul;
int in_call;
@@ -310,26 +312,40 @@ void select_devices(struct espresso_audio_device *adev)
{
int i;
- if (adev->active_devices == adev->devices)
+ if (adev->active_out_device == adev->out_device && adev->active_in_device == adev->in_device)
return;
- ALOGV("Changing devices %x => %x\n", adev->active_devices, adev->devices);
+ ALOGV("Changing output device %x => %x\n", adev->active_out_device, adev->out_device);
+ ALOGV("Changing input device %x => %x\n", adev->active_in_device, adev->in_device);
/* Turn on new devices first so we don't glitch due to powerdown... */
for (i = 0; i < adev->num_dev_cfgs; i++)
- if ((adev->devices & adev->dev_cfgs[i].mask) &&
- !(adev->active_devices & adev->dev_cfgs[i].mask))
+ if ((adev->out_device & adev->dev_cfgs[i].mask) &&
+ !(adev->active_out_device & adev->dev_cfgs[i].mask))
+ set_route_by_array(adev->mixer, adev->dev_cfgs[i].on,
+ adev->dev_cfgs[i].on_len);
+
+ for (i = 0; i < adev->num_dev_cfgs; i++)
+ if ((adev->in_device & adev->dev_cfgs[i].mask) &&
+ !(adev->active_in_device & adev->dev_cfgs[i].mask))
set_route_by_array(adev->mixer, adev->dev_cfgs[i].on,
adev->dev_cfgs[i].on_len);
/* ...then disable old ones. */
for (i = 0; i < adev->num_dev_cfgs; i++)
- if (!(adev->devices & adev->dev_cfgs[i].mask) &&
- (adev->active_devices & adev->dev_cfgs[i].mask))
+ if (!(adev->out_device & adev->dev_cfgs[i].mask) &&
+ (adev->active_out_device & adev->dev_cfgs[i].mask))
+ set_route_by_array(adev->mixer, adev->dev_cfgs[i].off,
+ adev->dev_cfgs[i].off_len);
+
+ for (i = 0; i < adev->num_dev_cfgs; i++)
+ if (!(adev->in_device & adev->dev_cfgs[i].mask) &&
+ (adev->active_in_device & adev->dev_cfgs[i].mask))
set_route_by_array(adev->mixer, adev->dev_cfgs[i].off,
adev->dev_cfgs[i].off_len);
- adev->active_devices = adev->devices;
+ adev->active_out_device = adev->out_device;
+ adev->active_in_device = adev->in_device;
}
static int start_call(struct espresso_audio_device *adev)
@@ -337,7 +353,7 @@ static int start_call(struct espresso_audio_device *adev)
ALOGE("Opening modem PCMs");
int bt_on;
- bt_on = adev->devices & AUDIO_DEVICE_OUT_ALL_SCO;
+ bt_on = adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO;
pcm_config_vx.rate = adev->wb_amr ? VX_WB_SAMPLING_RATE : VX_NB_SAMPLING_RATE;
/* Open modem PCM channels */
@@ -413,7 +429,7 @@ static void set_incall_device(struct espresso_audio_device *adev)
{
int device_type;
- switch(adev->devices & AUDIO_DEVICE_OUT_ALL) {
+ switch(adev->out_device) {
case AUDIO_DEVICE_OUT_EARPIECE:
device_type = SOUND_AUDIO_PATH_HANDSET;
break;
@@ -495,11 +511,11 @@ static void select_mode(struct espresso_audio_device *adev)
a call. This works because we're sure that the audio policy
manager will update the output device after the audio mode
change, even if the device selection did not change. */
- if ((adev->devices & AUDIO_DEVICE_OUT_ALL) == AUDIO_DEVICE_OUT_SPEAKER)
- adev->devices = AUDIO_DEVICE_OUT_EARPIECE |
- AUDIO_DEVICE_IN_BUILTIN_MIC;
- else
- adev->devices &= ~AUDIO_DEVICE_OUT_SPEAKER;
+ if (adev->out_device == AUDIO_DEVICE_OUT_SPEAKER) {
+ adev->out_device = AUDIO_DEVICE_OUT_EARPIECE;
+ adev->in_device = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN;
+ } else
+ adev->out_device &= ~AUDIO_DEVICE_OUT_SPEAKER;
select_output_device(adev);
start_call(adev);
ril_set_call_clock_sync(&adev->ril, SOUND_CLOCK_START);
@@ -529,13 +545,13 @@ static void select_output_device(struct espresso_audio_device *adev)
bool tty_volume = false;
unsigned int channel;
- headset_on = adev->devices & AUDIO_DEVICE_OUT_WIRED_HEADSET;
- headphone_on = adev->devices & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
- speaker_on = adev->devices & AUDIO_DEVICE_OUT_SPEAKER;
- earpiece_on = adev->devices & AUDIO_DEVICE_OUT_EARPIECE;
- bt_on = adev->devices & AUDIO_DEVICE_OUT_ALL_SCO;
+ headset_on = adev->out_device & AUDIO_DEVICE_OUT_WIRED_HEADSET;
+ headphone_on = adev->out_device & AUDIO_DEVICE_OUT_WIRED_HEADPHONE;
+ speaker_on = adev->out_device & AUDIO_DEVICE_OUT_SPEAKER;
+ earpiece_on = adev->out_device & AUDIO_DEVICE_OUT_EARPIECE;
+ bt_on = adev->out_device & AUDIO_DEVICE_OUT_ALL_SCO;
- switch(adev->devices & AUDIO_DEVICE_OUT_ALL) {
+ switch(adev->out_device) {
case AUDIO_DEVICE_OUT_SPEAKER:
ALOGD("%s: AUDIO_DEVICE_OUT_SPEAKER", __func__);
break;
@@ -627,7 +643,7 @@ static void select_output_device(struct espresso_audio_device *adev)
static void select_input_device(struct espresso_audio_device *adev)
{
- switch(adev->devices & AUDIO_DEVICE_IN_ALL) {
+ switch(adev->in_device) {
case AUDIO_DEVICE_IN_BUILTIN_MIC:
ALOGD("%s: AUDIO_DEVICE_IN_BUILTIN_MIC", __func__);
break;
@@ -661,8 +677,7 @@ static int start_output_stream_low_latency(struct espresso_stream_out *out)
* tinyalsa.
*/
- if (adev->devices & (AUDIO_DEVICE_OUT_ALL &
- ~(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | AUDIO_DEVICE_OUT_AUX_DIGITAL))) {
+ if (adev->out_device & ~(AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET | AUDIO_DEVICE_OUT_AUX_DIGITAL)) {
/* Something not a dock in use */
out->config[PCM_NORMAL] = pcm_config_tones;
out->config[PCM_NORMAL].rate = MM_FULL_POWER_SAMPLING_RATE;
@@ -670,7 +685,7 @@ static int start_output_stream_low_latency(struct espresso_stream_out *out)
flags, &out->config[PCM_NORMAL]);
}
- if (adev->devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
+ if (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) {
/* SPDIF output in use */
out->config[PCM_SPDIF] = pcm_config_tones;
out->config[PCM_SPDIF].rate = MM_FULL_POWER_SAMPLING_RATE;
@@ -908,7 +923,7 @@ static size_t out_get_buffer_size_deep_buffer(const struct audio_stream *stream)
return size * audio_stream_frame_size((struct audio_stream *)stream);
}
-static uint32_t out_get_channels(const struct audio_stream *stream)
+static audio_channel_mask_t out_get_channels(const struct audio_stream *stream)
{
struct espresso_stream_out *out = (struct espresso_stream_out *)stream;
@@ -1006,7 +1021,7 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
val = atoi(value);
pthread_mutex_lock(&adev->lock);
pthread_mutex_lock(&out->lock);
- if (((adev->devices & AUDIO_DEVICE_OUT_ALL) != val) && (val != 0)) {
+ if (((adev->out_device) != val) && (val != 0)) {
/* this is needed only when changing device on low latency output
* as other output streams are not used for voice use cases nor
* handle duplication to HDMI or SPDIF */
@@ -1025,26 +1040,25 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
* (several hundred ms of audio can be lost: e.g beginning of a ringtone. We must understand
* the root cause in audio HAL, driver or ABE.
if (((val & AUDIO_DEVICE_OUT_AUX_DIGITAL) ^
- (adev->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
+ (adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
((val & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) ^
- (adev->devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
- (adev->devices & (AUDIO_DEVICE_OUT_AUX_DIGITAL |
+ (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
+ (adev->out_device & (AUDIO_DEVICE_OUT_AUX_DIGITAL |
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)))
*/
if (((val & AUDIO_DEVICE_OUT_AUX_DIGITAL) ^
- (adev->devices & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
+ (adev->out_device & AUDIO_DEVICE_OUT_AUX_DIGITAL)) ||
((val & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET) ^
- (adev->devices & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
- (adev->devices & (AUDIO_DEVICE_OUT_AUX_DIGITAL |
+ (adev->out_device & AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
+ (adev->out_device & (AUDIO_DEVICE_OUT_AUX_DIGITAL |
AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) ||
((val & AUDIO_DEVICE_OUT_SPEAKER) ^
- (adev->devices & AUDIO_DEVICE_OUT_SPEAKER)) ||
+ (adev->out_device & AUDIO_DEVICE_OUT_SPEAKER)) ||
(adev->mode == AUDIO_MODE_IN_CALL))
do_output_standby(out);
}
if (out != adev->outputs[OUTPUT_HDMI]) {
- adev->devices &= ~AUDIO_DEVICE_OUT_ALL;
- adev->devices |= val;
+ adev->out_device = val;
select_output_device(adev);
}
}
@@ -1335,8 +1349,7 @@ static int start_input_stream(struct espresso_stream_in *in)
adev->active_input = in;
if (adev->mode != AUDIO_MODE_IN_CALL) {
- adev->devices &= ~AUDIO_DEVICE_IN_ALL;
- adev->devices |= in->device;
+ adev->in_device = in->device;
select_input_device(adev);
}
@@ -1364,7 +1377,7 @@ static int start_input_stream(struct espresso_stream_in *in)
if (in->need_echo_reference && in->echo_reference == NULL)
in->echo_reference = get_echo_reference(adev,
AUDIO_FORMAT_PCM_16_BIT,
- in->config.channels,
+ popcount(in->main_channels),
in->requested_rate);
/* this assumes routing is done previously */
@@ -1409,7 +1422,7 @@ static size_t in_get_buffer_size(const struct audio_stream *stream)
popcount(in->main_channels));
}
-static uint32_t in_get_channels(const struct audio_stream *stream)
+static audio_channel_mask_t in_get_channels(const struct audio_stream *stream)
{
struct espresso_stream_in *in = (struct espresso_stream_in *)stream;
@@ -1437,7 +1450,7 @@ static int do_input_standby(struct espresso_stream_in *in)
adev->active_input = 0;
if (adev->mode != AUDIO_MODE_IN_CALL) {
- adev->devices &= ~AUDIO_DEVICE_IN_ALL;
+ adev->in_device = AUDIO_DEVICE_NONE;
select_input_device(adev);
}
@@ -1498,7 +1511,7 @@ static int in_set_parameters(struct audio_stream *stream, const char *kvpairs)
ret = str_parms_get_str(parms, AUDIO_PARAMETER_STREAM_ROUTING, value, sizeof(value));
if (ret >= 0) {
- val = atoi(value);
+ val = atoi(value) & ~AUDIO_DEVICE_BIT_IN;
if ((in->device != val) && (val != 0)) {
in->device = val;
do_standby = true;
@@ -2400,8 +2413,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
/* FIXME: when we support multiple output devices, we will want to
* do the following:
- * adev->devices &= ~AUDIO_DEVICE_OUT_ALL;
- * adev->devices |= out->device;
+ * adev->out_device = out->device;
* select_output_device(adev);
* This is because out_set_parameters() with a route is not
* guaranteed to be called after an output stream is opened. */
@@ -2510,11 +2522,13 @@ static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
{
struct espresso_audio_device *adev = (struct espresso_audio_device *)dev;
+ pthread_mutex_lock(&adev->lock);
adev->voice_volume = volume;
if (adev->mode == AUDIO_MODE_IN_CALL)
ril_set_call_volume(&adev->ril, SOUND_TYPE_VOICE, volume);
+ pthread_mutex_unlock(&adev->lock);
return 0;
}
@@ -2637,7 +2651,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
in->dev = ladev;
in->standby = 1;
- in->device = devices;
+ in->device = devices & ~AUDIO_DEVICE_BIT_IN;
*stream_in = &in->stream;
return 0;
@@ -2694,23 +2708,6 @@ static int adev_close(hw_device_t *device)
return 0;
}
-static uint32_t adev_get_supported_devices(const struct audio_hw_device *dev)
-{
- return (/* OUT */
- AUDIO_DEVICE_OUT_EARPIECE |
- AUDIO_DEVICE_OUT_SPEAKER |
- AUDIO_DEVICE_OUT_WIRED_HEADSET |
- AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
- AUDIO_DEVICE_OUT_ANLG_DOCK_HEADSET |
- AUDIO_DEVICE_OUT_ALL_SCO |
- AUDIO_DEVICE_OUT_DEFAULT |
- /* IN */
- AUDIO_DEVICE_IN_BUILTIN_MIC |
- AUDIO_DEVICE_IN_WIRED_HEADSET |
- AUDIO_DEVICE_IN_ALL_SCO |
- AUDIO_DEVICE_IN_DEFAULT);
-}
-
struct config_parse_state {
struct espresso_audio_device *adev;
struct espresso_dev_cfg *dev;
@@ -2947,11 +2944,10 @@ static int adev_open(const hw_module_t* module, const char* name,
return -ENOMEM;
adev->hw_device.common.tag = HARDWARE_DEVICE_TAG;
- adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_1_0;
+ adev->hw_device.common.version = AUDIO_DEVICE_API_VERSION_2_0;
adev->hw_device.common.module = (struct hw_module_t *) module;
adev->hw_device.common.close = adev_close;
- adev->hw_device.get_supported_devices = adev_get_supported_devices;
adev->hw_device.init_check = adev_init_check;
adev->hw_device.set_voice_volume = adev_set_voice_volume;
adev->hw_device.set_master_volume = adev_set_master_volume;
@@ -2981,7 +2977,8 @@ static int adev_open(const hw_module_t* module, const char* name,
/* Set the default route before the PCM stream is opened */
pthread_mutex_init(&adev->lock, NULL);
adev->mode = AUDIO_MODE_NORMAL;
- adev->devices = AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_IN_BUILTIN_MIC;
+ adev->out_device = AUDIO_DEVICE_OUT_SPEAKER;
+ adev->in_device = AUDIO_DEVICE_IN_BUILTIN_MIC & ~AUDIO_DEVICE_BIT_IN;
select_devices(adev);
adev->pcm_modem_dl = NULL;