Merge tag android-5.1.0_r1 into AOSP_5.1_MERGE

Change-Id: Ibbb1c6d1c760f9cb9a4a241725244eb895477e49
diff --git a/videodecoder/Android.mk b/videodecoder/Android.mk
index 53e3283..d3ff4f2 100644
--- a/videodecoder/Android.mk
+++ b/videodecoder/Android.mk
@@ -2,8 +2,8 @@
 
 include $(CLEAR_VARS)
 
-ifeq ($(TARGET_HAS_VPP),true)
-LOCAL_CFLAGS += -DTARGET_HAS_VPP
+ifeq ($(TARGET_HAS_ISV),true)
+LOCAL_CFLAGS += -DTARGET_HAS_ISV
 endif
 
 LOCAL_SRC_FILES := \
diff --git a/videodecoder/VideoDecoderAVC.cpp b/videodecoder/VideoDecoderAVC.cpp
index 8ed91f9..ad4ad33 100644
--- a/videodecoder/VideoDecoderAVC.cpp
+++ b/videodecoder/VideoDecoderAVC.cpp
@@ -517,6 +517,13 @@
     VAPictureH264 *dpb = picParam->ReferenceFrames;
     VAPictureH264 *refFrame = NULL;
 
+    for(int i = 0; i < picParam->num_ref_frames; i++) {
+        dpb->picture_id = findSurface(dpb);
+        dpb++;
+    }
+
+    return DECODE_SUCCESS;
+
     // invalidate DPB in the picture buffer
     memset(picParam->ReferenceFrames, 0xFF, sizeof(picParam->ReferenceFrames));
     picParam->num_ref_frames = 0;
diff --git a/videodecoder/VideoDecoderBase.cpp b/videodecoder/VideoDecoderBase.cpp
index 1065cd4..8c66e80 100644
--- a/videodecoder/VideoDecoderBase.cpp
+++ b/videodecoder/VideoDecoderBase.cpp
@@ -775,7 +775,7 @@
 
     mRotationDegrees = 0;
     if (mConfigBuffer.flag & USE_NATIVE_GRAPHIC_BUFFER){
-#ifdef TARGET_HAS_VPP
+#ifdef TARGET_HAS_ISV
         if (mVideoFormatInfo.actualBufferNeeded > mConfigBuffer.surfaceNumber - mConfigBuffer.vppBufferNum)
 #else
         if (mVideoFormatInfo.actualBufferNeeded > mConfigBuffer.surfaceNumber)
diff --git a/videodecoder/VideoDecoderDefs.h b/videodecoder/VideoDecoderDefs.h
index c9b5d30..708725b 100644
--- a/videodecoder/VideoDecoderDefs.h
+++ b/videodecoder/VideoDecoderDefs.h
@@ -153,7 +153,7 @@
     VideoExtensionBuffer *ext;
     void* nativeWindow;
     uint32_t rotationDegrees;
-#ifdef TARGET_HAS_VPP
+#ifdef TARGET_HAS_ISV
     uint32_t vppBufferNum;
 #endif
 };
diff --git a/videodecoder/securevideo/moorefield/VideoDecoderAVCSecure.cpp b/videodecoder/securevideo/moorefield/VideoDecoderAVCSecure.cpp
index 2867ad9..029484c 100644
--- a/videodecoder/securevideo/moorefield/VideoDecoderAVCSecure.cpp
+++ b/videodecoder/securevideo/moorefield/VideoDecoderAVCSecure.cpp
@@ -149,6 +149,16 @@
 
             VTRACE("nalu_type = 0x%x, nalu_size = %d, nalu_offset = 0x%x", nalu_type, nalu_size, nalu_offset);
 
+            // FIXME: this is a w/a to handle the case when two frame data was wrongly packed into one buffer
+            // especially IDR + Slice. let it gracefully quit.
+            if ((naluType == h264_NAL_UNIT_TYPE_SLICE) && (i > 0)) {
+                uint8_t former_naluType = pFrameInfo->nalus[i-1].type & NALU_TYPE_MASK;
+                if (former_naluType == h264_NAL_UNIT_TYPE_IDR) {
+                    ETRACE("Invalid parameter: IDR slice + SLICE in one buffer");
+                    break; // abandon this slice
+                }
+            }
+
             if (naluType >= h264_NAL_UNIT_TYPE_SLICE && naluType <= h264_NAL_UNIT_TYPE_IDR) {
 
                 mIsEncryptData = 1;
@@ -381,14 +391,18 @@
     CHECK_STATUS("acquireSurfaceBuffer");
 
     if (mModularMode) {
-        parseModularSliceHeader(data);
+        status = parseModularSliceHeader(data);
     }
     else {
-        parseClassicSliceHeader(data);
+        status = parseClassicSliceHeader(data);
     }
 
     if (status != DECODE_SUCCESS) {
         endDecodingFrame(true);
+        if (status == DECODE_PARSER_FAIL) {
+            ETRACE("parse frame failed with DECODE_PARSER_FAIL");
+            status = DECODE_INVALID_DATA;
+        }
         return status;
     }
 
diff --git a/videoencoder/Android.mk b/videoencoder/Android.mk
index 1fc4d9a..487ebfc 100644
--- a/videoencoder/Android.mk
+++ b/videoencoder/Android.mk
@@ -46,8 +46,6 @@
     libva \
     libva-android \
     libva-tpi \
-    libui \
-    libutils \
     libhardware \
     libintelmetadatabuffer