blob: e831cea4b33553af0c26a682d22d00915ee9a4d6 [file] [log] [blame]
Shunkai Yaoea24c1a2022-09-28 17:39:23 +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 <atomic>
19#include <string>
20#include <thread>
21
22#include <android-base/thread_annotations.h>
23#include <system/thread_defs.h>
24
25namespace aidl::android::hardware::audio::effect {
26
27enum class RetCode { SUCCESS, ERROR };
28
29std::string toString(RetCode& code);
30
31class EffectThread {
32 public:
33 // default priority is same as HIDL: ANDROID_PRIORITY_URGENT_AUDIO
34 EffectThread();
35 virtual ~EffectThread();
36
37 // called by effect implementation.
38 RetCode create(const std::string& name, const int priority = ANDROID_PRIORITY_URGENT_AUDIO);
39 RetCode destroy();
40 RetCode start();
41 RetCode stop();
42
43 // Will call process() in a loop if the thread is running.
44 void threadLoop();
45
46 // User of EffectThread must implement the effect processing logic in this method.
47 virtual void process() = 0;
48 const int MAX_TASK_COMM_LEN = 15;
49
50 private:
51 std::mutex mMutex;
52 std::condition_variable mCv;
53 bool mExit GUARDED_BY(mMutex) = false;
54 bool mStop GUARDED_BY(mMutex) = true;
55 std::thread mThread;
56 int mPriority;
57 std::string mName;
58};
59} // namespace aidl::android::hardware::audio::effect