Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9e21e0f7 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Add physical camera crop metadata tag

Allow CameraHal implementations to report the physical
camera source crop.
Additionally extend the capture results with
intra-frame lens intrinsics samples.

Bug: 297083874
Test: atest VtsAidlHalCameraProvider_TargetTest
Change-Id: Ib2ad0a3b8f51813dc1aaa52f110a2946ab8787ce
parent 7d937140
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -283,6 +283,8 @@ enum CameraMetadataTag {
  ANDROID_STATISTICS_OIS_TIMESTAMPS,
  ANDROID_STATISTICS_OIS_X_SHIFTS,
  ANDROID_STATISTICS_OIS_Y_SHIFTS,
  ANDROID_STATISTICS_LENS_INTRINSIC_TIMESTAMPS,
  ANDROID_STATISTICS_LENS_INTRINSIC_SAMPLES,
  ANDROID_STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES = android.hardware.camera.metadata.CameraMetadataSectionStart.ANDROID_STATISTICS_INFO_START /* 1179648 */,
  ANDROID_STATISTICS_INFO_HISTOGRAM_BUCKET_COUNT,
  ANDROID_STATISTICS_INFO_MAX_FACE_COUNT,
@@ -329,6 +331,7 @@ enum CameraMetadataTag {
  ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS = android.hardware.camera.metadata.CameraMetadataSectionStart.ANDROID_LOGICAL_MULTI_CAMERA_START /* 1703936 */,
  ANDROID_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE,
  ANDROID_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID,
  ANDROID_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_SENSOR_CROP_REGION,
  ANDROID_DISTORTION_CORRECTION_MODE = android.hardware.camera.metadata.CameraMetadataSectionStart.ANDROID_DISTORTION_CORRECTION_START /* 1769472 */,
  ANDROID_DISTORTION_CORRECTION_AVAILABLE_MODES,
  ANDROID_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS = android.hardware.camera.metadata.CameraMetadataSectionStart.ANDROID_HEIC_START /* 1835008 */,
+19 −0
Original line number Diff line number Diff line
@@ -1867,6 +1867,18 @@ enum CameraMetadataTag {
     * <p>An array of shifts of OIS samples, in y direction.</p>
     */
    ANDROID_STATISTICS_OIS_Y_SHIFTS,
    /**
     * android.statistics.lensIntrinsicTimestamps [dynamic, int64[], ndk_public]
     *
     * <p>An array of timestamps of lens intrinsics samples, in nanoseconds.</p>
     */
    ANDROID_STATISTICS_LENS_INTRINSIC_TIMESTAMPS,
    /**
     * android.statistics.lensIntrinsicSamples [dynamic, float[], ndk_public]
     *
     * <p>An array of intra-frame lens intrinsics.</p>
     */
    ANDROID_STATISTICS_LENS_INTRINSIC_SAMPLES,
    /**
     * android.statistics.info.availableFaceDetectModes [static, byte[], public]
     *
@@ -2240,6 +2252,13 @@ enum CameraMetadataTag {
     * <p>String containing the ID of the underlying active physical camera.</p>
     */
    ANDROID_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID,
    /**
     * android.logicalMultiCamera.activePhysicalSensorCropRegion [dynamic, int32[], public]
     *
     * <p>The current region of the active physical sensor that will be read out for this
     * capture.</p>
     */
    ANDROID_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_SENSOR_CROP_REGION,
    /**
     * android.distortionCorrection.mode [dynamic, enum, public]
     *
+36 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include <aidlcommonsupport/NativeHandle.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
#include <com_android_internal_camera_flags.h>
#include <device_cb.h>
#include <empty_device_cb.h>
#include <grallocusage/GrallocUsageConversion.h>
@@ -39,6 +40,7 @@
#include <ui/GraphicBufferAllocator.h>
#include <regex>
#include <typeinfo>
#include "utils/Errors.h"

using ::aidl::android::hardware::camera::common::CameraDeviceStatus;
using ::aidl::android::hardware::camera::common::TorchModeStatus;
@@ -101,6 +103,8 @@ bool parseProviderName(const std::string& serviceDescriptor, std::string* type /
    return true;
}

namespace flags = com::android::internal::camera::flags;

const std::vector<int64_t> kMandatoryUseCases = {
        ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT,
        ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW,
@@ -478,6 +482,38 @@ void CameraAidlTest::verifyLogicalCameraResult(const camera_metadata_t* staticMe
    } else {
        ADD_FAILURE() << "Get LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID failed!";
    }

    if (flags::concert_mode()) {
        auto ret = find_camera_metadata_ro_entry(
                metadata, ANDROID_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_SENSOR_CROP_REGION, &entry);
        if ((ret == android::OK) && (entry.count > 0)) {
            ASSERT_TRUE(entry.count == 4);
            ASSERT_GE(entry.data.i32[0], 0);  // Top must be non-negative
            ASSERT_GE(entry.data.i32[1], 0);  // Left must be non-negative
            ASSERT_GT(entry.data.i32[2], 0);  // Width must be positive
            ASSERT_GT(entry.data.i32[3], 0);  // Height must be positive
        }
    }
}

void CameraAidlTest::verifyLensIntrinsicsResult(const std::vector<uint8_t>& resultMetadata) {
    if (flags::concert_mode()) {
        camera_metadata_t* metadata = (camera_metadata_t*)resultMetadata.data();

        camera_metadata_ro_entry timestampsEntry, intrinsicsEntry;
        auto tsRet = find_camera_metadata_ro_entry(
                metadata, ANDROID_STATISTICS_LENS_INTRINSIC_TIMESTAMPS, &timestampsEntry);
        auto inRet = find_camera_metadata_ro_entry(
                metadata, ANDROID_STATISTICS_LENS_INTRINSIC_SAMPLES, &intrinsicsEntry);
        ASSERT_EQ(tsRet, inRet);
        ASSERT_TRUE((intrinsicsEntry.count % 5) == 0);
        ASSERT_EQ(timestampsEntry.count, intrinsicsEntry.count / 5);
        if (timestampsEntry.count > 0) {
            for (size_t i = 0; i < timestampsEntry.count - 1; i++) {
                ASSERT_GE(timestampsEntry.data.i64[i + 1], timestampsEntry.data.i64[i]);
            }
        }
    }
}

Status CameraAidlTest::getPhysicalCameraIds(const camera_metadata_t* staticMeta,
+2 −0
Original line number Diff line number Diff line
@@ -279,6 +279,8 @@ class CameraAidlTest : public ::testing::TestWithParam<std::string> {
    static void verifyLogicalCameraResult(const camera_metadata_t* staticMetadata,
                                          const std::vector<uint8_t>& resultMetadata);

    static void verifyLensIntrinsicsResult(const std::vector<uint8_t>& resultMetadata);

    static void verifyBuffersReturned(const std::shared_ptr<ICameraDeviceSession>& session,
                                      int32_t streamId, const std::shared_ptr<DeviceCb>& cb,
                                      uint32_t streamConfigCounter = 0);
+7 −6
Original line number Diff line number Diff line
@@ -388,15 +388,16 @@ bool DeviceCb::processCaptureResultLocked(
        // Verify logical camera result metadata
        bool isLogicalCamera =
                Status::OK == CameraAidlTest::isLogicalMultiCamera(staticMetadataBuffer);
        if (isLogicalCamera) {
        camera_metadata_t* collectedMetadata =
                const_cast<camera_metadata_t*>(request->collectedResult.getAndLock());
        uint8_t* rawMetadata = reinterpret_cast<uint8_t*>(collectedMetadata);
            std::vector metadata = std::vector(
                    rawMetadata, rawMetadata + get_camera_metadata_size(collectedMetadata));
        std::vector metadata =
                std::vector(rawMetadata, rawMetadata + get_camera_metadata_size(collectedMetadata));
        if (isLogicalCamera) {
            CameraAidlTest::verifyLogicalCameraResult(staticMetadataBuffer, metadata);
            request->collectedResult.unlock(collectedMetadata);
        }
        CameraAidlTest::verifyLensIntrinsicsResult(metadata);
        request->collectedResult.unlock(collectedMetadata);
    }

    uint32_t numBuffersReturned = results.outputBuffers.size();