r_submix : Fix minor issues in AIDL implementation

1. Update refinePosition for output stream
2. Add missing exitStandby on transfer
3. Add check for availableToRead in read functionality

Bug: 286914845
Test: atest VtsHalAudioCoreTargetTest
Change-Id: Ibab914e5e09474c2b55a6c64cc004ebc1bb6cb47
This commit is contained in:
Shraddha Basantwani 2023-08-22 15:07:16 +00:00
parent f9e524c5b1
commit 95f9232923

View file

@ -179,7 +179,7 @@ void StreamRemoteSubmix::shutdown() {
LOG(ERROR) << __func__ << ": transfer without a pipe!";
return ::android::UNEXPECTED_NULL;
}
mCurrentRoute->exitStandby(mIsInput);
return (mIsInput ? inRead(buffer, frameCount, actualFrameCount)
: outWrite(buffer, frameCount, actualFrameCount));
}
@ -190,17 +190,14 @@ void StreamRemoteSubmix::shutdown() {
return ::android::NO_INIT;
}
const ssize_t framesInPipe = source->availableToRead();
if (framesInPipe < 0) {
return ::android::INVALID_OPERATION;
if (framesInPipe <= 0) {
// No need to update the position frames
return ::android::OK;
}
if (mIsInput) {
position->frames += framesInPipe;
} else {
if (position->frames > framesInPipe) {
} else if (position->frames >= framesInPipe) {
position->frames -= framesInPipe;
} else {
position->frames = 0;
}
}
return ::android::OK;
}
@ -280,7 +277,6 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
size_t* actualFrameCount) {
// about to read from audio source
sp<MonoPipeReader> source = mCurrentRoute->getSource();
if (source == nullptr || source->availableToRead() == 0) {
if (source == nullptr) {
int readErrorCount = mCurrentRoute->notifyReadError();
if (readErrorCount < kMaxReadErrorLogs) {
@ -290,9 +286,6 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
} else {
LOG(ERROR) << __func__ << ": Read errors " << readErrorCount;
}
} else {
LOG(INFO) << __func__ << ": no data to read yet, providing empty data";
}
const size_t delayUs = static_cast<size_t>(
std::roundf(frameCount * MICROS_PER_SECOND / mStreamConfig.sampleRate));
usleep(delayUs);
@ -306,9 +299,10 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
const size_t delayUs = static_cast<size_t>(std::roundf(kReadAttemptSleepUs));
char* buff = (char*)buffer;
size_t remainingFrames = frameCount;
int availableToRead = source->availableToRead();
while ((remainingFrames > 0) && (attempts < kMaxReadFailureAttempts)) {
LOG(VERBOSE) << __func__ << ": frames available to read " << source->availableToRead();
while ((remainingFrames > 0) && (availableToRead > 0) && (attempts < kMaxReadFailureAttempts)) {
LOG(VERBOSE) << __func__ << ": frames available to read " << availableToRead;
ssize_t framesRead = source->read(buff, remainingFrames);
@ -317,6 +311,7 @@ size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
if (framesRead > 0) {
remainingFrames -= framesRead;
buff += framesRead * mStreamConfig.frameSize;
availableToRead -= framesRead;
LOG(VERBOSE) << __func__ << ": (attempts = " << attempts << ") got " << framesRead
<< " frames, remaining=" << remainingFrames;
} else {