aaudio: fix timestamps and underruns
Start the client after we get valid timing data from the server.
That can take a while because of the long cold start times.
The client is synced with the current position of the service.
Now the client can start clean with no underruns.
Bug: 63918065
Test: test_timestamps.cpp
Change-Id: I5d01eb844e4b14cd5477d56ea1dd9e309abc1c52
diff --git a/services/oboeservice/AAudioServiceStreamShared.cpp b/services/oboeservice/AAudioServiceStreamShared.cpp
index 834f39f..348d407 100644
--- a/services/oboeservice/AAudioServiceStreamShared.cpp
+++ b/services/oboeservice/AAudioServiceStreamShared.cpp
@@ -237,9 +237,15 @@
aaudio_result_t AAudioServiceStreamShared::getHardwareTimestamp(int64_t *positionFrames,
int64_t *timeNanos) {
- aaudio_result_t result = mServiceEndpoint->getTimestamp(positionFrames, timeNanos);
+ int64_t position = 0;
+ aaudio_result_t result = mServiceEndpoint->getTimestamp(&position, timeNanos);
if (result == AAUDIO_OK) {
- *positionFrames -= mTimestampPositionOffset.load(); // Offset from shared MMAP stream
+ int64_t offset = mTimestampPositionOffset.load();
+ // TODO, do not go below starting value
+ position -= offset; // Offset from shared MMAP stream
+ ALOGV("getHardwareTimestamp() %8lld = %8lld - %8lld",
+ (long long) position, (long long) (position + offset), (long long) offset);
}
+ *positionFrames = position;
return result;
}