QCamera3: Fail unsupported stream configurations

If there are two streams on ISP encoder path, the jpeg stream may
skip post processing so HQ post processing settings will be ignored

Ack-by: Chien-Yu Chen

Bug: 24617874
Change-Id: Ibca4756068a0211315c2a49116f880e63150a959
diff --git a/QCamera2/HAL3/QCamera3HWI.cpp b/QCamera2/HAL3/QCamera3HWI.cpp
index b7e938e..1b250a6 100644
--- a/QCamera2/HAL3/QCamera3HWI.cpp
+++ b/QCamera2/HAL3/QCamera3HWI.cpp
@@ -1341,7 +1341,9 @@
     for (List<stream_info_t*>::iterator it = mStreamInfo.begin();
             it != mStreamInfo.end(); it++) {
         QCamera3ProcessingChannel *channel = (QCamera3ProcessingChannel*)(*it)->stream->priv;
-        channel->stop();
+        if (channel) {
+          channel->stop();
+        }
         (*it)->status = INVALID;
     }
 
@@ -1400,6 +1402,7 @@
     cam_dimension_t largeYuv888Size = {0, 0};
     cam_dimension_t maxViewfinderSize = {0, 0};
     bool bJpegExceeds4K = false;
+    bool bJpegOnEncoder = false;
     bool bUseCommonFeatureMask = false;
     cam_feature_mask_t commonFeatureMask = 0;
     bool bSmallJpegSize = false;
@@ -1500,6 +1503,7 @@
                 if (isOnEncoder(maxViewfinderSize, newStream->width,
                         newStream->height)) {
                     numStreamsOnEncoder++;
+                    bJpegOnEncoder = true;
                 }
                 width_ratio = CEIL_DIVISION(gCamCapability[mCameraId]->active_array_size.width,
                         newStream->width);
@@ -1603,6 +1607,21 @@
         return -EINVAL;
     }
 
+    // When JPEG and preview streams share VFE output, CPP will not apply CAC2
+    // on JPEG stream. So disable such configurations to ensure CAC2 is applied.
+    // Don't fail for reprocess configurations. Also don't fail if bJpegExceeds4K
+    // is not true. Otherwise testMandatoryOutputCombinations will fail with following
+    // configurations:
+    //    {[PRIV, PREVIEW] [PRIV, RECORD] [JPEG, RECORD]}
+    //    {[PRIV, PREVIEW] [YUV, RECORD] [JPEG, RECORD]}
+    //    (These two configurations will not have CAC2 enabled even in HQ modes.)
+    if (!isZsl && bJpegOnEncoder && bJpegExceeds4K && bUseCommonFeatureMask) {
+        ALOGE("%s: Blob size greater than 4k and multiple streams are on encoder output",
+                __func__);
+        pthread_mutex_unlock(&mMutex);
+        return -EINVAL;
+    }
+
     // If jpeg stream is available, and a YUV 888 stream is on Encoder path, and
     // the YUV stream's size is greater or equal to the JPEG size, set common
     // postprocess mask to NONE, so that we can take advantage of postproc bypass.
@@ -3996,6 +4015,7 @@
     latestRequest = mPendingRequestsList.insert(
             mPendingRequestsList.end(), pendingRequest);
     if(mFlush) {
+        LOGI("mFlush is true");
         pthread_mutex_unlock(&mMutex);
         return NO_ERROR;
     }