Camera: Add support for stream combination query
Support runtime "SessionConfiguration" queries by camera
clients.
Bug: 111593096
Test: adb shell /data/nativetest64/camera_client_test/camera_client_test
--gtest_filter=CameraClientBinderTest.CheckBinderCameraDeviceUser,
Camera CTS
Change-Id: I1505e7bccdce468490b46ad4546e459354a4cda3
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index 6da05c3..c1a4c11 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -27,6 +27,8 @@
#include <camera/CameraUtils.h>
#include "common/CameraDeviceBase.h"
+#include "device3/Camera3Device.h"
+#include "device3/Camera3OutputStream.h"
#include "api2/CameraDeviceClient.h"
#include <camera_metadata_hidden.h>
@@ -471,6 +473,68 @@
return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
}
+ res = checkOperatingModeLocked(operatingMode);
+ if (!res.isOk()) {
+ return res;
+ }
+
+ status_t err = mDevice->configureStreams(sessionParams, operatingMode);
+ if (err == BAD_VALUE) {
+ String8 msg = String8::format("Camera %s: Unsupported set of inputs/outputs provided",
+ mCameraIdStr.string());
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+ } else if (err != OK) {
+ String8 msg = String8::format("Camera %s: Error configuring streams: %s (%d)",
+ mCameraIdStr.string(), strerror(-err), err);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
+ }
+
+ return res;
+}
+
+binder::Status CameraDeviceClient::checkSurfaceTypeLocked(size_t numBufferProducers,
+ bool deferredConsumer, int surfaceType) const {
+ if (numBufferProducers > MAX_SURFACES_PER_STREAM) {
+ ALOGE("%s: GraphicBufferProducer count %zu for stream exceeds limit of %d",
+ __FUNCTION__, numBufferProducers, MAX_SURFACES_PER_STREAM);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Surface count is too high");
+ } else if ((numBufferProducers == 0) && (!deferredConsumer)) {
+ ALOGE("%s: Number of consumers cannot be smaller than 1", __FUNCTION__);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "No valid consumers.");
+ }
+
+ bool validSurfaceType = ((surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) ||
+ (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE));
+
+ if (deferredConsumer && !validSurfaceType) {
+ ALOGE("%s: Target surface has invalid surfaceType = %d.", __FUNCTION__, surfaceType);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
+ }
+
+ return binder::Status::ok();
+}
+
+binder::Status CameraDeviceClient::checkPhysicalCameraIdLocked(String8 physicalCameraId) {
+ if (physicalCameraId.size() > 0) {
+ std::vector<std::string> physicalCameraIds;
+ bool logicalCamera =
+ mProviderManager->isLogicalCamera(mCameraIdStr.string(), &physicalCameraIds);
+ if (!logicalCamera ||
+ std::find(physicalCameraIds.begin(), physicalCameraIds.end(),
+ physicalCameraId.string()) == physicalCameraIds.end()) {
+ String8 msg = String8::format("Camera %s: Camera doesn't support physicalCameraId %s.",
+ mCameraIdStr.string(), physicalCameraId.string());
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+ }
+ }
+
+ return binder::Status::ok();
+}
+
+binder::Status CameraDeviceClient::checkOperatingModeLocked(int operatingMode) const {
if (operatingMode < 0) {
String8 msg = String8::format(
"Camera %s: Invalid operating mode %d requested", mCameraIdStr.string(), operatingMode);
@@ -479,7 +543,6 @@
msg.string());
}
- // Sanitize the high speed session against necessary capability bit.
bool isConstrainedHighSpeed = (operatingMode == ICameraDeviceUser::CONSTRAINED_HIGH_SPEED_MODE);
if (isConstrainedHighSpeed) {
CameraMetadata staticInfo = mDevice->info();
@@ -502,17 +565,163 @@
}
}
- status_t err = mDevice->configureStreams(sessionParams, operatingMode);
- if (err == BAD_VALUE) {
- String8 msg = String8::format("Camera %s: Unsupported set of inputs/outputs provided",
- mCameraIdStr.string());
+ return binder::Status::ok();
+}
+
+void CameraDeviceClient::mapStreamInfo(const OutputStreamInfo &streamInfo,
+ camera3_stream_rotation_t rotation, String8 physicalId,
+ hardware::camera::device::V3_4::Stream *stream /*out*/) {
+ if (stream == nullptr) {
+ return;
+ }
+
+ stream->v3_2.streamType = hardware::camera::device::V3_2::StreamType::OUTPUT;
+ stream->v3_2.width = streamInfo.width;
+ stream->v3_2.height = streamInfo.height;
+ stream->v3_2.format = Camera3Device::mapToPixelFormat(streamInfo.format);
+ auto u = streamInfo.consumerUsage;
+ camera3::Camera3OutputStream::applyZSLUsageQuirk(streamInfo.format, &u);
+ stream->v3_2.usage = Camera3Device::mapToConsumerUsage(u);
+ stream->v3_2.dataSpace = Camera3Device::mapToHidlDataspace(streamInfo.dataSpace);
+ stream->v3_2.rotation = Camera3Device::mapToStreamRotation(rotation);
+ stream->physicalCameraId = std::string(physicalId.string());
+ stream->bufferSize = 0;
+}
+
+binder::Status CameraDeviceClient::isSessionConfigurationSupported(
+ const SessionConfiguration& sessionConfiguration, bool *status /*out*/) {
+ ATRACE_CALL();
+
+ binder::Status res;
+ if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
+
+ Mutex::Autolock icl(mBinderSerializationLock);
+
+ if (!mDevice.get()) {
+ return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+ }
+
+ auto operatingMode = sessionConfiguration.getOperatingMode();
+ res = checkOperatingModeLocked(operatingMode);
+ if (!res.isOk()) {
+ return res;
+ }
+
+ if (status == nullptr) {
+ String8 msg = String8::format( "Camera %s: Invalid status!", mCameraIdStr.string());
ALOGE("%s: %s", __FUNCTION__, msg.string());
- res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
- } else if (err != OK) {
- String8 msg = String8::format("Camera %s: Error configuring streams: %s (%d)",
- mCameraIdStr.string(), strerror(-err), err);
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+ }
+
+ hardware::camera::device::V3_4::StreamConfiguration streamConfiguration;
+ auto ret = Camera3Device::mapToStreamConfigurationMode(
+ static_cast<camera3_stream_configuration_mode_t> (operatingMode),
+ /*out*/ &streamConfiguration.operationMode);
+ if (ret != OK) {
+ String8 msg = String8::format(
+ "Camera %s: Failed mapping operating mode %d requested: %s (%d)", mCameraIdStr.string(),
+ operatingMode, strerror(-ret), ret);
ALOGE("%s: %s", __FUNCTION__, msg.string());
- res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
+ return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ msg.string());
+ }
+
+ bool isInputValid = (sessionConfiguration.getInputWidth() > 0) &&
+ (sessionConfiguration.getInputHeight() > 0) &&
+ (sessionConfiguration.getInputFormat() > 0);
+ auto outputConfigs = sessionConfiguration.getOutputConfigurations();
+ size_t streamCount = outputConfigs.size();
+ streamCount = isInputValid ? streamCount + 1 : streamCount;
+ streamConfiguration.streams.resize(streamCount);
+ size_t streamIdx = 0;
+ if (isInputValid) {
+ streamConfiguration.streams[streamIdx++] = {{/*streamId*/0,
+ hardware::camera::device::V3_2::StreamType::INPUT,
+ static_cast<uint32_t> (sessionConfiguration.getInputWidth()),
+ static_cast<uint32_t> (sessionConfiguration.getInputHeight()),
+ Camera3Device::mapToPixelFormat(sessionConfiguration.getInputFormat()),
+ /*usage*/ 0, HAL_DATASPACE_UNKNOWN,
+ hardware::camera::device::V3_2::StreamRotation::ROTATION_0},
+ /*physicalId*/ nullptr, /*bufferSize*/0};
+ }
+
+ for (const auto &it : outputConfigs) {
+ const std::vector<sp<IGraphicBufferProducer>>& bufferProducers =
+ it.getGraphicBufferProducers();
+ bool deferredConsumer = it.isDeferred();
+ String8 physicalCameraId = String8(it.getPhysicalCameraId());
+ size_t numBufferProducers = bufferProducers.size();
+ bool isStreamInfoValid = false;
+ OutputStreamInfo streamInfo;
+
+ res = checkSurfaceTypeLocked(numBufferProducers, deferredConsumer, it.getSurfaceType());
+ if (!res.isOk()) {
+ return res;
+ }
+
+ res = checkPhysicalCameraIdLocked(physicalCameraId);
+ if (!res.isOk()) {
+ return res;
+ }
+
+ if (deferredConsumer) {
+ streamInfo.width = it.getWidth();
+ streamInfo.height = it.getHeight();
+ streamInfo.format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
+ streamInfo.dataSpace = android_dataspace_t::HAL_DATASPACE_UNKNOWN;
+ auto surfaceType = it.getSurfaceType();
+ streamInfo.consumerUsage = GraphicBuffer::USAGE_HW_TEXTURE;
+ if (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) {
+ streamInfo.consumerUsage |= GraphicBuffer::USAGE_HW_COMPOSER;
+ }
+ mapStreamInfo(streamInfo, CAMERA3_STREAM_ROTATION_0, physicalCameraId,
+ &streamConfiguration.streams[streamIdx++]);
+ isStreamInfoValid = true;
+
+ if (numBufferProducers == 0) {
+ continue;
+ }
+ }
+
+ for (auto& bufferProducer : bufferProducers) {
+ sp<Surface> surface;
+ res = createSurfaceFromGbp(streamInfo, isStreamInfoValid, surface, bufferProducer,
+ physicalCameraId);
+
+ if (!res.isOk())
+ return res;
+
+ if (!isStreamInfoValid) {
+ mapStreamInfo(streamInfo, static_cast<camera3_stream_rotation_t> (it.getRotation()),
+ physicalCameraId, &streamConfiguration.streams[streamIdx++]);
+ isStreamInfoValid = true;
+ }
+ }
+ }
+
+ *status = false;
+ ret = mProviderManager->isSessionConfigurationSupported(mCameraIdStr.string(),
+ streamConfiguration, status);
+ switch (ret) {
+ case OK:
+ // Expected, do nothing.
+ break;
+ case INVALID_OPERATION: {
+ String8 msg = String8::format(
+ "Camera %s: Session configuration query not supported!",
+ mCameraIdStr.string());
+ ALOGD("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION, msg.string());
+ }
+
+ break;
+ default: {
+ String8 msg = String8::format( "Camera %s: Error: %s (%d)", mCameraIdStr.string(),
+ strerror(-ret), ret);
+ ALOGE("%s: %s", __FUNCTION__, msg.string());
+ res = STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT,
+ msg.string());
+ }
}
return res;
@@ -605,40 +814,23 @@
bool deferredConsumer = outputConfiguration.isDeferred();
bool isShared = outputConfiguration.isShared();
String8 physicalCameraId = String8(outputConfiguration.getPhysicalCameraId());
-
- if (numBufferProducers > MAX_SURFACES_PER_STREAM) {
- ALOGE("%s: GraphicBufferProducer count %zu for stream exceeds limit of %d",
- __FUNCTION__, bufferProducers.size(), MAX_SURFACES_PER_STREAM);
- return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Surface count is too high");
- }
bool deferredConsumerOnly = deferredConsumer && numBufferProducers == 0;
- int surfaceType = outputConfiguration.getSurfaceType();
- bool validSurfaceType = ((surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_VIEW) ||
- (surfaceType == OutputConfiguration::SURFACE_TYPE_SURFACE_TEXTURE));
- if (deferredConsumer && !validSurfaceType) {
- ALOGE("%s: Target surface is invalid: bufferProducer = %p, surfaceType = %d.",
- __FUNCTION__, bufferProducers[0].get(), surfaceType);
- return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, "Target Surface is invalid");
+ res = checkSurfaceTypeLocked(numBufferProducers, deferredConsumer,
+ outputConfiguration.getSurfaceType());
+ if (!res.isOk()) {
+ return res;
}
if (!mDevice.get()) {
return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
}
- if (physicalCameraId.size() > 0) {
- std::vector<std::string> physicalCameraIds;
- bool logicalCamera =
- mProviderManager->isLogicalCamera(mCameraIdStr.string(), &physicalCameraIds);
- if (!logicalCamera ||
- std::find(physicalCameraIds.begin(), physicalCameraIds.end(),
- physicalCameraId.string()) == physicalCameraIds.end()) {
- String8 msg = String8::format("Camera %s: Camera doesn't support physicalCameraId %s.",
- mCameraIdStr.string(), physicalCameraId.string());
- ALOGE("%s: %s", __FUNCTION__, msg.string());
- return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
- }
+ res = checkPhysicalCameraIdLocked(physicalCameraId);
+ if (!res.isOk()) {
+ return res;
}
+
std::vector<sp<Surface>> surfaces;
std::vector<sp<IBinder>> binders;
status_t err;
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.h b/services/camera/libcameraservice/api2/CameraDeviceClient.h
index 09ce977..17a0983 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.h
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.h
@@ -20,6 +20,7 @@
#include <android/hardware/camera2/BnCameraDeviceUser.h>
#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
#include <camera/camera2/OutputConfiguration.h>
+#include <camera/camera2/SessionConfiguration.h>
#include <camera/camera2/SubmitInfo.h>
#include "CameraService.h"
@@ -89,6 +90,12 @@
virtual binder::Status endConfigure(int operatingMode,
const hardware::camera2::impl::CameraMetadataNative& sessionParams) override;
+ // Verify specific session configuration.
+ virtual binder::Status isSessionConfigurationSupported(
+ const SessionConfiguration& sessionConfiguration,
+ /*out*/
+ bool* streamStatus) override;
+
// Returns -EBUSY if device is not idle or in error state
virtual binder::Status deleteStream(int streamId) override;
@@ -230,6 +237,13 @@
/** Utility members */
binder::Status checkPidStatus(const char* checkLocation);
+ binder::Status checkOperatingModeLocked(int operatingMode) const;
+ binder::Status checkPhysicalCameraIdLocked(String8 physicalCameraId);
+ binder::Status checkSurfaceTypeLocked(size_t numBufferProducers, bool deferredConsumer,
+ int surfaceType) const;
+ static void mapStreamInfo(const OutputStreamInfo &streamInfo,
+ camera3_stream_rotation_t rotation, String8 physicalId,
+ hardware::camera::device::V3_4::Stream *stream /*out*/);
bool enforceRequestPermissions(CameraMetadata& metadata);
// Find the square of the euclidean distance between two points
@@ -300,7 +314,7 @@
// stream ID -> outputStreamInfo mapping
std::unordered_map<int32_t, OutputStreamInfo> mStreamInfoMap;
- static const int32_t MAX_SURFACES_PER_STREAM = 2;
+ static const int32_t MAX_SURFACES_PER_STREAM = 4;
sp<CameraProviderManager> mProviderManager;
};
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.cpp b/services/camera/libcameraservice/common/CameraProviderManager.cpp
index 2542ab2..a82f0f7 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.cpp
+++ b/services/camera/libcameraservice/common/CameraProviderManager.cpp
@@ -177,6 +177,19 @@
return deviceInfo->getCameraInfo(info);
}
+status_t CameraProviderManager::isSessionConfigurationSupported(const std::string& id,
+ const hardware::camera::device::V3_4::StreamConfiguration &configuration,
+ bool *status /*out*/) const {
+ std::lock_guard<std::mutex> lock(mInterfaceMutex);
+
+ auto deviceInfo = findDeviceInfoLocked(id);
+ if (deviceInfo == nullptr) {
+ return NAME_NOT_FOUND;
+ }
+
+ return deviceInfo->isSessionConfigurationSupported(configuration, status);
+}
+
status_t CameraProviderManager::getCameraCharacteristics(const std::string &id,
CameraMetadata* characteristics) const {
std::lock_guard<std::mutex> lock(mInterfaceMutex);
@@ -1381,6 +1394,43 @@
return OK;
}
+status_t CameraProviderManager::ProviderInfo::DeviceInfo3::isSessionConfigurationSupported(
+ const hardware::camera::device::V3_4::StreamConfiguration &configuration,
+ bool *status /*out*/) const {
+ auto castResult = device::V3_5::ICameraDevice::castFrom(mInterface);
+ sp<hardware::camera::device::V3_5::ICameraDevice> interface_3_5 = castResult;
+ if (interface_3_5 == nullptr) {
+ return INVALID_OPERATION;
+ }
+
+ status_t res;
+ Status callStatus;
+ auto ret = interface_3_5->isStreamCombinationSupported(configuration,
+ [&callStatus, &status] (Status s, bool combStatus) {
+ callStatus = s;
+ *status = combStatus;
+ });
+ if (ret.isOk()) {
+ switch (callStatus) {
+ case Status::OK:
+ // Expected case, do nothing.
+ res = OK;
+ break;
+ case Status::METHOD_NOT_SUPPORTED:
+ res = INVALID_OPERATION;
+ break;
+ default:
+ ALOGE("%s: Session configuration query failed: %d", __FUNCTION__, callStatus);
+ res = UNKNOWN_ERROR;
+ }
+ } else {
+ ALOGE("%s: Unexpected binder error: %s", __FUNCTION__, ret.description().c_str());
+ res = UNKNOWN_ERROR;
+ }
+
+ return res;
+}
+
status_t CameraProviderManager::ProviderInfo::parseProviderName(const std::string& name,
std::string *type, uint32_t *id) {
// Format must be "<type>/<id>"
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.h b/services/camera/libcameraservice/common/CameraProviderManager.h
index c506d35..99b87fb 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.h
+++ b/services/camera/libcameraservice/common/CameraProviderManager.h
@@ -28,6 +28,7 @@
#include <utils/Errors.h>
#include <android/hardware/camera/common/1.0/types.h>
#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
+#include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
//#include <android/hardware/camera/provider/2.4/ICameraProviderCallbacks.h>
#include <android/hidl/manager/1.0/IServiceNotification.h>
#include <camera/VendorTagDescriptor.h>
@@ -166,6 +167,13 @@
CameraMetadata* characteristics) const;
/**
+ * Check for device support of specific stream combination.
+ */
+ status_t isSessionConfigurationSupported(const std::string& id,
+ const hardware::camera::device::V3_4::StreamConfiguration &configuration,
+ bool *status /*out*/) const;
+
+ /**
* Return the highest supported device interface version for this ID
*/
status_t getHighestSupportedVersion(const std::string &id,
@@ -315,6 +323,13 @@
return INVALID_OPERATION;
}
+ virtual status_t isSessionConfigurationSupported(
+ const hardware::camera::device::V3_4::StreamConfiguration &/*configuration*/,
+ bool * /*status*/)
+ const {
+ return INVALID_OPERATION;
+ }
+
DeviceInfo(const std::string& name, const metadata_vendor_id_t tagId,
const std::string &id, const hardware::hidl_version& version,
const std::vector<std::string>& publicCameraIds,
@@ -375,6 +390,10 @@
CameraMetadata *characteristics) const override;
virtual status_t getPhysicalCameraCharacteristics(const std::string& physicalCameraId,
CameraMetadata *characteristics) const override;
+ virtual status_t isSessionConfigurationSupported(
+ const hardware::camera::device::V3_4::StreamConfiguration &configuration,
+ bool *status /*out*/)
+ const override;
DeviceInfo3(const std::string& name, const metadata_vendor_id_t tagId,
const std::string &id, uint16_t minorVersion,
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 35b9d6d..c11a6f8 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -194,6 +194,28 @@
*/
status_t dropStreamBuffers(bool dropping, int streamId) override;
+ /**
+ * Helper functions to map between framework and HIDL values
+ */
+ static hardware::graphics::common::V1_0::PixelFormat mapToPixelFormat(int frameworkFormat);
+ static hardware::camera::device::V3_2::DataspaceFlags mapToHidlDataspace(
+ android_dataspace dataSpace);
+ static hardware::camera::device::V3_2::BufferUsageFlags mapToConsumerUsage(uint64_t usage);
+ static hardware::camera::device::V3_2::StreamRotation mapToStreamRotation(
+ camera3_stream_rotation_t rotation);
+ // Returns a negative error code if the passed-in operation mode is not valid.
+ static status_t mapToStreamConfigurationMode(camera3_stream_configuration_mode_t operationMode,
+ /*out*/ hardware::camera::device::V3_2::StreamConfigurationMode *mode);
+ static camera3_buffer_status_t mapHidlBufferStatus(
+ hardware::camera::device::V3_2::BufferStatus status);
+ static int mapToFrameworkFormat(hardware::graphics::common::V1_0::PixelFormat pixelFormat);
+ static android_dataspace mapToFrameworkDataspace(
+ hardware::camera::device::V3_2::DataspaceFlags);
+ static uint64_t mapConsumerToFrameworkUsage(
+ hardware::camera::device::V3_2::BufferUsageFlags usage);
+ static uint64_t mapProducerToFrameworkUsage(
+ hardware::camera::device::V3_2::BufferUsageFlags usage);
+
private:
status_t disconnectImpl();
@@ -676,27 +698,6 @@
*/
static nsecs_t getMonoToBoottimeOffset();
- /**
- * Helper functions to map between framework and HIDL values
- */
- static hardware::graphics::common::V1_0::PixelFormat mapToPixelFormat(int frameworkFormat);
- static hardware::camera::device::V3_2::DataspaceFlags mapToHidlDataspace(
- android_dataspace dataSpace);
- static hardware::camera::device::V3_2::BufferUsageFlags mapToConsumerUsage(uint64_t usage);
- static hardware::camera::device::V3_2::StreamRotation mapToStreamRotation(
- camera3_stream_rotation_t rotation);
- // Returns a negative error code if the passed-in operation mode is not valid.
- static status_t mapToStreamConfigurationMode(camera3_stream_configuration_mode_t operationMode,
- /*out*/ hardware::camera::device::V3_2::StreamConfigurationMode *mode);
- static camera3_buffer_status_t mapHidlBufferStatus(hardware::camera::device::V3_2::BufferStatus status);
- static int mapToFrameworkFormat(hardware::graphics::common::V1_0::PixelFormat pixelFormat);
- static android_dataspace mapToFrameworkDataspace(
- hardware::camera::device::V3_2::DataspaceFlags);
- static uint64_t mapConsumerToFrameworkUsage(
- hardware::camera::device::V3_2::BufferUsageFlags usage);
- static uint64_t mapProducerToFrameworkUsage(
- hardware::camera::device::V3_2::BufferUsageFlags usage);
-
struct RequestTrigger {
// Metadata tag number, e.g. android.control.aePrecaptureTrigger
uint32_t metadataTag;
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
index 219cc24..8cd575d 100644
--- a/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3OutputStream.cpp
@@ -663,12 +663,11 @@
return res;
}
-status_t Camera3OutputStream::getEndpointUsageForSurface(uint64_t *usage,
- const sp<Surface>& surface) const {
- status_t res;
- uint64_t u = 0;
+void Camera3OutputStream::applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/) {
+ if (consumerUsage == nullptr) {
+ return;
+ }
- res = native_window_get_consumer_usage(static_cast<ANativeWindow*>(surface.get()), &u);
// If an opaque output stream's endpoint is ImageReader, add
// GRALLOC_USAGE_HW_CAMERA_ZSL to the usage so HAL knows it will be used
// for the ZSL use case.
@@ -677,12 +676,20 @@
// 2. GRALLOC_USAGE_HW_RENDER
// 3. GRALLOC_USAGE_HW_COMPOSER
// 4. GRALLOC_USAGE_HW_VIDEO_ENCODER
- if (camera3_stream::format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED &&
- (u & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
+ if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED &&
+ (*consumerUsage & (GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_HW_RENDER |
GRALLOC_USAGE_HW_COMPOSER | GRALLOC_USAGE_HW_VIDEO_ENCODER)) == 0) {
- u |= GRALLOC_USAGE_HW_CAMERA_ZSL;
+ *consumerUsage |= GRALLOC_USAGE_HW_CAMERA_ZSL;
}
+}
+status_t Camera3OutputStream::getEndpointUsageForSurface(uint64_t *usage,
+ const sp<Surface>& surface) const {
+ status_t res;
+ uint64_t u = 0;
+
+ res = native_window_get_consumer_usage(static_cast<ANativeWindow*>(surface.get()), &u);
+ applyZSLUsageQuirk(camera3_stream::format, &u);
*usage = u;
return res;
}
diff --git a/services/camera/libcameraservice/device3/Camera3OutputStream.h b/services/camera/libcameraservice/device3/Camera3OutputStream.h
index 410905d..2128da2 100644
--- a/services/camera/libcameraservice/device3/Camera3OutputStream.h
+++ b/services/camera/libcameraservice/device3/Camera3OutputStream.h
@@ -201,6 +201,11 @@
const std::vector<size_t> &removedSurfaceIds,
KeyedVector<sp<Surface>, size_t> *outputMap/*out*/);
+ /**
+ * Apply ZSL related consumer usage quirk.
+ */
+ static void applyZSLUsageQuirk(int format, uint64_t *consumerUsage /*inout*/);
+
protected:
Camera3OutputStream(int id, camera3_stream_type_t type,
uint32_t width, uint32_t height, int format,
diff --git a/services/camera/libcameraservice/tests/Android.mk b/services/camera/libcameraservice/tests/Android.mk
index 8d80ff1..ad9963a 100644
--- a/services/camera/libcameraservice/tests/Android.mk
+++ b/services/camera/libcameraservice/tests/Android.mk
@@ -30,7 +30,8 @@
android.hardware.camera.common@1.0 \
android.hardware.camera.provider@2.4 \
android.hardware.camera.device@1.0 \
- android.hardware.camera.device@3.2
+ android.hardware.camera.device@3.2 \
+ android.hardware.camera.device@3.4
LOCAL_C_INCLUDES += \
system/media/private/camera/include \