Loading hal/audio_hw.c +46 −38 Original line number Diff line number Diff line Loading @@ -1057,7 +1057,7 @@ static bool allow_hdmi_channel_config(struct audio_device *adev) ret = false; break; } else if (usecase->id == USECASE_AUDIO_PLAYBACK_OFFLOAD && popcount(usecase->stream.out->channel_mask) > 2) { audio_channel_count_from_out_mask(usecase->stream.out->channel_mask) > 2) { ALOGD("%s: multi-channel(%x) compress offload playback is active, " "no change in HDMI channels", __func__, usecase->stream.out->channel_mask); ret = false; Loading Loading @@ -1341,7 +1341,8 @@ static size_t out_get_buffer_size(const struct audio_stream *stream) else if(out->usecase == USECASE_COMPRESS_VOIP_CALL) return voice_extn_compress_voip_out_get_buffer_size(out); return out->config.period_size * audio_stream_frame_size(stream); return out->config.period_size * audio_stream_out_frame_size((const struct audio_stream_out *)stream); } static uint32_t out_get_channels(const struct audio_stream *stream) Loading Loading @@ -1721,7 +1722,7 @@ exit: if (out->pcm) ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm)); out_standby(&out->stream.common); usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) / usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / out_get_sample_rate(&out->stream.common)); } return bytes; Loading Loading @@ -1907,7 +1908,8 @@ static size_t in_get_buffer_size(const struct audio_stream *stream) else if(audio_extn_compr_cap_usecase_supported(in->usecase)) return audio_extn_compr_cap_get_buffer_size(in->config.format); return in->config.period_size * audio_stream_frame_size(stream); return in->config.period_size * audio_stream_in_frame_size((const struct audio_stream_in *)stream); } static uint32_t in_get_channels(const struct audio_stream *stream) Loading Loading @@ -2072,7 +2074,8 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer, } if (in->pcm) { if (audio_extn_ssr_get_enabled() && popcount(in->channel_mask) == 6) if (audio_extn_ssr_get_enabled() && audio_channel_count_from_in_mask(in->channel_mask) == 6) ret = audio_extn_ssr_read(stream, buffer, bytes); else if (audio_extn_compr_cap_usecase_supported(in->usecase)) ret = audio_extn_compr_cap_read(in, buffer, bytes); Loading @@ -2095,7 +2098,7 @@ exit: if (ret != 0) { in_standby(&in->stream.common); ALOGV("%s: read failed - sleeping for buffer duration", __func__); usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) / usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) / in_get_sample_rate(&in->stream.common)); } return bytes; Loading Loading @@ -2177,9 +2180,6 @@ static int adev_open_output_stream(struct audio_hw_device *dev, return -ENOMEM; } pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); if (devices == AUDIO_DEVICE_NONE) devices = AUDIO_DEVICE_OUT_SPEAKER; Loading Loading @@ -2223,7 +2223,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; out->config = pcm_config_hdmi_multi; out->config.rate = config->sample_rate; out->config.channels = popcount(out->channel_mask); out->config.channels = audio_channel_count_from_out_mask(out->channel_mask); out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); #ifdef COMPRESS_VOIP_ENABLED } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && Loading Loading @@ -2292,7 +2292,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->compr_config.codec->bit_rate = config->offload_info.bit_rate; out->compr_config.codec->ch_in = popcount(config->channel_mask); audio_channel_count_from_out_mask(config->channel_mask); out->compr_config.codec->ch_out = out->compr_config.codec->ch_in; out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW; Loading Loading @@ -2405,6 +2405,9 @@ static int adev_open_output_stream(struct audio_hw_device *dev, /* out->muted = false; by calloc() */ /* out->written = 0; by calloc() */ pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); config->format = out->stream.common.get_format(&out->stream.common); config->channel_mask = out->stream.common.get_channels(&out->stream.common); config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); Loading Loading @@ -2459,23 +2462,24 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) char *str; char value[32]; int val; int ret = 0, err; int ret; int status = 0; ALOGD("%s: enter: %s", __func__, kvpairs); pthread_mutex_lock(&adev->lock); parms = str_parms_create_str(kvpairs); ret = voice_set_parameters(adev, parms); if (ret != 0) status = voice_set_parameters(adev, parms); if (status != 0) goto done; ret = platform_set_parameters(adev->platform, parms); if (ret != 0) status = platform_set_parameters(adev->platform, parms); if (status != 0) goto done; err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); if (err >= 0) { ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); if (ret >= 0) { /* When set to false, HAL should disable EC and NS * But it is currently not supported. */ Loading @@ -2485,16 +2489,16 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) adev->bluetooth_nrec = false; } err = str_parms_get_str(parms, "screen_state", value, sizeof(value)); if (err >= 0) { ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); if (ret >= 0) { if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) adev->screen_off = false; else adev->screen_off = true; } err = str_parms_get_int(parms, "rotation", &val); if (err >= 0) { ret = str_parms_get_int(parms, "rotation", &val); if (ret >= 0) { bool reverse_speakers = false; switch(val) { // FIXME: note that the code below assumes that the speakers are in the correct placement Loading @@ -2509,7 +2513,9 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) break; default: ALOGE("%s: unexpected rotation of %d", __func__, val); status = -EINVAL; } if (status == 0) { if (adev->speaker_lr_swap != reverse_speakers) { adev->speaker_lr_swap = reverse_speakers; // only update the selected device if there is active pcm playback Loading @@ -2524,14 +2530,15 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) } } } } audio_extn_set_parameters(adev, parms); done: str_parms_destroy(parms); pthread_mutex_unlock(&adev->lock); ALOGV("%s: exit with code(%d)", __func__, ret); return ret; ALOGV("%s: exit with code(%d)", __func__, status); return status; } static char* adev_get_parameters(const struct audio_hw_device *dev, Loading Loading @@ -2629,7 +2636,7 @@ static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev __unused, const struct audio_config *config) { int channel_count = popcount(config->channel_mask); int channel_count = audio_channel_count_from_in_mask(config->channel_mask); return get_input_buffer_size(config->sample_rate, config->format, channel_count); } Loading @@ -2646,7 +2653,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, struct audio_device *adev = (struct audio_device *)dev; struct stream_in *in; int ret = 0, buffer_size, frame_size; int channel_count = popcount(config->channel_mask); int channel_count = audio_channel_count_from_in_mask(config->channel_mask); *stream_in = NULL; Loading Loading @@ -2724,7 +2731,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, audio_extn_compr_cap_init(in); } else { in->config.channels = channel_count; frame_size = audio_stream_frame_size((struct audio_stream *)in); frame_size = audio_stream_in_frame_size(&in->stream); buffer_size = get_input_buffer_size(config->sample_rate, config->format, channel_count); Loading Loading @@ -2756,7 +2763,8 @@ static void adev_close_input_stream(struct audio_hw_device *dev __unused, } else in_standby(&stream->common); if (audio_extn_ssr_get_enabled() && (popcount(in->channel_mask) == 6)) { if (audio_extn_ssr_get_enabled() && (audio_channel_count_from_in_mask(in->channel_mask) == 6)) { audio_extn_ssr_deinit(); } free(stream); Loading Loading
hal/audio_hw.c +46 −38 Original line number Diff line number Diff line Loading @@ -1057,7 +1057,7 @@ static bool allow_hdmi_channel_config(struct audio_device *adev) ret = false; break; } else if (usecase->id == USECASE_AUDIO_PLAYBACK_OFFLOAD && popcount(usecase->stream.out->channel_mask) > 2) { audio_channel_count_from_out_mask(usecase->stream.out->channel_mask) > 2) { ALOGD("%s: multi-channel(%x) compress offload playback is active, " "no change in HDMI channels", __func__, usecase->stream.out->channel_mask); ret = false; Loading Loading @@ -1341,7 +1341,8 @@ static size_t out_get_buffer_size(const struct audio_stream *stream) else if(out->usecase == USECASE_COMPRESS_VOIP_CALL) return voice_extn_compress_voip_out_get_buffer_size(out); return out->config.period_size * audio_stream_frame_size(stream); return out->config.period_size * audio_stream_out_frame_size((const struct audio_stream_out *)stream); } static uint32_t out_get_channels(const struct audio_stream *stream) Loading Loading @@ -1721,7 +1722,7 @@ exit: if (out->pcm) ALOGE("%s: error %d - %s", __func__, ret, pcm_get_error(out->pcm)); out_standby(&out->stream.common); usleep(bytes * 1000000 / audio_stream_frame_size(&out->stream.common) / usleep(bytes * 1000000 / audio_stream_out_frame_size(stream) / out_get_sample_rate(&out->stream.common)); } return bytes; Loading Loading @@ -1907,7 +1908,8 @@ static size_t in_get_buffer_size(const struct audio_stream *stream) else if(audio_extn_compr_cap_usecase_supported(in->usecase)) return audio_extn_compr_cap_get_buffer_size(in->config.format); return in->config.period_size * audio_stream_frame_size(stream); return in->config.period_size * audio_stream_in_frame_size((const struct audio_stream_in *)stream); } static uint32_t in_get_channels(const struct audio_stream *stream) Loading Loading @@ -2072,7 +2074,8 @@ static ssize_t in_read(struct audio_stream_in *stream, void *buffer, } if (in->pcm) { if (audio_extn_ssr_get_enabled() && popcount(in->channel_mask) == 6) if (audio_extn_ssr_get_enabled() && audio_channel_count_from_in_mask(in->channel_mask) == 6) ret = audio_extn_ssr_read(stream, buffer, bytes); else if (audio_extn_compr_cap_usecase_supported(in->usecase)) ret = audio_extn_compr_cap_read(in, buffer, bytes); Loading @@ -2095,7 +2098,7 @@ exit: if (ret != 0) { in_standby(&in->stream.common); ALOGV("%s: read failed - sleeping for buffer duration", __func__); usleep(bytes * 1000000 / audio_stream_frame_size(&in->stream.common) / usleep(bytes * 1000000 / audio_stream_in_frame_size(stream) / in_get_sample_rate(&in->stream.common)); } return bytes; Loading Loading @@ -2177,9 +2180,6 @@ static int adev_open_output_stream(struct audio_hw_device *dev, return -ENOMEM; } pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); if (devices == AUDIO_DEVICE_NONE) devices = AUDIO_DEVICE_OUT_SPEAKER; Loading Loading @@ -2223,7 +2223,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->usecase = USECASE_AUDIO_PLAYBACK_MULTI_CH; out->config = pcm_config_hdmi_multi; out->config.rate = config->sample_rate; out->config.channels = popcount(out->channel_mask); out->config.channels = audio_channel_count_from_out_mask(out->channel_mask); out->config.period_size = HDMI_MULTI_PERIOD_BYTES / (out->config.channels * 2); #ifdef COMPRESS_VOIP_ENABLED } else if ((out->dev->mode == AUDIO_MODE_IN_COMMUNICATION) && Loading Loading @@ -2292,7 +2292,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->compr_config.codec->bit_rate = config->offload_info.bit_rate; out->compr_config.codec->ch_in = popcount(config->channel_mask); audio_channel_count_from_out_mask(config->channel_mask); out->compr_config.codec->ch_out = out->compr_config.codec->ch_in; out->compr_config.codec->format = SND_AUDIOSTREAMFORMAT_RAW; Loading Loading @@ -2405,6 +2405,9 @@ static int adev_open_output_stream(struct audio_hw_device *dev, /* out->muted = false; by calloc() */ /* out->written = 0; by calloc() */ pthread_mutex_init(&out->lock, (const pthread_mutexattr_t *) NULL); pthread_cond_init(&out->cond, (const pthread_condattr_t *) NULL); config->format = out->stream.common.get_format(&out->stream.common); config->channel_mask = out->stream.common.get_channels(&out->stream.common); config->sample_rate = out->stream.common.get_sample_rate(&out->stream.common); Loading Loading @@ -2459,23 +2462,24 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) char *str; char value[32]; int val; int ret = 0, err; int ret; int status = 0; ALOGD("%s: enter: %s", __func__, kvpairs); pthread_mutex_lock(&adev->lock); parms = str_parms_create_str(kvpairs); ret = voice_set_parameters(adev, parms); if (ret != 0) status = voice_set_parameters(adev, parms); if (status != 0) goto done; ret = platform_set_parameters(adev->platform, parms); if (ret != 0) status = platform_set_parameters(adev->platform, parms); if (status != 0) goto done; err = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); if (err >= 0) { ret = str_parms_get_str(parms, AUDIO_PARAMETER_KEY_BT_NREC, value, sizeof(value)); if (ret >= 0) { /* When set to false, HAL should disable EC and NS * But it is currently not supported. */ Loading @@ -2485,16 +2489,16 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) adev->bluetooth_nrec = false; } err = str_parms_get_str(parms, "screen_state", value, sizeof(value)); if (err >= 0) { ret = str_parms_get_str(parms, "screen_state", value, sizeof(value)); if (ret >= 0) { if (strcmp(value, AUDIO_PARAMETER_VALUE_ON) == 0) adev->screen_off = false; else adev->screen_off = true; } err = str_parms_get_int(parms, "rotation", &val); if (err >= 0) { ret = str_parms_get_int(parms, "rotation", &val); if (ret >= 0) { bool reverse_speakers = false; switch(val) { // FIXME: note that the code below assumes that the speakers are in the correct placement Loading @@ -2509,7 +2513,9 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) break; default: ALOGE("%s: unexpected rotation of %d", __func__, val); status = -EINVAL; } if (status == 0) { if (adev->speaker_lr_swap != reverse_speakers) { adev->speaker_lr_swap = reverse_speakers; // only update the selected device if there is active pcm playback Loading @@ -2524,14 +2530,15 @@ static int adev_set_parameters(struct audio_hw_device *dev, const char *kvpairs) } } } } audio_extn_set_parameters(adev, parms); done: str_parms_destroy(parms); pthread_mutex_unlock(&adev->lock); ALOGV("%s: exit with code(%d)", __func__, ret); return ret; ALOGV("%s: exit with code(%d)", __func__, status); return status; } static char* adev_get_parameters(const struct audio_hw_device *dev, Loading Loading @@ -2629,7 +2636,7 @@ static int adev_get_mic_mute(const struct audio_hw_device *dev, bool *state) static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev __unused, const struct audio_config *config) { int channel_count = popcount(config->channel_mask); int channel_count = audio_channel_count_from_in_mask(config->channel_mask); return get_input_buffer_size(config->sample_rate, config->format, channel_count); } Loading @@ -2646,7 +2653,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, struct audio_device *adev = (struct audio_device *)dev; struct stream_in *in; int ret = 0, buffer_size, frame_size; int channel_count = popcount(config->channel_mask); int channel_count = audio_channel_count_from_in_mask(config->channel_mask); *stream_in = NULL; Loading Loading @@ -2724,7 +2731,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, audio_extn_compr_cap_init(in); } else { in->config.channels = channel_count; frame_size = audio_stream_frame_size((struct audio_stream *)in); frame_size = audio_stream_in_frame_size(&in->stream); buffer_size = get_input_buffer_size(config->sample_rate, config->format, channel_count); Loading Loading @@ -2756,7 +2763,8 @@ static void adev_close_input_stream(struct audio_hw_device *dev __unused, } else in_standby(&stream->common); if (audio_extn_ssr_get_enabled() && (popcount(in->channel_mask) == 6)) { if (audio_extn_ssr_get_enabled() && (audio_channel_count_from_in_mask(in->channel_mask) == 6)) { audio_extn_ssr_deinit(); } free(stream); Loading