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

Commit 76d38c1b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audio: Update FMQ error reporting handler

Switch to use the error handler mechanism of the FMQ.

Bug: 338974476
Test: m
Change-Id: I795f1ee173771cdd7af899c0339280576378ca8e
parent dc578038
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -47,6 +47,17 @@ using aidl::android::media::audio::common::MicrophoneInfo;

namespace aidl::android::hardware::audio::core {

namespace {

template <typename MQTypeError>
auto fmqErrorHandler(const char* mqName) {
    return [m = std::string(mqName)](MQTypeError fmqError, std::string&& errorMessage) {
        CHECK_EQ(fmqError, MQTypeError::NONE) << m << ": " << errorMessage;
    };
}

}  // namespace

void StreamContext::fillDescriptor(StreamDescriptor* desc) {
    if (mCommandMQ) {
        desc->command = mCommandMQ->dupeDesc();
@@ -332,11 +343,7 @@ StreamInWorkerLogic::Status StreamInWorkerLogic::cycle() {
bool StreamInWorkerLogic::read(size_t clientSize, StreamDescriptor::Reply* reply) {
    ATRACE_CALL();
    StreamContext::DataMQ* const dataMQ = mContext->getDataMQ();
    StreamContext::DataMQ::Error fmqError = StreamContext::DataMQ::Error::NONE;
    std::string fmqErrorMsg;
    const size_t byteCount = std::min(
            {clientSize, dataMQ->availableToWrite(&fmqError, &fmqErrorMsg), mDataBufferSize});
    CHECK(fmqError == StreamContext::DataMQ::Error::NONE) << fmqErrorMsg;
    const size_t byteCount = std::min({clientSize, dataMQ->availableToWrite(), mDataBufferSize});
    const bool isConnected = mIsConnected;
    const size_t frameSize = mContext->getFrameSize();
    size_t actualFrameCount = 0;
@@ -612,10 +619,7 @@ StreamOutWorkerLogic::Status StreamOutWorkerLogic::cycle() {
bool StreamOutWorkerLogic::write(size_t clientSize, StreamDescriptor::Reply* reply) {
    ATRACE_CALL();
    StreamContext::DataMQ* const dataMQ = mContext->getDataMQ();
    StreamContext::DataMQ::Error fmqError = StreamContext::DataMQ::Error::NONE;
    std::string fmqErrorMsg;
    const size_t readByteCount = dataMQ->availableToRead(&fmqError, &fmqErrorMsg);
    CHECK(fmqError == StreamContext::DataMQ::Error::NONE) << fmqErrorMsg;
    const size_t readByteCount = dataMQ->availableToRead();
    const size_t frameSize = mContext->getFrameSize();
    bool fatal = false;
    int32_t latency = mContext->getNominalLatencyMs();
@@ -719,6 +723,14 @@ ndk::ScopedAStatus StreamCommonImpl::initInstance(
            LOG(WARNING) << __func__ << ": invalid worker tid: " << workerTid;
        }
    }
    getContext().getCommandMQ()->setErrorHandler(
            fmqErrorHandler<StreamContext::CommandMQ::Error>("CommandMQ"));
    getContext().getReplyMQ()->setErrorHandler(
            fmqErrorHandler<StreamContext::ReplyMQ::Error>("ReplyMQ"));
    if (getContext().getDataMQ() != nullptr) {
        getContext().getDataMQ()->setErrorHandler(
                fmqErrorHandler<StreamContext::DataMQ::Error>("DataMQ"));
    }
    return ndk::ScopedAStatus::ok();
}