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

Commit 0d2d8a4b authored by Avichal Rakesh's avatar Avichal Rakesh
Browse files

Camera: Move common-helper target out of HIDL directory

This CL moves the common helper classes from inside the HIDL directory
and refactors the HIDL-esque namespaces to android style namespaces.

To preserve compatibility, the header files export the new symbols under
old namespace and the old build module exports symbols from the new
build module. This refactor is transparent to the codebase.

Also ran clangformat to appease the repohook gods.

Bug: 219974678
Test: Existing VTS tests pass on Cuttlefish
Change-Id: I8c3160497c1e2fe7a0a7155641f0e1f5e47ec32e
parent e1857f8d
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ package {
}

cc_library_static {
    name: "android.hardware.camera.common@1.0-helper",
    name: "android.hardware.camera.common-helper",
    vendor_available: true,
    defaults: ["hidl_defaults"],
    srcs: [
@@ -38,3 +38,11 @@ cc_library_static {
    include_dirs: ["system/media/private/camera/include"],
    export_include_dirs: ["include"],
}

// NOTE: Deprecated module kept for compatibility reasons.
// Depend on "android.hardware.camera.common-helper" instead
cc_library_static {
    name: "android.hardware.camera.common@1.0-helper",
    vendor_available: true,
    whole_static_libs: ["android.hardware.camera.common-helper"],
}
+72 −106
Original line number Diff line number Diff line
@@ -27,29 +27,21 @@ namespace android {
namespace hardware {
namespace camera {
namespace common {
namespace V1_0 {
namespace helper {

#define ALIGN_TO(val, alignment) \
    (((uintptr_t)(val) + ((alignment) - 1)) & ~((alignment) - 1))
#define ALIGN_TO(val, alignment) (((uintptr_t)(val) + ((alignment)-1)) & ~((alignment)-1))

CameraMetadata::CameraMetadata() :
        mBuffer(NULL), mLocked(false) {
}
CameraMetadata::CameraMetadata() : mBuffer(NULL), mLocked(false) {}

CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) :
        mLocked(false)
{
CameraMetadata::CameraMetadata(size_t entryCapacity, size_t dataCapacity) : mLocked(false) {
    mBuffer = allocate_camera_metadata(entryCapacity, dataCapacity);
}

CameraMetadata::CameraMetadata(const CameraMetadata &other) :
        mLocked(false) {
CameraMetadata::CameraMetadata(const CameraMetadata& other) : mLocked(false) {
    mBuffer = clone_camera_metadata(other.mBuffer);
}

CameraMetadata::CameraMetadata(camera_metadata_t *buffer) :
        mBuffer(NULL), mLocked(false) {
CameraMetadata::CameraMetadata(camera_metadata_t* buffer) : mBuffer(NULL), mLocked(false) {
    acquire(buffer);
}

@@ -87,8 +79,7 @@ status_t CameraMetadata::unlock(const camera_metadata_t *buffer) const {
        return INVALID_OPERATION;
    }
    if (buffer != mBuffer) {
        ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!",
                __FUNCTION__);
        ALOGE("%s: Can't unlock CameraMetadata with wrong pointer!", __FUNCTION__);
        return BAD_VALUE;
    }
    mLocked = false;
@@ -125,8 +116,7 @@ void CameraMetadata::acquire(camera_metadata_t *buffer) {
    mBuffer = buffer;

    ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/ NULL) != OK,
             "%s: Failed to validate metadata structure %p",
             __FUNCTION__, buffer);
             "%s: Failed to validate metadata structure %p", __FUNCTION__, buffer);
}

void CameraMetadata::acquire(CameraMetadata& other) {
@@ -154,8 +144,7 @@ status_t CameraMetadata::append(const camera_metadata_t* other) {
}

size_t CameraMetadata::entryCount() const {
    return (mBuffer == NULL) ? 0 :
            get_camera_metadata_entry_count(mBuffer);
    return (mBuffer == NULL) ? 0 : get_camera_metadata_entry_count(mBuffer);
}

bool CameraMetadata::isEmpty() const {
@@ -186,8 +175,7 @@ status_t CameraMetadata::checkType(uint32_t tag, uint8_t expectedType) {
    return OK;
}

status_t CameraMetadata::update(uint32_t tag,
        const int32_t *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const int32_t* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -199,8 +187,7 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const uint8_t *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const uint8_t* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -212,8 +199,7 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const float *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const float* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -225,8 +211,7 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const int64_t *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const int64_t* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -238,8 +223,7 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const double *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const double* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -251,8 +235,8 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const camera_metadata_rational_t *data, size_t data_count) {
status_t CameraMetadata::update(uint32_t tag, const camera_metadata_rational_t* data,
                                size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -264,8 +248,7 @@ status_t CameraMetadata::update(uint32_t tag,
    return updateImpl(tag, (const void*)data, data_count);
}

status_t CameraMetadata::update(uint32_t tag,
        const String8 &string) {
status_t CameraMetadata::update(uint32_t tag, const String8& string) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -290,8 +273,7 @@ status_t CameraMetadata::update(const camera_metadata_ro_entry &entry) {
    return updateImpl(entry.tag, (const void*)entry.data.u8, entry.count);
}

status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
        size_t data_count) {
status_t CameraMetadata::updateImpl(uint32_t tag, const void* data, size_t data_count) {
    status_t res;
    if (mLocked) {
        ALOGE("%s: CameraMetadata is locked", __FUNCTION__);
@@ -308,13 +290,11 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
    uintptr_t bufAddr = reinterpret_cast<uintptr_t>(mBuffer);
    uintptr_t dataAddr = reinterpret_cast<uintptr_t>(data);
    if (dataAddr > bufAddr && dataAddr < (bufAddr + bufferSize)) {
        ALOGE("%s: Update attempted with data from the same metadata buffer!",
                __FUNCTION__);
        ALOGE("%s: Update attempted with data from the same metadata buffer!", __FUNCTION__);
        return INVALID_OPERATION;
    }

    size_t data_size = calculate_camera_metadata_entry_data_size(type,
            data_count);
    size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count);

    res = resizeIfNeeded(1, data_size);

@@ -322,11 +302,9 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
        camera_metadata_entry_t entry;
        res = find_camera_metadata_entry(mBuffer, tag, &entry);
        if (res == NAME_NOT_FOUND) {
            res = add_camera_metadata_entry(mBuffer,
                    tag, data, data_count);
            res = add_camera_metadata_entry(mBuffer, tag, data, data_count);
        } else if (res == OK) {
            res = update_camera_metadata_entry(mBuffer,
                    entry.index, data, data_count, NULL);
            res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL);
        }
    }

@@ -337,11 +315,10 @@ status_t CameraMetadata::updateImpl(uint32_t tag, const void *data,
    }

    IF_ALOGV() {
        ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) !=
                 OK,
        ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/ NULL) != OK,

                 "%s: Failed to validate metadata structure after update %p",
                 __FUNCTION__, mBuffer);
                 "%s: Failed to validate metadata structure after update %p", __FUNCTION__,
                 mBuffer);
    }

    return res;
@@ -418,23 +395,17 @@ status_t CameraMetadata::resizeIfNeeded(size_t extraEntries, size_t extraData) {
    } else {
        size_t currentEntryCount = get_camera_metadata_entry_count(mBuffer);
        size_t currentEntryCap = get_camera_metadata_entry_capacity(mBuffer);
        size_t newEntryCount = currentEntryCount +
                extraEntries;
        newEntryCount = (newEntryCount > currentEntryCap) ?
                newEntryCount * 2 : currentEntryCap;
        size_t newEntryCount = currentEntryCount + extraEntries;
        newEntryCount = (newEntryCount > currentEntryCap) ? newEntryCount * 2 : currentEntryCap;

        size_t currentDataCount = get_camera_metadata_data_count(mBuffer);
        size_t currentDataCap = get_camera_metadata_data_capacity(mBuffer);
        size_t newDataCount = currentDataCount +
                extraData;
        newDataCount = (newDataCount > currentDataCap) ?
                newDataCount * 2 : currentDataCap;
        size_t newDataCount = currentDataCount + extraData;
        newDataCount = (newDataCount > currentDataCap) ? newDataCount * 2 : currentDataCap;

        if (newEntryCount > currentEntryCap ||
                newDataCount > currentDataCap) {
        if (newEntryCount > currentEntryCap || newDataCount > currentDataCap) {
            camera_metadata_t* oldBuffer = mBuffer;
            mBuffer = allocate_camera_metadata(newEntryCount,
                    newDataCount);
            mBuffer = allocate_camera_metadata(newEntryCount, newDataCount);
            if (mBuffer == NULL) {
                ALOGE("%s: Can't allocate larger metadata buffer", __FUNCTION__);
                return NO_MEMORY;
@@ -462,9 +433,8 @@ void CameraMetadata::swap(CameraMetadata& other) {
    mBuffer = otherBuf;
}

status_t CameraMetadata::getTagFromName(const char *name,
        const VendorTagDescriptor* vTags, uint32_t *tag) {

status_t CameraMetadata::getTagFromName(const char* name, const VendorTagDescriptor* vTags,
                                        uint32_t* tag) {
    if (name == nullptr || tag == nullptr) return BAD_VALUE;

    size_t nameLength = strlen(name);
@@ -483,9 +453,9 @@ status_t CameraMetadata::getTagFromName(const char *name,
    size_t sectionLength = 0;
    size_t totalSectionCount = ANDROID_SECTION_COUNT + vendorSectionCount;
    for (size_t i = 0; i < totalSectionCount; ++i) {

        const char *str = (i < ANDROID_SECTION_COUNT) ? camera_metadata_section_names[i] :
                (*vendorSections)[i - ANDROID_SECTION_COUNT].string();
        const char* str = (i < ANDROID_SECTION_COUNT)
                                  ? camera_metadata_section_names[i]
                                  : (*vendorSections)[i - ANDROID_SECTION_COUNT].string();

        ALOGV("%s: Trying to match against section '%s'", __FUNCTION__, str);

@@ -508,8 +478,7 @@ status_t CameraMetadata::getTagFromName(const char *name,
    if (section == NULL) {
        return NAME_NOT_FOUND;
    } else {
        ALOGV("%s: Found matched section '%s' (%zu)",
              __FUNCTION__, section, sectionIndex);
        ALOGV("%s: Found matched section '%s' (%zu)", __FUNCTION__, section, sectionIndex);
    }

    // Get the tag name component of the name
@@ -530,8 +499,7 @@ status_t CameraMetadata::getTagFromName(const char *name,
            const char* tagName = get_camera_metadata_tag_name(candidateTag);

            if (strcmp(nameTagName, tagName) == 0) {
                ALOGV("%s: Found matched tag '%s' (%d)",
                      __FUNCTION__, tagName, candidateTag);
                ALOGV("%s: Found matched tag '%s' (%d)", __FUNCTION__, tagName, candidateTag);
                break;
            }
        }
@@ -554,9 +522,7 @@ status_t CameraMetadata::getTagFromName(const char *name,
    return OK;
}


}  // namespace helper
} // namespace V1_0
}  // namespace common
}  // namespace camera
}  // namespace hardware
+55 −72
Original line number Diff line number Diff line
@@ -26,11 +26,9 @@ namespace android {
namespace hardware {
namespace camera {
namespace common {
namespace V1_0 {
namespace helper {

void CameraModule::deriveCameraCharacteristicsKeys(
        uint32_t deviceVersion, CameraMetadata &chars) {
void CameraModule::deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata& chars) {
    ATRACE_CALL();

    Vector<int32_t> derivedCharKeys;
@@ -160,10 +158,8 @@ void CameraModule::deriveCameraCharacteristicsKeys(
                rawOpaqueSizes.push(width * height * 2);
            }
            if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
                    (format == HAL_PIXEL_FORMAT_RAW16 ||
                     format == HAL_PIXEL_FORMAT_RAW10 ||
                     format == HAL_PIXEL_FORMAT_RAW12 ||
                     format == HAL_PIXEL_FORMAT_RAW_OPAQUE)) {
                (format == HAL_PIXEL_FORMAT_RAW16 || format == HAL_PIXEL_FORMAT_RAW10 ||
                 format == HAL_PIXEL_FORMAT_RAW12 || format == HAL_PIXEL_FORMAT_RAW_OPAQUE)) {
                supportAnyRaw = true;
            }
        }
@@ -183,9 +179,7 @@ void CameraModule::deriveCameraCharacteristicsKeys(
            entry = chars.find(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
            if (entry.count == 0) {
                // Fill in default value (100, 100)
                chars.update(
                        ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE,
                        defaultRange, 2);
                chars.update(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE, defaultRange, 2);
                derivedCharKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
                // Actual request/results will be derived by camera device.
                derivedRequestKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST);
@@ -197,22 +191,19 @@ void CameraModule::deriveCameraCharacteristicsKeys(
    // Add those newly added keys to AVAILABLE_CHARACTERISTICS_KEYS
    // This has to be done at this end of this function.
    if (derivedCharKeys.size() > 0) {
        appendAvailableKeys(
                chars, ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, derivedCharKeys);
        appendAvailableKeys(chars, ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, derivedCharKeys);
    }
    if (derivedRequestKeys.size() > 0) {
        appendAvailableKeys(
                chars, ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, derivedRequestKeys);
        appendAvailableKeys(chars, ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, derivedRequestKeys);
    }
    if (derivedResultKeys.size() > 0) {
        appendAvailableKeys(
                chars, ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, derivedResultKeys);
        appendAvailableKeys(chars, ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, derivedResultKeys);
    }
    return;
}

void CameraModule::appendAvailableKeys(CameraMetadata &chars,
        int32_t keyTag, const Vector<int32_t>& appendKeys) {
void CameraModule::appendAvailableKeys(CameraMetadata& chars, int32_t keyTag,
                                       const Vector<int32_t>& appendKeys) {
    camera_metadata_entry entry = chars.find(keyTag);
    Vector<int32_t> availableKeys;
    availableKeys.setCapacity(entry.count + appendKeys.size());
@@ -233,8 +224,7 @@ CameraModule::CameraModule(camera_module_t *module) : mNumberOfCameras(0) {
    mModule = module;
}

CameraModule::~CameraModule()
{
CameraModule::~CameraModule() {
    while (mCameraInfoMap.size() > 0) {
        camera_info cameraInfo = mCameraInfoMap.editValueAt(0);
        if (cameraInfo.static_camera_characteristics != NULL) {
@@ -256,8 +246,7 @@ CameraModule::~CameraModule()
int CameraModule::init() {
    ATRACE_CALL();
    int res = OK;
    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 &&
            mModule->init != NULL) {
    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 && mModule->init != NULL) {
        ATRACE_BEGIN("camera_module->init");
        res = mModule->init();
        ATRACE_END();
@@ -396,8 +385,7 @@ bool CameraModule::isOpenLegacyDefined() const {
    return mModule->open_legacy != NULL;
}

int CameraModule::openLegacy(
        const char* id, uint32_t halVersion, struct hw_device_t** device) {
int CameraModule::openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device) {
    int res;
    ATRACE_BEGIN("camera_module->open_legacy");
    res = mModule->open_legacy(&mModule->common, id, halVersion, device);
@@ -438,8 +426,7 @@ void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) {
bool CameraModule::isSetTorchModeSupported() const {
    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) {
        if (mModule->set_torch_mode == NULL) {
            ALOGE("%s: Module 2.4 device must support set torch API!",
                    __FUNCTION__);
            ALOGE("%s: Module 2.4 device must support set torch API!", __FUNCTION__);
            return false;
        }
        return true;
@@ -478,8 +465,7 @@ void CameraModule::notifyDeviceStateChange(uint64_t deviceState) {
    }
}

bool CameraModule::isLogicalMultiCamera(
        const common::V1_0::helper::CameraMetadata& metadata,
bool CameraModule::isLogicalMultiCamera(const common::helper::CameraMetadata& metadata,
                                        std::unordered_set<std::string>* physicalCameraIds) {
    if (physicalCameraIds == nullptr) {
        ALOGE("%s: physicalCameraIds must not be null", __FUNCTION__);
@@ -487,8 +473,7 @@ bool CameraModule::isLogicalMultiCamera(
    }

    bool isLogicalMultiCamera = false;
    camera_metadata_ro_entry_t capabilities =
            metadata.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
    camera_metadata_ro_entry_t capabilities = metadata.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
    for (size_t i = 0; i < capabilities.count; i++) {
        if (capabilities.data.u8[i] ==
            ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) {
@@ -498,8 +483,7 @@ bool CameraModule::isLogicalMultiCamera(
    }

    if (isLogicalMultiCamera) {
        camera_metadata_ro_entry_t entry =
                metadata.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS);
        camera_metadata_ro_entry_t entry = metadata.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS);
        const uint8_t* ids = entry.data.u8;
        size_t start = 0;
        for (size_t i = 0; i < entry.count; ++i) {
@@ -535,7 +519,7 @@ void CameraModule::removeCamera(int cameraId) {
        std::unordered_set<std::string> physicalIds;
        camera_metadata_t* metadata = const_cast<camera_metadata_t*>(
                mCameraInfoMap.valueFor(cameraId).static_camera_characteristics);
        common::V1_0::helper::CameraMetadata hidlMetadata(metadata);
        common::helper::CameraMetadata hidlMetadata(metadata);

        if (isLogicalMultiCamera(hidlMetadata, &physicalIds)) {
            for (const auto& id : physicalIds) {
@@ -576,7 +560,6 @@ void* CameraModule::getDso() {
}

}  // namespace helper
} // namespace V1_0
}  // namespace common
}  // namespace camera
}  // namespace hardware
+79 −153

File changed and moved.

Preview size limit exceeded, changes collapsed.

Loading