check hardware capability before vaCreateConfig

BZ: 143181

check hardware capability before vaCreateConfig,
now it is only implemented in H263

Change-Id: Ia5bd841153e5085f6935b4ab00061a374dbec37d
Signed-off-by: ywan171 <yi.a.wang@intel.com>
Reviewed-on: http://android.intel.com:8080/137398
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/videodecoder/VideoDecoderBase.cpp b/videodecoder/VideoDecoderBase.cpp
index 6509e01..afd68df 100755
--- a/videodecoder/VideoDecoderBase.cpp
+++ b/videodecoder/VideoDecoderBase.cpp
@@ -769,6 +769,10 @@
     CHECK_VA_STATUS("vaInitialize");
 
     if ((int32_t)profile != VAProfileSoftwareDecoding) {
+
+        status = isHardwareSupported(profile);
+        CHECK_STATUS("isHardwareSupported");
+
 #ifdef USE_AVC_SHORT_FORMAT
         status = getCodecSpecificConfigs(profile, &mVAConfig);
         CHECK_STATUS("getCodecSpecificAttributes");
@@ -1307,4 +1311,7 @@
     return DECODE_SUCCESS;
 }
 #endif
+Decode_Status VideoDecoderBase::isHardwareSupported(VAProfile profile) {
+    return DECODE_SUCCESS;
+}
 
diff --git a/videodecoder/VideoDecoderBase.h b/videodecoder/VideoDecoderBase.h
index eab4058..1f69cf1 100644
--- a/videodecoder/VideoDecoderBase.h
+++ b/videodecoder/VideoDecoderBase.h
@@ -92,6 +92,7 @@
     Decode_Status setParserType(_vbp_parser_type type);
     virtual Decode_Status getCodecSpecificConfigs(VAProfile profile, VAConfigID *config);
 #endif
+    virtual Decode_Status isHardwareSupported(VAProfile profile);
 private:
     Decode_Status mapSurface(void);
     Decode_Status getRawDataFromSurface(void);
diff --git a/videodecoder/VideoDecoderMPEG4.cpp b/videodecoder/VideoDecoderMPEG4.cpp
index 7bd9f22..be3c662 100644
--- a/videodecoder/VideoDecoderMPEG4.cpp
+++ b/videodecoder/VideoDecoderMPEG4.cpp
@@ -30,6 +30,7 @@
     : VideoDecoderBase(mimeType, VBP_MPEG4),
       mLastVOPTimeIncrement(0),
       mExpectingNVOP(false),
+      mIsShortHeader(false),
       mSendIQMatrixBuf(false),
       mLastVOPCodingType(MP4_VOP_TYPE_I) {
 }
@@ -522,6 +523,8 @@
         vaProfile = VAProfileMPEG4Simple;
     }
 
+    mIsShortHeader = data->codec_data.short_video_header;
+
     return VideoDecoderBase::setupVA(MP4_SURFACE_NUMBER, vaProfile);
 }
 
@@ -573,3 +576,25 @@
     //mVideoFormatInfo.bitrate = data->codec_data.bit_rate;
     mVideoFormatInfo.valid = true;
 }
+
+Decode_Status VideoDecoderMPEG4::isHardwareSupported(VAProfile profile) {
+    if (!mIsShortHeader) {
+        // TODO: add support for MPEG4 in the future;
+        return DECODE_SUCCESS;
+    }
+
+    VAStatus vaStatus;
+    VAConfigAttrib cfgAttribs[2];
+    cfgAttribs[0].type = VAConfigAttribMaxPictureWidth;
+    cfgAttribs[1].type = VAConfigAttribMaxPictureHeight;
+    vaStatus = vaGetConfigAttributes(mVADisplay, VAProfileH263Baseline,
+            VAEntrypointVLD, cfgAttribs, 2);
+    CHECK_VA_STATUS("vaGetConfigAttributes");
+    if (cfgAttribs[0].value * cfgAttribs[1].value < (uint32_t)mVideoFormatInfo.width * (uint32_t)mVideoFormatInfo.height) {
+        ETRACE("hardware supports resolution %d * %d smaller than the clip resolution %d * %d",
+                cfgAttribs[0].value, cfgAttribs[1].value, mVideoFormatInfo.width, mVideoFormatInfo.height);
+        return DECODE_DRIVER_FAIL;
+    }
+
+    return DECODE_SUCCESS;
+}
diff --git a/videodecoder/VideoDecoderMPEG4.h b/videodecoder/VideoDecoderMPEG4.h
index 234eaac..5f641ee 100644
--- a/videodecoder/VideoDecoderMPEG4.h
+++ b/videodecoder/VideoDecoderMPEG4.h
@@ -38,6 +38,9 @@
     virtual void flush(void);
     virtual Decode_Status decode(VideoDecodeBuffer *buffer);
 
+protected:
+    virtual Decode_Status isHardwareSupported(VAProfile profile);
+
 private:
     Decode_Status decodeFrame(VideoDecodeBuffer *buffer, vbp_data_mp42 *data);
     Decode_Status beginDecodingFrame(vbp_data_mp42 *data);
@@ -65,6 +68,7 @@
     bool mSendIQMatrixBuf; // indicate if iq_matrix_buffer is sent to driver
     int32_t mLastVOPCodingType;
     bool mIsSyncFrame; // indicate if it is SyncFrame in container
+    bool mIsShortHeader; // indicate if it is short header format
     VideoExtensionBuffer mExtensionBuffer;
     PackedFrameData mPackedFrame;
 };