c2 hal: handle C2_BAD_INDEX
In Codec 2.0 API query/config may return C2_BAD_INDEX but has valid
out params. In AIDL when the result is not OK the out params are
invalidated. To reconcile the differences, HAL adaptation returns OK
for C2_BAD_INDEX and the client side recovers the error code from the
out params.
Bug: 315555457
Test: atest android.media.decoder.cts.DecoderTest
Change-Id: If7c285929b0e7782ea305d5f1e268ff28900f2b5
diff --git a/media/codec2/hal/client/client.cpp b/media/codec2/hal/client/client.cpp
index b872cea..85b5ec8 100644
--- a/media/codec2/hal/client/client.cpp
+++ b/media/codec2/hal/client/client.cpp
@@ -649,8 +649,8 @@
return C2_CORRUPTED;
}
size_t i = 0;
- for (auto it = paramPointers.begin();
- it != paramPointers.end(); ) {
+ size_t numUpdatedStackParams = 0;
+ for (auto it = paramPointers.begin(); it != paramPointers.end(); ) {
C2Param* paramPointer = *it;
if (numStackIndices > 0) {
--numStackIndices;
@@ -677,7 +677,9 @@
status = C2_BAD_INDEX;
continue;
}
- if (!stackParams[i++]->updateFrom(*paramPointer)) {
+ if (stackParams[i++]->updateFrom(*paramPointer)) {
+ ++numUpdatedStackParams;
+ } else {
LOG(WARNING) << "query -- param update failed: "
"index = "
<< paramPointer->index() << ".";
@@ -697,6 +699,13 @@
}
++it;
}
+ size_t numQueried = numUpdatedStackParams;
+ if (heapParams) {
+ numQueried += heapParams->size();
+ }
+ if (status == C2_OK && indices.size() != numQueried) {
+ status = C2_BAD_INDEX;
+ }
return status;
}