Solve the issue that the injection camera cannot be injected when the stream configuration is completed and the camera device is active
It runs normally in “First call injectCamera() and then run
configureStreamsLocked()" case, but there are the following issues in
"First run configureStreamsLocked() and then call injectCamera()"
case:
- The streaming configuration of the internal camera is not stored
correctly.
Solution: Added storeInjectionConfig() to store internal configure
when the stream configuration is completed and injectCamera() has not
been called.
- After internalPauseAndWaitLocked(), readOneCameraMetadataLocked()
will have the problem of "Cannot read camera metadata from fmq",
resulting in removeInFlightRequestIfReadyLocked() unable to completely
clear mInFlightMap. The root cause is to directly override
mResultMetadataQueue in injectionInitialize(), but the above issue
will occur when the camera device is active.
Solution: Generate mInjectionResultMetadataQueue during
injectionInitialize(). When injecting camera, save the original
mResultMetadataQueue into mBackupResultMetadataQueue, and replace the
original mResultMetadataQueue with mInjectionResultMetadataQueue.
- When the camera device is active, injectCamera() and stopInjection()
will call internalPauseAndWaitLocked() and internalResumeLocked(), and
then they will call mStatusChanged.waitRelative(mLock, timeout) of
waitUntilStateThenRelock(). But mStatusChanged.waitRelative(mLock,
timeout)'s parameter: mutex "mLock" must be in the locked state
(https://source.corp.google.com/android/system/core/libutils/include/utils/Condition.h;l=67)
, so we need to add "Mutex::Autolock l(mLock)" here to lock the
"mLock" before calling internalPauseAndWaitLocked() or
internalResumeLocked(). If we don't do this, it may cause the mutex
"mLock" state to be out of order. After that, all functions that use
the mutex "mLock" will be in a waiting state, such as
clearStreamingRequest() called when the camera is closed.
Solution: Added "Mutex::Autolock l(mLock)" in injectCamera() and
stopInjection().
- Unable to run stopInjection() function from app.
Solution: First obtain the client descriptor from ActiveClientManager,
and then call clearInjectionParameters(), otherwise
mInjectionInternalCamId iscleared and the corresponding client
descriptor cannot be obtained.
Bug: 189289800
Test: Manual
Change-Id: If5ca8d7a8431d58d97214d5e6faa7a0e5013f862
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index efb0a04..7b138a6 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -3854,7 +3854,6 @@
void CameraService::InjectionStatusListener::notifyInjectionError(
String8 injectedCamId, status_t err) {
- Mutex::Autolock lock(mListenerLock);
if (mCameraInjectionCallback == nullptr) {
ALOGW("InjectionStatusListener: mCameraInjectionCallback == nullptr");
return;
@@ -3901,16 +3900,15 @@
void CameraService::InjectionStatusListener::binderDied(
const wp<IBinder>& /*who*/) {
- Mutex::Autolock lock(mListenerLock);
ALOGV("InjectionStatusListener: ICameraInjectionCallback has died");
auto parent = mParent.promote();
if (parent != nullptr) {
- parent->clearInjectionParameters();
auto clientDescriptor = parent->mActiveClientManager.get(parent->mInjectionInternalCamId);
if (clientDescriptor != nullptr) {
BasicClient* baseClientPtr = clientDescriptor->getValue().get();
baseClientPtr->stopInjection();
}
+ parent->clearInjectionParameters();
}
}
@@ -3928,7 +3926,6 @@
}
status_t res = NO_ERROR;
- parent->clearInjectionParameters();
auto clientDescriptor = parent->mActiveClientManager.get(parent->mInjectionInternalCamId);
if (clientDescriptor != nullptr) {
BasicClient* baseClientPtr = clientDescriptor->getValue().get();
@@ -3940,6 +3937,7 @@
"Camera session encountered error");
}
}
+ parent->clearInjectionParameters();
return binder::Status::ok();
}