CCodec: protect C2OMXNode::mBufferIdsInUse
Bug: 129736016
Test: atest CtsMediaTestCases -- --module-arg CtsMediaTestCases:size:small
Change-Id: Ifad57b5b0da49d2acdcfba063671c9748d06dc12
diff --git a/media/codec2/sfplugin/C2OMXNode.cpp b/media/codec2/sfplugin/C2OMXNode.cpp
index 962df0f..6ae1c13 100644
--- a/media/codec2/sfplugin/C2OMXNode.cpp
+++ b/media/codec2/sfplugin/C2OMXNode.cpp
@@ -287,7 +287,7 @@
return UNKNOWN_ERROR;
}
- (void)mBufferIdsInUse.emplace(index, buffer);
+ mBufferIdsInUse.lock()->emplace(index, buffer);
return OK;
}
@@ -327,13 +327,19 @@
ALOGD("Buffer source not set (index=%llu)", index.peekull());
return;
}
- auto it = mBufferIdsInUse.find(index.peeku());
- if (it == mBufferIdsInUse.end()) {
- ALOGV("Untracked input index %llu (maybe already removed)", index.peekull());
- return;
+
+ int32_t bufferId = 0;
+ {
+ decltype(mBufferIdsInUse)::Locked bufferIds(mBufferIdsInUse);
+ auto it = bufferIds->find(index.peeku());
+ if (it == bufferIds->end()) {
+ ALOGV("Untracked input index %llu (maybe already removed)", index.peekull());
+ return;
+ }
+ bufferId = it->second;
+ (void)bufferIds->erase(it);
}
- (void)mBufferSource->onInputBufferEmptied(it->second, -1);
- (void)mBufferIdsInUse.erase(it);
+ (void)mBufferSource->onInputBufferEmptied(bufferId, -1);
}
} // namespace android
diff --git a/media/codec2/sfplugin/C2OMXNode.h b/media/codec2/sfplugin/C2OMXNode.h
index b7bd696..3ca6c0a 100644
--- a/media/codec2/sfplugin/C2OMXNode.h
+++ b/media/codec2/sfplugin/C2OMXNode.h
@@ -20,9 +20,10 @@
#include <atomic>
#include <android/IOMXBufferSource.h>
+#include <codec2/hidl/client.h>
+#include <media/stagefright/foundation/Mutexed.h>
#include <media/IOMX.h>
#include <media/OMXBuffer.h>
-#include <codec2/hidl/client.h>
namespace android {
@@ -111,7 +112,7 @@
c2_cntr64_t mPrevInputTimestamp; // input timestamp for previous frame
c2_cntr64_t mPrevCodecTimestamp; // adjusted (codec) timestamp for previous frame
- std::map<uint64_t, buffer_id> mBufferIdsInUse;
+ Mutexed<std::map<uint64_t, buffer_id>> mBufferIdsInUse;
};
} // namespace android