From 2be5078e25cb26d952de365feb28f455add54b57 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Wed, 17 Jul 2024 11:12:50 -0700 Subject: [PATCH] audio: Prolong reading attempts from the remote submix pipe In order to use the time interval for reading from the remote submix pipe more efficiently, increase the deadline time to the buffer duration minus a small amount. This should minimize chances to have discontinuities in the remote submix input. Bug: 334363414 Test: atest --test-filter=".*RemoteSubmixTest#testRemoteSubmixRecordingContinuity" CtsMediaAudioTestCases Change-Id: I02968d09afd8ecdad4d61e635393842d7280e55f --- audio/aidl/default/r_submix/StreamRemoteSubmix.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp index ca3f91aefc..a266b54ae5 100644 --- a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp +++ b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp @@ -285,9 +285,12 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() { char* buff = (char*)buffer; size_t actuallyRead = 0; long remainingFrames = frameCount; - const int64_t deadlineTimeNs = - ::android::uptimeNanos() + - getDelayInUsForFrameCount(frameCount) * NANOS_PER_MICROSECOND / 2; + // Try to wait as long as possible for the audio duration, but leave some time for the call to + // 'transfer' to complete. 'kReadAttemptSleepUs' is a good constant for this purpose because it + // is by definition "strictly inferior" to the typical buffer duration. + const long durationUs = + std::max(0L, getDelayInUsForFrameCount(frameCount) - kReadAttemptSleepUs); + const int64_t deadlineTimeNs = ::android::uptimeNanos() + durationUs * NANOS_PER_MICROSECOND; while (remainingFrames > 0) { ssize_t framesRead = source->read(buff, remainingFrames); LOG(VERBOSE) << __func__ << ": frames read " << framesRead;