audio: Add optional 'DriverInterface::getPosition' method.
This is a method which can be optionally implemented
by a stream in case it can provide more exact position,
for example by taking into account data in intermediate
buffers.
Implemented this method for StreamAlsa and StreamRemoteSubmix.
Bug: 264712385
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I392933f8f6b22d784726925199db00dcb0313648
diff --git a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
index 5af0d91..6d5185b 100644
--- a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
+++ b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
@@ -179,6 +179,27 @@
: outWrite(buffer, frameCount, actualFrameCount));
}
+::android::status_t StreamRemoteSubmix::getPosition(StreamDescriptor::Position* position) {
+ sp<MonoPipeReader> source = mCurrentRoute->getSource();
+ if (source == nullptr) {
+ return ::android::NO_INIT;
+ }
+ const ssize_t framesInPipe = source->availableToRead();
+ if (framesInPipe < 0) {
+ return ::android::INVALID_OPERATION;
+ }
+ if (mIsInput) {
+ position->frames += framesInPipe;
+ } else {
+ if (position->frames > framesInPipe) {
+ position->frames -= framesInPipe;
+ } else {
+ position->frames = 0;
+ }
+ }
+ return ::android::OK;
+}
+
// Calculate the maximum size of the pipe buffer in frames for the specified stream.
size_t StreamRemoteSubmix::getStreamPipeSizeInFrames() {
auto pipeConfig = mCurrentRoute->mPipeConfig;