camera2 传参流程以及hal添加自定义参数方法

一、下面以设置自动对焦模式为例,分析一下是设置参数流程
// 设置自动对焦模式
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

1. /frameworks/base/core/java/android/hardware/camera2/CaptureRequest.java
Key<Integer> CONTROL_AF_MODE = new Key<Integer>("android.control.afMode", int.class)
mKey = new CameraMetadataNative.Key<T>(name, type);
CameraMetadataNative.Key(String name, Class<T> type)

CaptureRequest.set(@NonNull Key<T> key, T value) //mRequest是mPreviewBuilder 创建的 CaptureRequest实例类
mRequest.mSettings.set(key, value); // mRequest.mSettings = new CameraMetadataNative();

2./frameworks/base/core/java/android/hardware/camera2/impl/CameraMetadataNative.java
CameraMetadataNative.set(Key<T> key, T value)
CameraMetadataNative.setBase(CaptureRequest.Key<T> key, T value)
setBase(key.getNativeKey(), value); //key.getNativeKey() 对应CaptureRequest.getNativeKey 即 mKey,CameraMetadataNative.Key 封装的对象
CameraMetadataNative.setBase(Key<T> key, T value)
int tag = nativeGetTagFromKeyLocal(key.getName());
int nativeType = nativeGetTypeFromTagLocal(tag);
3./frameworks/base/core/jni/android_hardware_camera2_CameraMetadata.cpp
android_hardware_camera2_CameraMetadata.CameraMetadata_getTagFromKeyLocal
CameraMetadata::getTagFromName(key, vTags.get(), &tag)
4./frameworks/av/camera/CameraMetadata.cpp
CameraMetadata::getTagFromName(const char *name,const VendorTagDescriptor* vTags, uint32_t *tag)
vendorSections = vTags->getAllSectionNames() //获取可以设置的 name 列表
5./frameworks/av/camera/VendorTagDescriptor.cpp //vTags 数据初始化
SortedVector<String8>* VendorTagDescriptor::getAllSectionNames() //vendorSections最终返回android_control 数组,遍历 vendorSections
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();
if (strstr(name, str) == name) { //遍历到 strstr("android.control.afMode", "android.control") 时, if添加返回值为true
section = str; //设置 section 为android.control
sectionIndex = i;
sectionLength = strLength;
}
}
// Get the tag name component of the name
const char *nameTagName = name + sectionLength + 1; // x.y.z -> z
if (sectionIndex < ANDROID_SECTION_COUNT) {
// Match built-in tags (typically android.*)
uint32_t tagBegin, tagEnd; // [tagBegin, tagEnd)
tagBegin = camera_metadata_section_bounds[sectionIndex][0];
tagEnd = camera_metadata_section_bounds[sectionIndex][1];

for (candidateTag = tagBegin; candidateTag < tagEnd; ++candidateTag) {
const char *tagName = get_camera_metadata_tag_name(candidateTag); //遍历获取tag_info_t 中的 ANDROID_CONTROL_AF_MODE 信息 afMode,此时为tag赋值 ANDROID_CONTROL_AF_MODE

if (strcmp(nameTagName, tagName) == 0) {
ALOGV("%s: Found matched tag '%s' (%d)",
__FUNCTION__, tagName, candidateTag);
break;
}
}

if (candidateTag == tagEnd) {
return NAME_NOT_FOUND;
}
*tag = candidateTag;
}
6./system/media/camera/src/camera_metadata_tag_info.c
//android_control 数组定义了例如 afMode 对应的key
33const char *camera_metadata_section_names[ANDROID_SECTION_COUNT] = {
[ANDROID_COLOR_CORRECTION] = "android.colorCorrection",
[ANDROID_CONTROL] = "android.control",
...
};
static tag_info_t android_control[ANDROID_CONTROL_END -
ANDROID_CONTROL_START] = {
...
[ ANDROID_CONTROL_AF_MODE - ANDROID_CONTROL_START ] =
{ "afMode", TYPE_BYTE },
};

7. /system/media/camera/include/system/camera_metadata_tags.h
typedef enum camera_metadata_tag {
...
ANDROID_CONTROL_AE_ANTIBANDING_MODE = // enum | public ANDROID_CONTROL_START,
..
ANDROID_CONTROL_AF_MODE, // enum | public
...
ANDROID_CONTROL_END,
...
}

af对应的参数值枚举
// ANDROID_CONTROL_AF_MODE
typedef enum camera_metadata_enum_android_control_af_mode {
ANDROID_CONTROL_AF_MODE_OFF,
ANDROID_CONTROL_AF_MODE_AUTO,
ANDROID_CONTROL_AF_MODE_MACRO,
ANDROID_CONTROL_AF_MODE_CONTINUOUS_VIDEO,
ANDROID_CONTROL_AF_MODE_CONTINUOUS_PICTURE,
ANDROID_CONTROL_AF_MODE_EDOF,
} camera_metadata_enum_android_control_af_mode_t;

----
二、比如需要扩展美颜参数 android.control.facebeauty 方法,可以执行如下操作:
1.在 camera_metadata_tags.h 文件camera_metadata_tag中ANDROID_CONTROL_START和 ANDROID_CONTROL_END 之间添加ANDROID_CONTROL_FACEBEAUTY类型,
2.在 camera_metadata_tags.h 文件 添加 美颜参数值枚举
3.在camera_metadata_tag_info.c 文件 android_control 添加facebeauty

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值