codec2: set input buffer to nullptr when work is done
In C2Work contract, when work is returned via onWorkDone, the input
buffer-pack's buffer vector shall contain nullptrs.
Bug: 77501776
Test: CtsMediaTestCases
Test: C2VDAComponent_test
Change-Id: I6e8de1d7f1ee106012f32142333b7cba9824e9c1
diff --git a/C2VDAComponent.cpp b/C2VDAComponent.cpp
index a8f69c4..4e8023e 100644
--- a/C2VDAComponent.cpp
+++ b/C2VDAComponent.cpp
@@ -640,8 +640,8 @@
return;
}
- // When the work is done, the input buffers vector shall be cleared by component.
- work->input.buffers.clear();
+ // When the work is done, the input buffer shall be reset by component.
+ work->input.buffers.front().reset();
reportFinishedWorkIfAny();
}
@@ -1300,10 +1300,10 @@
}
bool C2VDAComponent::isWorkDone(const C2Work* work) const {
- if (!work->input.buffers.empty()) {
+ if (work->input.buffers.front()) {
// Input buffer is still owned by VDA.
// This condition could also recognize dummy EOS work since it won't get
- // onInputBufferDone(), input.buffers won't be cleared until reportEOSWork().
+ // onInputBufferDone(), input buffer won't be reset until reportEOSWork().
return false;
}
if (mComponentState == ComponentState::DRAINING && mDrainWithEOS &&
@@ -1333,7 +1333,7 @@
std::unique_ptr<C2Work> eosWork(std::move(mPendingWorks.front()));
mPendingWorks.pop_front();
- eosWork->input.buffers.clear();
+ eosWork->input.buffers.front().reset();
eosWork->result = C2_OK;
eosWork->workletsProcessed = static_cast<uint32_t>(eosWork->worklets.size());
eosWork->worklets.front()->output.flags = C2FrameData::FLAG_END_OF_STREAM;
@@ -1353,8 +1353,8 @@
// TODO: correlate the definition of flushed work result to framework.
work->result = C2_NOT_FOUND;
- // When the work is abandoned, the input buffers vector shall be cleared by component.
- work->input.buffers.clear();
+ // When the work is abandoned, the input.buffers.front() shall reset by component.
+ work->input.buffers.front().reset();
abandonedWorks.emplace_back(std::move(work));
}
diff --git a/cmds/codec2.cpp b/cmds/codec2.cpp
index 85f94c8..fe3fbff 100644
--- a/cmds/codec2.cpp
+++ b/cmds/codec2.cpp
@@ -326,8 +326,9 @@
}
bool eos = work->worklets.front()->output.flags & C2FrameData::FLAG_END_OF_STREAM;
- // input buffers should be cleared in component side.
- CHECK(work->input.buffers.empty());
+ // input buffer should be reset in component side.
+ CHECK_EQ(work->input.buffers.size(), 1u);
+ CHECK(work->input.buffers.front() == nullptr);
work->worklets.clear();
work->workletsProcessed = 0;
diff --git a/tests/C2VDAComponent_test.cpp b/tests/C2VDAComponent_test.cpp
index 6bc6289..e8ef7ce 100644
--- a/tests/C2VDAComponent_test.cpp
+++ b/tests/C2VDAComponent_test.cpp
@@ -547,8 +547,9 @@
bool iteration_end =
work->worklets.front()->output.flags & C2FrameData::FLAG_END_OF_STREAM;
- // input buffers should be cleared in component side.
- ASSERT_TRUE(work->input.buffers.empty());
+ // input buffer should be reset in component side.
+ ASSERT_EQ(work->input.buffers.size(), 1u);
+ ASSERT_TRUE(work->input.buffers.front() == nullptr);
work->worklets.clear();
work->workletsProcessed = 0;