OSDN Git Service

Camera: Allow finalizeOutputConfiguration not adding new surface
authorShuzhen Wang <shuzhenwang@google.com>
Fri, 10 Feb 2017 00:40:07 +0000 (16:40 -0800)
committerShuzhen Wang <shuzhenwang@google.com>
Mon, 13 Feb 2017 21:39:29 +0000 (13:39 -0800)
If the application calls finalizeOutputConfiguration without adding new
surface, as long as there is at least one surface in the
OutputConfiguration, do not throw exception.

Add logic to not allow finalizeOutputConfigurations twice on a
particular stream.

Test: testDeferredSurfaces cts and GoogleCameraApp manual test.
Bug: 35137641
Change-Id: I96061231e9b884e73c92520e7f2c021db32fa731

services/camera/libcameraservice/api2/CameraDeviceClient.cpp
services/camera/libcameraservice/api2/CameraDeviceClient.h

index 2618838..e710f0a 100644 (file)
@@ -1217,6 +1217,13 @@ binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId
         return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
     }
 
+    if (mStreamInfoMap[streamId].finalized) {
+        String8 msg = String8::format("Camera %s: finalizeOutputConfigurations has been called"
+                " on stream ID %d", mCameraIdStr.string(), streamId);
+        ALOGW("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+    }
+
     if (!mDevice.get()) {
         return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
     }
@@ -1246,13 +1253,6 @@ binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId
         surfaceId++;
     }
 
-    if (consumerSurfaces.size() == 0) {
-        String8 msg = String8::format("Camera %s: New OutputConfiguration has the same surfaces"
-                " for stream (ID %d)", mCameraIdStr.string(), streamId);
-        ALOGW("%s: %s", __FUNCTION__, msg.string());
-        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
-    }
-
     // Finish the deferred stream configuration with the surface.
     status_t err;
     err = mDevice->setConsumerSurfaces(streamId, consumerSurfaces);
@@ -1267,6 +1267,7 @@ binder::Status CameraDeviceClient::finalizeOutputConfigurations(int32_t streamId
         if (deferredStreamIndex != NAME_NOT_FOUND) {
             mDeferredStreams.removeItemsAt(deferredStreamIndex);
         }
+        mStreamInfoMap[streamId].finalized = true;
     } else if (err == NO_INIT) {
         res = STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
                 "Camera %s: Deferred surface is invalid: %s (%d)",
index 2f6d414..012beb4 100644 (file)
@@ -215,6 +215,7 @@ private:
         int format;
         android_dataspace dataSpace;
         int32_t consumerUsage;
+        bool finalized = false;
         OutputStreamInfo() :
                 width(-1), height(-1), format(-1), dataSpace(HAL_DATASPACE_UNKNOWN),
                 consumerUsage(0) {}