标签:mutex codec manage 定义 ras cse err erro efault
frameworks/av/services/mediacodec/main_codecservice.cpp
// Default codec services using namespace ::android::hardware::media::omx::V1_0; sp<IOmxStore> omxStore = new implementation::OmxStore(); if (omxStore == nullptr) { LOG(ERROR) << "Cannot create IOmxStore HAL service."; } else if (omxStore->registerAsService() != OK) { LOG(ERROR) << "Cannot register IOmxStore HAL service."; } sp<IOmx> omx = new implementation::Omx(); if (omx == nullptr) { LOG(ERROR) << "Cannot create IOmx HAL service."; } else if (omx->registerAsService() != OK) { LOG(ERROR) << "Cannot register IOmx HAL service.";
omxall.cpp
registerAsService()
-->
servicemanagerall.cpp
BpHwServiceManager::_hidl_add()
if (service == nullptr) { _hidl_err = _hidl_data.writeStrongBinder(nullptr); } else { ::android::sp<::android::hardware::IBinder> _hidl_binder = ::android::hardware::toBinder< ::android::hidl::base::V1_0::IBase>(service); if (_hidl_binder.get() != nullptr) { _hidl_err = _hidl_data.writeStrongBinder(_hidl_binder); } else { _hidl_err = ::android::UNKNOWN_ERROR; } }
关键是上面的toBinder(),它是定义在hidlbindersupport.h中的宏:
sp<IBinder> toBinder(sp<IType> iface) { IType *ifacePtr = iface.get(); if (ifacePtr == nullptr) { return nullptr; } if (ifacePtr->isRemote()) { return ::android::hardware::IInterface::asBinder( static_cast<BpInterface<IType>*>(ifacePtr)); } else { std::string myDescriptor = details::getDescriptor(ifacePtr); if (myDescriptor.empty()) { // interfaceDescriptor fails return nullptr; } // for get + set std::unique_lock<std::mutex> _lock = details::gBnMap.lock(); wp<BHwBinder> wBnObj = details::gBnMap.getLocked(ifacePtr, nullptr); sp<IBinder> sBnObj = wBnObj.promote(); if (sBnObj == nullptr) { auto func = details::getBnConstructorMap().get(myDescriptor, nullptr); if (!func) { func = details::gBnConstructorMap.get(myDescriptor, nullptr); if (!func) { return nullptr; } } sBnObj = sp<IBinder>(func(static_cast<void*>(ifacePtr))); if (sBnObj != nullptr) { details::gBnMap.setLocked(ifacePtr, static_cast<BHwBinder*>(sBnObj.get())); } } return sBnObj; } }
对于implementation::Omx,对应在omxall.cpp里,isRemote()会返回false,所以上面ifacePtr->isRemote()条件不成立,所以会跑else cae。
所以然后是details::gBnMap.getLocked(ifacePtr, nullptr)
这里是拿到一个BnHwOmx对象,然后将其转化为一个sp<IBinder>
__attribute__((constructor)) static void static_constructor() { ::android::hardware::details::getBnConstructorMap().set(IOmx::descriptor, [](void *iIntf) -> ::android::sp<::android::hardware::IBinder> { return new BnHwOmx(static_cast<IOmx *>(iIntf)); }); ::android::hardware::details::getBsConstructorMap().set(IOmx::descriptor, [](void *iIntf) -> ::android::sp<::android::hidl::base::V1_0::IBase> { return new BsOmx(static_cast<IOmx *>(iIntf)); }); };
所以上面toBinder拿到的是一个BnHwOmx sp
标签:mutex codec manage 定义 ras cse err erro efault
原文地址:https://www.cnblogs.com/aspirs/p/11558580.html