Skip to content

Commit f609b66

Browse files
committed
TimedAudioTrack: Fix continuity threshold handling.
DO NOT MERGE this change must be hand-merged into master due to directory restructuring. Fix issues with continuity threshold handling; notably + If the steady-state continuity threshold is exceeded, be sure to clear the on-time flag. Failure to do this will result in the system picking a new mix point which simply satisfies the steady-state continuity threshold instead of the startup threshold. Since we are putting a discontinuity in presentation anyway, we really want to pick a perfect point, not just an OK point. + Tighten the steady-state continuity threshold. It was currently set to 100mSec which is enormous. 4mSec (the new setting) is much more appropriate. On systems with a VCXO (like tungsten) this should never be wrong by more than a sample. If TimedAudioTracks are ever to be used on VCXO-less systems, this threshold should probably be a a parameter configurable by applications on a track by track basis so they can make the tradeoff between allowed error and frequency of disruptive corrections. + Reset the on-time flag if the mixer provides no PTS during a mix operation. This makes for a convenient way for the HAL to reset timed tracks when it makes changes for delay compensation across multiple outputs. Change-Id: I2cb23de5a3d1f75618abc1c8ab903db883837aa8 Signed-off-by: John Grossman <johngro@google.com>
1 parent aa0c94f commit f609b66

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4053,6 +4053,7 @@ status_t AudioFlinger::PlaybackThread::TimedTrack::getNextBuffer(
40534053
if (pts == AudioBufferProvider::kInvalidPTS) {
40544054
buffer->raw = 0;
40554055
buffer->frameCount = 0;
4056+
mTimedAudioOutputOnTime = false;
40564057
return INVALID_OPERATION;
40574058
}
40584059

@@ -4151,21 +4152,28 @@ status_t AudioFlinger::PlaybackThread::TimedTrack::getNextBuffer(
41514152
// the current output position is within this threshold, then we will
41524153
// concatenate the next input samples to the previous output
41534154
const int64_t kSampleContinuityThreshold =
4154-
(static_cast<int64_t>(sampleRate()) << 32) / 10;
4155+
(static_cast<int64_t>(sampleRate()) << 32) / 250;
41554156

41564157
// if this is the first buffer of audio that we're emitting from this track
41574158
// then it should be almost exactly on time.
41584159
const int64_t kSampleStartupThreshold = 1LL << 32;
41594160

41604161
if ((mTimedAudioOutputOnTime && llabs(sampleDelta) <= kSampleContinuityThreshold) ||
4161-
(!mTimedAudioOutputOnTime && llabs(sampleDelta) <= kSampleStartupThreshold)) {
4162+
(!mTimedAudioOutputOnTime && llabs(sampleDelta) <= kSampleStartupThreshold)) {
41624163
// the next input is close enough to being on time, so concatenate it
41634164
// with the last output
41644165
timedYieldSamples_l(buffer);
41654166

4166-
LOGVV("*** on time: head.pos=%d frameCount=%u", head.position(), buffer->frameCount);
4167+
LOGVV("*** on time: head.pos=%d frameCount=%u",
4168+
head.position(), buffer->frameCount);
41674169
return NO_ERROR;
4168-
} else if (sampleDelta > 0) {
4170+
}
4171+
4172+
// Looks like our output is not on time. Reset our on timed status.
4173+
// Next time we mix samples from our input queue, then should be within
4174+
// the StartupThreshold.
4175+
mTimedAudioOutputOnTime = false;
4176+
if (sampleDelta > 0) {
41694177
// the gap between the current output position and the proper start of
41704178
// the next input sample is too big, so fill it with silence
41714179
uint32_t framesUntilNextInput = (sampleDelta + 0x80000000) >> 32;

0 commit comments

Comments
 (0)