注:以下code基于Android nougat-x86 (Android 7.0 release) (Nougat),最后同步时间2017-06-06。获取code方法参考:【记录】编译测试Android nougat-x86
总结了一下Camera App的API 1和API 2与HAL 1和HAL 3互相匹配的camera运行流程:
HAL & API | API 1 | API 2 |
---|---|---|
HAL 1 | 1>2>3>4>5>6 | 9>13>1>2>3>4>5>6 |
HAL 3 | 1>2>3>7>8>11>12 | 9>10>11>12 |
一、API 1 + HAL 1
这就是以前旧版本Android Camera,在图上路径是:
1 -> 2 -> 3 -> 4 -> 5 -> 6
二、API 1 + HAL 3
如果是API 1的camera app,但手机上camera驱动是HAL 3,在图上路径是:
1 -> 2 -> 3 -> 7 -> 8 -> 11 -> 12
其中,在CameraServer里面判断选择4和7的code在
frameworks/av/services/camera/libcameraservice/CameraService.cpp
CameraService::makeClient
函数中:
// Default path: HAL version is unspecified by caller, create CameraClient
// based on device version reported by the HAL.
switch(deviceVersion) {
case CAMERA_DEVICE_API_VERSION_1_0:
if (effectiveApiLevel == API_1) { // Camera1 API route
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
*client = new CameraClient(cameraService, tmp, packageName, cameraId, facing,
clientPid, clientUid, getpid(), legacyMode);
} else { // Camera2 API route
ALOGW("Camera using old HAL version: %d", deviceVersion);
return STATUS_ERROR_FMT(ERROR_DEPRECATED_HAL,
"Camera device \"%d\" HAL version %d does not support camera2 API",
cameraId, deviceVersion);
}
break;
case CAMERA_DEVICE_API_VERSION_3_0:
case CAMERA_DEVICE_API_VERSION_3_1:
case CAMERA_DEVICE_API_VERSION_3_2:
case CAMERA_DEVICE_API_VERSION_3_3:
case CAMERA_DEVICE_API_VERSION_3_4:
if (effectiveApiLevel == API_1) { // Camera1 API route
sp<ICameraClient> tmp = static_cast<ICameraClient*>(cameraCb.get());
*client = new Camera2Client(cameraService, tmp, packageName, cameraId, facing,
clientPid, clientUid, servicePid, legacyMode);
} else { // Camera2 API route
sp<hardware::camera2::ICameraDeviceCallbacks> tmp =
static_cast<hardware::camera2::ICameraDeviceCallbacks*>(cameraCb.get());
*client = new CameraDeviceClient(cameraService, tmp, packageName, cameraId,
facing, clientPid, clientUid, servicePid);
}
break;
default:
// Should not be reachable
ALOGE("Unknown camera device HAL version: %d", deviceVersion);
return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION,
"Camera device \"%d\" has unknown HAL version %d",
cameraId, deviceVersion);
}
三、API 2 + HAL 1
如果camera app采用新的API 2,但手机上的camera驱动还是旧的HAL 1,API 2会通过CameraDeviceUserShim
走API 1调用HAL 1,路径为:
9 -> 13 -> 1 -> 2 -> 3 -> 4 -> 5 -> 6
选择走13和10的判断是在CameraManager.java里面的private CameraDevice openCameraDeviceUserAsync
函数里进行的,code如下:
frameworks/base/core/java/android/hardware/camera2/CameraManager.java
if (supportsCamera2ApiLocked(cameraId)) {
// Use cameraservice's cameradeviceclient implementation for HAL3.2+ devices
ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
if (cameraService == null) {
throw new ServiceSpecificException(
ICameraService.ERROR_DISCONNECTED,
"Camera service is currently unavailable");
}
cameraUser = cameraService.connectDevice(callbacks, id,
mContext.getOpPackageName(), uid);
} else {
// Use legacy camera implementation for HAL1 devices
Log.i(TAG, "Using legacy camera HAL.");
cameraUser = CameraDeviceUserShim.connectBinderShim(callbacks, id);
}
四、API 2 + HAL 3
最后一种是app和HAL都采用新的API 2和HAL 3,这样的流程最简单,从java直接连接CameraServer,路径为:
9 -> 10 -> 11 -> 12
相关文章
【记录】Win8安装adb【原创】Android x86上的Camera HAL(2)
【原创】Steps of Camera HAL Module Searching
【转载】Android Camera Overview
【转载】Android x86睡眠触发时间修改
【原创】在Github上建立clean study
【原创】Android x86上Camera流程
【原创】写了一个Camera App:GoldCam
【原创】Android x86屏幕旋转设定apk
【记录】USB硬盘安装Android x86
【记录】Ubuntu 16.04安装Android Studio
【记录】编译测试Android nougat-x86