Camera3: Skip no-op stream configurations.

If configuring the same set of streams more than once, don't actually
call into the HAL for the second and subsequent configure calls, since
they're no-ops.

This can speed up camera operation substantially if the
HAL implementation does not detect no-ops on its own and does a full
shutdown/restart on each configure call.

Bug: 9392513
Change-Id: I23baf4acbae2304735899adcf8e17565fa94d31d
diff --git a/services/camera/libcameraservice/Camera3Device.cpp b/services/camera/libcameraservice/Camera3Device.cpp
index c7edb76..bc4db91 100644
--- a/services/camera/libcameraservice/Camera3Device.cpp
+++ b/services/camera/libcameraservice/Camera3Device.cpp
@@ -170,6 +170,7 @@
     mHal3Device = device;
     mStatus = STATUS_IDLE;
     mNextStreamId = 0;
+    mNeedConfig = true;
 
     return OK;
 }
@@ -582,6 +583,7 @@
     }
 
     *id = mNextStreamId++;
+    mNeedConfig = true;
 
     // Continue captures if active at start
     if (wasActive) {
@@ -707,6 +709,7 @@
         // fall through since we want to still list the stream as deleted.
     }
     mDeletedStreams.add(deletedStream);
+    mNeedConfig = true;
 
     return res;
 }
@@ -1007,6 +1010,11 @@
         return INVALID_OPERATION;
     }
 
+    if (!mNeedConfig) {
+        ALOGV("%s: Skipping config, no stream changes", __FUNCTION__);
+        return OK;
+    }
+
     // Start configuring the streams
 
     camera3_stream_configuration config;
@@ -1091,6 +1099,7 @@
     // Finish configuring the streams lazily on first reference
 
     mStatus = STATUS_ACTIVE;
+    mNeedConfig = false;
 
     return OK;
 }
diff --git a/services/camera/libcameraservice/Camera3Device.h b/services/camera/libcameraservice/Camera3Device.h
index 7a8c22a..faa42b9 100644
--- a/services/camera/libcameraservice/Camera3Device.h
+++ b/services/camera/libcameraservice/Camera3Device.h
@@ -149,6 +149,7 @@
     StreamSet                  mOutputStreams;
     sp<camera3::Camera3Stream> mInputStream;
     int                        mNextStreamId;
+    bool                       mNeedConfig;
 
     // Need to hold on to stream references until configure completes.
     Vector<sp<camera3::Camera3StreamInterface> > mDeletedStreams;