Adding error handling and protection when vaInitialize fail.

BZ: 53697

vaInitialize may return a fail value rarely.It can cause mediaserver died.
So, we need adding some error handling and protectionwhen va initialize failure.
Add a variable to flag vaInitialize is successful or not.If not, it will marked as false.
Before starting encoding,check this variable.
If it is false, reture a error code toOMX Component and stop encoding.

Change-Id: I335d21e36c77b5978fa2db978699b6068c8401ed
Signed-off-by: Liu Bolun <bolunx.liu@intel.com>
Reviewed-on: http://android.intel.com:8080/63634
Reviewed-by: Wang, Elaine <elaine.wang@intel.com>
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/videoencoder/VideoEncoderBase.cpp b/videoencoder/VideoEncoderBase.cpp
index 5af1aaa..d102165 100644
--- a/videoencoder/VideoEncoderBase.cpp
+++ b/videoencoder/VideoEncoderBase.cpp
@@ -73,7 +73,8 @@
     ,mSliceSizeOverflow(false)
     ,mCodedBufferMapped(false)
     ,mDataCopiedOut(false)
-    ,mKeyFrame(true) {
+    ,mKeyFrame(true)
+    ,mInitCheck(true) {
 
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     // here the display can be any value, use following one
@@ -96,6 +97,7 @@
     LOG_V("vaInitialize \n");
     if (vaStatus != VA_STATUS_SUCCESS) {
         LOG_E( "Failed vaInitialize, vaStatus = %d\n", vaStatus);
+        mInitCheck = false;
     }
 
 #ifdef VIDEO_ENC_STATISTICS_ENABLE
@@ -135,6 +137,11 @@
         return ENCODE_ALREADY_INIT;
     }
 
+    if (!mInitCheck) {
+        LOGE("Encoder Initialize fail can not start");
+        return ENCODE_DRIVER_FAIL;
+    }
+
     vaAttrib[0].type = VAConfigAttribRTFormat;
     vaAttrib[1].type = VAConfigAttribRateControl;
     vaAttrib[0].value = VA_RT_FORMAT_YUV420;
diff --git a/videoencoder/VideoEncoderBase.h b/videoencoder/VideoEncoderBase.h
index cf65085..9ab7bc6 100644
--- a/videoencoder/VideoEncoderBase.h
+++ b/videoencoder/VideoEncoderBase.h
@@ -155,6 +155,8 @@
     bool mDataCopiedOut;
     bool mKeyFrame;
 
+    int32_t  mInitCheck;
+
 #ifdef VIDEO_ENC_STATISTICS_ENABLE
     VideoStatistics mVideoStat;
 #endif