Skip to content

Commit 999a9e1

Browse files
authored
OboeTester: Cold Start Latency should wait for valid timestamps (#2276)
1 parent 15281c9 commit 999a9e1

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

apps/OboeTester/app/src/main/cpp/TestColdStartLatency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ int32_t TestColdStartLatency::getColdStartTimeMicros() {
9696
return coldStartLatencyNanos / NANOS_PER_MICROSECOND;
9797
}
9898

99+
void TestColdStartLatency::waitForValidTimestamp() {
100+
while (!mStream->getTimestamp(CLOCK_MONOTONIC)) {
101+
usleep(kPollPeriodMillis * 1000);
102+
}
103+
}
104+
99105
// Callback that sleeps then touches the audio buffer.
100106
DataCallbackResult TestColdStartLatency::MyDataCallback::onAudioReady(
101107
AudioStream *audioStream,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class TestColdStartLatency {
3030
int32_t start();
3131
int32_t close();
3232

33+
void waitForValidTimestamp();
34+
3335
int32_t getColdStartTimeMicros();
3436

3537
int32_t getOpenTimeMicros() {
@@ -71,6 +73,7 @@ class TestColdStartLatency {
7173
std::shared_ptr<MyDataCallback> mDataCallback;
7274

7375
static constexpr int kChannelCount = 1;
76+
static constexpr int kPollPeriodMillis = 1;
7477
};
7578

7679
#endif //OBOETESTER_TEST_COLD_START_LATENCY_H

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,12 @@ Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getColdStartTimeMicros
10821082
return sColdStartLatency.getColdStartTimeMicros();
10831083
}
10841084

1085+
JNIEXPORT void JNICALL
1086+
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_waitForValidTimestamp(
1087+
JNIEnv *env, jobject instance) {
1088+
sColdStartLatency.waitForValidTimestamp();
1089+
}
1090+
10851091
JNIEXPORT jint JNICALL
10861092
Java_com_mobileer_oboetester_TestColdStartLatencyActivity_getAudioDeviceId(
10871093
JNIEnv *env, jobject instance) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void run() {
140140
startStream();
141141
log("requestStart() Latency: " + getStartTimeMicros() / 1000 + " msec");
142142
sleep(startSleepTimeMillis);
143+
waitForValidTimestamp();
143144
log("Cold Start Latency: " + getColdStartTimeMicros() / 1000 + " msec");
144145
closeStream();
145146
} catch (InterruptedException e) {
@@ -181,6 +182,7 @@ private native int openStream(boolean useInput, boolean useLowLatency, boolean u
181182
boolean useExclusive);
182183
private native int startStream();
183184
private native int closeStream();
185+
private native void waitForValidTimestamp();
184186
private native int getOpenTimeMicros();
185187
private native int getStartTimeMicros();
186188
private native int getColdStartTimeMicros();

0 commit comments

Comments
 (0)