Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f604b36d authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Gerrit Code Review
Browse files

Merge "audio: Use auto-generated MicrophoneInfoFw class"

parents a2557b1d 2a6a3013
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ aidl_interface {
    srcs: [
        "aidl/android/media/InterpolatorConfig.aidl",
        "aidl/android/media/InterpolatorType.aidl",
        "aidl/android/media/MicrophoneInfoData.aidl",
        "aidl/android/media/MicrophoneInfoFw.aidl",
        "aidl/android/media/VolumeShaperConfiguration.aidl",
        "aidl/android/media/VolumeShaperConfigurationOptionFlag.aidl",
        "aidl/android/media/VolumeShaperConfigurationType.aidl",
@@ -52,6 +52,9 @@ aidl_interface {
        "aidl/android/media/VolumeShaperOperationFlag.aidl",
        "aidl/android/media/VolumeShaperState.aidl",
    ],
    imports: [
        "android.media.audio.common.types-V2",
    ],
    backend: {
        cpp: {
            min_sdk_version: "29",
@@ -62,6 +65,9 @@ aidl_interface {
                "com.android.media.swcodec",
            ],
        },
        java: {
            sdk_version: "module_current",
        },
    },
}

+6 −16
Original line number Diff line number Diff line
@@ -16,24 +16,14 @@

package android.media;

import android.media.audio.common.MicrophoneDynamicInfo;
import android.media.audio.common.MicrophoneInfo;

/**
 * {@hide}
 */
parcelable MicrophoneInfoData {
    @utf8InCpp String deviceId;
parcelable MicrophoneInfoFw {
    MicrophoneInfo info;
    MicrophoneDynamicInfo dynamic;
    int portId;
    int type;
    @utf8InCpp String address;
    int deviceLocation;
    int deviceGroup;
    int indexInTheGroup;
    float[] geometricLocation;
    float[] orientation;
    float[] frequencies;
    float[] frequencyResponses;
    int[] channelMapping;
    float sensitivity;
    float maxSpl;
    float minSpl;
    int directionality;
}

include/media/MicrophoneInfo.h

deleted100644 → 0
+0 −239
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ANDROID_MICROPHONE_INFO_H
#define ANDROID_MICROPHONE_INFO_H

#include <android/media/MicrophoneInfoData.h>
#include <binder/Parcel.h>
#include <binder/Parcelable.h>
#include <media/AidlConversionUtil.h>
#include <system/audio.h>

namespace android {
namespace media {

class MicrophoneInfo : public Parcelable {
public:
    MicrophoneInfo() = default;
    MicrophoneInfo(const MicrophoneInfo& microphoneInfo) = default;
    MicrophoneInfo(audio_microphone_characteristic_t& characteristic) {
        mDeviceId = std::string(&characteristic.device_id[0]);
        mPortId = characteristic.id;
        mType = characteristic.device;
        mAddress = std::string(&characteristic.address[0]);
        mDeviceLocation = characteristic.location;
        mDeviceGroup = characteristic.group;
        mIndexInTheGroup = characteristic.index_in_the_group;
        mGeometricLocation.push_back(characteristic.geometric_location.x);
        mGeometricLocation.push_back(characteristic.geometric_location.y);
        mGeometricLocation.push_back(characteristic.geometric_location.z);
        mOrientation.push_back(characteristic.orientation.x);
        mOrientation.push_back(characteristic.orientation.y);
        mOrientation.push_back(characteristic.orientation.z);
        std::vector<float> frequencies;
        std::vector<float> responses;
        for (size_t i = 0; i < characteristic.num_frequency_responses; i++) {
            frequencies.push_back(characteristic.frequency_responses[0][i]);
            responses.push_back(characteristic.frequency_responses[1][i]);
        }
        mFrequencyResponses.push_back(frequencies);
        mFrequencyResponses.push_back(responses);
        for (size_t i = 0; i < AUDIO_CHANNEL_COUNT_MAX; i++) {
            mChannelMapping.push_back(characteristic.channel_mapping[i]);
        }
        mSensitivity = characteristic.sensitivity;
        mMaxSpl = characteristic.max_spl;
        mMinSpl = characteristic.min_spl;
        mDirectionality = characteristic.directionality;
    }

    virtual ~MicrophoneInfo() = default;

    virtual status_t writeToParcel(Parcel* parcel) const {
        MicrophoneInfoData parcelable;
        return writeToParcelable(&parcelable)
               ?: parcelable.writeToParcel(parcel);
    }

    virtual status_t writeToParcelable(MicrophoneInfoData* parcelable) const {
#if defined(BACKEND_NDK)
        using ::aidl::android::convertReinterpret;
#endif
        parcelable->deviceId = mDeviceId;
        parcelable->portId = mPortId;
        parcelable->type = VALUE_OR_RETURN_STATUS(convertReinterpret<int32_t>(mType));
        parcelable->address = mAddress;
        parcelable->deviceGroup = mDeviceGroup;
        parcelable->indexInTheGroup = mIndexInTheGroup;
        parcelable->geometricLocation = mGeometricLocation;
        parcelable->orientation = mOrientation;
        if (mFrequencyResponses.size() != 2) {
            return BAD_VALUE;
        }
        parcelable->frequencies = mFrequencyResponses[0];
        parcelable->frequencyResponses = mFrequencyResponses[1];
        parcelable->channelMapping = mChannelMapping;
        parcelable->sensitivity = mSensitivity;
        parcelable->maxSpl = mMaxSpl;
        parcelable->minSpl = mMinSpl;
        parcelable->directionality = mDirectionality;
        return OK;
    }

    virtual status_t readFromParcel(const Parcel* parcel) {
        MicrophoneInfoData data;
        return data.readFromParcel(parcel)
            ?: readFromParcelable(data);
    }

    virtual status_t readFromParcelable(const MicrophoneInfoData& parcelable) {
#if defined(BACKEND_NDK)
        using ::aidl::android::convertReinterpret;
#endif
        mDeviceId = parcelable.deviceId;
        mPortId = parcelable.portId;
        mType = VALUE_OR_RETURN_STATUS(convertReinterpret<uint32_t>(parcelable.type));
        mAddress = parcelable.address;
        mDeviceLocation = parcelable.deviceLocation;
        mDeviceGroup = parcelable.deviceGroup;
        mIndexInTheGroup = parcelable.indexInTheGroup;
        if (parcelable.geometricLocation.size() != 3) {
            return BAD_VALUE;
        }
        mGeometricLocation = parcelable.geometricLocation;
        if (parcelable.orientation.size() != 3) {
            return BAD_VALUE;
        }
        mOrientation = parcelable.orientation;
        if (parcelable.frequencies.size() != parcelable.frequencyResponses.size()) {
            return BAD_VALUE;
        }

        mFrequencyResponses.push_back(parcelable.frequencies);
        mFrequencyResponses.push_back(parcelable.frequencyResponses);
        if (parcelable.channelMapping.size() != AUDIO_CHANNEL_COUNT_MAX) {
            return BAD_VALUE;
        }
        mChannelMapping = parcelable.channelMapping;
        mSensitivity = parcelable.sensitivity;
        mMaxSpl = parcelable.maxSpl;
        mMinSpl = parcelable.minSpl;
        mDirectionality = parcelable.directionality;
        return OK;
    }

    std::string getDeviceId() const {
        return mDeviceId;
    }

    int getPortId() const {
        return mPortId;
    }

    unsigned int getType() const {
        return mType;
    }

    std::string getAddress() const {
        return mAddress;
    }

    int getDeviceLocation() const {
        return mDeviceLocation;
    }

    int getDeviceGroup() const {
        return mDeviceGroup;
    }

    int getIndexInTheGroup() const {
        return mIndexInTheGroup;
    }

    const std::vector<float>& getGeometricLocation() const {
        return mGeometricLocation;
    }

    const std::vector<float>& getOrientation() const {
        return mOrientation;
    }

    const std::vector<std::vector<float>>& getFrequencyResponses() const {
        return mFrequencyResponses;
    }

    const std::vector<int>& getChannelMapping() const {
        return mChannelMapping;
    }

    float getSensitivity() const {
        return mSensitivity;
    }

    float getMaxSpl() const {
        return mMaxSpl;
    }

    float getMinSpl() const {
        return mMinSpl;
    }

    int getDirectionality() const {
        return mDirectionality;
    }

private:
    std::string mDeviceId;
    int32_t mPortId;
    uint32_t mType;
    std::string mAddress;
    int32_t mDeviceLocation;
    int32_t mDeviceGroup;
    int32_t mIndexInTheGroup;
    std::vector<float> mGeometricLocation;
    std::vector<float> mOrientation;
    std::vector<std::vector<float>> mFrequencyResponses;
    std::vector<int> mChannelMapping;
    float mSensitivity;
    float mMaxSpl;
    float mMinSpl;
    int32_t mDirectionality;
};

#if defined(BACKEND_NDK)
using ::aidl::ConversionResult;
#endif

// Conversion routines, according to AidlConversion.h conventions.
inline ConversionResult<MicrophoneInfo>
aidl2legacy_MicrophoneInfo(const media::MicrophoneInfoData& aidl) {
    MicrophoneInfo legacy;
    RETURN_IF_ERROR(legacy.readFromParcelable(aidl));
    return legacy;
}

inline ConversionResult<media::MicrophoneInfoData>
legacy2aidl_MicrophoneInfo(const MicrophoneInfo& legacy) {
    media::MicrophoneInfoData aidl;
    RETURN_IF_ERROR(legacy.writeToParcelable(&aidl));
    return aidl;
}

} // namespace media
} // namespace android

#endif
+276 −0
Original line number Diff line number Diff line
@@ -83,6 +83,8 @@ using media::audio::common::AudioUsage;
using media::audio::common::AudioUuid;
using media::audio::common::ExtraAudioDescriptor;
using media::audio::common::Int;
using media::audio::common::MicrophoneDynamicInfo;
using media::audio::common::MicrophoneInfo;
using media::audio::common::PcmType;

////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -2711,6 +2713,280 @@ legacy2aidl_audio_latency_mode_t_AudioLatencyMode(audio_latency_mode_t legacy) {
    return unexpected(BAD_VALUE);
}

ConversionResult<audio_microphone_location_t>
aidl2legacy_MicrophoneInfoLocation_audio_microphone_location_t(MicrophoneInfo::Location aidl) {
    switch (aidl) {
        case MicrophoneInfo::Location::UNKNOWN:
            return AUDIO_MICROPHONE_LOCATION_UNKNOWN;
        case MicrophoneInfo::Location::MAINBODY:
            return AUDIO_MICROPHONE_LOCATION_MAINBODY;
        case MicrophoneInfo::Location::MAINBODY_MOVABLE:
            return AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE;
        case MicrophoneInfo::Location::PERIPHERAL:
            return AUDIO_MICROPHONE_LOCATION_PERIPHERAL;
    }
    return unexpected(BAD_VALUE);
}
ConversionResult<MicrophoneInfo::Location>
legacy2aidl_audio_microphone_location_t_MicrophoneInfoLocation(audio_microphone_location_t legacy) {
    switch (legacy) {
        case AUDIO_MICROPHONE_LOCATION_UNKNOWN:
            return MicrophoneInfo::Location::UNKNOWN;
        case AUDIO_MICROPHONE_LOCATION_MAINBODY:
            return MicrophoneInfo::Location::MAINBODY;
        case AUDIO_MICROPHONE_LOCATION_MAINBODY_MOVABLE:
            return MicrophoneInfo::Location::MAINBODY_MOVABLE;
        case AUDIO_MICROPHONE_LOCATION_PERIPHERAL:
            return MicrophoneInfo::Location::PERIPHERAL;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<audio_microphone_group_t> aidl2legacy_int32_t_audio_microphone_group_t(
        int32_t aidl) {
    return convertReinterpret<audio_microphone_group_t>(aidl);
}

ConversionResult<int32_t> legacy2aidl_audio_microphone_group_t_int32_t(
        audio_microphone_group_t legacy) {
    return convertReinterpret<int32_t>(legacy);
}

ConversionResult<audio_microphone_directionality_t>
aidl2legacy_MicrophoneInfoDirectionality_audio_microphone_directionality_t(
        MicrophoneInfo::Directionality aidl) {
    switch (aidl) {
        case MicrophoneInfo::Directionality::UNKNOWN:
            return AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN;
        case MicrophoneInfo::Directionality::OMNI:
            return AUDIO_MICROPHONE_DIRECTIONALITY_OMNI;
        case MicrophoneInfo::Directionality::BI_DIRECTIONAL:
            return AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL;
        case MicrophoneInfo::Directionality::CARDIOID:
            return AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID;
        case MicrophoneInfo::Directionality::HYPER_CARDIOID:
            return AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID;
        case MicrophoneInfo::Directionality::SUPER_CARDIOID:
            return AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID;
    }
    return unexpected(BAD_VALUE);
}
ConversionResult<MicrophoneInfo::Directionality>
legacy2aidl_audio_microphone_directionality_t_MicrophoneInfoDirectionality(
        audio_microphone_directionality_t legacy) {
    switch (legacy) {
        case AUDIO_MICROPHONE_DIRECTIONALITY_UNKNOWN:
            return MicrophoneInfo::Directionality::UNKNOWN;
        case AUDIO_MICROPHONE_DIRECTIONALITY_OMNI:
            return MicrophoneInfo::Directionality::OMNI;
        case AUDIO_MICROPHONE_DIRECTIONALITY_BI_DIRECTIONAL:
            return MicrophoneInfo::Directionality::BI_DIRECTIONAL;
        case AUDIO_MICROPHONE_DIRECTIONALITY_CARDIOID:
            return MicrophoneInfo::Directionality::CARDIOID;
        case AUDIO_MICROPHONE_DIRECTIONALITY_HYPER_CARDIOID:
            return MicrophoneInfo::Directionality::HYPER_CARDIOID;
        case AUDIO_MICROPHONE_DIRECTIONALITY_SUPER_CARDIOID:
            return MicrophoneInfo::Directionality::SUPER_CARDIOID;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<audio_microphone_coordinate>
aidl2legacy_MicrophoneInfoCoordinate_audio_microphone_coordinate(
        const MicrophoneInfo::Coordinate& aidl) {
    audio_microphone_coordinate legacy;
    legacy.x = aidl.x;
    legacy.y = aidl.y;
    legacy.z = aidl.z;
    return legacy;
}
ConversionResult<MicrophoneInfo::Coordinate>
legacy2aidl_audio_microphone_coordinate_MicrophoneInfoCoordinate(
        const audio_microphone_coordinate& legacy) {
    MicrophoneInfo::Coordinate aidl;
    aidl.x = legacy.x;
    aidl.y = legacy.y;
    aidl.z = legacy.z;
    return aidl;
}

ConversionResult<audio_microphone_channel_mapping_t>
aidl2legacy_MicrophoneDynamicInfoChannelMapping_audio_microphone_channel_mapping_t(
        MicrophoneDynamicInfo::ChannelMapping aidl) {
    switch (aidl) {
        case MicrophoneDynamicInfo::ChannelMapping::UNUSED:
            return AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
        case MicrophoneDynamicInfo::ChannelMapping::DIRECT:
            return AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT;
        case MicrophoneDynamicInfo::ChannelMapping::PROCESSED:
            return AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED;
    }
    return unexpected(BAD_VALUE);
}
ConversionResult<MicrophoneDynamicInfo::ChannelMapping>
legacy2aidl_audio_microphone_channel_mapping_t_MicrophoneDynamicInfoChannelMapping(
        audio_microphone_channel_mapping_t legacy) {
    switch (legacy) {
        case AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED:
            return MicrophoneDynamicInfo::ChannelMapping::UNUSED;
        case AUDIO_MICROPHONE_CHANNEL_MAPPING_DIRECT:
            return MicrophoneDynamicInfo::ChannelMapping::DIRECT;
        case AUDIO_MICROPHONE_CHANNEL_MAPPING_PROCESSED:
            return MicrophoneDynamicInfo::ChannelMapping::PROCESSED;
    }
    return unexpected(BAD_VALUE);
}

ConversionResult<audio_microphone_characteristic_t>
aidl2legacy_MicrophoneInfos_audio_microphone_characteristic_t(
        const MicrophoneInfo& aidlInfo, const MicrophoneDynamicInfo& aidlDynamic) {
    static const audio_microphone_coordinate kCoordinateUnknown = {
        AUDIO_MICROPHONE_COORDINATE_UNKNOWN, AUDIO_MICROPHONE_COORDINATE_UNKNOWN,
        AUDIO_MICROPHONE_COORDINATE_UNKNOWN };
    audio_microphone_characteristic_t legacy{};
    if (aidlInfo.id != aidlDynamic.id) {
        return unexpected(BAD_VALUE);
    }
    // Note: in the legacy structure, 'device_id' is the mic's ID, 'id' is APM port id.
    RETURN_IF_ERROR(aidl2legacy_string(aidlInfo.id, legacy.device_id, AUDIO_MICROPHONE_ID_MAX_LEN));
    RETURN_IF_ERROR(aidl2legacy_AudioDevice_audio_device(
                    aidlInfo.device, &legacy.device, legacy.address));
    legacy.location = VALUE_OR_RETURN(
            aidl2legacy_MicrophoneInfoLocation_audio_microphone_location_t(aidlInfo.location));
    legacy.group = VALUE_OR_RETURN(aidl2legacy_int32_t_audio_microphone_group_t(aidlInfo.group));
    // For some reason, the legacy field is unsigned, however in the SDK layer it is signed,
    // as it is in AIDL. So, use UINT_MAX for INDEX_IN_THE_GROUP_UNKNOWN which is -1.
    if (aidlInfo.indexInTheGroup != MicrophoneInfo::INDEX_IN_THE_GROUP_UNKNOWN) {
        legacy.index_in_the_group = VALUE_OR_RETURN(
                convertReinterpret<unsigned int>(aidlInfo.indexInTheGroup));
    } else {
        legacy.index_in_the_group = UINT_MAX;
    }
    if (aidlInfo.sensitivity.has_value()) {
        legacy.sensitivity = aidlInfo.sensitivity.value().leveldBFS;
        legacy.max_spl = aidlInfo.sensitivity.value().maxSpldB;
        legacy.min_spl = aidlInfo.sensitivity.value().minSpldB;
    } else {
        legacy.sensitivity = AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN;
        legacy.max_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
        legacy.min_spl = AUDIO_MICROPHONE_SPL_UNKNOWN;
    }
    legacy.directionality = VALUE_OR_RETURN(
            aidl2legacy_MicrophoneInfoDirectionality_audio_microphone_directionality_t(
                    aidlInfo.directionality));
    if (aidlInfo.frequencyResponse.size() > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
        return unexpected(BAD_VALUE);
    }
    legacy.num_frequency_responses = 0;
    for (const auto& p: aidlInfo.frequencyResponse) {
        legacy.frequency_responses[0][legacy.num_frequency_responses] = p.frequencyHz;
        legacy.frequency_responses[1][legacy.num_frequency_responses++] = p.leveldB;
    }
    if (aidlInfo.position.has_value()) {
        legacy.geometric_location = VALUE_OR_RETURN(
                aidl2legacy_MicrophoneInfoCoordinate_audio_microphone_coordinate(
                        aidlInfo.position.value()));
    } else {
        legacy.geometric_location = kCoordinateUnknown;
    }
    if (aidlInfo.orientation.has_value()) {
        legacy.orientation = VALUE_OR_RETURN(
                aidl2legacy_MicrophoneInfoCoordinate_audio_microphone_coordinate(
                        aidlInfo.orientation.value()));
    } else {
        legacy.orientation = kCoordinateUnknown;
    }
    if (aidlDynamic.channelMapping.size() > AUDIO_CHANNEL_COUNT_MAX) {
        return unexpected(BAD_VALUE);
    }
    size_t i = 0;
    for (; i < aidlDynamic.channelMapping.size(); ++i) {
        legacy.channel_mapping[i] = VALUE_OR_RETURN(
                aidl2legacy_MicrophoneDynamicInfoChannelMapping_audio_microphone_channel_mapping_t(
                        aidlDynamic.channelMapping[i]));
    }
    for (; i < AUDIO_CHANNEL_COUNT_MAX; ++i) {
        legacy.channel_mapping[i] = AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED;
    }
    return legacy;
}

status_t
legacy2aidl_audio_microphone_characteristic_t_MicrophoneInfos(
        const audio_microphone_characteristic_t& legacy,
        MicrophoneInfo* aidlInfo, MicrophoneDynamicInfo* aidlDynamic) {
    aidlInfo->id = VALUE_OR_RETURN_STATUS(
            legacy2aidl_string(legacy.device_id, AUDIO_MICROPHONE_ID_MAX_LEN));
    aidlDynamic->id = aidlInfo->id;
    aidlInfo->device = VALUE_OR_RETURN_STATUS(legacy2aidl_audio_device_AudioDevice(
                    legacy.device, legacy.address));
    aidlInfo->location = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_microphone_location_t_MicrophoneInfoLocation(legacy.location));
    aidlInfo->group = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_microphone_group_t_int32_t(legacy.group));
    // For some reason, the legacy field is unsigned, however in the SDK layer it is signed,
    // as it is in AIDL. So, use UINT_MAX for INDEX_IN_THE_GROUP_UNKNOWN which is -1.
    if (legacy.index_in_the_group != UINT_MAX) {
        aidlInfo->indexInTheGroup = VALUE_OR_RETURN_STATUS(
                convertReinterpret<int32_t>(legacy.index_in_the_group));
    } else {
        aidlInfo->indexInTheGroup = MicrophoneInfo::INDEX_IN_THE_GROUP_UNKNOWN;
    }
    if (legacy.sensitivity != AUDIO_MICROPHONE_SENSITIVITY_UNKNOWN &&
            legacy.max_spl != AUDIO_MICROPHONE_SPL_UNKNOWN &&
            legacy.min_spl != AUDIO_MICROPHONE_SPL_UNKNOWN) {
        MicrophoneInfo::Sensitivity sensitivity;
        sensitivity.leveldBFS = legacy.sensitivity;
        sensitivity.maxSpldB = legacy.max_spl;
        sensitivity.minSpldB = legacy.min_spl;
        aidlInfo->sensitivity = std::move(sensitivity);
    } else {
        aidlInfo->sensitivity = {};
    }
    aidlInfo->directionality = VALUE_OR_RETURN_STATUS(
            legacy2aidl_audio_microphone_directionality_t_MicrophoneInfoDirectionality(
                    legacy.directionality));
    if (legacy.num_frequency_responses > AUDIO_MICROPHONE_MAX_FREQUENCY_RESPONSES) {
        return BAD_VALUE;
    }
    aidlInfo->frequencyResponse.resize(legacy.num_frequency_responses);
    for (size_t i = 0; i < legacy.num_frequency_responses; ++i) {
        aidlInfo->frequencyResponse[i].frequencyHz = legacy.frequency_responses[0][i];
        aidlInfo->frequencyResponse[i].leveldB = legacy.frequency_responses[1][i];
    }
    if (legacy.geometric_location.x != AUDIO_MICROPHONE_COORDINATE_UNKNOWN &&
            legacy.geometric_location.y != AUDIO_MICROPHONE_COORDINATE_UNKNOWN &&
            legacy.geometric_location.z != AUDIO_MICROPHONE_COORDINATE_UNKNOWN) {
        aidlInfo->position = VALUE_OR_RETURN_STATUS(
                legacy2aidl_audio_microphone_coordinate_MicrophoneInfoCoordinate(
                        legacy.geometric_location));
    } else {
        aidlInfo->position = {};
    }
    if (legacy.orientation.x != AUDIO_MICROPHONE_COORDINATE_UNKNOWN &&
            legacy.orientation.y != AUDIO_MICROPHONE_COORDINATE_UNKNOWN &&
            legacy.orientation.z != AUDIO_MICROPHONE_COORDINATE_UNKNOWN) {
        aidlInfo->orientation = VALUE_OR_RETURN_STATUS(
                legacy2aidl_audio_microphone_coordinate_MicrophoneInfoCoordinate(
                        legacy.orientation));
    } else {
        aidlInfo->orientation = {};
    }
    size_t channelsUsed = AUDIO_CHANNEL_COUNT_MAX;
    while (channelsUsed != 0 &&
            legacy.channel_mapping[--channelsUsed] == AUDIO_MICROPHONE_CHANNEL_MAPPING_UNUSED) {}
    // Doing an increment is correct even when channel 0 is 'UNUSED',
    // that's because AIDL requires to have at least 1 element in the mapping.
    ++channelsUsed;
    aidlDynamic->channelMapping.resize(channelsUsed);
    for (size_t i = 0; i < channelsUsed; ++i) {
        aidlDynamic->channelMapping[i] = VALUE_OR_RETURN_STATUS(
                legacy2aidl_audio_microphone_channel_mapping_t_MicrophoneDynamicInfoChannelMapping(
                        legacy.channel_mapping[i]));
    }
    return OK;
}

}  // namespace android

#if defined(BACKEND_NDK)
+44 −0

File changed.

Preview size limit exceeded, changes collapsed.

Loading