Loading core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java +8 −4 Original line number Original line Diff line number Diff line Loading @@ -68,6 +68,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { /** This session is closed; all further calls will throw ISE */ /** This session is closed; all further calls will throw ISE */ private boolean mClosed = false; private boolean mClosed = false; /** This session failed to be configured successfully */ private final boolean mConfigureSuccess; /** Do not unconfigure if this is set; another session will overwrite configuration */ /** Do not unconfigure if this is set; another session will overwrite configuration */ private boolean mSkipUnconfigure = false; private boolean mSkipUnconfigure = false; Loading Loading @@ -119,10 +121,12 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { if (configureSuccess) { if (configureSuccess) { mStateListener.onConfigured(this); mStateListener.onConfigured(this); if (VERBOSE) Log.v(TAG, "ctor - Created session successfully"); if (VERBOSE) Log.v(TAG, "ctor - Created session successfully"); mConfigureSuccess = true; } else { } else { mStateListener.onConfigureFailed(this); mStateListener.onConfigureFailed(this); mClosed = true; // do not fire any other callbacks, do not allow any other work mClosed = true; // do not fire any other callbacks, do not allow any other work Log.e(TAG, "Failed to create capture session; configuration failed"); Log.e(TAG, "Failed to create capture session; configuration failed"); mConfigureSuccess = false; } } } } Loading Loading @@ -285,9 +289,9 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { // - This session is active, so close() below starts the shutdown drain // - This session is active, so close() below starts the shutdown drain // - This session is mid-shutdown drain, and hasn't yet reached the idle drain listener. // - This session is mid-shutdown drain, and hasn't yet reached the idle drain listener. // - This session is already closed and has executed the idle drain listener, and // - This session is already closed and has executed the idle drain listener, and // configureOutputs(null) has already been called. // configureOutputsChecked(null) has already been called. // // // Do not call configureOutputs(null) going forward, since it would race with the // Do not call configureOutputsChecked(null) going forward, since it would race with the // configuration for the new session. If it was already called, then we don't care, since it // configuration for the new session. If it was already called, then we don't care, since it // won't get called again. // won't get called again. mSkipUnconfigure = true; mSkipUnconfigure = true; Loading Loading @@ -506,7 +510,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { public void onUnconfigured(CameraDevice camera) { public void onUnconfigured(CameraDevice camera) { synchronized (session) { synchronized (session) { // Ignore #onUnconfigured before #close is called // Ignore #onUnconfigured before #close is called if (mClosed) { if (mClosed && mConfigureSuccess) { mUnconfigureDrainer.taskFinished(); mUnconfigureDrainer.taskFinished(); } } } } Loading Loading @@ -619,7 +623,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { try { try { mUnconfigureDrainer.taskStarted(); mUnconfigureDrainer.taskStarted(); mDeviceImpl.configureOutputs(null); // begin transition to unconfigured state mDeviceImpl.configureOutputsChecked(null); // begin transition to unconfigured } catch (CameraAccessException e) { } catch (CameraAccessException e) { // OK: do not throw checked exceptions. // OK: do not throw checked exceptions. Log.e(TAG, "Exception while configuring outputs: ", e); Log.e(TAG, "Exception while configuring outputs: ", e); Loading core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +45 −9 Original line number Original line Diff line number Diff line Loading @@ -312,10 +312,33 @@ public class CameraDeviceImpl extends CameraDevice { } } public void configureOutputs(List<Surface> outputs) throws CameraAccessException { public void configureOutputs(List<Surface> outputs) throws CameraAccessException { // Leave this here for backwards compatibility with older code using this directly configureOutputsChecked(outputs); } /** * Attempt to configure the outputs; the device goes to idle and then configures the * new outputs if possible. * * <p>The configuration may gracefully fail, if there are too many outputs, if the formats * are not supported, or if the sizes for that format is not supported. In this case this * function will return {@code false} and the unconfigured callback will be fired.</p> * * <p>If the configuration succeeds (with 1 or more outputs), then the idle callback is fired. * Unconfiguring the device always fires the idle callback.</p> * * @param outputs a list of one or more surfaces, or {@code null} to unconfigure * @return whether or not the configuration was successful * * @throws CameraAccessException if there were any unexpected problems during configuration */ public boolean configureOutputsChecked(List<Surface> outputs) throws CameraAccessException { // Treat a null input the same an empty list // Treat a null input the same an empty list if (outputs == null) { if (outputs == null) { outputs = new ArrayList<Surface>(); outputs = new ArrayList<Surface>(); } } boolean success = false; synchronized(mInterfaceLock) { synchronized(mInterfaceLock) { checkIfCameraClosedOrInError(); checkIfCameraClosedOrInError(); Loading Loading @@ -355,7 +378,17 @@ public class CameraDeviceImpl extends CameraDevice { mConfiguredOutputs.put(streamId, s); mConfiguredOutputs.put(streamId, s); } } try { mRemoteDevice.endConfigure(); mRemoteDevice.endConfigure(); } catch (IllegalArgumentException e) { // OK. camera service can reject stream config if it's not supported by HAL // This is only the result of a programmer misusing the camera2 api. Log.e(TAG, "Stream configuration failed", e); return false; } success = true; } catch (CameraRuntimeException e) { } catch (CameraRuntimeException e) { if (e.getReason() == CAMERA_IN_USE) { if (e.getReason() == CAMERA_IN_USE) { throw new IllegalStateException("The camera is currently busy." + throw new IllegalStateException("The camera is currently busy." + Loading @@ -365,17 +398,20 @@ public class CameraDeviceImpl extends CameraDevice { throw e.asChecked(); throw e.asChecked(); } catch (RemoteException e) { } catch (RemoteException e) { // impossible // impossible return; return false; } } finally { if (success && outputs.size() > 0) { if (outputs.size() > 0) { mDeviceHandler.post(mCallOnIdle); mDeviceHandler.post(mCallOnIdle); } else { } else { // Always return to the 'unconfigured' state if we didn't hit a fatal error mDeviceHandler.post(mCallOnUnconfigured); mDeviceHandler.post(mCallOnUnconfigured); } } } } } } return success; } @Override @Override public void createCaptureSession(List<Surface> outputs, public void createCaptureSession(List<Surface> outputs, CameraCaptureSession.StateListener listener, Handler handler) CameraCaptureSession.StateListener listener, Handler handler) Loading @@ -397,7 +433,7 @@ public class CameraDeviceImpl extends CameraDevice { boolean configureSuccess = true; boolean configureSuccess = true; CameraAccessException pendingException = null; CameraAccessException pendingException = null; try { try { configureOutputs(outputs); // and then block until IDLE configureSuccess = configureOutputsChecked(outputs); // and then block until IDLE } catch (CameraAccessException e) { } catch (CameraAccessException e) { configureSuccess = false; configureSuccess = false; pendingException = e; pendingException = e; Loading Loading
core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java +8 −4 Original line number Original line Diff line number Diff line Loading @@ -68,6 +68,8 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { /** This session is closed; all further calls will throw ISE */ /** This session is closed; all further calls will throw ISE */ private boolean mClosed = false; private boolean mClosed = false; /** This session failed to be configured successfully */ private final boolean mConfigureSuccess; /** Do not unconfigure if this is set; another session will overwrite configuration */ /** Do not unconfigure if this is set; another session will overwrite configuration */ private boolean mSkipUnconfigure = false; private boolean mSkipUnconfigure = false; Loading Loading @@ -119,10 +121,12 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { if (configureSuccess) { if (configureSuccess) { mStateListener.onConfigured(this); mStateListener.onConfigured(this); if (VERBOSE) Log.v(TAG, "ctor - Created session successfully"); if (VERBOSE) Log.v(TAG, "ctor - Created session successfully"); mConfigureSuccess = true; } else { } else { mStateListener.onConfigureFailed(this); mStateListener.onConfigureFailed(this); mClosed = true; // do not fire any other callbacks, do not allow any other work mClosed = true; // do not fire any other callbacks, do not allow any other work Log.e(TAG, "Failed to create capture session; configuration failed"); Log.e(TAG, "Failed to create capture session; configuration failed"); mConfigureSuccess = false; } } } } Loading Loading @@ -285,9 +289,9 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { // - This session is active, so close() below starts the shutdown drain // - This session is active, so close() below starts the shutdown drain // - This session is mid-shutdown drain, and hasn't yet reached the idle drain listener. // - This session is mid-shutdown drain, and hasn't yet reached the idle drain listener. // - This session is already closed and has executed the idle drain listener, and // - This session is already closed and has executed the idle drain listener, and // configureOutputs(null) has already been called. // configureOutputsChecked(null) has already been called. // // // Do not call configureOutputs(null) going forward, since it would race with the // Do not call configureOutputsChecked(null) going forward, since it would race with the // configuration for the new session. If it was already called, then we don't care, since it // configuration for the new session. If it was already called, then we don't care, since it // won't get called again. // won't get called again. mSkipUnconfigure = true; mSkipUnconfigure = true; Loading Loading @@ -506,7 +510,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { public void onUnconfigured(CameraDevice camera) { public void onUnconfigured(CameraDevice camera) { synchronized (session) { synchronized (session) { // Ignore #onUnconfigured before #close is called // Ignore #onUnconfigured before #close is called if (mClosed) { if (mClosed && mConfigureSuccess) { mUnconfigureDrainer.taskFinished(); mUnconfigureDrainer.taskFinished(); } } } } Loading Loading @@ -619,7 +623,7 @@ public class CameraCaptureSessionImpl extends CameraCaptureSession { try { try { mUnconfigureDrainer.taskStarted(); mUnconfigureDrainer.taskStarted(); mDeviceImpl.configureOutputs(null); // begin transition to unconfigured state mDeviceImpl.configureOutputsChecked(null); // begin transition to unconfigured } catch (CameraAccessException e) { } catch (CameraAccessException e) { // OK: do not throw checked exceptions. // OK: do not throw checked exceptions. Log.e(TAG, "Exception while configuring outputs: ", e); Log.e(TAG, "Exception while configuring outputs: ", e); Loading
core/java/android/hardware/camera2/impl/CameraDeviceImpl.java +45 −9 Original line number Original line Diff line number Diff line Loading @@ -312,10 +312,33 @@ public class CameraDeviceImpl extends CameraDevice { } } public void configureOutputs(List<Surface> outputs) throws CameraAccessException { public void configureOutputs(List<Surface> outputs) throws CameraAccessException { // Leave this here for backwards compatibility with older code using this directly configureOutputsChecked(outputs); } /** * Attempt to configure the outputs; the device goes to idle and then configures the * new outputs if possible. * * <p>The configuration may gracefully fail, if there are too many outputs, if the formats * are not supported, or if the sizes for that format is not supported. In this case this * function will return {@code false} and the unconfigured callback will be fired.</p> * * <p>If the configuration succeeds (with 1 or more outputs), then the idle callback is fired. * Unconfiguring the device always fires the idle callback.</p> * * @param outputs a list of one or more surfaces, or {@code null} to unconfigure * @return whether or not the configuration was successful * * @throws CameraAccessException if there were any unexpected problems during configuration */ public boolean configureOutputsChecked(List<Surface> outputs) throws CameraAccessException { // Treat a null input the same an empty list // Treat a null input the same an empty list if (outputs == null) { if (outputs == null) { outputs = new ArrayList<Surface>(); outputs = new ArrayList<Surface>(); } } boolean success = false; synchronized(mInterfaceLock) { synchronized(mInterfaceLock) { checkIfCameraClosedOrInError(); checkIfCameraClosedOrInError(); Loading Loading @@ -355,7 +378,17 @@ public class CameraDeviceImpl extends CameraDevice { mConfiguredOutputs.put(streamId, s); mConfiguredOutputs.put(streamId, s); } } try { mRemoteDevice.endConfigure(); mRemoteDevice.endConfigure(); } catch (IllegalArgumentException e) { // OK. camera service can reject stream config if it's not supported by HAL // This is only the result of a programmer misusing the camera2 api. Log.e(TAG, "Stream configuration failed", e); return false; } success = true; } catch (CameraRuntimeException e) { } catch (CameraRuntimeException e) { if (e.getReason() == CAMERA_IN_USE) { if (e.getReason() == CAMERA_IN_USE) { throw new IllegalStateException("The camera is currently busy." + throw new IllegalStateException("The camera is currently busy." + Loading @@ -365,17 +398,20 @@ public class CameraDeviceImpl extends CameraDevice { throw e.asChecked(); throw e.asChecked(); } catch (RemoteException e) { } catch (RemoteException e) { // impossible // impossible return; return false; } } finally { if (success && outputs.size() > 0) { if (outputs.size() > 0) { mDeviceHandler.post(mCallOnIdle); mDeviceHandler.post(mCallOnIdle); } else { } else { // Always return to the 'unconfigured' state if we didn't hit a fatal error mDeviceHandler.post(mCallOnUnconfigured); mDeviceHandler.post(mCallOnUnconfigured); } } } } } } return success; } @Override @Override public void createCaptureSession(List<Surface> outputs, public void createCaptureSession(List<Surface> outputs, CameraCaptureSession.StateListener listener, Handler handler) CameraCaptureSession.StateListener listener, Handler handler) Loading @@ -397,7 +433,7 @@ public class CameraDeviceImpl extends CameraDevice { boolean configureSuccess = true; boolean configureSuccess = true; CameraAccessException pendingException = null; CameraAccessException pendingException = null; try { try { configureOutputs(outputs); // and then block until IDLE configureSuccess = configureOutputsChecked(outputs); // and then block until IDLE } catch (CameraAccessException e) { } catch (CameraAccessException e) { configureSuccess = false; configureSuccess = false; pendingException = e; pendingException = e; Loading