The file writer thread is not thread-safe.

We can run into problem where deallocate() called from two
separate thread which breaks PV's thread model where
every task is scheduled to run within a single omx thread.

I am pretty sure that this is why the free chunk available
notification is lost sometimes; however, this is certainly
not the fix to all the problems that we have seen so far.

bug - 2484098

Change-Id: I88bc494a11ffd739bc5771fa75b4643de503714f
diff --git a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
index a5e5be3..7905c75 100644
--- a/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
+++ b/nodes/pvmp4ffcomposernode/src/pvmp4ffcn_node.cpp
@@ -19,6 +19,34 @@
  * @file pvmp4ffcn_node.cpp
  * @brief Node for PV MPEG4 file format composer
  */
+
+/*
+ * FIXME:
+ * The current implementation of the file writer is NOT
+ * thread-safe.
+ *
+ * A separate delete queue should be used to
+ * pass back the fragments from the file writer thread
+ * to the composer node and to let the composer node
+ * handle the deallocation of any fragments; otherwise,
+ * race condition may occur. Some lost free chunk
+ * notification has been found due to this race
+ * condition.
+ *
+ * The reason why there is race condition is that the
+ * rest of the OpenCore assumes a single-thread model.
+ * In other words, everything is scheduled to
+ * run within a single omx thread. A separate file writer
+ * thread breaks this model, and deallocate fragments
+ * here may cause deallocate() be called within two
+ * separate thread, and thus the free chunk available
+ * flag can be corrupted.
+ *
+ * Don't remove the following #undef line unless you
+ * fix the above issue.
+ */
+#undef ANDROID
+
 #ifdef ANDROID
 // #define LOG_NDEBUG 0
 #define LOG_TAG "PvMp4Composer"
diff --git a/nodes/pvomxencnode/src/pvmf_omx_enc_node.cpp b/nodes/pvomxencnode/src/pvmf_omx_enc_node.cpp
index 61aa7b0..a0bf09c 100644
--- a/nodes/pvomxencnode/src/pvmf_omx_enc_node.cpp
+++ b/nodes/pvomxencnode/src/pvmf_omx_enc_node.cpp
@@ -1206,8 +1206,6 @@
             PVLOGGER_LOGMSG(PVLOGMSG_INST_LLDBG, iLogger, PVLOGMSG_STACK_TRACE,
                             (0, "PVMFOMXEncNode-%s::Run(): Flush pending:  Changing Component State Executing->Idle or Pause->Idle", iNodeTypeId));
 
-            if (iOutPort) iOutPort->ClearMsgQueues();
-
             err = OMX_SendCommand(iOMXEncoder, OMX_CommandStateSet, OMX_StateIdle, NULL);
             if (err != OMX_ErrorNone)
             {
diff --git a/oscl/oscl/osclmemory/src/oscl_mem_mempool.cpp b/oscl/oscl/osclmemory/src/oscl_mem_mempool.cpp
index b86769c..efea048 100644
--- a/oscl/oscl/osclmemory/src/oscl_mem_mempool.cpp
+++ b/oscl/oscl/osclmemory/src/oscl_mem_mempool.cpp
@@ -16,7 +16,6 @@
  * -------------------------------------------------------------------
  */
 #include "oscl_mem_mempool.h"
-#include <utils/Log.h>
 
 
 /**
@@ -155,10 +154,6 @@
             iObserver->freechunkavailable(iNextAvailableContextData);
         }
     }
-    else if (iObserver && iCheckNextAvailableFreeChunk)
-    {
-        LOGW("We may have lost some free chunk %p available notification for memory pool %p with chunk size %d", ptmp, mptmp, iChunkSizeMemAligned);
-    }
 
     // Decrement the refcount since deallocating succeeded
     removeRef();