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