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

Commit 7668deda authored by Shunkai Yao's avatar Shunkai Yao Committed by Automerger Merge Worker
Browse files

Remove unused file EffectWorker.h am: 5b8638c6 am: 2ee2dade am: 07a9fa87 am: 81b6b5d6

parents c5ba9b1a 81b6b5d6
Loading
Loading
Loading
Loading
+0 −74
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */

#pragma once
#include <algorithm>
#include <memory>
#include <mutex>
#include <string>

#include "EffectContext.h"
#include "EffectThread.h"

namespace aidl::android::hardware::audio::effect {

std::string toString(RetCode& code);

class EffectWorker : public EffectThread {
  public:
    // set effect context for worker, suppose to only happen once here
    void setContext(std::shared_ptr<EffectContext> context) {
        std::call_once(mOnceFlag, [&]() { mContext = context; });
    };

    // handle FMQ and call effect implemented virtual function
    void process() override {
        RETURN_VALUE_IF(!mContext, void(), "nullContext");
        std::shared_ptr<EffectContext::StatusMQ> statusMQ = mContext->getStatusFmq();
        std::shared_ptr<EffectContext::DataMQ> inputMQ = mContext->getInputDataFmq();
        std::shared_ptr<EffectContext::DataMQ> outputMQ = mContext->getOutputDataFmq();

        // Only this worker will read from input data MQ and write to output data MQ.
        auto readSamples = inputMQ->availableToRead(), writeSamples = outputMQ->availableToWrite();
        if (readSamples && writeSamples) {
            auto processSamples = std::min(readSamples, writeSamples);
            LOG(VERBOSE) << __func__ << " available to read " << readSamples
                         << " available to write " << writeSamples << " process " << processSamples;

            auto buffer = mContext->getWorkBuffer();
            inputMQ->read(buffer, processSamples);

            IEffect::Status status = effectProcessImpl(buffer, buffer, processSamples);
            outputMQ->write(buffer, status.fmqProduced);
            statusMQ->writeBlocking(&status, 1);
            LOG(VERBOSE) << __func__ << " done processing, effect consumed " << status.fmqConsumed
                         << " produced " << status.fmqProduced;
        } else {
            // TODO: maybe add some sleep here to avoid busy waiting
        }
    }

    // must implement by each effect implementation
    // TODO: consider if this interface need adjustment to handle in-place processing
    virtual IEffect::Status effectProcessImpl(float* in, float* out, int samples) = 0;

  private:
    // make sure the context only set once.
    std::once_flag mOnceFlag;
    std::shared_ptr<EffectContext> mContext;
};

}  // namespace aidl::android::hardware::audio::effect