我们操作相机的所有工作在进程都是由中转来和进程进行通信的 。
109status_t Camera3Device::initialize(sp manager, const String8& monitorTags) {110ATRACE_CALL();111Mutex::Autolock il(mInterfaceLock);112Mutex::Autolock l(mLock);113114ALOGV("%s: Initializing HIDL device for camera %s", __FUNCTION__, mId.string());115if (mStatus != STATUS_UNINITIALIZED) {116CLOGE("Already initialized!");117return INVALID_OPERATION;118}119if (manager == nullptr) return INVALID_OPERATION;//在CameraDaemon进程中执行真正的camera的open过程,同时会返回一个session对象121sp session;122ATRACE_BEGIN("CameraHal::openSession");123status_t res = manager->openSession(mId.string(), this,124/*out*/ &session);125ATRACE_END();126if (res != OK) {127SET_ERR_L("Could not open camera session: %s (%d)", strerror(-res), res);128return res;129}130131res = manager->getCameraCharacteristics(mId.string(), &mDeviceInfo);132if (res != OK) {133SET_ERR_L("Could not retrieve camera characteristics: %s (%d)", strerror(-res), res);134session->close();135return res;136}137mSupportNativeZoomRatio = manager->supportNativeZoomRatio(mId.string());138139std::vector physicalCameraIds;140bool isLogical = manager->isLogicalCamera(mId.string(), &physicalCameraIds);141if (isLogical) {142for (auto& physicalId : physicalCameraIds) {143res = manager->getCameraCharacteristics(144physicalId, &mPhysicalDeviceInfoMap[physicalId]);145if (res != OK) {146SET_ERR_L("Could not retrieve camera %s characteristics: %s (%d)",147physicalId.c_str(), strerror(-res), res);148session->close();149return res;150}151152bool usePrecorrectArray =153DistortionMapper::isDistortionSupported(mPhysicalDeviceInfoMap[physicalId]);154if (usePrecorrectArray) {155res = mDistortionMappers[physicalId].setupStaticInfo(156mPhysicalDeviceInfoMap[physicalId]);157if (res != OK) {158SET_ERR_L("Unable to read camera %s's calibration fields for distortion "159"correction", physicalId.c_str());160session->close();161return res;162}163}164165mZoomRatioMappers[physicalId] = ZoomRatioMapper(166&mPhysicalDeviceInfoMap[physicalId],167mSupportNativeZoomRatio, usePrecorrectArray);168}169}170171std::shared_ptr queue;172auto requestQueueRet = session->getCaptureRequestMetadataQueue(173[&queue](const auto& descriptor) {174queue = std::make_shared(descriptor);175if (!queue->isValid() || queue->availableToWrite() <= 0) {176ALOGE("HAL returns empty request metadata fmq, not use it");177queue = nullptr;178// don't use the queue onwards.179}180});181if (!requestQueueRet.isOk()) {182ALOGE("Transaction error when getting request metadata fmq: %s, not use it",183requestQueueRet.description().c_str());184return DEAD_OBJECT;185}186187std::unique_ptr& resQueue = mResultMetadataQueue;188auto resultQueueRet = session->getCaptureResultMetadataQueue(189[&resQueue](const auto& descriptor) {190resQueue = std::make_unique(descriptor);191if (!resQueue->isValid() || resQueue->availableToWrite() <= 0) {192ALOGE("HAL returns empty result metadata fmq, not use it");193resQueue = nullptr;194// Don't use the resQueue onwards.195}196});197if (!resultQueueRet.isOk()) {198ALOGE("Transaction error when getting result metadata queue from camera session: %s",199resultQueueRet.description().c_str());200return DEAD_OBJECT;201}202IF_ALOGV() {203session->interfaceChain([](204::android::hardware::hidl_vec<::android::hardware::hidl_string> interfaceChain) {205ALOGV("Session interface chain:");206for (const auto& iface : interfaceChain) {207ALOGV("%s", iface.c_str());208}209});210}211212camera_metadata_entry bufMgrMode =213mDeviceInfo.find(ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION);214if (bufMgrMode.count > 0) {215mUseHalBufManager = (bufMgrMode.data.u8[0] ==216ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION_HIDL_DEVICE_3_5);217}218219camera_metadata_entry_t capabilities = mDeviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);220for (size_t i = 0; i