Camera Request 流程源码分析

时间:2024-11-17 07:24:10

和你一起终身学习,这里是程序员Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

Camera 起预览时候回调用CameraCaptureSession类的setRepeatingRequest方法,该方法的实现是由CameraCaptureSessionImpl来完成的。

(frameworks\base\core\java\android\hardware\camera2)

  1. // 主要功能实现是通过CameraCaptureSessionImpl 实现
  2. public abstract int setRepeatingRequest();

(frameworks\base\core\java\android\hardware\camera2\impl)

  1. public int setRepeatingRequest(CaptureRequest request,......){
  2. ... ...
  3. // 调用 CameraDeviceImpl中的 setRepeatingRequest方法
  4. return addPendingSequence(());
  5. ... ...
  6. }

第一个参数CaptureRequest只有一个Request,而在后面会将它包装成List.

(frameworks\base\core\java\android\hardware\camera2\impl)

  1. public int setRepeatingRequest(){
  2. List<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
  3. (request)
  4. return submitCaptureRequest(requestList, callback, handler, /*streaming*/true);
  5. }
  6. private int submitCaptureRequest() {
  7. ... ...
  8. // 通过Binder 调用 CameraDeviceClient 方法
  9. requestInfo = (requestArray, repeating);
  10. ... ...
  11. }

mRemoteDevice 是CameraServer进程当中执行openCamera成功后返回给Client端Binder对象的代理,它和CameraServer进程当中的CameraDeviceClient对象是对应的,只不过这里的mRemoteDevice还经过了Framework一点包装处理而已。

(frameworks\av\services\camera\libcameraservice\api2)

  1. binder::Status CameraDeviceClient::submitRequestList(){
  2. if(streaming){
  3. //预览
  4. mDevice->setStreamingRequestList();
  5. }else{
  6. //拍照
  7. mDevice->captureList();
  8. }
  9. }

(frameworks\av\services\camera\libcameraservice\device3)

  1. //预览
  2. status_t Camera3Device::setStreamingRequestList(){
  3. //预览和拍照都会调用到 submitRequestsHelper 方法
  4. submitRequestsHelper();
  5. }
  6. //拍照
  7. status_t Camera3Device::captureList(){
  8. //预览和拍照都会调用到 submitRequestsHelper 方法
  9. submitRequestsHelper();
  10. }
  11. // submitRequestsHelper 方法实现
  12. status_t Camera3Device::submitRequestsHelper(){
  13. if (repeating) {
  14. //预览流程 setRepeatingRequests处理
  15. res = mRequestThread->setRepeatingRequests(requestList, lastFrameNumber);
  16. } else {
  17. // 拍照流程处理 queueRequestList
  18. res = mRequestThread->queueRequestList(requestList, lastFrameNumber);
  19. }
  20. }
  21. //预览
  22. status_t Camera3Device::RequestThread::setRepeatingRequests(){
  23. ... ...
  24. }
  25. //拍照
  26. status_t Camera3Device::RequestThread::queueRequestList(){
  27. ... ...
  28. }
  29. //mRequestThread 流程分析
  30. status_t Camera3Device::initializeCommonLocked() {
  31. mRequestThread = new RequestThread();
  32. res=mRequestThread->run();
  33. }
  34. // (frameworks\av\services\camera\libcameraservice\device3)
  35. class RequestThread : public Thread {
  36. ... ...
  37. }
  38. bool Camera3Device::RequestThread::threadLoop(){
  39. // Handle paused state. 如果没有Request请求时,将会等待50ms,再进行下一次判断
  40. if (waitIfPaused()) {
  41. return true;
  42. }
  43. // 最重要的三个方法 for the next batch of requests.拍照请求的优先级肯定是高于预览请求
  44. waitForNextRequestBatch();
  45. ... ...
  46. // 最重要的三个方法 a batch of HAL requests and output buffers.
  47. res = prepareHalRequests();
  48. ... ...
  49. //最重要的三个方法 3.如果该值为true,那么继续循环
  50. submitRequestSuccess = sendRequestsBatch();
  51. }
  52. bool Camera3Device::RequestThread::sendRequestsBatch() {
  53. res = mInterface->processBatchCaptureRequests(requests, &numRequestProcessed);
  54. }
  55. status_t Camera3Device::HalInterface::processBatchCaptureRequests(){
  56. if (hidlSession_3_4 != nullptr) {
  57. // 调用 中的方法
  58. err = hidlSession_3_4->proce*tureRequest_3_4( );
  59. } else {
  60. err = mHidlSession->proce*tureRequest( );
  61. }
  62. }

(hardware\interfaces\camera\device\3.4\default)

  1. Return<void> CameraDeviceSession::proce*tureRequest_3_4(){
  2. s = processOneCaptureRequest_3_4(requests[i])
  3. }
  4. Status CameraDeviceSession::processOneCaptureRequest_3_4(){
  5. // 这个会跳转到 中的process_capture_request 方法, 需要继续厘清跳转地方
  6. ATRACE_BEGIN("camera3->process_capture_request");
  7. status_t ret = mDevice->ops->process_capture_request(mDevice, &halRequest);
  8. ATRACE_END();
  9. }

(vendor\qcom\proprietary\camx\src\core\hal)

  1. int process_capture_request(){
  2. // 会跳转到 process_capture_request 方法
  3. pHAL3->process_capture_request(pCamera3DeviceAPI, pCaptureRequestAPI);
  4. }

(vendor\qcom\proprietary\camx\src\core\hal)

  1. static int process_capture_request(){
  2. result = pHALDevice->Proce*tureRequest(pRequest);
  3. }

(vendor\qcom\proprietary\camx\src\core\hal)

  1. CamxResult HALDevice::Proce*tureRequest(){
  2. //调用 chi_override_process_request 方法
  3. result = GetCHIAppCallbacks()->chi_override_process_request()
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. static CDKResult chi_override_process_request(){
  2. // 调用 OverrideProcessRequest方法
  3. return pExtensionModule->OverrideProcessRequest();
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CDKResult ExtensionModule::OverrideProcessRequest(){
  2. //选取 Usecase 去做Proce*tureRequest操作
  3. result = m_pSelectedUsecase[logicalCameraId]->Proce*tureRequest(pCaptureRequest);
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CDKResult Usecase::Proce*tureRequest(){
  2. // 调用指定的UseCase
  3. result = ExecuteCaptureRequest(pRequest);
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiusecase)

  1. CDKResult AdvancedCameraUsecase::ExecuteCaptureRequest(){
  2. if(TRUE == AdvancedFeatureEnabled()){
  3. // AdvancedFeatureEnabled HDR MFNR
  4. result = pFeature->ExecuteProcessRequest(pRequest);
  5. }else{
  6. // 没有任何Feature 执行的流程,拍照
  7. result = CameraUsecaseBase::ExecuteCaptureRequest(pRequest);
  8. }
  9. }
  10. CDKResult CameraUsecaseBase::ExecuteCaptureRequest(){
  11. // 没有任何Feature 执行的流程
  12. CheckAndActivatePipeline(m_sessions[session].pSession);
  13. ... ...
  14. result = SubmitRequest(&submitRequest);
  15. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CHX_INLINE CDKResult CheckAndActivatePipeline(){
  2. //ActivatePipeline一般一个Feature 一个Pipeline,MFNR 有多个Pipeline
  3. result = ExtensionModule::GetInstance()->ActivatePipeline();
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CDKResult ExtensionModule::ActivatePipeline()
  2. {
  3. return g_chiContextOps.pActivatePipeline();
  4. }

(vendor\qcom\proprietary\camx\src\core\chi)

  1. static CDKResult ChiActivatePipeline(){
  2. result = pChiContext->ActivatePipeline();
  3. }

(vendor\qcom\proprietary\camx\src\core\chi)

  1. CamxResult ChiContext::ActivatePipeline(){
  2. result = pChiSession->StreamOn();
  3. }

(vendor\qcom\proprietary\camx\src\core)

  1. CamxResult Session::StreamOn(){
  2. result = pPipeline->StreamOn();
  3. }

(vendor\qcom\proprietary\camx\src\core)

  1. CamxResult Pipeline::StreamOn(){
  2. result = m_pChiContext->GetHwContext()->StreamOn();
  3. }

(vendor\qcom\proprietary\camx\src\core)

  1. CamxResult HwContext::StreamOn(){
  2. result = CSLStreamOn();
  3. }

(vendor\qcom\proprietary\camx\src\csl)

  1. CamxResult CSLStreamOn(){
  2. pJumpTable->CSLStreamOn();
  3. }

(vendor\qcom\proprietary\camx\src\csl\hw)

  1. CamxResult CSLStreamOnHW(){
  2. result = CSLHwStreamOnKMDHardwares();
  3. }

(vendor\qcom\proprietary\camx\src\csl\hw)

  1. CamxResult CSLHwStreamOnKMDHardwares(){
  2. result = pHWDevice->();
  3. }

然后返回执行 的CameraUsecaseBase::ExecuteCaptureRequest方法

  1. CDKResult AdvancedCameraUsecase::ExecuteCaptureRequest(){
  2. if(TRUE == AdvancedFeatureEnabled()){
  3. result = pFeature->ExecuteProcessRequest(pRequest);
  4. }else{
  5. // 没有任何Feature 执行的流程
  6. result = CameraUsecaseBase::ExecuteCaptureRequest(pRequest);
  7. }
  8. }
  9. CDKResult CameraUsecaseBase::ExecuteCaptureRequest(){
  10. // 没有任何Feature 执行的流程
  11. CheckAndActivatePipeline(m_sessions[session].pSession);
  12. //Chxusecase .cpp
  13. result = SubmitRequest(&submitRequest);
  14. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CDKResult Usecase::SubmitRequest(){
  2. //
  3. result = ExtensionModule::GetInstance()->SubmitRequest
  4. }

(vendor\qcom\proprietary\chi-cdk\core\chiframework)

  1. CDKResult ExtensionModule::SubmitRequest(){
  2. result = g_chiContextOps.pSubmitPipelineRequest();
  3. }

(vendor\qcom\proprietary\camx\src\core\chi)

  1. static CDKResult ChiSubmitPipelineRequest(){
  2. result = pChiContext->SubmitRequest();
  3. }

(vendor\qcom\proprietary\camx\src\core\chi)

  1. CamxResult ChiContext::SubmitRequest(){
  2. result = pSession->Proce*tureRequest();
  3. }

(vendor\qcom\proprietary\camx\src\core)

  1. CamxResult Session::Proce*tureRequest(){
  2. // 暂未找到跳转到ProcessRequest 的地方
  3. }
  4. CamxResult Session::ProcessRequest(){
  5. result = m_pipelineData[].pPipeline->OpenRequest();
  6. //
  7. result = m_pipelineData[].pPipeline->ProcessRequest();
  8. }

(vendor\qcom\proprietary\camx\src\core)

  1. CamxResult Pipeline::ProcessRequest(){
  2. m_ppOrderedNodes[nodeIndex]->SetupRequest();
  3. result = m_pDeferredRequestQueue->AddDeferredNode();
  4. // Consider any nodes now ready
  5. m_pDeferredRequestQueue->DispatchReadyNodes();
  6. }

(vendor\qcom\proprietary\camx\src\core)

  1. VOID DeferredRequestQueue::DispatchReadyNodes(){
  2. ... ...
  3. }

CamxRequest流程

参考文章
:///sinat_22657459/article/details/92380466
:///TaylorPotter/article/details/105630341

至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除。同时感谢您的阅读,期待您的关注。

点个在看,方便您使用时快速查找!