Frameworks处理请求参考
从代码的逻辑来看FrameWork层初始化Camera3Device时候就会启动一个请求线程,这个线程是专门处理上层下发的。
frameworks\av\services\camera \libcameraservice\device3\Camera3Device.cpp
status_t Camera3Device::initialize(sp<CameraProviderManager> manager, const String8& monitorTags)
status_t res = manager->openSession(mId.string(), this,/*out*/ &session);
manager->getCameraCharacteristics(mId.string(), &mDeviceInfo);
auto requestQueueRet = session->getCaptureRequestMetadataQueue([&queue](const auto& descriptor)
auto resultQueueRet = session->getCaptureResultMetadataQueue([&resQueue](const auto& descriptor)
mVendorTagId = manager->getProviderTagIdLocked(mId.string());
mInterface = new HalInterface(session, queue);
return initializeCommonLocked();
status_t Camera3Device::initializeCommonLocked()
/** Create buffer manager */
mBufferManager = new Camera3BufferManager();
mRequestThread = new RequestThread(this, mStatusTracker, mInterface);
res = mRequestThread->run(String8::format("C3Dev-%s-ReqQueue", mId.string()).string());
bool Camera3Device::RequestThread::threadLoop()
// Wait for the next batch of requests.
waitForNextRequestBatch();
void Camera3Device::RequestThread::waitForNextRequestBatch()
nextRequest.captureRequest = waitForNextRequestLocked();
sp<Camera3Device::CaptureRequest> Camera3Device::RequestThread::waitForNextRequestLocked()
sp<CaptureRequest> nextRequest;
while (mRequestQueue.empty())/*mRequestQueue 这个队列是拍照请求的队列,也就是说拍照请求为空则直接跳过处理预览请求*/
if (!mRepeatingRequests.empty())/*预览请求不为空的时候加入拍照请求,并且是优先处理*/
/***************************************************************
原文注释:
Always atomically enqueue all requests in a repeating request
list. Guarantees a complete in-sequence set of captures to
application.
****************************************************************/
const RequestList &requests = mRepeatingRequests;
RequestList::const_iterator firstRequest = requests.begin();
nextRequest = *firstRequest;
mRequestQueue.insert(mRequestQueue.end(),++firstRequest,requests.end());
// No need to wait any longer
mRepeatingLastFrameNumber = mFrameNumber + requests.size() - 1;
break;
if (nextRequest == NULL)/*还有一种情况就是预览请求也是空的*/
/***********************************************************
原文注释:
Don't have a repeating request already in hand, so queue must have an entry now.
************************************************************/
RequestList::iterator firstRequest = mRequestQueue.begin();
nextRequest = *firstRequest;
mRequestQueue.erase(firstRequest);
if (mRequestQueue.empty() && !nextRequest->mRepeating) {
sp<NotificationListener> listener = mListener.promote();
if (listener != NULL) {
listener->notifyRequestQueueEmpty();
}
}
// Wait for additional requests,附加的一般不会走暂时不看
const size_t batchSize = nextRequest.captureRequest->mBatchSize;
// Get the latest request ID, if any
requestIdEntry = mNextRequests[mNextRequests.size() - 1].captureRequest->mSettingsList.begin()->metadata.find(ANDROID_REQUEST_ID);
latestRequestId = requestIdEntry.data.i32[0];
/*原文注释:Prepare a batch of HAL requests and output buffers. */
res = prepareHalRequests();
status_t Camera3Device::RequestThread::prepareHalRequests()
for (size_t i = 0; i < mNextRequests.size(); i++)
// Prepare a request to HAL
// Insert any queued triggers (before metadata is locked)
submitRequestSuccess = sendRequestsOneByOne();
bool Camera3Device::RequestThread::sendRequestsOneByOne()
for (auto& nextRequest : mNextRequests)
// Submit request and block until ready for next one
res = mInterface->proce*tureRequest(&nextRequest.halRequest);/*mInterface 在初始化的时候就已经被实例化*/
status_t Camera3Device::HalInterface::proce*tureRequest()
std::vector<camera3_capture_request_t*> requests(1);
res = processBatchCaptureRequests(requests, &numRequestProcessed);
status_t Camera3Device::HalInterface::processBatchCaptureRequests(std::vector<camera3_capture_request_t*>& requests,/*out*/uint32_t* numRequestProcessed)
sp<device::V3_4::ICameraDeviceSession> hidlSession_3_4;
auto castResult_3_4 = device::V3_4::ICameraDeviceSession::castFrom(mHidlSession);
/*这里有两个:3.2和3.4目前只看3.2*/
hardware::hidl_vec<device::V3_2::CaptureRequest> captureRequests;
hardware::hidl_vec<device::V3_4::CaptureRequest> captureRequests_3_4;
// Write metadata to FMQ.
for (size_t i = 0; i < batchSize; i++)
device::V3_2::CaptureRequest* captureRequest;
if (hidlSession_3_4 != nullptr) {
captureRequest = &captureRequests_3_4[i].v3_2;
} else {
captureRequest = &captureRequests[i];
}
if (mRequestMetadataQueue != nullptr && mRequestMetadataQueue->write(reinterpret_cast<const uint8_t*>(request->settings), settingsSize))
mHidlSession->proce*tureRequest(captureRequests, cachesToRemove,[&status, &numRequestProcessed] (auto s, uint32_t n)
/*ICameraDeviceSession mHidlSession 在Camera3Device::initialize 由CameraManaage创建 */
Return<void> CameraDeviceSession::proce*tureRequest(const hidl_vec<CaptureRequest>& requests,const hidl_vec<BufferCache>& cachesToRemove,ICameraDeviceSession::proce*tureRequest_cb _hidl_cb)
for (size_t i = 0; i < requests.size(); i++, numRequestProcessed++)
processOneCaptureRequest(requests[i])
Status CameraDeviceSession::processOneCaptureRequest(const CaptureRequest& request)
status_t ret = mDevice->ops->process_capture_request(mDevice, &halRequest);
/*至此进入HAL3处理请求接口方法中*/
QCamera3HardwareInterface::process_capture_request(const struct camera3_device *device,camera3_capture_request_t *request)
QCamera3HardwareInterface *hw = reinterpret_cast<QCamera3HardwareInterface *>(device->priv);