cameraservice: Allow AIDL Devices to not support sensor readout timestamp
CameraService currently force adds
ANDROID_SENSOR_READOUT_TIMESTAMP_HARDWARE to all AIDL devices. This
effectively means all Camera HALs implementing the AIDL interfaces
are forced to support sensor timestamp.
Forcing AIDL HALs to support sensor readout timestamp means HALs will
have to fake sensor readout value if the camera sensor does not report
sensor readout timestamp (for example in the case of ExternalCameraHAL).
This CL allows AIDL HALs to not support sensor readout timestamp.
Bug: 309543399
Test: ReadoutTimestampTest#testReadoutTimestamp passes for
ExternalCameraHAL
Test: atest CtsCameraTestCases:android.hardware.camera2.cts.ReadoutTimestampTest
passes for normal AIDL HALs when the value is not explicitly set.
Change-Id: Iecf84372f2f6e2812d9c148a94b15eed01917fb1
diff --git a/services/camera/libcameraservice/Android.bp b/services/camera/libcameraservice/Android.bp
index 4883a09..b2a8121 100644
--- a/services/camera/libcameraservice/Android.bp
+++ b/services/camera/libcameraservice/Android.bp
@@ -101,7 +101,7 @@
"android.frameworks.cameraservice.device-V2-ndk",
"android.hardware.camera.common-V1-ndk",
"android.hardware.camera.device-V3-ndk",
- "android.hardware.camera.metadata-V2-ndk",
+ "android.hardware.camera.metadata-V3-ndk",
"android.hardware.camera.provider@2.4",
"android.hardware.camera.provider@2.5",
"android.hardware.camera.provider@2.6",
diff --git a/services/camera/libcameraservice/common/CameraProviderManager.cpp b/services/camera/libcameraservice/common/CameraProviderManager.cpp
index 1ba3de4..d5eb413 100644
--- a/services/camera/libcameraservice/common/CameraProviderManager.cpp
+++ b/services/camera/libcameraservice/common/CameraProviderManager.cpp
@@ -1807,18 +1807,13 @@
auto& c = mCameraCharacteristics;
auto entry = c.find(ANDROID_SENSOR_READOUT_TIMESTAMP);
- if (entry.count != 0) {
- ALOGE("%s: CameraCharacteristics must not contain ANDROID_SENSOR_READOUT_TIMESTAMP!",
- __FUNCTION__);
+ if (entry.count == 0) {
+ uint8_t defaultReadoutTimestamp = readoutTimestampSupported ?
+ ANDROID_SENSOR_READOUT_TIMESTAMP_HARDWARE :
+ ANDROID_SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED;
+ res = c.update(ANDROID_SENSOR_READOUT_TIMESTAMP, &defaultReadoutTimestamp, 1);
}
- uint8_t readoutTimestamp = ANDROID_SENSOR_READOUT_TIMESTAMP_NOT_SUPPORTED;
- if (readoutTimestampSupported) {
- readoutTimestamp = ANDROID_SENSOR_READOUT_TIMESTAMP_HARDWARE;
- }
-
- res = c.update(ANDROID_SENSOR_READOUT_TIMESTAMP, &readoutTimestamp, 1);
-
return res;
}
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.cpp b/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.cpp
index 97475f0..2ce4a07 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.cpp
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.cpp
@@ -337,6 +337,16 @@
mBatchSizeLimitEnabled = (deviceVersion >= CAMERA_DEVICE_API_VERSION_1_2);
+ camera_metadata_entry readoutSupported = mDeviceInfo.find(ANDROID_SENSOR_READOUT_TIMESTAMP);
+ if (readoutSupported.count == 0) {
+ ALOGW("%s: Could not find value corresponding to ANDROID_SENSOR_READOUT_TIMESTAMP. "
+ "Assuming true.", __FUNCTION__);
+ mSensorReadoutTimestampSupported = true;
+ } else {
+ mSensorReadoutTimestampSupported =
+ readoutSupported.data.u8[0] == ANDROID_SENSOR_READOUT_TIMESTAMP_HARDWARE;
+ }
+
return initializeCommonLocked();
}
@@ -450,7 +460,7 @@
mOverrideToPortrait, mActivePhysicalId}, mResultMetadataQueue
};
for (const auto& msg : msgs) {
- camera3::notify(states, msg);
+ camera3::notify(states, msg, mSensorReadoutTimestampSupported);
}
return ::ndk::ScopedAStatus::ok();
@@ -621,7 +631,8 @@
mZoomRatioMappers, mRotateAndCropMappers);
*session = new AidlCamera3OfflineSession(mId, inputStream, offlineStreamSet,
- std::move(bufferRecords), offlineReqs, offlineStates, offlineSession);
+ std::move(bufferRecords), offlineReqs, offlineStates,
+ offlineSession, mSensorReadoutTimestampSupported);
// Delete all streams that has been transferred to offline session
Mutex::Autolock l(mLock);
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.h b/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.h
index 90e2f97..f0a5f7e 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.h
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3Device.h
@@ -289,6 +289,9 @@
// capture requests.
bool mBatchSizeLimitEnabled = false;
+ // Whether the HAL supports reporting sensor readout timestamp
+ bool mSensorReadoutTimestampSupported = true;
+
}; // class AidlCamera3Device
}; // namespace android
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.cpp b/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.cpp
index 01c4e88..6243712 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.cpp
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.cpp
@@ -177,7 +177,7 @@
/*overrideToPortrait*/false, activePhysicalId}, mResultMetadataQueue
};
for (const auto& msg : msgs) {
- camera3::notify(states, msg);
+ camera3::notify(states, msg, mSensorReadoutTimestampSupported);
}
return ::ndk::ScopedAStatus::ok();
}
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.h b/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.h
index 33b638c..f8fdeb9 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.h
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3OfflineSession.h
@@ -105,19 +105,20 @@
};
// initialize by Camera3Device.
- explicit AidlCamera3OfflineSession(const std::string& id,
- const sp<camera3::Camera3Stream>& inputStream,
- const camera3::StreamSet& offlineStreamSet,
- camera3::BufferRecords&& bufferRecords,
+ explicit AidlCamera3OfflineSession(
+ const std::string& id, const sp<camera3::Camera3Stream>& inputStream,
+ const camera3::StreamSet& offlineStreamSet, camera3::BufferRecords&& bufferRecords,
const camera3::InFlightRequestMap& offlineReqs,
const Camera3OfflineStates& offlineStates,
std::shared_ptr<aidl::android::hardware::camera::device::ICameraOfflineSession>
- offlineSession) :
- Camera3OfflineSession(id, inputStream, offlineStreamSet, std::move(bufferRecords),
- offlineReqs, offlineStates),
- mSession(offlineSession) {
- mCallbacks = ndk::SharedRefBase::make<AidlCameraDeviceCallbacks>(this);
- };
+ offlineSession,
+ bool sensorReadoutTimestampSupported)
+ : Camera3OfflineSession(id, inputStream, offlineStreamSet, std::move(bufferRecords),
+ offlineReqs, offlineStates),
+ mSession(offlineSession),
+ mSensorReadoutTimestampSupported(sensorReadoutTimestampSupported) {
+ mCallbacks = ndk::SharedRefBase::make<AidlCameraDeviceCallbacks>(this);
+ };
/**
* End of CameraOfflineSessionBase interface
@@ -130,6 +131,8 @@
std::shared_ptr<AidlCameraDeviceCallbacks> mCallbacks;
+ bool mSensorReadoutTimestampSupported;
+
virtual void closeSessionLocked() override;
virtual void releaseSessionLocked() override;
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.cpp b/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.cpp
index 74d4230..c633a8e 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.cpp
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.cpp
@@ -67,7 +67,8 @@
}
void notify(CaptureOutputStates& states,
- const aidl::android::hardware::camera::device::NotifyMsg& msg) {
+ const aidl::android::hardware::camera::device::NotifyMsg& msg,
+ bool hasReadoutTimestamp) {
using ErrorCode = aidl::android::hardware::camera::device::ErrorCode;
using Tag = aidl::android::hardware::camera::device::NotifyMsg::Tag;
@@ -110,8 +111,9 @@
m.type = CAMERA_MSG_SHUTTER;
m.message.shutter.frame_number = msg.get<Tag::shutter>().frameNumber;
m.message.shutter.timestamp = msg.get<Tag::shutter>().timestamp;
- m.message.shutter.readout_timestamp_valid = true;
- m.message.shutter.readout_timestamp = msg.get<Tag::shutter>().readoutTimestamp;
+ m.message.shutter.readout_timestamp_valid = hasReadoutTimestamp;
+ m.message.shutter.readout_timestamp =
+ hasReadoutTimestamp ? msg.get<Tag::shutter>().readoutTimestamp : 0LL;
break;
}
notify(states, &m);
diff --git a/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.h b/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.h
index e795624..1e2e4d1 100644
--- a/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.h
+++ b/services/camera/libcameraservice/device3/aidl/AidlCamera3OutputUtils.h
@@ -83,7 +83,8 @@
bool hasReadoutTime, uint64_t readoutTime);
void notify(CaptureOutputStates& states,
- const aidl::android::hardware::camera::device::NotifyMsg& msg);
+ const aidl::android::hardware::camera::device::NotifyMsg& msg,
+ bool hasReadoutTimestamp);
void requestStreamBuffers(RequestBufferStates& states,
const std::vector<aidl::android::hardware::camera::device::BufferRequest>& bufReqs,