blob: 36492ec05fdcaf5671c3052c5ceea4e4ea957762 [file] [log] [blame]
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18#include <cstdint>
19#include <memory>
20#include <utility>
21#include <vector>
22
23#include <aidl/android/hardware/audio/effect/BnEffect.h>
24#include <fmq/AidlMessageQueue.h>
25
26namespace aidl::android::hardware::audio::effect {
27
28class EffectContext {
29 public:
30 typedef ::android::AidlMessageQueue<
31 IEffect::Status, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
32 StatusMQ;
33 typedef ::android::AidlMessageQueue<
34 int8_t, ::aidl::android::hardware::common::fmq::SynchronizedReadWrite>
35 DataMQ;
36
37 EffectContext(size_t statusDepth, size_t inBufferSize, size_t outBufferSize) {
38 mStatusMQ = std::make_shared<StatusMQ>(statusDepth, true /*configureEventFlagWord*/);
39 mInputMQ = std::make_shared<DataMQ>(inBufferSize);
40 mOutputMQ = std::make_shared<DataMQ>(outBufferSize);
41
42 if (!mStatusMQ->isValid() || !mInputMQ->isValid() || !mOutputMQ->isValid()) {
43 LOG(ERROR) << __func__ << " created invalid FMQ";
44 }
45 mWorkBuffer.reserve(std::max(inBufferSize, outBufferSize));
46 };
47
48 std::shared_ptr<StatusMQ> getStatusFmq() { return mStatusMQ; };
49 std::shared_ptr<DataMQ> getInputDataFmq() { return mInputMQ; };
50 std::shared_ptr<DataMQ> getOutputDataFmq() { return mOutputMQ; };
51
52 int8_t* getWorkBuffer() { return static_cast<int8_t*>(mWorkBuffer.data()); };
53 // TODO: update with actual available size
54 size_t availableToRead() { return mWorkBuffer.capacity(); };
55 size_t availableToWrite() { return mWorkBuffer.capacity(); };
56
57 private:
58 std::shared_ptr<StatusMQ> mStatusMQ;
59 std::shared_ptr<DataMQ> mInputMQ;
60 std::shared_ptr<DataMQ> mOutputMQ;
61 // TODO handle effect process input and output
62 // work buffer set by effect instances, the access and update are in same thread
63 std::vector<int8_t> mWorkBuffer;
64};
65} // namespace aidl::android::hardware::audio::effect