audio: Add @export annotations to microphone-related enums

This addresses long-standing TODOs in system/audio.h.
Annotated the following enums:

 - AudioMicrophoneChannelMapping;
 - AudioMicrophoneLocation;
 - AudioMicrophoneDirectionality.

This allows removing hand-written conversion functions
since the values are guaranteed to match between HIDL and
system/audio.h.

Bug: 122858783
Test: m
Change-Id: I2bf250ef9154a7ae86679afa566c80dfd01f1d5b
This commit is contained in:
Mikhail Naganov 2020-11-02 19:56:48 +00:00
parent 3214fcc65e
commit 9d9f970ee4
2 changed files with 7 additions and 50 deletions

View file

@ -126,16 +126,18 @@ struct AudioMicrophoneCoordinate {
* process (e.g. High Pass Filtering, dynamic compression)
* Simple processing as constant gain adjustment must be DIRECT.
*/
@export(name="audio_microphone_channel_mapping_t", value_prefix="AUDIO_MICROPHONE_CHANNEL_MAPPING_")
enum AudioMicrophoneChannelMapping : uint32_t {
UNUSED = 0, /* Channel not used */
DIRECT = 1, /* Channel used and signal not processed */
PROCESSED = 2, /* Channel used and signal has some process */
PROCESSED = 2, /* Channel used and signal has some processing */
};
/**
* Enum to identify locations of microphones in regards to the body of the
* android device.
*/
@export(name="audio_microphone_location_t", value_prefix="AUDIO_MICROPHONE_LOCATION_")
enum AudioMicrophoneLocation : uint32_t {
UNKNOWN = 0,
MAINBODY = 1,
@ -152,6 +154,7 @@ typedef int32_t AudioMicrophoneGroup;
/**
* Enum with standard polar patterns of microphones
*/
@export(name="audio_microphone_directionality_t", value_prefix="AUDIO_MICROPHONE_DIRECTIONALITY_")
enum AudioMicrophoneDirectionality : uint32_t {
UNKNOWN = 0,
OMNI = 1,

View file

@ -93,52 +93,6 @@ status_t deviceAddressFromHal(audio_devices_t device, const char* halAddress,
return OK;
}
AudioMicrophoneChannelMapping halToChannelMapping(audio_microphone_channel_mapping_t mapping) {
switch (mapping) {
case AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED:
return AudioMicrophoneChannelMapping::UNUSED;
case AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT:
return AudioMicrophoneChannelMapping::DIRECT;
case AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED:
return AudioMicrophoneChannelMapping::PROCESSED;
default:
ALOGE("Invalid channel mapping type: %d", mapping);
return AudioMicrophoneChannelMapping::UNUSED;
}
}
AudioMicrophoneLocation halToLocation(audio_microphone_location_t location) {
switch (location) {
default:
case AUDIO_MICROPHONE_LOCATION_UNKNOWN:
return AudioMicrophoneLocation::UNKNOWN;
case AUDIO_MICROPHONE_LOCATION_MAINBODY:
return AudioMicrophoneLocation::MAINBODY;
case AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE:
return AudioMicrophoneLocation::MAINBODY_MOVABLE;
case AUDIO_MICROPHONE_LOCATION_PERIPHERAL:
return AudioMicrophoneLocation::PERIPHERAL;
}
}
AudioMicrophoneDirectionality halToDirectionality(audio_microphone_directionality_t dir) {
switch (dir) {
default:
case AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN:
return AudioMicrophoneDirectionality::UNKNOWN;
case AUDIO_MICROPHONE_DIRECTIONALITY_OMNI:
return AudioMicrophoneDirectionality::OMNI;
case AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL:
return AudioMicrophoneDirectionality::BI_DIRECTIONAL;
case AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID:
return AudioMicrophoneDirectionality::CARDIOID;
case AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID:
return AudioMicrophoneDirectionality::HYPER_CARDIOID;
case AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID:
return AudioMicrophoneDirectionality::SUPER_CARDIOID;
}
}
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
const struct audio_microphone_characteristic_t& src) {
bool status = false;
@ -150,15 +104,15 @@ bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
}
pDst->channelMapping.resize(AUDIO_CHANNEL_COUNT_MAX);
for (size_t ch = 0; ch < pDst->channelMapping.size(); ch++) {
pDst->channelMapping[ch] = halToChannelMapping(src.channel_mapping[ch]);
pDst->channelMapping[ch] = AudioMicrophoneChannelMapping(src.channel_mapping[ch]);
}
pDst->location = halToLocation(src.location);
pDst->location = AudioMicrophoneLocation(src.location);
pDst->group = (AudioMicrophoneGroup)src.group;
pDst->indexInTheGroup = (uint32_t)src.index_in_the_group;
pDst->sensitivity = src.sensitivity;
pDst->maxSpl = src.max_spl;
pDst->minSpl = src.min_spl;
pDst->directionality = halToDirectionality(src.directionality);
pDst->directionality = AudioMicrophoneDirectionality(src.directionality);
pDst->frequencyResponse.resize(src.num_frequency_responses);
for (size_t k = 0; k < src.num_frequency_responses; k++) {
pDst->frequencyResponse[k].frequency = src.frequency_responses[0][k];