Flush surface map cache and buffer sharing cache

BZ: 189363

Flush surface map cache and buffer sharing cache if new session id is detected

Change-Id: Iea670ba2ea1977e6c3b9b5e856bd0039c80ad2ec
Signed-off-by: Zhao Liang <leo.zhao@intel.com>
diff --git a/test/mix_encoder2.cpp b/test/mix_encoder2.cpp
index f4e407c..ae81ea1 100755
--- a/test/mix_encoder2.cpp
+++ b/test/mix_encoder2.cpp
@@ -1033,6 +1033,7 @@
         pthread_attr_init(&attr);
         pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
 
+        mRunning = true;
         pthread_create(&mThread, &attr, MixEncoder::ThreadFunc, this);
         pthread_attr_destroy(&attr);
 
diff --git a/videoencoder/IntelMetadataBuffer.cpp b/videoencoder/IntelMetadataBuffer.cpp
index e275637..1cb2e39 100644
--- a/videoencoder/IntelMetadataBuffer.cpp
+++ b/videoencoder/IntelMetadataBuffer.cpp
@@ -691,7 +691,7 @@
 {
     mValue = (intptr_t)((intptr_t) ( mem->pointer() + 0x0FFF) & ~0x0FFF);
 
-    if (mSessionFlag == 0) //no sharing
+    if ( !(mSessionFlag & REMOTE_PROVIDER) && !(mSessionFlag & REMOTE_CONSUMER)) //no sharing
         return IMB_SUCCESS;
 
     if (mSessionFlag & REMOTE_PROVIDER) //is remote provider
@@ -744,7 +744,7 @@
 {
     mValue = (intptr_t)gbuffer->handle;
 
-    if (mSessionFlag == 0) //no sharing
+    if ( !(mSessionFlag & REMOTE_PROVIDER) && !(mSessionFlag & REMOTE_CONSUMER)) //no sharing
         return IMB_SUCCESS;
 
     if (mSessionFlag & REMOTE_PROVIDER == 0) //is remote provider
@@ -794,7 +794,7 @@
 
 IMB_Result IntelMetadataBuffer::ClearContext(uint32_t sessionflag, bool isProvider)
 {
-    if (sessionflag == 0) //no sharing
+    if ( !(sessionflag & REMOTE_PROVIDER) && !(sessionflag & REMOTE_CONSUMER)) //no sharing
         return IMB_SUCCESS;
 
     //clear local firstly
diff --git a/videoencoder/VideoEncoderBase.cpp b/videoencoder/VideoEncoderBase.cpp
index d9e92bd..4a0f376 100644
--- a/videoencoder/VideoEncoderBase.cpp
+++ b/videoencoder/VideoEncoderBase.cpp
@@ -1634,7 +1634,19 @@
     }
 
 #ifdef INTEL_VIDEO_XPROC_SHARING
+    uint32_t sflag = mSessionFlag;
     imb.GetSessionFlag(mSessionFlag);
+    if (mSessionFlag != sflag) {
+        //new sharing session, flush buffer sharing cache
+        IntelMetadataBuffer::ClearContext(sflag, false);
+        //flush surfacemap cache
+        LOG_V( "Flush Src Surface Map\n");
+        while(! mSrcSurfaceMapList.empty())
+        {
+            delete (*mSrcSurfaceMapList.begin());
+            mSrcSurfaceMapList.erase(mSrcSurfaceMapList.begin());
+        }
+    }
 #endif
 
     //find if mapped