From 675cce24d6f117c730ad949eea76389c4a9922dd Mon Sep 17 00:00:00 2001 From: Shraddha Basantwani Date: Fri, 28 Jul 2023 16:53:43 +0000 Subject: [PATCH] Audio r_submix : Handle the usecase when no data is available to read. Bug: 290116295 Test: atest VtsHalAudioCoreTargetTest Change-Id: Ifd6706d593f890dd8ae148523a37177774c8ffd4 --- .../default/r_submix/StreamRemoteSubmix.cpp | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp index 9537ebc56d..ea86950e68 100644 --- a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp +++ b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp @@ -275,14 +275,18 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() { size_t* actualFrameCount) { // about to read from audio source sp source = mCurrentRoute->getSource(); - if (source == nullptr) { - int readErrorCount = mCurrentRoute->notifyReadError(); - if (readErrorCount < kMaxReadErrorLogs) { - LOG(ERROR) - << __func__ - << ": no audio pipe yet we're trying to read! (not all errors will be logged)"; + if (source == nullptr || source->availableToRead() == 0) { + if (source == nullptr) { + int readErrorCount = mCurrentRoute->notifyReadError(); + if (readErrorCount < kMaxReadErrorLogs) { + LOG(ERROR) << __func__ + << ": no audio pipe yet we're trying to read! (not all errors will be " + "logged)"; + } else { + LOG(ERROR) << __func__ << ": Read errors " << readErrorCount; + } } else { - LOG(ERROR) << __func__ << ": Read errors " << readErrorCount; + LOG(INFO) << __func__ << ": no data to read yet, providing empty data"; } const size_t delayUs = static_cast( std::roundf(frameCount * MICROS_PER_SECOND / mStreamConfig.sampleRate)); @@ -339,11 +343,9 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() { // recording (including this call): it's converted to usec and compared to how long we've been // recording for, which gives us how long we must wait to sync the projected recording time, and // the observed recording time. - static constexpr float kScaleFactor = .8f; - const size_t projectedVsObservedOffsetUs = - kScaleFactor * (static_cast(std::roundf((readCounterFrames * MICROS_PER_SECOND / - mStreamConfig.sampleRate) - - recordDurationUs.count()))); + const size_t projectedVsObservedOffsetUs = static_cast( + std::roundf((readCounterFrames * MICROS_PER_SECOND / mStreamConfig.sampleRate) - + recordDurationUs.count())); LOG(VERBOSE) << __func__ << ": record duration " << recordDurationUs.count() << " microseconds, will wait: " << projectedVsObservedOffsetUs << " microseconds";