Merge "Camera: Release advanced extension references" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
7fa4d91518
@@ -77,18 +77,18 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
private static final String TAG = "CameraAdvancedExtensionSessionImpl";
|
private static final String TAG = "CameraAdvancedExtensionSessionImpl";
|
||||||
|
|
||||||
private final Executor mExecutor;
|
private final Executor mExecutor;
|
||||||
private final CameraDevice mCameraDevice;
|
private CameraDevice mCameraDevice;
|
||||||
private final Map<String, CameraMetadataNative> mCharacteristicsMap;
|
private final Map<String, CameraMetadataNative> mCharacteristicsMap;
|
||||||
private final long mExtensionClientId;
|
private final long mExtensionClientId;
|
||||||
private final Handler mHandler;
|
private final Handler mHandler;
|
||||||
private final HandlerThread mHandlerThread;
|
private final HandlerThread mHandlerThread;
|
||||||
private final CameraExtensionSession.StateCallback mCallbacks;
|
private final CameraExtensionSession.StateCallback mCallbacks;
|
||||||
private final IAdvancedExtenderImpl mAdvancedExtender;
|
private IAdvancedExtenderImpl mAdvancedExtender;
|
||||||
// maps registered camera surfaces to extension output configs
|
// maps registered camera surfaces to extension output configs
|
||||||
private final HashMap<Surface, CameraOutputConfig> mCameraConfigMap = new HashMap<>();
|
private final HashMap<Surface, CameraOutputConfig> mCameraConfigMap = new HashMap<>();
|
||||||
// maps camera extension output ids to camera registered image readers
|
// maps camera extension output ids to camera registered image readers
|
||||||
private final HashMap<Integer, ImageReader> mReaderMap = new HashMap<>();
|
private final HashMap<Integer, ImageReader> mReaderMap = new HashMap<>();
|
||||||
private final RequestProcessor mRequestProcessor = new RequestProcessor();
|
private RequestProcessor mRequestProcessor = new RequestProcessor();
|
||||||
private final int mSessionId;
|
private final int mSessionId;
|
||||||
|
|
||||||
private Surface mClientRepeatingRequestSurface;
|
private Surface mClientRepeatingRequestSurface;
|
||||||
@@ -100,7 +100,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
private final ExtensionSessionStatsAggregator mStatsAggregator;
|
private final ExtensionSessionStatsAggregator mStatsAggregator;
|
||||||
|
|
||||||
private boolean mInitialized;
|
private boolean mInitialized;
|
||||||
|
private boolean mSessionClosed;
|
||||||
|
|
||||||
// Lock to synchronize cross-thread access to device public interface
|
// Lock to synchronize cross-thread access to device public interface
|
||||||
final Object mInterfaceLock;
|
final Object mInterfaceLock;
|
||||||
@@ -237,6 +237,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
mHandlerThread.start();
|
mHandlerThread.start();
|
||||||
mHandler = new Handler(mHandlerThread.getLooper());
|
mHandler = new Handler(mHandlerThread.getLooper());
|
||||||
mInitialized = false;
|
mInitialized = false;
|
||||||
|
mSessionClosed = false;
|
||||||
mInitializeHandler = new InitializeSessionHandler();
|
mInitializeHandler = new InitializeSessionHandler();
|
||||||
mSessionId = sessionId;
|
mSessionId = sessionId;
|
||||||
mInterfaceLock = cameraDevice.mInterfaceLock;
|
mInterfaceLock = cameraDevice.mInterfaceLock;
|
||||||
@@ -424,7 +425,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
mSessionProcessor.setParameters(request);
|
mSessionProcessor.setParameters(request);
|
||||||
|
|
||||||
seqId = mSessionProcessor.startRepeating(new RequestCallbackHandler(request,
|
seqId = mSessionProcessor.startRepeating(new RequestCallbackHandler(request,
|
||||||
executor, listener));
|
executor, listener, mCameraDevice.getId()));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR,
|
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR,
|
||||||
"Failed to enable repeating request, extension service failed to respond!");
|
"Failed to enable repeating request, extension service failed to respond!");
|
||||||
@@ -452,7 +453,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
mSessionProcessor.setParameters(request);
|
mSessionProcessor.setParameters(request);
|
||||||
|
|
||||||
seqId = mSessionProcessor.startCapture(new RequestCallbackHandler(request,
|
seqId = mSessionProcessor.startCapture(new RequestCallbackHandler(request,
|
||||||
executor, listener), isPostviewRequested);
|
executor, listener, mCameraDevice.getId()), isPostviewRequested);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " +
|
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " +
|
||||||
" to submit capture request, extension service failed to respond!");
|
" to submit capture request, extension service failed to respond!");
|
||||||
@@ -460,8 +461,8 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
} else if ((mClientRepeatingRequestSurface != null) &&
|
} else if ((mClientRepeatingRequestSurface != null) &&
|
||||||
request.containsTarget(mClientRepeatingRequestSurface)) {
|
request.containsTarget(mClientRepeatingRequestSurface)) {
|
||||||
try {
|
try {
|
||||||
seqId = mSessionProcessor.startTrigger(request,
|
seqId = mSessionProcessor.startTrigger(request, new RequestCallbackHandler(
|
||||||
new RequestCallbackHandler(request, executor, listener));
|
request, executor, listener, mCameraDevice.getId()));
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " +
|
throw new CameraAccessException(CameraAccessException.CAMERA_ERROR, "Failed " +
|
||||||
" to submit trigger request, extension service failed to respond!");
|
" to submit trigger request, extension service failed to respond!");
|
||||||
@@ -528,6 +529,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
mCaptureSession.stopRepeating();
|
mCaptureSession.stopRepeating();
|
||||||
mSessionProcessor.stopRepeating();
|
mSessionProcessor.stopRepeating();
|
||||||
mSessionProcessor.onCaptureSessionEnd();
|
mSessionProcessor.onCaptureSessionEnd();
|
||||||
|
mSessionClosed = true;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Failed to stop the repeating request or end the session,"
|
Log.e(TAG, "Failed to stop the repeating request or end the session,"
|
||||||
+ " , extension service does not respond!") ;
|
+ " , extension service does not respond!") ;
|
||||||
@@ -560,6 +562,9 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
|
|
||||||
if (mSessionProcessor != null) {
|
if (mSessionProcessor != null) {
|
||||||
try {
|
try {
|
||||||
|
if (!mSessionClosed) {
|
||||||
|
mSessionProcessor.onCaptureSessionEnd();
|
||||||
|
}
|
||||||
mSessionProcessor.deInitSession();
|
mSessionProcessor.deInitSession();
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "Failed to de-initialize session processor, extension service"
|
Log.e(TAG, "Failed to de-initialize session processor, extension service"
|
||||||
@@ -584,6 +589,10 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
|
|
||||||
mClientRepeatingRequestSurface = null;
|
mClientRepeatingRequestSurface = null;
|
||||||
mClientCaptureSurface = null;
|
mClientCaptureSurface = null;
|
||||||
|
mCaptureSession = null;
|
||||||
|
mRequestProcessor = null;
|
||||||
|
mCameraDevice = null;
|
||||||
|
mAdvancedExtender = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (notifyClose && !skipCloseNotification) {
|
if (notifyClose && !skipCloseNotification) {
|
||||||
@@ -706,13 +715,16 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
private final CaptureRequest mClientRequest;
|
private final CaptureRequest mClientRequest;
|
||||||
private final Executor mClientExecutor;
|
private final Executor mClientExecutor;
|
||||||
private final ExtensionCaptureCallback mClientCallbacks;
|
private final ExtensionCaptureCallback mClientCallbacks;
|
||||||
|
private final String mCameraId;
|
||||||
|
|
||||||
private RequestCallbackHandler(@NonNull CaptureRequest clientRequest,
|
private RequestCallbackHandler(@NonNull CaptureRequest clientRequest,
|
||||||
@NonNull Executor clientExecutor,
|
@NonNull Executor clientExecutor,
|
||||||
@NonNull ExtensionCaptureCallback clientCallbacks) {
|
@NonNull ExtensionCaptureCallback clientCallbacks,
|
||||||
|
@NonNull String cameraId) {
|
||||||
mClientRequest = clientRequest;
|
mClientRequest = clientRequest;
|
||||||
mClientExecutor = clientExecutor;
|
mClientExecutor = clientExecutor;
|
||||||
mClientCallbacks = clientCallbacks;
|
mClientCallbacks = clientCallbacks;
|
||||||
|
mCameraId = cameraId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -784,7 +796,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
}
|
}
|
||||||
|
|
||||||
result.set(CaptureResult.SENSOR_TIMESTAMP, timestamp);
|
result.set(CaptureResult.SENSOR_TIMESTAMP, timestamp);
|
||||||
TotalCaptureResult totalResult = new TotalCaptureResult(mCameraDevice.getId(), result,
|
TotalCaptureResult totalResult = new TotalCaptureResult(mCameraId, result,
|
||||||
mClientRequest, requestId, timestamp, new ArrayList<>(), mSessionId,
|
mClientRequest, requestId, timestamp, new ArrayList<>(), mSessionId,
|
||||||
new PhysicalCaptureResultInfo[0]);
|
new PhysicalCaptureResultInfo[0]);
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
@@ -1036,6 +1048,11 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
public int submitBurst(List<Request> requests, IRequestCallback callback) {
|
public int submitBurst(List<Request> requests, IRequestCallback callback) {
|
||||||
int seqId = -1;
|
int seqId = -1;
|
||||||
try {
|
try {
|
||||||
|
synchronized (mInterfaceLock) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
return seqId;
|
||||||
|
}
|
||||||
|
|
||||||
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback);
|
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback);
|
||||||
ArrayList<CaptureRequest> captureRequests = new ArrayList<>();
|
ArrayList<CaptureRequest> captureRequests = new ArrayList<>();
|
||||||
for (Request request : requests) {
|
for (Request request : requests) {
|
||||||
@@ -1044,6 +1061,7 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
}
|
}
|
||||||
seqId = mCaptureSession.captureBurstRequests(captureRequests,
|
seqId = mCaptureSession.captureBurstRequests(captureRequests,
|
||||||
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback);
|
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback);
|
||||||
|
}
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
Log.e(TAG, "Failed to submit capture requests!");
|
Log.e(TAG, "Failed to submit capture requests!");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@@ -1057,11 +1075,17 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
public int setRepeating(Request request, IRequestCallback callback) {
|
public int setRepeating(Request request, IRequestCallback callback) {
|
||||||
int seqId = -1;
|
int seqId = -1;
|
||||||
try {
|
try {
|
||||||
|
synchronized (mInterfaceLock) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
return seqId;
|
||||||
|
}
|
||||||
|
|
||||||
CaptureRequest repeatingRequest = initializeCaptureRequest(mCameraDevice,
|
CaptureRequest repeatingRequest = initializeCaptureRequest(mCameraDevice,
|
||||||
request, mCameraConfigMap);
|
request, mCameraConfigMap);
|
||||||
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback);
|
CaptureCallbackHandler captureCallback = new CaptureCallbackHandler(callback);
|
||||||
seqId = mCaptureSession.setSingleRepeatingRequest(repeatingRequest,
|
seqId = mCaptureSession.setSingleRepeatingRequest(repeatingRequest,
|
||||||
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback);
|
new CameraExtensionUtils.HandlerExecutor(mHandler), captureCallback);
|
||||||
|
}
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
Log.e(TAG, "Failed to enable repeating request!");
|
Log.e(TAG, "Failed to enable repeating request!");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@@ -1074,7 +1098,13 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
@Override
|
@Override
|
||||||
public void abortCaptures() {
|
public void abortCaptures() {
|
||||||
try {
|
try {
|
||||||
|
synchronized (mInterfaceLock) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mCaptureSession.abortCaptures();
|
mCaptureSession.abortCaptures();
|
||||||
|
}
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
Log.e(TAG, "Failed during capture abort!");
|
Log.e(TAG, "Failed during capture abort!");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
@@ -1085,7 +1115,13 @@ public final class CameraAdvancedExtensionSessionImpl extends CameraExtensionSes
|
|||||||
@Override
|
@Override
|
||||||
public void stopRepeating() {
|
public void stopRepeating() {
|
||||||
try {
|
try {
|
||||||
|
synchronized (mInterfaceLock) {
|
||||||
|
if (!mInitialized) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mCaptureSession.stopRepeating();
|
mCaptureSession.stopRepeating();
|
||||||
|
}
|
||||||
} catch (CameraAccessException e) {
|
} catch (CameraAccessException e) {
|
||||||
Log.e(TAG, "Failed during repeating capture stop!");
|
Log.e(TAG, "Failed during repeating capture stop!");
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalStateException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user