aaudio: rename timestamp variables
There were several different timestamp variables with slightly
different meaning but with the same name.
That made it hard to debug the code.
Test: atest CtsNativeMediaAAudioTestCases
Change-Id: Iebf438676925c698377abe02c81f3d559829318a
diff --git a/media/libaaudio/src/client/AudioStreamInternal.cpp b/media/libaaudio/src/client/AudioStreamInternal.cpp
index 9c682b7..3b03601 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternal.cpp
@@ -62,7 +62,7 @@
, mServiceStreamHandle(AAUDIO_HANDLE_INVALID)
, mInService(inService)
, mServiceInterface(serviceInterface)
- , mAtomicTimestamp()
+ , mAtomicInternalTimestamp()
, mWakeupDelayNanos(AAudioProperty_getWakeupDelayMicros() * AAUDIO_NANOS_PER_MICROSECOND)
, mMinimumSleepNanos(AAudioProperty_getMinimumSleepMicros() * AAUDIO_NANOS_PER_MICROSECOND)
{
@@ -363,7 +363,7 @@
mClockModel.stop(AudioClock::getNanoseconds());
setState(AAUDIO_STREAM_STATE_STOPPING);
- mAtomicTimestamp.clear();
+ mAtomicInternalTimestamp.clear();
return mServiceInterface.stopStream(mServiceStreamHandle);
}
@@ -412,8 +412,8 @@
int64_t *framePosition,
int64_t *timeNanoseconds) {
// Generated in server and passed to client. Return latest.
- if (mAtomicTimestamp.isValid()) {
- Timestamp timestamp = mAtomicTimestamp.read();
+ if (mAtomicInternalTimestamp.isValid()) {
+ Timestamp timestamp = mAtomicInternalTimestamp.read();
int64_t position = timestamp.getPosition() + mFramesOffsetFromService;
if (position >= 0) {
*framePosition = position;
@@ -460,7 +460,7 @@
aaudio_result_t AudioStreamInternal::onTimestampHardware(AAudioServiceMessage *message) {
Timestamp timestamp(message->timestamp.position, message->timestamp.timestamp);
- mAtomicTimestamp.write(timestamp);
+ mAtomicInternalTimestamp.write(timestamp);
return AAUDIO_OK;
}
diff --git a/media/libaaudio/src/client/AudioStreamInternal.h b/media/libaaudio/src/client/AudioStreamInternal.h
index 3bb9e1e..1c88f52 100644
--- a/media/libaaudio/src/client/AudioStreamInternal.h
+++ b/media/libaaudio/src/client/AudioStreamInternal.h
@@ -163,7 +163,7 @@
AAudioServiceInterface &mServiceInterface; // abstract interface to the service
- SimpleDoubleBuffer<Timestamp> mAtomicTimestamp;
+ SimpleDoubleBuffer<Timestamp> mAtomicInternalTimestamp;
AtomicRequestor mNeedCatchUp; // Ask read() or write() to sync on first timestamp.
diff --git a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
index 0884fca..6af8e7d 100644
--- a/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
+++ b/media/libaaudio/src/client/AudioStreamInternalPlay.cpp
@@ -71,7 +71,7 @@
mClockModel.stop(AudioClock::getNanoseconds());
setState(AAUDIO_STREAM_STATE_PAUSING);
- mAtomicTimestamp.clear();
+ mAtomicInternalTimestamp.clear();
return mServiceInterface.pauseStream(mServiceStreamHandle);
}
diff --git a/services/oboeservice/AAudioServiceEndpoint.h b/services/oboeservice/AAudioServiceEndpoint.h
index 43b0a37..3616fa2 100644
--- a/services/oboeservice/AAudioServiceEndpoint.h
+++ b/services/oboeservice/AAudioServiceEndpoint.h
@@ -121,7 +121,7 @@
mutable std::mutex mLockStreams;
std::vector<android::sp<AAudioServiceStreamBase>> mRegisteredStreams;
- SimpleDoubleBuffer<Timestamp> mAtomicTimestamp;
+ SimpleDoubleBuffer<Timestamp> mAtomicEndpointTimestamp;
android::AudioClient mMmapClient; // set in open, used in open and startStream
diff --git a/services/oboeservice/AAudioServiceEndpointShared.cpp b/services/oboeservice/AAudioServiceEndpointShared.cpp
index 2f1ec7e..0a415fd 100644
--- a/services/oboeservice/AAudioServiceEndpointShared.cpp
+++ b/services/oboeservice/AAudioServiceEndpointShared.cpp
@@ -181,8 +181,8 @@
// Get timestamp that was written by the real-time service thread, eg. mixer.
aaudio_result_t AAudioServiceEndpointShared::getFreeRunningPosition(int64_t *positionFrames,
int64_t *timeNanos) {
- if (mAtomicTimestamp.isValid()) {
- Timestamp timestamp = mAtomicTimestamp.read();
+ if (mAtomicEndpointTimestamp.isValid()) {
+ Timestamp timestamp = mAtomicEndpointTimestamp.read();
*positionFrames = timestamp.getPosition();
*timeNanos = timestamp.getNanoseconds();
return AAUDIO_OK;
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index defbb7b..b16b5dc 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -43,7 +43,7 @@
AAudioServiceStreamBase::AAudioServiceStreamBase(AAudioService &audioService)
: mUpMessageQueue(nullptr)
, mTimestampThread("AATime")
- , mAtomicTimestamp()
+ , mAtomicStreamTimestamp()
, mAudioService(audioService) {
mMmapClient.clientUid = -1;
mMmapClient.clientPid = -1;
@@ -182,7 +182,7 @@
setSuspended(false);
// Start with fresh presentation timestamps.
- mAtomicTimestamp.clear();
+ mAtomicStreamTimestamp.clear();
mClientHandle = AUDIO_PORT_HANDLE_NONE;
result = startDevice();
@@ -291,16 +291,20 @@
}
// implement Runnable, periodically send timestamps to client
+__attribute__((no_sanitize("integer")))
void AAudioServiceStreamBase::run() {
ALOGD("%s() %s entering >>>>>>>>>>>>>> TIMESTAMPS", __func__, getTypeText());
TimestampScheduler timestampScheduler;
timestampScheduler.setBurstPeriod(mFramesPerBurst, getSampleRate());
timestampScheduler.start(AudioClock::getNanoseconds());
int64_t nextTime = timestampScheduler.nextAbsoluteTime();
+ int32_t loopCount = 0;
while(mThreadEnabled.load()) {
+ loopCount++;
if (AudioClock::getNanoseconds() >= nextTime) {
aaudio_result_t result = sendCurrentTimestamp();
if (result != AAUDIO_OK) {
+ ALOGE("%s() timestamp thread got result = %d", __func__, result);
break;
}
nextTime = timestampScheduler.nextAbsoluteTime();
@@ -310,7 +314,8 @@
AudioClock::sleepUntilNanoTime(nextTime);
}
}
- ALOGD("%s() %s exiting <<<<<<<<<<<<<< TIMESTAMPS", __func__, getTypeText());
+ ALOGD("%s() %s exiting after %d loops <<<<<<<<<<<<<< TIMESTAMPS",
+ __func__, getTypeText(), loopCount);
}
void AAudioServiceStreamBase::disconnect() {
diff --git a/services/oboeservice/AAudioServiceStreamBase.h b/services/oboeservice/AAudioServiceStreamBase.h
index 7904b25..ffc768b 100644
--- a/services/oboeservice/AAudioServiceStreamBase.h
+++ b/services/oboeservice/AAudioServiceStreamBase.h
@@ -301,7 +301,7 @@
// TODO rename mClientHandle to mPortHandle to be more consistent with AudioFlinger.
audio_port_handle_t mClientHandle = AUDIO_PORT_HANDLE_NONE;
- SimpleDoubleBuffer<Timestamp> mAtomicTimestamp;
+ SimpleDoubleBuffer<Timestamp> mAtomicStreamTimestamp;
android::AAudioService &mAudioService;
diff --git a/services/oboeservice/AAudioServiceStreamMMAP.cpp b/services/oboeservice/AAudioServiceStreamMMAP.cpp
index 9377945..837b080 100644
--- a/services/oboeservice/AAudioServiceStreamMMAP.cpp
+++ b/services/oboeservice/AAudioServiceStreamMMAP.cpp
@@ -162,7 +162,7 @@
aaudio_result_t result = serviceEndpointMMAP->getFreeRunningPosition(positionFrames, timeNanos);
if (result == AAUDIO_OK) {
Timestamp timestamp(*positionFrames, *timeNanos);
- mAtomicTimestamp.write(timestamp);
+ mAtomicStreamTimestamp.write(timestamp);
*positionFrames = timestamp.getPosition();
*timeNanos = timestamp.getNanoseconds();
} else if (result != AAUDIO_ERROR_UNAVAILABLE) {
@@ -184,8 +184,8 @@
static_cast<AAudioServiceEndpointMMAP *>(endpoint.get());
// TODO Get presentation timestamp from the HAL
- if (mAtomicTimestamp.isValid()) {
- Timestamp timestamp = mAtomicTimestamp.read();
+ if (mAtomicStreamTimestamp.isValid()) {
+ Timestamp timestamp = mAtomicStreamTimestamp.read();
*positionFrames = timestamp.getPosition();
*timeNanos = timestamp.getNanoseconds() + serviceEndpointMMAP->getHardwareTimeOffsetNanos();
return AAUDIO_OK;
diff --git a/services/oboeservice/AAudioServiceStreamShared.cpp b/services/oboeservice/AAudioServiceStreamShared.cpp
index d5450fe..14742dd 100644
--- a/services/oboeservice/AAudioServiceStreamShared.cpp
+++ b/services/oboeservice/AAudioServiceStreamShared.cpp
@@ -238,15 +238,15 @@
}
void AAudioServiceStreamShared::markTransferTime(Timestamp ×tamp) {
- mAtomicTimestamp.write(timestamp);
+ mAtomicStreamTimestamp.write(timestamp);
}
// Get timestamp that was written by mixer or distributor.
aaudio_result_t AAudioServiceStreamShared::getFreeRunningPosition(int64_t *positionFrames,
int64_t *timeNanos) {
// TODO Get presentation timestamp from the HAL
- if (mAtomicTimestamp.isValid()) {
- Timestamp timestamp = mAtomicTimestamp.read();
+ if (mAtomicStreamTimestamp.isValid()) {
+ Timestamp timestamp = mAtomicStreamTimestamp.read();
*positionFrames = timestamp.getPosition();
*timeNanos = timestamp.getNanoseconds();
return AAUDIO_OK;