Camera: Add support for single plane stride queries
Allow buffer mapper clients to query the current buffer
stride of the first plane.
Bug: 188992806
Test: Camera CTS
Change-Id: I503ad8ae2e144405f0f365636210275f8e56ae82
diff --git a/camera/common/1.0/default/HandleImporter.cpp b/camera/common/1.0/default/HandleImporter.cpp
index 05a552c..7fcf523 100644
--- a/camera/common/1.0/default/HandleImporter.cpp
+++ b/camera/common/1.0/default/HandleImporter.cpp
@@ -123,6 +123,24 @@
return layout;
}
+std::vector<PlaneLayout> getPlaneLayouts(const sp<IMapperV4> mapper, buffer_handle_t& buf) {
+ auto buffer = const_cast<native_handle_t*>(buf);
+ std::vector<PlaneLayout> planeLayouts;
+ hidl_vec<uint8_t> encodedPlaneLayouts;
+ mapper->get(buffer, gralloc4::MetadataType_PlaneLayouts,
+ [&](const auto& tmpError, const auto& tmpEncodedPlaneLayouts) {
+ if (tmpError == MapperErrorV4::NONE) {
+ encodedPlaneLayouts = tmpEncodedPlaneLayouts;
+ } else {
+ ALOGE("%s: failed to get plane layouts %d!", __FUNCTION__, tmpError);
+ }
+ });
+
+ gralloc4::decodePlaneLayouts(encodedPlaneLayouts, &planeLayouts);
+
+ return planeLayouts;
+}
+
template <>
YCbCrLayout HandleImporter::lockYCbCrInternal<IMapperV4, MapperErrorV4>(
const sp<IMapperV4> mapper, buffer_handle_t& buf, uint64_t cpuUsage,
@@ -147,19 +165,7 @@
return layout;
}
- hidl_vec<uint8_t> encodedPlaneLayouts;
- mapper->get(buffer, gralloc4::MetadataType_PlaneLayouts,
- [&](const auto& tmpError, const auto& tmpEncodedPlaneLayouts) {
- if (tmpError == MapperErrorV4::NONE) {
- encodedPlaneLayouts = tmpEncodedPlaneLayouts;
- } else {
- ALOGE("%s: failed to get plane layouts %d!", __FUNCTION__, tmpError);
- }
- });
-
- std::vector<PlaneLayout> planeLayouts;
- gralloc4::decodePlaneLayouts(encodedPlaneLayouts, &planeLayouts);
-
+ std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mapper, buf);
for (const auto& planeLayout : planeLayouts) {
for (const auto& planeLayoutComponent : planeLayout.components) {
const auto& type = planeLayoutComponent.type;
@@ -401,6 +407,33 @@
return {};
}
+status_t HandleImporter::getMonoPlanarStrideBytes(buffer_handle_t &buf, uint32_t *stride /*out*/) {
+ if (stride == nullptr) {
+ return BAD_VALUE;
+ }
+
+ Mutex::Autolock lock(mLock);
+
+ if (!mInitialized) {
+ initializeLocked();
+ }
+
+ if (mMapperV4 != nullptr) {
+ std::vector<PlaneLayout> planeLayouts = getPlaneLayouts(mMapperV4, buf);
+ if (planeLayouts.size() != 1) {
+ ALOGE("%s: Unexpected number of planes %zu!", __FUNCTION__, planeLayouts.size());
+ return BAD_VALUE;
+ }
+
+ *stride = planeLayouts[0].strideInBytes;
+ } else {
+ ALOGE("%s: mMapperV4 is null! Query not supported!", __FUNCTION__);
+ return NO_INIT;
+ }
+
+ return OK;
+}
+
int HandleImporter::unlock(buffer_handle_t& buf) {
if (mMapperV4 != nullptr) {
return unlockInternal<IMapperV4, MapperErrorV4>(mMapperV4, buf);
diff --git a/camera/common/1.0/default/include/HandleImporter.h b/camera/common/1.0/default/include/HandleImporter.h
index edc97ad..e404439 100644
--- a/camera/common/1.0/default/include/HandleImporter.h
+++ b/camera/common/1.0/default/include/HandleImporter.h
@@ -56,6 +56,9 @@
YCbCrLayout lockYCbCr(buffer_handle_t& buf, uint64_t cpuUsage,
const IMapper::Rect& accessRegion);
+ // Query the stride of the first plane in bytes.
+ status_t getMonoPlanarStrideBytes(buffer_handle_t& buf, uint32_t* stride /*out*/);
+
int unlock(buffer_handle_t& buf); // returns release fence
private: