相机请求预览实现流程

程序员Android

共 11561字,需浏览 24分钟

 ·

2024-04-15 08:38

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

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

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

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

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

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

    public int setRepeatingRequest(CaptureRequest request,......){
... ...
// 调用 CameraDeviceImpl中的 setRepeatingRequest方法
return addPendingSequence(mDeviceImpl.setRepeatingRequest());
... ...
}

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

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


public int setRepeatingRequest(){
List<CaptureRequest> requestList = new ArrayList<CaptureRequest>();
requestList.add(request)

return submitCaptureRequest(requestList, callback, handler, /*streaming*/true);
}


private int submitCaptureRequest() {
... ...
// 通过Binder 调用 CameraDeviceClient 方法
requestInfo = mRemoteDevice.submitRequestList(requestArray, repeating);
... ...
}

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

CameraDeviceClient.cpp (frameworks\av\services\camera\libcameraservice\api2)

    binder::Status CameraDeviceClient::submitRequestList(){
if(streaming){
//预览
mDevice->setStreamingRequestList();
}else{
//拍照
mDevice->captureList();
}
}

Camera3Device.cpp (frameworks\av\services\camera\libcameraservice\device3)

    //预览
status_t Camera3Device::setStreamingRequestList(){
//预览和拍照都会调用到 submitRequestsHelper 方法
submitRequestsHelper();
}


//拍照
status_t Camera3Device::captureList(){
//预览和拍照都会调用到 submitRequestsHelper 方法
submitRequestsHelper();
}

// submitRequestsHelper 方法实现
status_t Camera3Device::submitRequestsHelper(){

if (repeating) {
//预览流程 setRepeatingRequests处理
res = mRequestThread->setRepeatingRequests(requestList, lastFrameNumber);
} else {
// 拍照流程处理 queueRequestList
res = mRequestThread->queueRequestList(requestList, lastFrameNumber);
}
}
//预览
status_t Camera3Device::RequestThread::setRepeatingRequests(){
... ...
}
//拍照
status_t Camera3Device::RequestThread::queueRequestList(){
... ...
}

//mRequestThread 流程分析
status_t Camera3Device::initializeCommonLocked() {

mRequestThread = new RequestThread();
res=mRequestThread->run();

}

//Camera3Device.h (frameworks\av\services\camera\libcameraservice\device3)
class RequestThread : public Thread {
... ...
}

bool Camera3Device::RequestThread::threadLoop(){

// Handle paused state. 如果没有Request请求时,将会等待50ms,再进行下一次判断
if (waitIfPaused()) {
return true;
}
// 最重要的三个方法 1.Wait for the next batch of requests.拍照请求的优先级肯定是高于预览请求
waitForNextRequestBatch();

... ...
// 最重要的三个方法 2.Prepare a batch of HAL requests and output buffers.
res = prepareHalRequests();

... ...
//最重要的三个方法 3.如果该值为true,那么继续循环
submitRequestSuccess = sendRequestsBatch();
}

bool Camera3Device::RequestThread::sendRequestsBatch() {


res = mInterface->processBatchCaptureRequests(requests, &numRequestProcessed);

}
status_t Camera3Device::HalInterface::processBatchCaptureRequests(){


if (hidlSession_3_4 != nullptr) {
// 调用 CameraDeviceSession.cpp 中的方法
err = hidlSession_3_4->processCaptureRequest_3_4( );
} else {
err = mHidlSession->processCaptureRequest( );
}

}


CameraDeviceSession.cpp (hardware\interfaces\camera\device\3.4\default)

    Return<void> CameraDeviceSession::processCaptureRequest_3_4(){

s = processOneCaptureRequest_3_4(requests[i])
}

Status CameraDeviceSession::processOneCaptureRequest_3_4(){

// 这个会跳转到 Camxhal3entry.cpp 中的process_capture_request 方法, 需要继续厘清跳转地方
ATRACE_BEGIN("camera3->process_capture_request");
status_t ret = mDevice->ops->process_capture_request(mDevice, &halRequest);
ATRACE_END();
}



Camxhal3entry.cpp (vendor\qcom\proprietary\camx\src\core\hal)

    int process_capture_request(){
// 会跳转到Camxhal3.cpp process_capture_request 方法
pHAL3->process_capture_request(pCamera3DeviceAPI, pCaptureRequestAPI);
}

Camxhal3.cpp (vendor\qcom\proprietary\camx\src\core\hal)

    static int process_capture_request(){

result = pHALDevice->ProcessCaptureRequest(pRequest);
}

Camxhaldevice.cpp (vendor\qcom\proprietary\camx\src\core\hal)

    CamxResult HALDevice::ProcessCaptureRequest(){
//调用 Chxextensioninterface.cpp chi_override_process_request 方法
result = GetCHIAppCallbacks()->chi_override_process_request()
}

Chxextensioninterface.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

    static CDKResult chi_override_process_request(){
// 调用 Chxextensionmodule.cpp OverrideProcessRequest方法
return pExtensionModule->OverrideProcessRequest();

}

Chxextensionmodule.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

    CDKResult ExtensionModule::OverrideProcessRequest(){

//选取 Usecase 去做ProcessCaptureRequest操作
result = m_pSelectedUsecase[logicalCameraId]->ProcessCaptureRequest(pCaptureRequest);
}

Chxusecase.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

    CDKResult Usecase::ProcessCaptureRequest(){
// 调用指定的UseCase
result = ExecuteCaptureRequest(pRequest);

}

Chxadvancedcamerausecase.cpp (vendor\qcom\proprietary\chi-cdk\core\chiusecase)

    CDKResult AdvancedCameraUsecase::ExecuteCaptureRequest(){


if(TRUE == AdvancedFeatureEnabled()){
// AdvancedFeatureEnabled HDR MFNR
result = pFeature->ExecuteProcessRequest(pRequest);
}else{

// 没有任何Feature 执行的流程,拍照
result = CameraUsecaseBase::ExecuteCaptureRequest(pRequest);
}
}


CDKResult CameraUsecaseBase::ExecuteCaptureRequest(){
// 没有任何Feature 执行的流程
CheckAndActivatePipeline(m_sessions[session].pSession);
... ...
result = SubmitRequest(&submitRequest);
}

Chxusecase.h (vendor\qcom\proprietary\chi-cdk\core\chiframework)

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


Chxextensionmodule.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

    CDKResult ExtensionModule::ActivatePipeline()
{
return g_chiContextOps.pActivatePipeline();
}

Camxchi.cpp (vendor\qcom\proprietary\camx\src\core\chi)

    static CDKResult ChiActivatePipeline(){

result = pChiContext->ActivatePipeline();

}

Camxchicontext.cpp (vendor\qcom\proprietary\camx\src\core\chi)

    CamxResult ChiContext::ActivatePipeline(){

result = pChiSession->StreamOn();

}

Camxsession.cpp (vendor\qcom\proprietary\camx\src\core)

    CamxResult Session::StreamOn(){

result = pPipeline->StreamOn();

}

Camxpipeline.cpp (vendor\qcom\proprietary\camx\src\core)

    CamxResult Pipeline::StreamOn(){

result = m_pChiContext->GetHwContext()->StreamOn();


}

Camxhwcontext.cpp (vendor\qcom\proprietary\camx\src\core)

    CamxResult HwContext::StreamOn(){
result = CSLStreamOn();

}

Camxcsl.cpp (vendor\qcom\proprietary\camx\src\csl)

    CamxResult CSLStreamOn(){

pJumpTable->CSLStreamOn();

}

Camxcslhw.cpp (vendor\qcom\proprietary\camx\src\csl\hw)


CamxResult CSLStreamOnHW(){

result = CSLHwStreamOnKMDHardwares();

}

Camxcslhwinternal.cpp (vendor\qcom\proprietary\camx\src\csl\hw)

    CamxResult CSLHwStreamOnKMDHardwares(){

result = pHWDevice->deviceOp.StreamOn();
}

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

    CDKResult AdvancedCameraUsecase::ExecuteCaptureRequest(){


if(TRUE == AdvancedFeatureEnabled()){
result = pFeature->ExecuteProcessRequest(pRequest);
}else{

// 没有任何Feature 执行的流程
result = CameraUsecaseBase::ExecuteCaptureRequest(pRequest);
}
}


CDKResult CameraUsecaseBase::ExecuteCaptureRequest(){
// 没有任何Feature 执行的流程
CheckAndActivatePipeline(m_sessions[session].pSession);
//Chxusecase .cpp
result = SubmitRequest(&submitRequest);
}

Chxusecase.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

    CDKResult Usecase::SubmitRequest(){
//
result = ExtensionModule::GetInstance()->SubmitRequest
}

Chxextensionmodule.cpp (vendor\qcom\proprietary\chi-cdk\core\chiframework)

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

Camxchi.cpp (vendor\qcom\proprietary\camx\src\core\chi)

    static CDKResult ChiSubmitPipelineRequest(){


result = pChiContext->SubmitRequest();
}

Camxchicontext.cpp (vendor\qcom\proprietary\camx\src\core\chi)

    CamxResult ChiContext::SubmitRequest(){

result = pSession->ProcessCaptureRequest();
}

Camxsession.cpp (vendor\qcom\proprietary\camx\src\core)

    CamxResult Session::ProcessCaptureRequest(){

// 暂未找到跳转到ProcessRequest 的地方

}

CamxResult Session::ProcessRequest(){

result = m_pipelineData[rRequest.pipelineIndex].pPipeline->OpenRequest();
//
result = m_pipelineData[rRequest.pipelineIndex].pPipeline->ProcessRequest();
}


Camxpipeline.cpp (vendor\qcom\proprietary\camx\src\core)

    CamxResult Pipeline::ProcessRequest(){
m_ppOrderedNodes[nodeIndex]->SetupRequest();

result = m_pDeferredRequestQueue->AddDeferredNode();
// Consider any nodes now ready
m_pDeferredRequestQueue->DispatchReadyNodes();
}

Camxdeferredrequestqueue.cpp (vendor\qcom\proprietary\camx\src\core)

    VOID DeferredRequestQueue::DispatchReadyNodes(){
... ...
}

CamxRequest流程

参考文章
1.https://blog.csdn.net/sinat_22657459/article/details/92380466
2.https://blog.csdn.net/TaylorPotter/article/details/105630341

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

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

浏览 140
10点赞
评论
收藏
分享

手机扫一扫分享

分享
举报
评论
图片
表情
推荐
10点赞
评论
收藏
分享

手机扫一扫分享

分享
举报