audio: Add DriverInterface::start method
This method is used to bring out the hardware from standby.
It replaces the ad hoc 'exitStandby' method in StreamUsb.
Streamlined StreamUsb code to avoid locking during transfers.
Updated StreamRemoteSubmix to use 'start'.
Added extra checks to StreamStub to ensure that 'init/shutdown'
and 'standby/start' methods are called as expected. This allows
removing extra checks from non-stub stream implementations.
Bug: 205884982
Test: atest VtsHalAudioCoreTargetTest
Change-Id: I3615a7ca99cb4f1e149dcbfbc912f2ed58fb033f
diff --git a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
index 9cc6fb8..5af0d91 100644
--- a/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
+++ b/audio/aidl/default/r_submix/StreamRemoteSubmix.cpp
@@ -55,7 +55,7 @@
mCurrentRoute = std::make_shared<SubmixRoute>();
if (::android::OK != mCurrentRoute->createPipe(mStreamConfig)) {
LOG(ERROR) << __func__ << ": create pipe failed";
- return mStatus;
+ return ::android::NO_INIT;
}
{
std::lock_guard guard(sSubmixRoutesLock);
@@ -64,12 +64,12 @@
} else {
if (!mCurrentRoute->isStreamConfigValid(mIsInput, mStreamConfig)) {
LOG(ERROR) << __func__ << ": invalid stream config";
- return mStatus;
+ return ::android::NO_INIT;
}
sp<MonoPipe> sink = mCurrentRoute->getSink();
if (sink == nullptr) {
LOG(ERROR) << __func__ << ": nullptr sink when opening stream";
- return mStatus;
+ return ::android::NO_INIT;
}
// If the sink has been shutdown or pipe recreation is forced, delete the pipe and
// recreate it.
@@ -77,14 +77,13 @@
LOG(DEBUG) << __func__ << ": Non-nullptr shut down sink when opening stream";
if (::android::OK != mCurrentRoute->resetPipe()) {
LOG(ERROR) << __func__ << ": reset pipe failed";
- return mStatus;
+ return ::android::NO_INIT;
}
}
}
mCurrentRoute->openStream(mIsInput);
- mStatus = ::android::OK;
- return mStatus;
+ return ::android::OK;
}
::android::status_t StreamRemoteSubmix::drain(StreamDescriptor::DrainMode) {
@@ -102,6 +101,16 @@
return ::android::OK;
}
+::android::status_t StreamRemoteSubmix::standby() {
+ mCurrentRoute->standby(mIsInput);
+ return ::android::OK;
+}
+
+::android::status_t StreamRemoteSubmix::start() {
+ mCurrentRoute->exitStandby(mIsInput);
+ return ::android::OK;
+}
+
ndk::ScopedAStatus StreamRemoteSubmix::prepareToClose() {
if (!mIsInput) {
std::shared_ptr<SubmixRoute> route = nullptr;
@@ -138,17 +147,12 @@
std::lock_guard guard(sSubmixRoutesLock);
sSubmixRoutes.erase(mPortId);
- mStatus = ::android::NO_INIT;
}
+ mCurrentRoute.reset();
}
::android::status_t StreamRemoteSubmix::transfer(void* buffer, size_t frameCount,
size_t* actualFrameCount, int32_t* latencyMs) {
- if (mStatus != ::android::OK) {
- LOG(ERROR) << __func__ << ": failed, not configured";
- return ::android::NO_INIT;
- }
-
*latencyMs = (getStreamPipeSizeInFrames() * MILLIS_PER_SECOND) / mStreamConfig.sampleRate;
LOG(VERBOSE) << __func__ << ": Latency " << *latencyMs << "ms";
@@ -171,7 +175,6 @@
return ::android::UNEXPECTED_NULL;
}
- mCurrentRoute->exitStandby(mIsInput);
return (mIsInput ? inRead(buffer, frameCount, actualFrameCount)
: outWrite(buffer, frameCount, actualFrameCount));
}
@@ -329,11 +332,6 @@
return ::android::OK;
}
-::android::status_t StreamRemoteSubmix::standby() {
- mCurrentRoute->standby(mIsInput);
- return ::android::OK;
-}
-
StreamInRemoteSubmix::StreamInRemoteSubmix(const SinkMetadata& sinkMetadata,
StreamContext&& context,
const std::vector<MicrophoneInfo>& microphones)