Camera2ClientBase::disconnect() ->detachDevice()
Camera2ClientBase
close/disconnect/detachDevice的关系??? Camera3Device::disconnectImpl() CameraDeviceClient::detachDevice() Camera2ClientBase::detachDevice()
Camera3Device里HalInterface链接到如下: hardware/interfaces/camera/device/3.4/default/CameraDeviceSession.cpp
template <typename TClientBase>
Camera2ClientBase<TClientBase>::~Camera2ClientBase() {
ATRACE_CALL();
TClientBase::mDestructionStarted = true;
disconnect();
ALOGI("Closed Camera %s. Client was: %s (PID %d, UID %u)",
TClientBase::mCameraIdStr.string(),
String8(TClientBase::mClientPackageName).string(),
mInitialClientPid, TClientBase::mClientUid);
}
status_t Camera3Device::waitUntilDrained() {
ATRACE_CALL();
Mutex::Autolock il(mInterfaceLock);
nsecs_t maxExpectedDuration = getExpectedInFlightDuration();
Mutex::Autolock l(mLock);
return waitUntilDrainedLocked(maxExpectedDuration);
}
status_t Camera3Device::waitUntilDrainedLocked(nsecs_t maxExpectedDuration) {
switch (mStatus) {
case STATUS_UNINITIALIZED:
case STATUS_UNCONFIGURED:
ALOGV("%s: Already idle", __FUNCTION__);
return OK;
case STATUS_CONFIGURED:
case STATUS_ERROR:
case STATUS_ACTIVE:
break;
default:
SET_ERR_L("Unexpected status: %d",mStatus);
return INVALID_OPERATION;
}
ALOGV("%s: Camera %s: Waiting until idle (%" PRIi64 "ns)", __FUNCTION__, mId.string(),
maxExpectedDuration);
status_t res = waitUntilStateThenRelock( false, maxExpectedDuration);
if (res != OK) {
SET_ERR_L("Error waiting for HAL to drain: %s (%d)", strerror(-res),
res);
}
return res;
}
libcameraservice/device3/Camera3Device.cpp
void CameraDeviceClient::detachDevice() {
if (mDevice == 0) return;
ALOGV("Camera %s: Stopping processors", mCameraIdStr.string());
mFrameProcessor->removeListener(FRAME_PROCESSOR_LISTENER_MIN_ID,
FRAME_PROCESSOR_LISTENER_MAX_ID,
this);
mFrameProcessor->requestExit();
ALOGV("Camera %s: Waiting for threads", mCameraIdStr.string());
mFrameProcessor->join();
ALOGV("Camera %s: Disconnecting device", mCameraIdStr.string());
{
int64_t lastFrameNumber;
status_t code;
if ((code = mDevice->flush(&lastFrameNumber)) != OK) {
ALOGE("%s: flush failed with code 0x%x", __FUNCTION__, code);
}
if ((code = mDevice->waitUntilDrained()) != OK) {
ALOGE("%s: waitUntilDrained failed with code 0x%x", __FUNCTION__,
code);
}
}
for (size_t i = 0; i < mCompositeStreamMap.size(); i++) {
auto ret = mCompositeStreamMap.valueAt(i)->deleteInternalStreams();
if (ret != OK) {
ALOGE("%s: Failed removing composite stream %s (%d)", __FUNCTION__,
strerror(-ret), ret);
}
}
mCompositeStreamMap.clear();
Camera2ClientBase::detachDevice();
}
libcameraservice/api2/CameraDeviceClient.cpp
|