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:
Mikhail Naganov 2020-10-05 17:12:45 -07:00
parent ad5602aa0c
commit afea6a410f
2 changed files with 11 additions and 7 deletions

View file

@ -90,10 +90,10 @@ static uint32_t audio_device_conv_table[][HAL_API_REV_NUM] =
{ 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;
uint32_t to_device = AUDIO_DEVICE_NONE;
audio_devices_t to_device = AUDIO_DEVICE_NONE;
uint32_t in_bit = 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++) {
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;
}
}
@ -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);
uint32_t raw_channel_mask = config->channel_mask;
out->legacy_out = ladev->hwif->openOutputStreamWithFlags(devices, flags,
(int *) &config->format,
&config->channel_mask,
&raw_channel_mask,
&config->sample_rate, &status);
if (!out->legacy_out) {
ret = status;
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.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);
uint32_t raw_channel_mask = config->channel_mask;
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);
if (!in->legacy_in) {
ret = status;
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.set_sample_rate = in_set_sample_rate;

View file

@ -345,10 +345,10 @@ public:
static bool isLinearPCM(uint32_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);
}
static bool isInputChannel(uint32_t channel) {
static bool isInputChannel(audio_channel_mask_t channel) {
return audio_is_input_channel(channel);
}