Convert mask types from uint32_t to enum type
This applies to the following types: - audio_gain_mode_t; - audio_flags_mask_t; - audio_channel_representation_t; - audio_channel_mask_t; - audio_devices_t. Enum types are distinct thus proper overloading on the type is possible in C++. Also, assignments to enum types are less prone to errors. Bug: 169889714 Test: basic audio functionality Change-Id: I6366511b421ccab2782310ecc15a13e08d9c17af
This commit is contained in:
parent
ad5602aa0c
commit
afea6a410f
2 changed files with 11 additions and 7 deletions
|
@ -90,10 +90,10 @@ static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] =
|
||||||
{ AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT },
|
{ AudioSystem::DEVICE_IN_DEFAULT, AUDIO_DEVICE_IN_DEFAULT },
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint32_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev)
|
static audio_devices_t convert_audio_device(uint32_t from_device, int from_rev, int to_rev)
|
||||||
{
|
{
|
||||||
const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM;
|
const uint32_t k_num_devices = sizeof(audio_device_conv_table)/sizeof(uint32_t)/HAL_API_REV_NUM;
|
||||||
uint32_t to_device = AUDIO_DEVICE_NONE;
|
audio_devices_t to_device = AUDIO_DEVICE_NONE;
|
||||||
uint32_t in_bit = 0;
|
uint32_t in_bit = 0;
|
||||||
|
|
||||||
if (from_rev != HAL_API_REV_1_0) {
|
if (from_rev != HAL_API_REV_1_0) {
|
||||||
|
@ -107,7 +107,7 @@ static uint32_t convert_audio_device(uint32_t from_device, int from_rev, int to_
|
||||||
|
|
||||||
for (i = 0; i < k_num_devices; i++) {
|
for (i = 0; i < k_num_devices; i++) {
|
||||||
if (audio_device_conv_table[i][from_rev] == cur_device) {
|
if (audio_device_conv_table[i][from_rev] == cur_device) {
|
||||||
to_device |= audio_device_conv_table[i][to_rev];
|
to_device = (audio_devices_t)(to_device | audio_device_conv_table[i][to_rev]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,14 +504,16 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
|
||||||
|
|
||||||
devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
|
devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
|
||||||
|
|
||||||
|
uint32_t raw_channel_mask = config->channel_mask;
|
||||||
out->legacy_out = ladev->hwif->openOutputStreamWithFlags(devices, flags,
|
out->legacy_out = ladev->hwif->openOutputStreamWithFlags(devices, flags,
|
||||||
(int *) &config->format,
|
(int *) &config->format,
|
||||||
&config->channel_mask,
|
&raw_channel_mask,
|
||||||
&config->sample_rate, &status);
|
&config->sample_rate, &status);
|
||||||
if (!out->legacy_out) {
|
if (!out->legacy_out) {
|
||||||
ret = status;
|
ret = status;
|
||||||
goto err_open;
|
goto err_open;
|
||||||
}
|
}
|
||||||
|
config->channel_mask = (audio_channel_mask_t)raw_channel_mask;
|
||||||
|
|
||||||
out->stream.common.get_sample_rate = out_get_sample_rate;
|
out->stream.common.get_sample_rate = out_get_sample_rate;
|
||||||
out->stream.common.set_sample_rate = out_set_sample_rate;
|
out->stream.common.set_sample_rate = out_set_sample_rate;
|
||||||
|
@ -571,13 +573,15 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
|
||||||
|
|
||||||
devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
|
devices = convert_audio_device(devices, HAL_API_REV_2_0, HAL_API_REV_1_0);
|
||||||
|
|
||||||
|
uint32_t raw_channel_mask = config->channel_mask;
|
||||||
in->legacy_in = ladev->hwif->openInputStream(devices, (int *) &config->format,
|
in->legacy_in = ladev->hwif->openInputStream(devices, (int *) &config->format,
|
||||||
&config->channel_mask, &config->sample_rate,
|
&raw_channel_mask, &config->sample_rate,
|
||||||
&status, (AudioSystem::audio_in_acoustics)0);
|
&status, (AudioSystem::audio_in_acoustics)0);
|
||||||
if (!in->legacy_in) {
|
if (!in->legacy_in) {
|
||||||
ret = status;
|
ret = status;
|
||||||
goto err_open;
|
goto err_open;
|
||||||
}
|
}
|
||||||
|
config->channel_mask = (audio_channel_mask_t)raw_channel_mask;
|
||||||
|
|
||||||
in->stream.common.get_sample_rate = in_get_sample_rate;
|
in->stream.common.get_sample_rate = in_get_sample_rate;
|
||||||
in->stream.common.set_sample_rate = in_set_sample_rate;
|
in->stream.common.set_sample_rate = in_set_sample_rate;
|
||||||
|
|
|
@ -345,10 +345,10 @@ public:
|
||||||
static bool isLinearPCM(uint32_t format) {
|
static bool isLinearPCM(uint32_t format) {
|
||||||
return audio_is_linear_pcm((audio_format_t) format);
|
return audio_is_linear_pcm((audio_format_t) format);
|
||||||
}
|
}
|
||||||
static bool isOutputChannel(uint32_t channel) {
|
static bool isOutputChannel(audio_channel_mask_t channel) {
|
||||||
return audio_is_output_channel(channel);
|
return audio_is_output_channel(channel);
|
||||||
}
|
}
|
||||||
static bool isInputChannel(uint32_t channel) {
|
static bool isInputChannel(audio_channel_mask_t channel) {
|
||||||
return audio_is_input_channel(channel);
|
return audio_is_input_channel(channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue