renderlib: CB2 add underflow detect in renderlib [1/1]

PD#SWPL-184946

Problem:
add underflow detect in renderlib

Solution:
add underflow detect in renderlib

Verify:
AH212

Signed-off-by: le.han <le.han@amlogic.com>
Change-Id: Icf5d00f3bab6a5b1e24eaf57bfaee6b3a6812dfc
diff --git a/weston/wayland_plugin.cpp b/weston/wayland_plugin.cpp
index 1c6fae9..4fd8c7f 100644
--- a/weston/wayland_plugin.cpp
+++ b/weston/wayland_plugin.cpp
@@ -23,6 +23,8 @@
 
 #define TAG "rlib:wayland_plugin"
 
+#define UNDER_FLOW_EXPIRED_TIME_MS 83
+
 WaylandPlugin::WaylandPlugin(int logCatgory)
     : mRenderLock("renderlock"),
     mLogCategory(logCatgory)
@@ -31,6 +33,7 @@
     mQueue = new Tls::Queue();
     mPaused = false;
     mImmediatelyOutput = false;
+    mUnderFlowDetect = false;
 }
 
 WaylandPlugin::~WaylandPlugin()
@@ -129,6 +132,9 @@
      */
     WaylandDisplay::AmlConfigAPIList *amlconfig = mDisplay->getAmlConfigAPIList();
     if (!amlconfig->enableSetPts) {
+        if (mUnderFlowDetect) {
+            mUnderFlowDetect = false;
+        }
         buffer->time = displayTime;
         mQueue->push(buffer);
         DEBUG(mLogCategory,"queue size:%d,pts:%lld us",mQueue->getCnt(),buffer->pts/1000);
@@ -310,6 +316,12 @@
 
     //if queue is empty or paused, loop next
     if (mQueue->isEmpty() || mPaused) {
+        if (mQueue->isEmpty() &&
+            Tls::Times::getSystemTimeMs() - mLastDisplayTime > UNDER_FLOW_EXPIRED_TIME_MS &&
+            !mUnderFlowDetect) {
+            mUnderFlowDetect = true;
+            handleMsgNotify(MSG_UNDER_FLOW, NULL);
+        }
         goto tag_next;
     }
 
@@ -355,6 +367,7 @@
     }
 
     if (mDisplay) {
+        mLastDisplayTime = Tls::Times::getSystemTimeMs();
         TRACE(mLogCategory,"post,now:%lld,display:%lld(pts:%lld ms),n-d::%lld ms, size:%d",
             nowMonotime,expiredFrameEntity->time,expiredFrameEntity->pts/1000000,
             (nowMonotime - expiredFrameEntity->time)/1000,mQueue->getCnt());