libmix: optimize video decoder MW to avoid unnecessary delay when playback starts

BZ: 78808

optimization:
(1) if AVC ES is baseline profile, low delay mode is automatically enabled
(2) if DPB size of AVC ES is smaller than OUTPUT_WINDOW_SIZE, DPB will be used as output window size

Change-Id: Ic14d535c294f4fa043848f0a9e295368248a6fc1
Signed-off-by: ywan171 <yi.a.wang@intel.com>
Reviewed-on: http://android.intel.com:8080/85536
Reviewed-by: Qiu, Junhai <junhai.qiu@intel.com>
Reviewed-by: Feng, Wei <wei.feng@intel.com>
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: Liang, Dan <dan.liang@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/videodecoder/VideoDecoderAVC.cpp b/videodecoder/VideoDecoderAVC.cpp
index 8863738..15328bd 100644
--- a/videodecoder/VideoDecoderAVC.cpp
+++ b/videodecoder/VideoDecoderAVC.cpp
@@ -605,13 +605,20 @@
             vaProfile = VAProfileH264ConstrainedBaseline;
         }
     }
+
+    VideoDecoderBase::setOutputWindowSize(DPBSize);
+
    // for 1080p, limit the total surface to 19, according the hardware limitation
    // change the max surface number from 19->10 to workaround memory shortage
    // remove the workaround
     if(mVideoFormatInfo.height == 1088 && DPBSize + AVC_EXTRA_SURFACE_NUMBER > 19) {
         DPBSize = 19 - AVC_EXTRA_SURFACE_NUMBER;
     }
-    VideoDecoderBase::setOutputWindowSize(DPBSize);
+
+    // for baseline profile, enable low delay mode automatically
+    if (data->codec_data->profile_idc == 66) {
+        enableLowDelayMode(true);
+    }
     return VideoDecoderBase::setupVA(DPBSize + AVC_EXTRA_SURFACE_NUMBER, vaProfile);
 }
 
diff --git a/videodecoder/VideoDecoderBase.cpp b/videodecoder/VideoDecoderBase.cpp
index d5a47dd..0dd07ae 100644
--- a/videodecoder/VideoDecoderBase.cpp
+++ b/videodecoder/VideoDecoderBase.cpp
@@ -33,12 +33,6 @@
 #define MINIMUM_POC  0x80000000
 #define ANDROID_DISPLAY_HANDLE 0x18C34078
 
-// TODO: check what is the best number. Must be at least 2 to support one backward reference frame.
-// Currently set to 8 to support 7 backward reference frames. This value is used for AVC frame reordering only.
-// e.g:
-// POC: 4P,  8P,  10P,  6B and mNextOutputPOC = 5
-#define OUTPUT_WINDOW_SIZE 8
-
 VideoDecoderBase::VideoDecoderBase(const char *mimeType, _vbp_parser_type type)
     : mDisplay(NULL),
       mVADisplay(NULL),
@@ -442,7 +436,7 @@
             output = p;
             outputleastpoc = p;
         }
-        if (poc == mNextOutputPOC || count == OUTPUT_WINDOW_SIZE) {
+        if (poc == mNextOutputPOC || count == mOutputWindowSize) {
             if (output != NULL) {
                 // this indicates two cases:
                 // 1) the next output POC is found.
diff --git a/videodecoder/VideoDecoderBase.h b/videodecoder/VideoDecoderBase.h
index 8ebd067..048da3c 100644
--- a/videodecoder/VideoDecoderBase.h
+++ b/videodecoder/VideoDecoderBase.h
@@ -40,6 +40,11 @@
 typedef unsigned int Display;
 #endif
 
+// TODO: check what is the best number. Must be at least 2 to support one backward reference frame.
+// Currently set to 8 to support 7 backward reference frames. This value is used for AVC frame reordering only.
+// e.g:
+// POC: 4P,  8P,  10P,  6B and mNextOutputPOC = 5
+#define OUTPUT_WINDOW_SIZE 8
 
 class VideoDecoderBase : public IVideoDecoder {
 public:
@@ -144,8 +149,9 @@
 protected:
     void ManageReference(bool enable) {mManageReference = enable;}
     void setOutputMethod(OUTPUT_METHOD method) {mOutputMethod = method;}
-    void setOutputWindowSize(int32_t size) {mOutputWindowSize = size;}
+    void setOutputWindowSize(int32_t size) {mOutputWindowSize = (size < OUTPUT_WINDOW_SIZE) ? size : OUTPUT_WINDOW_SIZE;}
     void querySurfaceRenderStatus(VideoSurfaceBuffer* surface);
+    void enableLowDelayMode(bool enable) {mLowDelay = enable;}
 };