Audio HAL VTS: refactor prepareFor{Reading,Writing}
Those functions had lots of copy paste on errors and
the following patch will even add more error detections.
Refactor the hidl_cb call to avoid all duplication.
Note that both function should be refactored as 99% identical.
Test: vts-tradefed run vts --module VtsHalAudioV2_0Target
Test: call/play music/record/video...
Bug: 36311550
Change-Id: I40d6926b4f9f5e3aba51e878f55fb013f4ca09c1
Signed-off-by: Kevin Rocard <krocard@google.com>
diff --git a/audio/2.0/default/StreamOut.cpp b/audio/2.0/default/StreamOut.cpp
index 63b9ae3..fc055be 100644
--- a/audio/2.0/default/StreamOut.cpp
+++ b/audio/2.0/default/StreamOut.cpp
@@ -295,11 +295,18 @@
prepareForWriting_cb _hidl_cb) {
status_t status;
ThreadInfo threadInfo = {0, 0};
+
+ // Wrap the _hidl_cb to return an error
+ auto sendError = [this, &threadInfo, &_hidl_cb](Result result) {
+ _hidl_cb(result, CommandMQ::Descriptor(), DataMQ::Descriptor(),
+ StatusMQ::Descriptor(), threadInfo);
+
+ };
+
// Create message queues.
if (mDataMQ) {
ALOGE("the client attempts to call prepareForWriting twice");
- _hidl_cb(Result::INVALID_STATE, CommandMQ::Descriptor(),
- DataMQ::Descriptor(), StatusMQ::Descriptor(), threadInfo);
+ sendError(Result::INVALID_STATE);
return Void();
}
std::unique_ptr<CommandMQ> tempCommandMQ(new CommandMQ(1));
@@ -320,8 +327,7 @@
ALOGE_IF(!tempCommandMQ->isValid(), "command MQ is invalid");
ALOGE_IF(!tempDataMQ->isValid(), "data MQ is invalid");
ALOGE_IF(!tempStatusMQ->isValid(), "status MQ is invalid");
- _hidl_cb(Result::INVALID_ARGUMENTS, CommandMQ::Descriptor(),
- DataMQ::Descriptor(), StatusMQ::Descriptor(), threadInfo);
+ sendError(Result::INVALID_ARGUMENTS);
return Void();
}
EventFlag* tempRawEfGroup{};
@@ -331,8 +337,7 @@
tempRawEfGroup, [](auto* ef) { EventFlag::deleteEventFlag(&ef); });
if (status != OK || !tempElfGroup) {
ALOGE("failed creating event flag for data MQ: %s", strerror(-status));
- _hidl_cb(Result::INVALID_ARGUMENTS, CommandMQ::Descriptor(),
- DataMQ::Descriptor(), StatusMQ::Descriptor(), threadInfo);
+ sendError(Result::INVALID_ARGUMENTS);
return Void();
}
@@ -341,15 +346,14 @@
&mStopWriteThread, mStream, tempCommandMQ.get(), tempDataMQ.get(),
tempStatusMQ.get(), tempElfGroup.get());
if (!tempWriteThread->init()) {
- _hidl_cb(Result::INVALID_ARGUMENTS, CommandMQ::Descriptor(),
- DataMQ::Descriptor(), StatusMQ::Descriptor(), threadInfo);
+ ALOGW("failed to start writer thread: %s", strerror(-status));
+ sendError(Result::INVALID_ARGUMENTS);
return Void();
}
status = tempWriteThread->run("writer", PRIORITY_URGENT_AUDIO);
if (status != OK) {
ALOGW("failed to start writer thread: %s", strerror(-status));
- _hidl_cb(Result::INVALID_ARGUMENTS, CommandMQ::Descriptor(),
- DataMQ::Descriptor(), StatusMQ::Descriptor(), threadInfo);
+ sendError(Result::INVALID_ARGUMENTS);
return Void();
}