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

Commit d24fc51e authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Automerger Merge Worker
Browse files

audio: Enable more compile time checks in the default impl am: b511b8aa am:...

audio: Enable more compile time checks in the default impl am: b511b8aa am: 796d7846 am: 7daa2861

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2592261



Change-Id: I58a138b32c11796cea34491c1bd7477991bb62ee
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6717069b 7daa2861
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,12 @@ cc_library {
        "audio_policy_configuration_aidl_default",
        "audio_policy_configuration_aidl_default",
        "audio_policy_engine_configuration_aidl_default",
        "audio_policy_engine_configuration_aidl_default",
    ],
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wthread-safety",
    ],
}
}


cc_binary {
cc_binary {
+2 −2
Original line number Original line Diff line number Diff line
@@ -187,7 +187,7 @@ ndk::ScopedAStatus Module::createStreamContext(
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }
    }
    LOG(DEBUG) << __func__ << ": frame size " << frameSize << " bytes";
    LOG(DEBUG) << __func__ << ": frame size " << frameSize << " bytes";
    if (frameSize > kMaximumStreamBufferSizeBytes / in_bufferSizeFrames) {
    if (frameSize > static_cast<size_t>(kMaximumStreamBufferSizeBytes / in_bufferSizeFrames)) {
        LOG(ERROR) << __func__ << ": buffer size " << in_bufferSizeFrames
        LOG(ERROR) << __func__ << ": buffer size " << in_bufferSizeFrames
                   << " frames is too large, maximum size is "
                   << " frames is too large, maximum size is "
                   << kMaximumStreamBufferSizeBytes / frameSize;
                   << kMaximumStreamBufferSizeBytes / frameSize;
@@ -281,7 +281,7 @@ ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, Audio
                   << " does not correspond to a mix port";
                   << " does not correspond to a mix port";
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
        return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
    }
    }
    const int32_t maxOpenStreamCount = portIt->ext.get<AudioPortExt::Tag::mix>().maxOpenStreamCount;
    const size_t maxOpenStreamCount = portIt->ext.get<AudioPortExt::Tag::mix>().maxOpenStreamCount;
    if (maxOpenStreamCount != 0 && mStreams.count(portId) >= maxOpenStreamCount) {
    if (maxOpenStreamCount != 0 && mStreams.count(portId) >= maxOpenStreamCount) {
        LOG(ERROR) << __func__ << ": port id " << portId
        LOG(ERROR) << __func__ << ": port id " << portId
                   << " has already reached maximum allowed opened stream count: "
                   << " has already reached maximum allowed opened stream count: "
+7 −4
Original line number Original line Diff line number Diff line
@@ -106,11 +106,14 @@ DriverUsb::DriverUsb(const StreamContext& context, bool isInput)


::android::status_t DriverUsb::transfer(void* buffer, size_t frameCount, size_t* actualFrameCount,
::android::status_t DriverUsb::transfer(void* buffer, size_t frameCount, size_t* actualFrameCount,
                                        int32_t* latencyMs) {
                                        int32_t* latencyMs) {
    {
        std::lock_guard guard(mLock);
        if (!mConfig.has_value() || mConnectedDevices.empty()) {
        if (!mConfig.has_value() || mConnectedDevices.empty()) {
            LOG(ERROR) << __func__ << ": failed, has config: " << mConfig.has_value()
            LOG(ERROR) << __func__ << ": failed, has config: " << mConfig.has_value()
                       << ", has connected devices: " << mConnectedDevices.empty();
                       << ", has connected devices: " << mConnectedDevices.empty();
            return ::android::NO_INIT;
            return ::android::NO_INIT;
        }
        }
    }
    if (mIsStandby) {
    if (mIsStandby) {
        if (::android::status_t status = exitStandby(); status != ::android::OK) {
        if (::android::status_t status = exitStandby(); status != ::android::OK) {
            LOG(ERROR) << __func__ << ": failed to exit standby, status=" << status;
            LOG(ERROR) << __func__ << ": failed to exit standby, status=" << status;
+4 −11
Original line number Original line Diff line number Diff line
@@ -99,16 +99,6 @@ int volumeFloatToInteger(float fValue, int maxValue, int minValue) {
    return minValue + std::ceil((maxValue - minValue) * fValue);
    return minValue + std::ceil((maxValue - minValue) * fValue);
}
}


float volumeIntegerToFloat(int iValue, int maxValue, int minValue) {
    if (iValue > maxValue) {
        return 1.0f;
    }
    if (iValue < minValue) {
        return 0.0f;
    }
    return static_cast<float>(iValue - minValue) / (maxValue - minValue);
}

}  // namespace
}  // namespace


ndk::ScopedAStatus AlsaMixer::setMasterMute(bool muted) {
ndk::ScopedAStatus AlsaMixer::setMasterMute(bool muted) {
@@ -146,11 +136,14 @@ ndk::ScopedAStatus AlsaMixer::setVolumes(std::vector<float> volumes) {
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
        return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
    }
    }
    const int numValues = it->second->getNumValues();
    const int numValues = it->second->getNumValues();
    if (numValues < 0) {
        LOG(FATAL) << __func__ << ": negative number of values: " << numValues;
    }
    const int maxValue = it->second->getMaxValue();
    const int maxValue = it->second->getMaxValue();
    const int minValue = it->second->getMinValue();
    const int minValue = it->second->getMinValue();
    std::vector<int> values;
    std::vector<int> values;
    size_t i = 0;
    size_t i = 0;
    for (; i < numValues && i < values.size(); ++i) {
    for (; i < static_cast<size_t>(numValues) && i < values.size(); ++i) {
        values.emplace_back(volumeFloatToInteger(volumes[i], maxValue, minValue));
        values.emplace_back(volumeFloatToInteger(volumes[i], maxValue, minValue));
    }
    }
    if (int err = it->second->setArray(values.data(), values.size()); err != 0) {
    if (int err = it->second->setArray(values.data(), values.size()); err != 0) {