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
gugelfrei
Phil Burk 6 years ago
parent 9f81192d77
commit a53ffa67b3

@ -62,7 +62,7 @@ AudioStreamInternal::AudioStreamInternal(AAudioServiceInterface &serviceInterfa
, 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 @@ aaudio_result_t AudioStreamInternal::requestStop() {
mClockModel.stop(AudioClock::getNanoseconds());
setState(AAUDIO_STREAM_STATE_STOPPING);
mAtomicTimestamp.clear();
mAtomicInternalTimestamp.clear();
return mServiceInterface.stopStream(mServiceStreamHandle);
}
@ -412,8 +412,8 @@ aaudio_result_t AudioStreamInternal::getTimestamp(clockid_t clockId,
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::onTimestampService(AAudioServiceMessage *me
aaudio_result_t AudioStreamInternal::onTimestampHardware(AAudioServiceMessage *message) {
Timestamp timestamp(message->timestamp.position, message->timestamp.timestamp);
mAtomicTimestamp.write(timestamp);
mAtomicInternalTimestamp.write(timestamp);
return AAUDIO_OK;
}

@ -163,7 +163,7 @@ protected:
AAudioServiceInterface &mServiceInterface; // abstract interface to the service
SimpleDoubleBuffer<Timestamp> mAtomicTimestamp;
SimpleDoubleBuffer<Timestamp> mAtomicInternalTimestamp;
AtomicRequestor mNeedCatchUp; // Ask read() or write() to sync on first timestamp.

@ -71,7 +71,7 @@ aaudio_result_t AudioStreamInternalPlay::requestPause()
mClockModel.stop(AudioClock::getNanoseconds());
setState(AAUDIO_STREAM_STATE_PAUSING);
mAtomicTimestamp.clear();
mAtomicInternalTimestamp.clear();
return mServiceInterface.pauseStream(mServiceStreamHandle);
}

@ -121,7 +121,7 @@ protected:
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

@ -181,8 +181,8 @@ aaudio_result_t AAudioServiceEndpointShared::stopStream(sp<AAudioServiceStreamBa
// 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;

@ -43,7 +43,7 @@ using namespace aaudio; // TODO just import names needed
AAudioServiceStreamBase::AAudioServiceStreamBase(AAudioService &audioService)
: mUpMessageQueue(nullptr)
, mTimestampThread("AATime")
, mAtomicTimestamp()
, mAtomicStreamTimestamp()
, mAudioService(audioService) {
mMmapClient.clientUid = -1;
mMmapClient.clientPid = -1;
@ -182,7 +182,7 @@ aaudio_result_t AAudioServiceStreamBase::start() {
setSuspended(false);
// Start with fresh presentation timestamps.
mAtomicTimestamp.clear();
mAtomicStreamTimestamp.clear();
mClientHandle = AUDIO_PORT_HANDLE_NONE;
result = startDevice();
@ -291,16 +291,20 @@ aaudio_result_t AAudioServiceStreamBase::flush() {
}
// 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 @@ void AAudioServiceStreamBase::run() {
AudioClock::sleepUntilNanoTime(nextTime);
}
}
ALOGD("%s() %s exiting <<<<<<<<<<<<<< TIMESTAMPS", __func__, getTypeText());
ALOGD("%s() %s exiting after %d loops <<<<<<<<<<<<<< TIMESTAMPS",
__func__, getTypeText(), loopCount);
}
void AAudioServiceStreamBase::disconnect() {

@ -301,7 +301,7 @@ protected:
// 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;

@ -162,7 +162,7 @@ aaudio_result_t AAudioServiceStreamMMAP::getFreeRunningPosition(int64_t *positio
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 @@ aaudio_result_t AAudioServiceStreamMMAP::getHardwareTimestamp(int64_t *positionF
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;

@ -238,15 +238,15 @@ aaudio_result_t AAudioServiceStreamShared::getAudioDataDescription(
}
void AAudioServiceStreamShared::markTransferTime(Timestamp &timestamp) {
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;

Loading…
Cancel
Save