Android Camera2架构-RequestThread处理队列中的预览和拍照请求流程Frameworks层到HAL层(1)

Frameworks下发请求流程

Android P Camera2架构-Frameworks下发预览和拍照请求流程Frameworks层到HAL层(1)

 

Frameworks处理请求参考

从代码的逻辑来看FrameWork层初始化Camera3Device时候就会启动一个请求线程,这个线程是专门处理上层下发的。



frameworks\av\services\camera \libcameraservice\device3\Camera3Device.cpp
status_t Camera3Device::initialize(sp 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::RequestThread::waitForNextRequestLocked()
							sp 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 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->processCaptureRequest(&nextRequest.halRequest);/*mInterface 在初始化的时候就已经被实例化*/
							status_t Camera3Device::HalInterface::processCaptureRequest()
								std::vector requests(1);
									res = processBatchCaptureRequests(requests, &numRequestProcessed);
										status_t Camera3Device::HalInterface::processBatchCaptureRequests(std::vector& requests,/*out*/uint32_t* numRequestProcessed)
											sp hidlSession_3_4;
											auto castResult_3_4 = device::V3_4::ICameraDeviceSession::castFrom(mHidlSession);
											/*这里有两个:3.2和3.4目前只看3.2*/
											hardware::hidl_vec captureRequests;
											hardware::hidl_vec 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(request->settings), settingsSize))
											mHidlSession->processCaptureRequest(captureRequests, cachesToRemove,[&status, &numRequestProcessed] (auto s, uint32_t n)
											/*ICameraDeviceSession mHidlSession 在Camera3Device::initialize 由CameraManaage创建 */
											Return CameraDeviceSession::processCaptureRequest(const hidl_vec& requests,const hidl_vec& cachesToRemove,ICameraDeviceSession::processCaptureRequest_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(device->priv);
													
													
													
													
													
													
										
										
										

 

 

 

你可能感兴趣的:(Android系统)