Skip to content

Commit 4f48137

Browse files
authored
Add audio performance to AdpfWrapper (#2330)
* WIP: Test potential APERF_HINT_HIGH_PERFORMANCE_AUDIO * rename to audio performance * addd option to remove ADPF set duration * address comments * add tracing to Oboe callbacks * address comments
1 parent 38e8d0c commit 4f48137

20 files changed

Lines changed: 400 additions & 26 deletions

apps/OboeTester/app/src/main/cpp/NativeAudioContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ class ActivityContext {
341341
oboeCallbackProxy->setNotifyWorkloadIncreaseEnabled(enabled);
342342
}
343343

344+
void setReportActualDurationDisabled(bool disabled) {
345+
std::shared_ptr<oboe::AudioStream> stream = getOutputStream();
346+
if (stream) {
347+
stream->setReportActualDurationDisabled(disabled);
348+
}
349+
}
350+
344351
int32_t setBufferSizeInFrames(int streamIndex, int threshold);
345352

346353
virtual void setupMemoryBuffer([[maybe_unused]] std::unique_ptr<uint8_t[]>& buffer,

apps/OboeTester/app/src/main/cpp/cpu/AudioWorkloadTest.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ class AudioWorkloadTest : oboe::AudioStreamDataCallback {
9898
return static_cast<int32_t>(result);
9999
}
100100

101+
// Apply the current setting for reporting actual duration once the stream exists.
102+
mStream->setReportActualDurationDisabled(mReportActualDurationDisabled);
103+
101104
mFramesPerBurst = mStream->getFramesPerBurst();
102105
mSampleRate = mStream->getSampleRate();
103106
mPreviousXRunCount = 0;
@@ -149,7 +152,8 @@ class AudioWorkloadTest : oboe::AudioStreamDataCallback {
149152
*/
150153
int32_t start(int32_t targetDurationMillis, int32_t numBursts, int32_t numVoices,
151154
int32_t alternateNumVoices, int32_t alternatingPeriodMs, bool adpfEnabled,
152-
bool adpfWorkloadIncreaseEnabled, bool hearWorkload) {
155+
bool adpfWorkloadIncreaseEnabled, bool hearWorkload, bool highPerformanceAudio,
156+
bool reportActualDurationDisabled) {
153157
std::lock_guard<std::mutex> lock(mStreamLock);
154158
if (!mStream) {
155159
LOGE("Error: Stream not open.");
@@ -175,7 +179,13 @@ class AudioWorkloadTest : oboe::AudioStreamDataCallback {
175179
mRunning = true;
176180
mHearWorkload = hearWorkload;
177181
mAdpfWorkloadIncreaseEnabled = adpfWorkloadIncreaseEnabled;
182+
mReportActualDurationDisabled = reportActualDurationDisabled;
178183
mStream->setPerformanceHintEnabled(adpfEnabled);
184+
mStream->setReportActualDurationDisabled(mReportActualDurationDisabled);
185+
// Apply performance hint configuration if requested via runner flags.
186+
oboe::PerformanceHintConfig cfg;
187+
cfg.highPerformanceAudio = highPerformanceAudio;
188+
mStream->setPerformanceHintConfig(cfg);
179189
mStream->setBufferSizeInFrames(mNumBursts * mFramesPerBurst);
180190
mBufferSizeInFrames = mStream->getBufferSizeInFrames();
181191
oboe::Result result = mStream->start();
@@ -422,6 +432,7 @@ class AudioWorkloadTest : oboe::AudioStreamDataCallback {
422432
std::atomic<int64_t> mStartTimeMs{0};
423433
std::atomic<bool> mHearWorkload{false};
424434
std::atomic<bool> mAdpfWorkloadIncreaseEnabled{false};
435+
std::atomic<bool> mReportActualDurationDisabled{false};
425436

426437
// Lock to protect mCallbackStatistics
427438
std::mutex mStatisticsLock;

apps/OboeTester/app/src/main/cpp/cpu/AudioWorkloadTestRunner.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ class AudioWorkloadTestRunner {
7474
int32_t alternatingPeriodMs,
7575
bool adpfEnabled,
7676
bool adpfWorkloadIncreaseEnabled,
77-
bool hearWorkload) {
77+
bool hearWorkload,
78+
bool highPerformanceAudio,
79+
bool reportActualDurationDisabled) {
7880
if (mIsRunning) {
7981
LOGE("Error: Test already running.");
8082
return -1;
@@ -90,15 +92,17 @@ class AudioWorkloadTestRunner {
9092
mIsDone = false;
9193
mResult = 0;
9294

93-
int32_t result = mAudioWorkloadTest.start(
94-
targetDurationMs,
95-
numBursts,
96-
numVoices,
97-
alternateNumVoices,
98-
alternatingPeriodMs,
99-
adpfEnabled,
100-
adpfWorkloadIncreaseEnabled,
101-
hearWorkload);
95+
int32_t result = mAudioWorkloadTest.start(
96+
targetDurationMs,
97+
numBursts,
98+
numVoices,
99+
alternateNumVoices,
100+
alternatingPeriodMs,
101+
adpfEnabled,
102+
adpfWorkloadIncreaseEnabled,
103+
hearWorkload,
104+
highPerformanceAudio,
105+
reportActualDurationDisabled);
102106

103107
if (result != static_cast<int32_t>(oboe::Result::OK)) {
104108
mResult = -1;

apps/OboeTester/app/src/main/cpp/jni-bridge.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ Java_com_mobileer_oboetester_NativeEngine_getCpuCount(JNIEnv *env, jclass type)
151151
return sysconf(_SC_NPROCESSORS_CONF);
152152
}
153153

154+
JNIEXPORT jboolean JNICALL
155+
Java_com_mobileer_oboetester_NativeEngine_isHighPerformanceAudioSupported(JNIEnv *env, jclass type) {
156+
return oboe::AdpfWrapper::isHighPerformanceAudioSupported();
157+
}
158+
154159
JNIEXPORT void JNICALL
155160
Java_com_mobileer_oboetester_NativeEngine_setCpuAffinityMask(JNIEnv *env,
156161
jclass type,
@@ -320,6 +325,13 @@ Java_com_mobileer_oboetester_TestAudioActivity_setUseAlternativeAdpf(JNIEnv *env
320325
oboe::AdpfWrapper::setUseAlternative(enabled);
321326
}
322327

328+
JNIEXPORT void JNICALL
329+
Java_com_mobileer_oboetester_NativeEngine_setReportActualDurationDisabled(JNIEnv *env,
330+
jclass type,
331+
jboolean disabled) {
332+
engine.getCurrentActivity()->setReportActualDurationDisabled(disabled);
333+
}
334+
323335
JNIEXPORT jint JNICALL
324336
Java_com_mobileer_oboetester_OboeAudioStream_setBufferSizeInFrames(
325337
JNIEnv *env, jobject, jint streamIndex, jint threshold) {
@@ -352,6 +364,17 @@ Java_com_mobileer_oboetester_OboeAudioStream_setPerformanceHintEnabled(
352364
}
353365
}
354366

367+
JNIEXPORT void JNICALL
368+
Java_com_mobileer_oboetester_OboeAudioStream_setPerformanceHintConfig(
369+
JNIEnv *env, jobject, jint streamIndex, jboolean highPerformance) {
370+
std::shared_ptr<oboe::AudioStream> oboeStream = engine.getCurrentActivity()->getStream(streamIndex);
371+
if (oboeStream != nullptr) {
372+
oboe::PerformanceHintConfig cfg;
373+
cfg.highPerformanceAudio = highPerformance;
374+
oboeStream->setPerformanceHintConfig(cfg);
375+
}
376+
}
377+
355378
JNIEXPORT jint JNICALL
356379
Java_com_mobileer_oboetester_OboeAudioStream_getBufferCapacityInFrames(
357380
JNIEnv *env, jobject, jint streamIndex) {
@@ -1244,10 +1267,12 @@ JNIEXPORT jint JNICALL
12441267
Java_com_mobileer_oboetester_AudioWorkloadTestActivity_start(JNIEnv *env, jobject thiz,
12451268
jint targetDurationMs, jint numBursts, jint numVoices, jint numAlternateVoices,
12461269
jint alternatingPeriodMs, jboolean adpfEnabled, jboolean adpfWorkloadIncreaseEnabled,
1247-
jboolean hearWorkload) {
1270+
jboolean hearWorkload, jboolean highPerformanceAudio,
1271+
jboolean reportActualDurationDisabled) {
12481272
return sAudioWorkload.start(targetDurationMs, numBursts, numVoices,
12491273
numAlternateVoices, alternatingPeriodMs, adpfEnabled,
1250-
adpfWorkloadIncreaseEnabled, hearWorkload);
1274+
adpfWorkloadIncreaseEnabled, hearWorkload, highPerformanceAudio,
1275+
reportActualDurationDisabled);
12511276
}
12521277

12531278
JNIEXPORT jint JNICALL
@@ -1475,10 +1500,14 @@ Java_com_mobileer_oboetester_AudioWorkloadTestRunnerActivity_start(JNIEnv *env,
14751500
jint alternatingPeriodMillis,
14761501
jboolean adpfEnabled,
14771502
jboolean adpfWorkloadIncreaseEnabled,
1478-
jboolean hearWorkload) {
1479-
return sAudioWorkloadRunner.start(targetDurationMs, numBursts, numVoices,
1503+
jboolean hearWorkload,
1504+
jboolean highPerformanceAudio,
1505+
jboolean reportActualDurationDisabled) {
1506+
int32_t result = sAudioWorkloadRunner.start(targetDurationMs, numBursts, numVoices,
14801507
alternateNumVoices, alternatingPeriodMillis, adpfEnabled,
1481-
adpfWorkloadIncreaseEnabled, hearWorkload);
1508+
adpfWorkloadIncreaseEnabled, hearWorkload, highPerformanceAudio,
1509+
reportActualDurationDisabled);
1510+
return result;
14821511
}
14831512

14841513
JNIEXPORT jboolean JNICALL

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/AudioStreamBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ public void setPerformanceHintEnabled(boolean checked) {
8888
}
8989
public void setHearWorkload(boolean checked) {
9090
}
91+
/**
92+
* Configure performance hint options for this stream. Default implementation is no-op.
93+
* @param highPerformance true to request high performance audio mode when creating the session.
94+
*/
95+
public void setPerformanceHintConfig(boolean highPerformance) {
96+
}
9197
public int notifyWorkloadIncrease(boolean cpu, boolean gpu) {
9298
return -1;
9399
}

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/AudioWorkloadTestActivity.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class AudioWorkloadTestActivity extends BaseOboeTesterActivity {
4747
private CheckBox mEnableAdpfBox;
4848
private CheckBox mEnableAdpfWorkloadIncreaseBox;
4949
private CheckBox mHearWorkloadBox;
50+
private CheckBox mHighPerformanceAudioBox;
51+
private CheckBox mDisableAdpfDurationBox;
5052

5153
private int mCpuCount;
5254
private LinearLayout mAffinityLayout;
@@ -149,6 +151,9 @@ protected void onCreate(Bundle savedInstanceState) {
149151
mEnableAdpfBox = (CheckBox) findViewById(R.id.enable_adpf);
150152
mEnableAdpfWorkloadIncreaseBox = (CheckBox) findViewById(R.id.enable_adpf_workload_increase);
151153
mHearWorkloadBox = (CheckBox) findViewById(R.id.hear_workload);
154+
mHighPerformanceAudioBox = (CheckBox) findViewById(R.id.high_performance_audio);
155+
156+
mDisableAdpfDurationBox = (CheckBox) findViewById(R.id.disable_adpf_duration);
152157

153158
mOpenButton = (Button) findViewById(R.id.button_open);
154159
mStartButton = (Button) findViewById(R.id.button_start);
@@ -221,10 +226,13 @@ public void openAudio(View view) {
221226
}
222227

223228
public void startTest(View view) {
229+
boolean reportActualDurationDisabled = mDisableAdpfDurationBox.isChecked();
230+
224231
int result = start(mTargetDurationMsSlider.getValue(), mNumBurstsSlider.getValue(),
225-
mNumVoicesSlider.getValue(), mAlternateNumVoicesSlider.getValue(),
226-
mAlternatingPeriodMsSlider.getValue(), mEnableAdpfBox.isChecked(),
227-
mEnableAdpfWorkloadIncreaseBox.isChecked(), mHearWorkloadBox.isChecked());
232+
mNumVoicesSlider.getValue(), mAlternateNumVoicesSlider.getValue(),
233+
mAlternatingPeriodMsSlider.getValue(), mEnableAdpfBox.isChecked(),
234+
mEnableAdpfWorkloadIncreaseBox.isChecked(), mHearWorkloadBox.isChecked(),
235+
mHighPerformanceAudioBox.isChecked(), reportActualDurationDisabled);
228236
if (result != OPERATION_SUCCESS) {
229237
showErrorToast("start failed! Error:" + result);
230238
return;
@@ -318,6 +326,8 @@ public void enableParamsUI(boolean enabled) {
318326
mEnableAdpfBox.setEnabled(enabled);
319327
mEnableAdpfWorkloadIncreaseBox.setEnabled(enabled);
320328
mHearWorkloadBox.setEnabled(enabled);
329+
mHighPerformanceAudioBox.setEnabled(enabled);
330+
mDisableAdpfDurationBox.setEnabled(enabled);
321331
}
322332

323333
public void updateStreamInfoView() {
@@ -331,7 +341,8 @@ public void updateStreamInfoView() {
331341
private native int getBufferSizeInFrames();
332342
private native int start(int targetDurationMs, int numBursts, int numVoices,
333343
int numAlternateVoices, int alternatingPeriodMs, boolean adpfEnabled,
334-
boolean adpfWorkloadIncreaseEnabled, boolean hearWorkload);
344+
boolean adpfWorkloadIncreaseEnabled, boolean hearWorkload,
345+
boolean highPerformanceAudio, boolean reportActualDurationDisabled);
335346
private native int getCpuCount();
336347
private native int setCpuAffinityForCallback(int mask);
337348
private native int getXRunCount();

apps/OboeTester/app/src/main/java/com/mobileer/oboetester/AudioWorkloadTestRunnerActivity.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class AudioWorkloadTestRunnerActivity extends BaseOboeTesterActivity {
3838
private CheckBox mEnableAdpfBox;
3939
private CheckBox mEnableAdpfWorkloadIncreaseBox;
4040
private CheckBox mHearWorkloadBox;
41+
private CheckBox mHighPerformanceAudioBox;
42+
private CheckBox mDisableAdpfDurationBox;
4143

4244
private Button mStartButton;
4345
private Button mStopButton;
@@ -79,6 +81,8 @@ protected void onCreate(Bundle savedInstanceState) {
7981
mEnableAdpfBox = findViewById(R.id.enable_adpf);
8082
mEnableAdpfWorkloadIncreaseBox = findViewById(R.id.enable_adpf_workload_increase);
8183
mHearWorkloadBox = findViewById(R.id.hear_workload);
84+
mHighPerformanceAudioBox = findViewById(R.id.high_performance_audio);
85+
mDisableAdpfDurationBox = findViewById(R.id.disable_adpf_duration);
8286

8387
mStartButton = findViewById(R.id.button_start_test);
8488
mStopButton = findViewById(R.id.button_stop_test);
@@ -107,9 +111,12 @@ public void startTest(View view) {
107111
boolean adpfEnabled = mEnableAdpfBox.isChecked();
108112
boolean adpfWorkloadIncreaseEnabled = mEnableAdpfWorkloadIncreaseBox.isChecked();
109113
boolean hearWorkload = mHearWorkloadBox.isChecked();
114+
boolean highPerformanceAudio = mHighPerformanceAudioBox.isChecked();
115+
boolean reportActualDurationDisabled = mDisableAdpfDurationBox.isChecked();
110116

111117
int result = start(targetDurationMs, numBursts, numVoices, alternateNumVoices,
112-
alternatingPeriodMs, adpfEnabled, adpfWorkloadIncreaseEnabled, hearWorkload);
118+
alternatingPeriodMs, adpfEnabled, adpfWorkloadIncreaseEnabled, hearWorkload,
119+
highPerformanceAudio, reportActualDurationDisabled);
113120
if (result != OPERATION_SUCCESS) {
114121
showErrorToast("start failed! Error:" + result);
115122
return;
@@ -144,6 +151,8 @@ public void enableParamsUI(boolean enabled) {
144151
mEnableAdpfBox.setEnabled(enabled);
145152
mEnableAdpfWorkloadIncreaseBox.setEnabled(enabled);
146153
mHearWorkloadBox.setEnabled(enabled);
154+
mHighPerformanceAudioBox.setEnabled(enabled);
155+
mDisableAdpfDurationBox.setEnabled(enabled);
147156
}
148157

149158
private void updateResultTextView() {
@@ -160,7 +169,9 @@ private void updateResultTextView() {
160169

161170
public native int start(int targetDurationMs, int numBursts, int numVoices,
162171
int alternateNumVoices, int alternatingPeriodMs, boolean adpfEnabled,
163-
boolean adpfWorkloadIncreaseEnabled, boolean hearWorkload);
172+
boolean adpfWorkloadIncreaseEnabled, boolean hearWorkload,
173+
boolean highPerformanceAudio,
174+
boolean reportActualDurationDisabled);
164175
public native boolean stopIfDone();
165176
public native String getStatus();
166177
public native int stop();

0 commit comments

Comments
 (0)