status_t CameraMetadata::update(uint32_t tag, const void *data, size_t data_count) { status_t res; int type = get_camera_metadata_tag_type(tag); if (type == -1) { ALOGE("%s: Tag %d not found", __FUNCTION__, tag); return BAD_VALUE; } size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count); res = resizeIfNeeded(1, data_size); if (res == OK) { 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); } else if (res == OK) { res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL); } } if (res != OK) { ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__, get_camera_metadata_section_name(tag), get_camera_metadata_tag_name(tag), tag, strerror(-res), res); } return res; }
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__); return INVALID_OPERATION; } int type = get_camera_metadata_tag_type(tag); if (type == -1) { ALOGE("%s: Tag %d not found", __FUNCTION__, tag); return BAD_VALUE; } // Safety check - ensure that data isn't pointing to this metadata, since // that would get invalidated if a resize is needed size_t bufferSize = get_camera_metadata_size(mBuffer); 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__); return INVALID_OPERATION; } size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count); res = resizeIfNeeded(1, data_size); if (res == OK) { 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); } else if (res == OK) { res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL); } } if (res != OK) { ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__, get_camera_metadata_section_name(tag), get_camera_metadata_tag_name(tag), tag, strerror(-res), res); } IF_ALOGV() { ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != OK, "%s: Failed to validate metadata structure after update %p", __FUNCTION__, mBuffer); } return res; }
bool Metadata::validate(uint32_t tag, int tag_type, int count) { if (get_camera_metadata_tag_type(tag) < 0) { ALOGE("%s: Invalid metadata entry tag: %d", __func__, tag); return false; } if (tag_type < 0 || tag_type >= NUM_TYPES) { ALOGE("%s: Invalid metadata entry tag type: %d", __func__, tag_type); return false; } if (tag_type != get_camera_metadata_tag_type(tag)) { ALOGE("%s: Tag %d called with incorrect type: %s(%d)", __func__, tag, camera_metadata_type_names[tag_type], tag_type); return false; } if (count < 1) { ALOGE("%s: Invalid metadata entry count: %d", __func__, count); return false; } return true; }
status_t CameraMetadata::checkType(uint32_t tag, uint8_t expectedType) { int tagType = get_camera_metadata_tag_type(tag); if ( CC_UNLIKELY(tagType == -1)) { ALOGE("Update metadata entry: Unknown tag %d", tag); return INVALID_OPERATION; } if ( CC_UNLIKELY(tagType != expectedType) ) { ALOGE("Mismatched tag type when updating entry %s (%d) of type %s; " "got type %s data instead ", get_camera_metadata_tag_name(tag), tag, camera_metadata_type_names[tagType], camera_metadata_type_names[expectedType]); return INVALID_OPERATION; } return OK; }
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__); return INVALID_OPERATION; } int type = get_camera_metadata_tag_type(tag); if (type == -1) { ALOGE("%s: Tag %d not found", __FUNCTION__, tag); return BAD_VALUE; } size_t data_size = calculate_camera_metadata_entry_data_size(type, data_count); res = resizeIfNeeded(1, data_size); if (res == OK) { 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); } else if (res == OK) { res = update_camera_metadata_entry(mBuffer, entry.index, data, data_count, NULL); } } if (res != OK) { ALOGE("%s: Unable to update metadata entry %s.%s (%x): %s (%d)", __FUNCTION__, get_camera_metadata_section_name(tag), get_camera_metadata_tag_name(tag), tag, strerror(-res), res); } IF_ALOGV() { ALOGE_IF(validate_camera_metadata_structure(mBuffer, /*size*/NULL) != OK, "%s: Failed to validate metadata structure after update %p", __FUNCTION__, mBuffer); } return res; }
int Metadata::add(uint32_t tag, int count, void *tag_data) { int tag_type = get_camera_metadata_tag_type(tag); size_t type_sz = camera_metadata_type_size[tag_type]; // Allocate array to hold new metadata void *data = malloc(count * type_sz); if (data == NULL) return -ENOMEM; memcpy(data, tag_data, count * type_sz); pthread_mutex_lock(&mMutex); mEntryCount++; mDataCount += calculate_camera_metadata_entry_data_size(tag_type, count); push(new Entry(tag, data, count)); mDirty = true; pthread_mutex_unlock(&mMutex); return 0; }
static status_t addOrSize(camera_metadata_t *request, bool sizeRequest, size_t *entryCount, size_t *dataCount, uint32_t tag, const void *entryData, size_t entryDataCount) { status_t res; if (!sizeRequest) { return add_camera_metadata_entry(request, tag, entryData, entryDataCount); } else { int type = get_camera_metadata_tag_type(tag); if (type < 0 ) return BAD_VALUE; (*entryCount)++; (*dataCount) += calculate_camera_metadata_entry_data_size(type, entryDataCount); return OK; } }
int GetTypeFromTag(uint32_t tag) const { return get_camera_metadata_tag_type(tag); }