CameraService: Implement SCALER_ROTATE_AND_CROP_AUTO, part 1
When an app sets SCALER_ROTATE_AND_CROP to AUTO, the camera service
needs to select the right ROTATE_AND_CROP mode given the application
UI state at the moment, received from the window manager.
In addition, some of the metadata in the active array coordinate
system needs to be converted to/from the cropped+rotated coordinate
system to ensure roundtripping UI information works as before.
Also ensure that the available rotate and crop metadata field is
always available, with a value of NONE if nothing else.
This commit adds support for doing the coordinate transforms and
overriding AUTO to a concrete value; it does not wire up a connection
to another system service to receive the correct override value, but
does add a command to set the override value for all current camera
clients.
Test: New CTS tests pass, unit tests for RotateAndCropMapper pass
Bug: 134631897
Change-Id: Icc45530e2cfbaf838a1e4d04e4fd2aef8122e8e1
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 23e26ce..d38bfee 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -351,6 +351,10 @@
mZoomRatioMappers[mId.c_str()] = ZoomRatioMapper(&mDeviceInfo,
mSupportNativeZoomRatio, usePrecorrectArray);
+ if (RotateAndCropMapper::isNeeded(&mDeviceInfo)) {
+ mRotateAndCropMappers.emplace(mId.c_str(), &mDeviceInfo);
+ }
+
return OK;
}
@@ -881,17 +885,12 @@
// Setup burst Id and request Id
newRequest->mResultExtras.burstId = burstId++;
- if (metadataIt->begin()->metadata.exists(ANDROID_REQUEST_ID)) {
- if (metadataIt->begin()->metadata.find(ANDROID_REQUEST_ID).count == 0) {
- CLOGE("RequestID entry exists; but must not be empty in metadata");
- return BAD_VALUE;
- }
- newRequest->mResultExtras.requestId = metadataIt->begin()->metadata.find(
- ANDROID_REQUEST_ID).data.i32[0];
- } else {
+ auto requestIdEntry = metadataIt->begin()->metadata.find(ANDROID_REQUEST_ID);
+ if (requestIdEntry.count == 0) {
CLOGE("RequestID does not exist in metadata");
return BAD_VALUE;
}
+ newRequest->mResultExtras.requestId = requestIdEntry.data.i32[0];
requestList->push_back(newRequest);
@@ -1049,8 +1048,8 @@
mNextReprocessResultFrameNumber, mNextZslStillResultFrameNumber,
mUseHalBufManager, mUsePartialResult, mNeedFixupMonochromeTags,
mNumPartialResults, mVendorTagId, mDeviceInfo, mPhysicalDeviceInfoMap,
- mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mTagMonitor,
- mInputStream, mOutputStreams, listener, *this, *this, *mInterface
+ mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mRotateAndCropMappers,
+ mTagMonitor, mInputStream, mOutputStreams, listener, *this, *this, *mInterface
};
for (const auto& result : results) {
@@ -1106,8 +1105,8 @@
mNextReprocessResultFrameNumber, mNextZslStillResultFrameNumber,
mUseHalBufManager, mUsePartialResult, mNeedFixupMonochromeTags,
mNumPartialResults, mVendorTagId, mDeviceInfo, mPhysicalDeviceInfoMap,
- mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mTagMonitor,
- mInputStream, mOutputStreams, listener, *this, *this, *mInterface
+ mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mRotateAndCropMappers,
+ mTagMonitor, mInputStream, mOutputStreams, listener, *this, *this, *mInterface
};
for (const auto& result : results) {
@@ -1145,8 +1144,8 @@
mNextReprocessResultFrameNumber, mNextZslStillResultFrameNumber,
mUseHalBufManager, mUsePartialResult, mNeedFixupMonochromeTags,
mNumPartialResults, mVendorTagId, mDeviceInfo, mPhysicalDeviceInfoMap,
- mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mTagMonitor,
- mInputStream, mOutputStreams, listener, *this, *this, *mInterface
+ mResultMetadataQueue, mDistortionMappers, mZoomRatioMappers, mRotateAndCropMappers,
+ mTagMonitor, mInputStream, mOutputStreams, listener, *this, *this, *mInterface
};
for (const auto& msg : msgs) {
camera3::notify(states, msg);
@@ -2222,7 +2221,7 @@
const PhysicalCameraSettingsList &request, const SurfaceMap &surfaceMap) {
ATRACE_CALL();
- sp<CaptureRequest> newRequest = new CaptureRequest;
+ sp<CaptureRequest> newRequest = new CaptureRequest();
newRequest->mSettingsList = request;
camera_metadata_entry_t inputStreams =
@@ -2293,6 +2292,15 @@
newRequest->mSettingsList.begin()->metadata.erase(ANDROID_REQUEST_OUTPUT_STREAMS);
newRequest->mBatchSize = 1;
+ auto rotateAndCropEntry =
+ newRequest->mSettingsList.begin()->metadata.find(ANDROID_SCALER_ROTATE_AND_CROP);
+ if (rotateAndCropEntry.count > 0 &&
+ rotateAndCropEntry.data.u8[0] == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
+ newRequest->mRotateAndCropAuto = true;
+ } else {
+ newRequest->mRotateAndCropAuto = false;
+ }
+
return newRequest;
}
@@ -2730,7 +2738,7 @@
int32_t numBuffers, CaptureResultExtras resultExtras, bool hasInput,
bool hasAppCallback, nsecs_t maxExpectedDuration,
std::set<String8>& physicalCameraIds, bool isStillCapture,
- bool isZslCapture, const std::set<std::string>& cameraIdsWithZoom,
+ bool isZslCapture, bool rotateAndCropAuto, const std::set<std::string>& cameraIdsWithZoom,
const SurfaceMap& outputSurfaces) {
ATRACE_CALL();
std::lock_guard<std::mutex> l(mInFlightLock);
@@ -2738,7 +2746,7 @@
ssize_t res;
res = mInFlightMap.add(frameNumber, InFlightRequest(numBuffers, resultExtras, hasInput,
hasAppCallback, maxExpectedDuration, physicalCameraIds, isStillCapture, isZslCapture,
- cameraIdsWithZoom, outputSurfaces));
+ rotateAndCropAuto, cameraIdsWithZoom, outputSurfaces));
if (res < 0) return res;
if (mInFlightMap.size() == 1) {
@@ -3725,6 +3733,7 @@
mLatestRequestId(NAME_NOT_FOUND),
mCurrentAfTriggerId(0),
mCurrentPreCaptureTriggerId(0),
+ mRotateAndCropOverride(ANDROID_SCALER_ROTATE_AND_CROP_NONE),
mRepeatingLastFrameNumber(
hardware::camera2::ICameraDeviceUser::NO_IN_FLIGHT_REPEATING_FRAMES),
mPrepareVideoStream(false),
@@ -4358,8 +4367,11 @@
bool triggersMixedIn = (triggerCount > 0 || mPrevTriggers > 0);
mPrevTriggers = triggerCount;
+ bool rotateAndCropChanged = overrideAutoRotateAndCrop(captureRequest);
+
// If the request is the same as last, or we had triggers last time
- bool newRequest = (mPrevRequest != captureRequest || triggersMixedIn) &&
+ bool newRequest =
+ (mPrevRequest != captureRequest || triggersMixedIn || rotateAndCropChanged) &&
// Request settings are all the same within one batch, so only treat the first
// request in a batch as new
!(batchedRequest && i > 0);
@@ -4419,6 +4431,21 @@
return INVALID_OPERATION;
}
}
+ if (captureRequest->mRotateAndCropAuto) {
+ for (it = captureRequest->mSettingsList.begin();
+ it != captureRequest->mSettingsList.end(); it++) {
+ auto mapper = parent->mRotateAndCropMappers.find(it->cameraId);
+ if (mapper != parent->mRotateAndCropMappers.end()) {
+ res = mapper->second.updateCaptureRequest(&(it->metadata));
+ if (res != OK) {
+ SET_ERR("RequestThread: Unable to correct capture requests "
+ "for rotate-and-crop for request %d: %s (%d)",
+ halRequest->frame_number, strerror(-res), res);
+ return INVALID_OPERATION;
+ }
+ }
+ }
+ }
}
}
@@ -4617,7 +4644,8 @@
/*hasInput*/halRequest->input_buffer != NULL,
hasCallback,
calculateMaxExpectedDuration(halRequest->settings),
- requestedPhysicalCameras, isStillCapture, isZslCapture, mPrevCameraIdsWithZoom,
+ requestedPhysicalCameras, isStillCapture, isZslCapture,
+ captureRequest->mRotateAndCropAuto, mPrevCameraIdsWithZoom,
(mUseHalBufManager) ? uniqueSurfaceIdMap :
SurfaceMap{});
ALOGVV("%s: registered in flight requestId = %" PRId32 ", frameNumber = %" PRId64
@@ -4763,6 +4791,17 @@
streamsToKeep, offlineSessionInfo, offlineSession, bufferRecords);
}
+status_t Camera3Device::RequestThread::setRotateAndCropAutoBehavior(
+ camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue) {
+ ATRACE_CALL();
+ Mutex::Autolock l(mTriggerMutex);
+ if (rotateAndCropValue == ANDROID_SCALER_ROTATE_AND_CROP_AUTO) {
+ return BAD_VALUE;
+ }
+ mRotateAndCropOverride = rotateAndCropValue;
+ return OK;
+}
+
nsecs_t Camera3Device::getExpectedInFlightDuration() {
ATRACE_CALL();
std::lock_guard<std::mutex> l(mInFlightLock);
@@ -5278,6 +5317,32 @@
return OK;
}
+bool Camera3Device::RequestThread::overrideAutoRotateAndCrop(
+ const sp<CaptureRequest> &request) {
+ ATRACE_CALL();
+
+ if (request->mRotateAndCropAuto) {
+ Mutex::Autolock l(mTriggerMutex);
+ CameraMetadata &metadata = request->mSettingsList.begin()->metadata;
+
+ auto rotateAndCropEntry = metadata.find(ANDROID_SCALER_ROTATE_AND_CROP);
+ if (rotateAndCropEntry.count > 0) {
+ if (rotateAndCropEntry.data.u8[0] == mRotateAndCropOverride) {
+ return false;
+ } else {
+ rotateAndCropEntry.data.u8[0] = mRotateAndCropOverride;
+ return true;
+ }
+ } else {
+ uint8_t rotateAndCrop_u8 = mRotateAndCropOverride;
+ metadata.update(ANDROID_SCALER_ROTATE_AND_CROP,
+ &rotateAndCrop_u8, 1);
+ return true;
+ }
+ }
+ return false;
+}
+
/**
* PreparerThread inner class methods
*/
@@ -5813,7 +5878,7 @@
mNextReprocessResultFrameNumber, mNextZslStillResultFrameNumber,
mNextShutterFrameNumber, mNextReprocessShutterFrameNumber,
mNextZslStillShutterFrameNumber, mDeviceInfo, mPhysicalDeviceInfoMap,
- mDistortionMappers, mZoomRatioMappers);
+ mDistortionMappers, mZoomRatioMappers, mRotateAndCropMappers);
*session = new Camera3OfflineSession(mId, inputStream, offlineStreamSet,
std::move(bufferRecords), offlineReqs, offlineStates, offlineSession);
@@ -5889,4 +5954,15 @@
}
}
+status_t Camera3Device::setRotateAndCropAutoBehavior(
+ camera_metadata_enum_android_scaler_rotate_and_crop_t rotateAndCropValue) {
+ ATRACE_CALL();
+ Mutex::Autolock il(mInterfaceLock);
+ Mutex::Autolock l(mLock);
+ if (mRequestThread == nullptr) {
+ return INVALID_OPERATION;
+ }
+ return mRequestThread->setRotateAndCropAutoBehavior(rotateAndCropValue);
+}
+
}; // namespace android