CameraProvider进程-Android12
Posted xhBruce
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CameraProvider进程-Android12相关的知识,希望对你有一定的参考价值。
CameraProvider进程-android12
android12-release
CameraService启动-Android12 看到CameraProviderManager与CameraProvider进程建立联系。这里我们查看一下CameraProvider进程
1. rc文件android.hardware.camera.provider@2.4-service_64.rc
CameraProvider进程名:vendor.camera-provider-2-4
,
bin文件:/vendor/bin/hw/android.hardware.camera.provider@2.4-service_64
对应启动入口:hardware/interfaces/camera/provider/2.4/default/service.cpp
hardware/interfaces/camera/provider/2.4/default/android.hardware.camera.provider@2.4-service_64.rc
2. service.cpp#main()启动
android::ProcessState::initWithDriver("/dev/vndbinder");
kernel底层/dev/vndbinder
驱动defaultPassthroughServiceImplementation<ICameraProvider>("legacy/0", 6)
直通式Passthrough注册服务给hwservicemanager
。(其中使用了#include <android/hardware/camera/provider/2.4/ICameraProvider.h>
类,ICameraProvider类是由HIDL接口定义文件 ICameraProvider.hal 经过hidl-gen编译工具编译生成
)
int main()
ALOGI("CameraProvider@2.4 legacy service is starting.");
// The camera HAL may communicate to other vendor components via
// /dev/vndbinder
android::ProcessState::initWithDriver("/dev/vndbinder");
// b/166675194
if (property_get_bool("ro.vendor.camera.provider24.disable_mem_init", false))
if (mallopt(M_BIONIC_ZERO_INIT, 0) == 0)
// Note - heap initialization is only present on devices with Scudo.
// Devices with jemalloc don't have heap-init, and thus the mallopt
// will fail. On these devices, you probably just want to remove the
// property.
ALOGE("Disabling heap initialization failed.");
status_t status;
if (kLazyService)
status = defaultLazyPassthroughServiceImplementation<ICameraProvider>("legacy/0",
/*maxThreads*/ 6);
else
status = defaultPassthroughServiceImplementation<ICameraProvider>("legacy/0",
/*maxThreads*/ 6);
return status;
2.1 ICameraProvider.hal生成CameraProvider.h
可以查看 HIDL实战笔记,相关文件查看上面rc目录等相关文件
。HIDL机制本身是跨进程通信,所以Camera Service本身通过HIDL接口获取的对象都会有Bn端和Bp端,分别代表了Binder两端。
hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.h
hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp
ICameraProvider.hal文件中定义了ICameraProvider接口类,由CameraProvider继承并实现,主要接口如下:
getCameraDeviceInterface_V3_x
: 该方法主要用于Camera Service获取ICameraDevice,通过该对象可以控制Camera 设备的诸如配置数据流、下发request等具体行为。setCallback
:将Camera Service 实现的ICameraProviderCallback传入Camera Provider,一旦Provider有事件产生时便可以通过该对象通知Camera Service。
ICameraProviderCallback.hal文件中定义了ICameraProviderCallback回调接口类,该接口由Camera Service 中的CameraProviderManager::ProviderInfo继承并实现,在Camera Service 启动的时候被实例化,通过调用ICameraProvider::setCallback接口注册到Camera Provider中,其主要接口如下:
cameraDeviceStatusChange
:将Camera 设备状态上传至Camera Service,状态由CameraDeviceStatus定义
hardware/interfaces/camera/provider/2.4/ICameraProvider.hal
package android.hardware.camera.provider@2.4;
import ICameraProviderCallback;
import android.hardware.camera.common@1.0::types;
import android.hardware.camera.device@1.0::ICameraDevice;
import android.hardware.camera.device@3.2::ICameraDevice;
interface ICameraProvider
setCallback(ICameraProviderCallback callback) generates (Status status);
getVendorTags() generates (Status status, vec<VendorTagSection> sections);
getCameraIdList()
generates (Status status, vec<string> cameraDeviceNames);
isSetTorchModeSupported() generates (Status status, bool support);
getCameraDeviceInterface_V1_x(string cameraDeviceName) generates
(Status status,
android.hardware.camera.device@1.0::ICameraDevice device);
getCameraDeviceInterface_V3_x(string cameraDeviceName) generates
(Status status,
android.hardware.camera.device@3.2::ICameraDevice device);
;
hardware/interfaces/camera/provider/2.4/ICameraProviderCallback.hal
package android.hardware.camera.provider@2.4;
import android.hardware.camera.common@1.0::types;
/**
* Callback functions for a camera provider HAL to use to inform the camera
* service of changes to the camera subsystem.
*/
interface ICameraProviderCallback
cameraDeviceStatusChange(string cameraDeviceName,
CameraDeviceStatus newStatus);
torchModeStatusChange(string cameraDeviceName,
TorchModeStatus newStatus);
;
2.2 HIDL直通式
ServiceManagement.cpp中openLibs()
调用到CameraProvider_2_4.cpp
的HIDL_FETCH_ICameraProvider(const char* name)
方法
(HAL 接口定义语言 (AIDL/HIDL) 在 Android 10 中,HIDL 功能已整合到 AIDL 中。此后,HIDL 就被废弃了,并且仅供尚未转换为 AIDL 的子系统使用。
)
system/libhidl/transport/include/hidl/LegacySupport.h
system/libhidl/transport/LegacySupport.cpp
system/libhidl/transport/ServiceManagement.cpp
hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp
fqName为android.hardware.camera.provider@2.4::ICameraProvider
2.3 CameraProvider初始化模板
template<typename IMPL>
其中IMPL
相关文件hardware/interfaces/camera/provider/2.4/default/LegacyCameraProviderImpl_2_4.cpp、hardware/interfaces/camera/provider/2.4/default/ExternalCameraProviderImpl_2_4.cpp
hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.h
template<typename IMPL>
struct CameraProvider : public ICameraProvider
CameraProvider() : impl()
~CameraProvider()
// Caller must use this method to check if CameraProvider ctor failed
bool isInitFailed() return impl.isInitFailed();
// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
Return<Status> setCallback(const sp<ICameraProviderCallback>& callback) override
return impl.setCallback(callback);
Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override
return impl.getVendorTags(_hidl_cb);
Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override
return impl.getCameraIdList(_hidl_cb);
Return<void> isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) override
return impl.isSetTorchModeSupported(_hidl_cb);
Return<void> getCameraDeviceInterface_V1_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V1_x_cb _hidl_cb) override
return impl.getCameraDeviceInterface_V1_x(cameraDeviceName, _hidl_cb);
Return<void> getCameraDeviceInterface_V3_x(
const hidl_string& cameraDeviceName,
getCameraDeviceInterface_V3_x_cb _hidl_cb) override
return impl.getCameraDeviceInterface_V3_x(cameraDeviceName, _hidl_cb);
private:
IMPL impl;
;
hardware/interfaces/camera/provider/2.4/default/CameraProvider_2_4.cpp
template<typename IMPL>
CameraProvider<IMPL>* getProviderImpl()
CameraProvider<IMPL> *provider = new CameraProvider<IMPL>();
if (provider == nullptr)
ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
return nullptr;
if (provider->isInitFailed())
ALOGE("%s: camera provider init failed!", __FUNCTION__);
delete provider;
return nullptr;
return provider;
3. 简要时序图
4. HAL硬件框架
深入理解高通 Camx CHI 架构 - segmentfault
高通CamX关键流程 - 腾讯云
CamX关键流程 - 简书
以上是关于CameraProvider进程-Android12的主要内容,如果未能解决你的问题,请参考以下文章
CameraServiceProxy启动-Android12