1.AIDL
用于 APP 和 cameraservice 端交互的
https://android.googlesource.com/platform/frameworks/av/+/refs/tags/android-9.0.0_r55/camera/aidl/android/hardware
编译后的路径在
out/soong/.intermediates/frameworks/av/camera/libcamera_client/android_arm64_armv8-a_cortex-a53_core_shared/gen/aidl/
cameraservice端的代码在frameworks/av/services/camera/libcameraservice/下面
2.HIDL
用于cameraservice 和 camerahal 端交互的
https://android.googlesource.com/platform/hardware/interfaces/+/master/camera/provider/2.4/
ICameraProvider.hal
ICameraProviderCallback.hal
https://android.googlesource.com/platform/hardware/interfaces/+/master/camera/device/3.2/
ICameraDevice.hal
ICameraDeviceCallback.hal
ICameraDeviceSession.hal
编译后的路径在
out/soong/.intermediates/frameworks/hardware/interfaces/camera/device/3.2/android.hardware.camera.device@3.2_genc++/gen/android.hardware/camera/device/3.2/
下面分析一下open的操作
/services/camera/libcameraservice/common/CameraProviderManager.cpp
status_t CameraProviderManager::openSession(const std::string &id,
const sp<hardware::camera::device::V3_2::ICameraDeviceCallback>& callback,
/*out*/
sp<hardware::camera::device::V3_2::ICameraDeviceSession> *session) {
std::lock_guard<std::mutex> lock(mInterfaceMutex);
auto deviceInfo = findDeviceInfoLocked(id,
/*minVersion*/ {3,0}, /*maxVersion*/ {4,0});
if (deviceInfo == nullptr) return NAME_NOT_FOUND;
auto *deviceInfo3 = static_cast<ProviderInfo::DeviceInfo3*>(deviceInfo);
Status status;
hardware::Return<void> ret;
ret = deviceInfo3->mInterface->open(callback, [&status, &session]
(Status s, const sp<device::V3_2::ICameraDeviceSession>& cameraSession) {
status = s;
if (status == Status::OK) {
*session = cameraSession;
}
});
if (!ret.isOk()) {
ALOGE("%s: Transaction error opening a session for camera device %s: %s",
__FUNCTION__, id.c_str(), ret.description().c_str());
return DEAD_OBJECT;
}
return mapToStatusT(status);
}
可以 参考如下链接:Android8.0相机源码深入解析(四)
这个open 最终会调用的是
camera/device/3.2/ICameraDevice.hal
/**
* open:
*
* Power on and initialize this camera device for active use, returning a
* session handle for active operations.
*
* @param callback Interface to invoke by the HAL for device asynchronous
* events. For HALs newer than version 3.2, HAL must use castFrom
* method to check the exact version of callback sent by camera service.
*
* @return status Status code for the operation, one of:
* OK:
* On a successful open of the camera device.
* INTERNAL_ERROR:
* The camera device cannot be opened due to an internal
* error.
* ILLEGAL_ARGUMENT:
* The callbacks handle is invalid (for example, it is null).
* CAMERA_IN_USE:
* This camera device is already open.
* MAX_CAMERAS_IN_USE:
* The maximal number of camera devices that can be
* opened concurrently were opened already.
* CAMERA_DISCONNECTED:
* This external camera device has been disconnected, and is no
* longer available. This interface is now stale, and a new instance
* must be acquired if the device is reconnected. All subsequent
* calls on this interface must return CAMERA_DISCONNECTED.
* @return session The interface to the newly-opened camera session,
* or null if status is not OK.
*/
open(ICameraDeviceCallback callback) generates
(Status status, ICameraDeviceSession session);
可以发现 ICameraDevice 又在HAL被实现,Framework -> HAL 进程间通信就这样实现操作完成了