public class BlockingSessionCallback extends CameraCaptureSession.StateCallback
Provides a waiter that can be used to block until the next unobserved state of the requested type arrives.
Pass-through all StateCallback changes to the proxy.
getStateWaiter()
Modifier and Type | Field and Description |
---|---|
static int |
SESSION_ACTIVE
Session is active (transitory)
|
static int |
SESSION_CLOSED
Session is closed
|
static int |
SESSION_CONFIGURE_FAILED
Session has failed to configure, can't do any captures
|
static int |
SESSION_CONFIGURED
Session is configured, ready for captures
|
static int |
SESSION_READY
Session is ready
|
Constructor and Description |
---|
BlockingSessionCallback()
Create a blocking session listener without forwarding the session listener invocations
to another session listener.
|
BlockingSessionCallback(CameraCaptureSession.StateCallback listener)
Create a blocking session listener; forward original listener invocations
into
listener . |
Modifier and Type | Method and Description |
---|---|
StateWaiter |
getStateWaiter()
Acquire the state waiter; can be used to block until a set of state transitions have
been reached.
|
void |
onActive(CameraCaptureSession session)
This method is called when the session starts actively processing capture requests.
|
void |
onClosed(CameraCaptureSession session)
This method is called when the session is closed.
|
void |
onConfigured(CameraCaptureSession session)
This method is called when the camera device has finished configuring itself, and the
session can start processing capture requests.
|
void |
onConfigureFailed(CameraCaptureSession session)
This method is called if the session cannot be configured as requested.
|
void |
onReady(CameraCaptureSession session)
This method is called every time the session has no more capture requests to process.
|
void |
onSurfacePrepared(CameraCaptureSession session,
Surface surface)
This method is called when the buffer pre-allocation for an output Surface is complete.
|
CameraCaptureSession |
waitAndGetSession(long timeoutMs)
Return session if already have it; otherwise wait until any of the session listener
invocations fire and the session is available.
|
void |
waitForSurfacePrepared(CameraCaptureSession session,
Surface surface,
long timeoutMs)
Wait until the designated surface is prepared by the camera capture session.
|
public static final int SESSION_CONFIGURED
public static final int SESSION_CONFIGURE_FAILED
public static final int SESSION_READY
public static final int SESSION_ACTIVE
public static final int SESSION_CLOSED
public BlockingSessionCallback()
public BlockingSessionCallback(CameraCaptureSession.StateCallback listener)
listener
.listener
- a non-null
listener to forward invocations intoNullPointerException
- if listener
was null
public StateWaiter getStateWaiter()
Only one thread should wait at a time.
public CameraCaptureSession waitAndGetSession(long timeoutMs)
Does not consume any of the states from the state waiter.
timeoutMs
- how many milliseconds to wait fornull
CameraCaptureSession
instanceTimeoutRuntimeException
- if waiting for more than public void onActive(CameraCaptureSession session)
CameraCaptureSession.StateCallback
If capture requests are submitted prior to CameraCaptureSession.StateCallback.onConfigured(android.hardware.camera2.CameraCaptureSession)
being called,
then the session will start processing those requests immediately after the callback,
and this method will be immediately called after CameraCaptureSession.StateCallback.onConfigured(android.hardware.camera2.CameraCaptureSession)
.
If the session runs out of capture requests to process and calls CameraCaptureSession.StateCallback.onReady(android.hardware.camera2.CameraCaptureSession)
,
then this callback will be invoked again once new requests are submitted for capture.
onActive
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
public void onClosed(CameraCaptureSession session)
CameraCaptureSession.StateCallback
A session is closed when a new session is created by the parent camera device, or when the parent camera device is closed (either by the user closing the device, or due to a camera device disconnection or fatal error).
Once a session is closed, all methods on it will throw an IllegalStateException, and
any repeating requests or bursts are stopped (as if CameraCaptureSession.stopRepeating()
was called).
However, any in-progress capture requests submitted to the session will be completed
as normal.
onClosed
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
public void onConfigured(CameraCaptureSession session)
CameraCaptureSession.StateCallback
If there are capture requests already queued with the session, they will start
processing once this callback is invoked, and the session will call CameraCaptureSession.StateCallback.onActive(android.hardware.camera2.CameraCaptureSession)
right after this callback is invoked.
If no capture requests have been submitted, then the session will invoke
CameraCaptureSession.StateCallback.onReady(android.hardware.camera2.CameraCaptureSession)
right after this callback.
If the camera device configuration fails, then CameraCaptureSession.StateCallback.onConfigureFailed(android.hardware.camera2.CameraCaptureSession)
will
be invoked instead of this callback.
onConfigured
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
public void onConfigureFailed(CameraCaptureSession session)
CameraCaptureSession.StateCallback
This can happen if the set of requested outputs contains unsupported sizes, or too many outputs are requested at once.
The session is considered to be closed, and all methods called on it after this callback is invoked will throw an IllegalStateException. Any capture requests submitted to the session prior to this callback will be discarded and will not produce any callbacks on their listeners.
onConfigureFailed
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
public void onReady(CameraCaptureSession session)
CameraCaptureSession.StateCallback
During the creation of a new session, this callback is invoked right after
CameraCaptureSession.StateCallback.onConfigured(android.hardware.camera2.CameraCaptureSession)
if no capture requests were submitted to the session prior to it
completing configuration.
Otherwise, this callback will be invoked any time the session finishes processing all of its active capture requests, and no repeating request or burst is set up.
onReady
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
public void onSurfacePrepared(CameraCaptureSession session, Surface surface)
CameraCaptureSession.StateCallback
Buffer pre-allocation for an output Surface is started by the CameraCaptureSession.prepare(android.view.Surface)
call.
While allocation is underway, the Surface must not be used as a capture target.
Once this callback fires, the output Surface provided can again be used as a target for
a capture request.
In case of a error during pre-allocation (such as running out of suitable memory), this callback is still invoked after the error is encountered, though some buffers may not have been successfully pre-allocated.
onSurfacePrepared
in class CameraCaptureSession.StateCallback
session
- the session returned by CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)
surface
- the Surface that was used with the CameraCaptureSession.prepare(android.view.Surface)
call.public void waitForSurfacePrepared(CameraCaptureSession session, Surface surface, long timeoutMs)
session
- the input CameraCaptureSession
to wait forsurface
- the input Surface
to wait fortimeoutMs
- how many milliseconds to wait forTimeoutRuntimeException
- if waiting for more than