Skip to content

Commit 95a3c3f

Browse files
committed
Builds 3 versions with aosp build system
1 parent 3396fd0 commit 95a3c3f

4 files changed

Lines changed: 502 additions & 324 deletions

File tree

Android.bp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ cc_defaults {
55
// Main
66
"src/viper/ViPER.cpp",
77
"src/ViperContext.cpp",
8+
"src/ViPER4Aidl.cpp",
9+
"src/ViPER4Android.cpp",
10+
"src/EffectThread.cpp",
811
// Effects
912
"src/viper/effects/AnalogX.cpp",
1013
"src/viper/effects/ColorfulMusic.cpp",
@@ -60,29 +63,66 @@ cc_defaults {
6063
"-DVIPER_VERSION=20240314",
6164

6265
"-Wno-unused-parameter",
66+
"-DBACKEND_NDK",
6367
],
6468
cppflags: [
6569
"-Wno-unused-parameter",
6670
],
6771
shared_libs: [
72+
"libaudioaidlcommon",
73+
"libaudioutils",
74+
"libbase",
75+
"libbinder_ndk",
76+
"libcutils",
77+
"libfmq",
6878
"liblog",
79+
"libutils",
6980
],
7081
header_libs: [
7182
"libaudioeffects",
7283
"libaudioutils_headers",
84+
"libaudioaidl_headers",
85+
"libaudio_system_headers",
86+
"libsystem_headers",
7387
],
7488
relative_install_path: "soundfx",
7589
}
7690

7791
cc_library_shared {
78-
name: "libv4a_re",
92+
name: "libv4a_re-V1",
7993
defaults: [
80-
"aidlaudioeffectservice_defaults",
8194
"v4a_defaults",
8295
],
83-
srcs: [
84-
":effectCommonFile",
85-
"src/ViPER4Aidl.cpp",
86-
"src/ViPER4Android.cpp",
96+
shared_libs: [
97+
"android.hardware.audio.effect-V1-ndk",
98+
],
99+
cflags: [
100+
"-DVIPER_AIDL_VERSION=1",
101+
],
102+
}
103+
104+
cc_library_shared {
105+
name: "libv4a_re-V2",
106+
defaults: [
107+
"v4a_defaults",
108+
],
109+
shared_libs: [
110+
"android.hardware.audio.effect-V2-ndk",
111+
],
112+
cflags: [
113+
"-DVIPER_AIDL_VERSION=2",
114+
],
115+
}
116+
117+
cc_library_shared {
118+
name: "libv4a_re-V3",
119+
defaults: [
120+
"v4a_defaults",
121+
],
122+
shared_libs: [
123+
"android.hardware.audio.effect-V3-ndk",
124+
],
125+
cflags: [
126+
"-DVIPER_AIDL_VERSION=3",
87127
],
88128
}

src/EffectThread.cpp

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
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+
#include <cstddef>
18+
#include <memory>
19+
20+
#define LOG_TAG "AHAL_EffectThread"
21+
#include <android-base/logging.h>
22+
#include <pthread.h>
23+
#include <sys/resource.h>
24+
25+
#include "effect-impl/EffectThread.h"
26+
#include "effect-impl/EffectTypes.h"
27+
28+
namespace aidl::android::hardware::audio::effect {
29+
30+
EffectThread::~EffectThread() {
31+
destroyThread();
32+
}
33+
34+
RetCode EffectThread::createThread(const std::string& name, int priority) {
35+
if (mThread.joinable()) {
36+
LOG(WARNING) << mName << __func__ << " thread already created, no-op";
37+
return RetCode::SUCCESS;
38+
}
39+
40+
mName = name;
41+
mPriority = priority;
42+
{
43+
std::lock_guard lg(mThreadMutex);
44+
mStop = true;
45+
mExit = false;
46+
}
47+
48+
mThread = std::thread(&EffectThread::threadLoop, this);
49+
LOG(VERBOSE) << mName << __func__ << " priority " << mPriority << " done";
50+
return RetCode::SUCCESS;
51+
}
52+
53+
RetCode EffectThread::destroyThread() {
54+
{
55+
std::lock_guard lg(mThreadMutex);
56+
mStop = mExit = true;
57+
}
58+
59+
mCv.notify_one();
60+
if (mThread.joinable()) {
61+
mThread.join();
62+
}
63+
64+
LOG(VERBOSE) << mName << __func__;
65+
return RetCode::SUCCESS;
66+
}
67+
68+
RetCode EffectThread::startThread() {
69+
{
70+
std::lock_guard lg(mThreadMutex);
71+
if (mDraining) {
72+
mDraining = false;
73+
} else {
74+
mStop = false;
75+
}
76+
mCv.notify_one();
77+
}
78+
79+
LOG(VERBOSE) << mName << __func__;
80+
return RetCode::SUCCESS;
81+
}
82+
83+
RetCode EffectThread::stopThread() {
84+
{
85+
std::lock_guard lg(mThreadMutex);
86+
mStop = true;
87+
mCv.notify_one();
88+
}
89+
90+
LOG(VERBOSE) << mName << __func__;
91+
return RetCode::SUCCESS;
92+
}
93+
94+
RetCode EffectThread::startDraining() {
95+
std::lock_guard lg(mThreadMutex);
96+
mDraining = true;
97+
mCv.notify_one();
98+
99+
LOG(VERBOSE) << mName << __func__;
100+
return RetCode::SUCCESS;
101+
}
102+
103+
RetCode EffectThread::finishDraining() {
104+
std::lock_guard lg(mThreadMutex);
105+
mDraining = false;
106+
mStop = true;
107+
mCv.notify_one();
108+
109+
LOG(VERBOSE) << mName << __func__;
110+
return RetCode::SUCCESS;
111+
}
112+
113+
void EffectThread::threadLoop() {
114+
pthread_setname_np(pthread_self(), mName.substr(0, kMaxTaskNameLen - 1).c_str());
115+
setpriority(PRIO_PROCESS, 0, mPriority);
116+
while (true) {
117+
{
118+
std::unique_lock l(mThreadMutex);
119+
::android::base::ScopedLockAssertion lock_assertion(mThreadMutex);
120+
mCv.wait(l, [&]() REQUIRES(mThreadMutex) { return mExit || !mStop; });
121+
if (mExit) {
122+
LOG(VERBOSE) << mName << " threadLoop EXIT!";
123+
return;
124+
}
125+
}
126+
process();
127+
}
128+
}
129+
130+
} // namespace aidl::android::hardware::audio::effect

0 commit comments

Comments
 (0)