/frameworks/base/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
mCaptureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
public CaptureRequest.Builder createCaptureRequest(int templateType,Set physicalCameraIdSet)
templatedRequest = mRemoteDevice.createDefaultRequest(templateType);
CaptureRequest.Builder builder = new CaptureRequest.Builder(templatedRequest, /*reprocess*/false, CameraCaptureSession.SESSION_ID_NONE,getId(), physicalCameraIdSet);
return builder;
mCameraDevice.createCaptureSession(Arrays.asList(previewSurface, mImageReader.getSurface()), new CameraCaptureSession.StateCallback() {
public void createCaptureSession(List outputs,CameraCaptureSession.StateCallback callback, Handler handler)
List outConfigurations = new ArrayList<>(outputs.size());
for (Surface surface : outputs) {
outConfigurations.add(new OutputConfiguration(surface));
}
createCaptureSessionInternal(null, outConfigurations, callback,checkAndWrapHandler(handler), /*operatingMode*/ICameraDeviceUser.NORMAL_MODE,/*sessionParams*/ null);
private void createCaptureSessionInternal(InputConfiguration inputConfig,List outputConfigurations,
CameraCaptureSession.StateCallback callback, Executor executor,
int operatingMode, CaptureRequest sessionParams)
/*configure streams and then block until IDLE 这里就是配流*/
configureSuccess = configureStreamsChecked(inputConfig, outputConfigurations,operatingMode, sessionParams);
public boolean configureStreamsChecked(InputConfiguration inputConfig,List outputs, int operatingMode, CaptureRequest sessionParams)
/*前面一堆很多,看最主要的 Add all new streams*/
for (OutputConfiguration outConfig : outputs)
if (addSet.contains(outConfig))
int streamId = mRemoteDevice.createStream(outConfig);/*通过IPC这里就是CameraDeviceClient.cpp*/
mConfiguredOutputs.put(streamId, outConfig);
mRemoteDevice.endConfigure(operatingMode, sessionParams.getNativeCopy());/*上面创建完成configurestream后需要执行end*/
/*最终会到HAL的配流*/
return success;
newSession = new CameraCaptureSessionImpl(mNextSessionId++, input,callback, executor, this, mDeviceExecutor, configureSuccess);
mCurrentSession = newSession;
CameraCaptureSessionImpl构造函数
CameraCaptureSessionImpl(int id, Surface input,CameraCaptureSession.StateCallback callback, Executor stateExecutor,
android.hardware.camera2.impl.CameraDeviceImpl deviceImpl,Executor deviceStateExecutor, boolean configureSuccess)
mStateCallback = createUserStateCallbackProxy(mStateExecutor, callback);
/**********************************************************************************
这里会执行一个配流完成的回调 this是当前对象CameraCaptureSessionImpl
用来执行CameraCaptureSessionImpl->setRepeatingRequest
************************************************************************************/
mStateCallback.onConfigured(this);
/frameworks/base/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
mCameraCaptureSession.setRepeatingRequest(mCaptureRequest, null, mCameraHandler);
public int setRepeatingRequest(CaptureRequest request, CaptureCallback callback,Handler handler)
return addPendingSequence(mDeviceImpl.setRepeatingRequest(request,createCaptureCallbackProxy(handler, callback), mDeviceExecutor));
/*Notify the session that a pending capture sequence has just been queued.*/
private int addPendingSequence(int sequenceId)
/*拍照*/
/frameworks/base/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
public int capture(CaptureRequest request, CaptureCallback callback,Handler handler)
return addPendingSequence(mDeviceImpl.capture(request,createCaptureCallbackProxy(handler, callback), mDeviceExecutor));
private int addPendingSequence(int sequenceId) {
mSequenceDrainer.taskStarted(sequenceId);
return sequenceId;
}
/*/frameworks/base/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java*/
mDeviceImpl.capture(request,createCaptureCallbackProxy(handler, callback)
public int capture(CaptureRequest request, CaptureCallback callback, Executor executor)
List requestList = new ArrayList();
requestList.add(request);
return submitCaptureRequest(requestList, callback, executor, /*streaming*/false);/*拍照和预览都会调用该方法差别在最后一个参数*/
/*预览*/
/frameworks/base/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
public int setRepeatingRequest(CaptureRequest request, CaptureCallback callback,Executor executor)
return submitCaptureRequest(requestList, callback, executor, /*streaming*/true);/*streaming 这个参数拍照的时候是false,但不是这个方法*/
private int submitCaptureRequest(List requestList, CaptureCallback callback,Executor executor, boolean repeating)
requestInfo = mRemoteDevice.submitRequestList(requestArray, repeating);
binder::Status CameraDeviceClient::submitRequestList(/*/frameworks/av/services/camera/libcameraservice/api2/CameraDeviceClient.cpp*/
const std::vector& requests,
bool streaming,/*out*/hardware::camera2::utils::SubmitInfo *submitInfo)
binder::Status CameraDeviceClient::submitRequestList(const std::vector& requests,
bool streaming,/*out*/hardware::camera2::utils::SubmitInfo *submitInfo)
/*这个方法很多只看最后*/
if (streaming) {/*拍照和预览都会走这里 streaming 这个参数拍照的时候是false*/
err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,&(submitInfo->mLastFrameNumber));
if (err != OK) {
String8 msg = String8::format(
"Camera %s: Got error %s (%d) after trying to set streaming request",
mCameraIdStr.string(), strerror(-err), err);
ALOGE("%s: %s", __FUNCTION__, msg.string());
res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,msg.string());
} else {
Mutex::Autolock idLock(mStreamingRequestIdLock);
mStreamingRequestId = submitInfo->mRequestId;
}
} else {/*streaming == false 这里就是拍照流程*/
err = mDevice->captureList(metadataRequestList, surfaceMapList, &(submitInfo->mLastFrameNumber));
if (err != OK) {
String8 msg = String8::format(
"Camera %s: Got error %s (%d) after trying to submit capture request",
mCameraIdStr.string(), strerror(-err), err);
ALOGE("%s: %s", __FUNCTION__, msg.string());
res = STATUS_ERROR(CameraService::ERROR_INVALID_OPERATION,
msg.string());
}
ALOGV("%s: requestId = %d ", __FUNCTION__, submitInfo->mRequestId);
}
/frameworks/av/services/camera/libcameraservice/device3/Camera3Device.cpp
/*预览流程*/
err = mDevice->setStreamingRequestList(metadataRequestList, surfaceMapList,&(submitInfo->mLastFrameNumber));
status_t Camera3Device::setStreamingRequestList(const List &requestsList,const std::list &surfaceMaps, int64_t *lastFrameNumber)
return submitRequestsHelper(requestsList, surfaceMaps, /*repeating*/true, lastFrameNumber);
/*拍照流程*/
err = mDevice->captureList(metadataRequestList, surfaceMapList, &(submitInfo->mLastFrameNumber));
status_t Camera3Device::captureList(const List &requestsList,const std::list &surfaceMaps,int64_t *lastFrameNumber)
return submitRequestsHelper(requestsList, surfaceMaps, /*repeating*/false, lastFrameNumber);
/*预览和拍照都会走*/
status_t Camera3Device::submitRequestsHelper(const List &requests,
const std::list &surfaceMaps,
bool repeating,/*out*/int64_t *lastFrameNumber)
if (repeating) {
res = mRequestThread->setRepeatingRequests(requestList, lastFrameNumber);
status_t Camera3Device::RequestThread::setRepeatingRequests(const RequestList &requests,/*out*/int64_t *lastFrameNumber)
mRepeatingRequests.insert(mRepeatingRequests.begin(),requests.begin(), requests.end());
} else {
res = mRequestThread->queueRequestList(requestList, lastFrameNumber);
Camera3Device::RequestThread::queueRequestList(List > &requests,/*out*/int64_t *lastFrameNumber)
for (List >::iterator it = requests.begin(); it != requests.end();++it) {
mRequestQueue.push_back(*it);/*这里就是体现了拍照请求的优先级将当前的请求都放到拍照请求之后*/
}
}
至此就交给Frameworks中的请求处理线程执行,可以得出一个结论就是拍照请求需要APP下发一次,但是预览请求APP下发一次后Frameworks会连续循环下发请求