OMXNodeInstance: Guard mActiveBuffers by mLock

Test: atest CtsMediaTestCases

Bug: 135003556
Bug: 142777721
Change-Id: I02b5c0be94a674fe21884d9faa0c0c9cfbedd5fc
Merged-In: I02b5c0be94a674fe21884d9faa0c0c9cfbedd5fc
(cherry picked from commit 0329492f9e2169ddba5b19f379ddc842db1efdb1)
gugelfrei
Pawin Vongmasa 4 years ago
parent ba8fee2a1d
commit 301dd5f1d9

@ -47,6 +47,8 @@
#include <hidlmemory/mapping.h> #include <hidlmemory/mapping.h>
#include <vector>
static const OMX_U32 kPortIndexInput = 0; static const OMX_U32 kPortIndexInput = 0;
static const OMX_U32 kPortIndexOutput = 1; static const OMX_U32 kPortIndexOutput = 1;
@ -493,9 +495,7 @@ status_t OMXNodeInstance::freeNode() {
case OMX_StateLoaded: case OMX_StateLoaded:
{ {
if (mActiveBuffers.size() > 0) { freeActiveBuffers();
freeActiveBuffers();
}
FALLTHROUGH_INTENDED; FALLTHROUGH_INTENDED;
} }
case OMX_StateInvalid: case OMX_StateInvalid:
@ -2430,11 +2430,19 @@ void OMXNodeInstance::removeActiveBuffer(
} }
void OMXNodeInstance::freeActiveBuffers() { void OMXNodeInstance::freeActiveBuffers() {
// Make sure to count down here, as freeBuffer will in turn remove std::vector<OMX_U32> portIndices;
// the active buffer from the vector... std::vector<IOMX::buffer_id> bufferIds;
for (size_t i = mActiveBuffers.size(); i > 0;) { {
i--; // Access to mActiveBuffers must be protected by mLock.
freeBuffer(mActiveBuffers[i].mPortIndex, mActiveBuffers[i].mID); Mutex::Autolock _l(mLock);
for (const ActiveBuffer& activeBuffer : mActiveBuffers) {
portIndices.emplace_back(activeBuffer.mPortIndex);
bufferIds.emplace_back(activeBuffer.mID);
}
}
for (size_t i = bufferIds.size(); i > 0; ) {
--i;
freeBuffer(portIndices[i], bufferIds[i]);
} }
} }

Loading…
Cancel
Save