FileDocCategorySizeDatePackage
BlockingSessionCallback.javaAPI DocAndroid 5.1 API7295Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.blocking

BlockingSessionCallback

public class BlockingSessionCallback extends CameraCaptureSession.StateCallback
A camera session listener that implements blocking operations on session state changes.

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.

see
#getStateWaiter

Fields Summary
public static final int
SESSION_CONFIGURED
Session is configured, ready for captures
public static final int
SESSION_CONFIGURE_FAILED
Session has failed to configure, can't do any captures
public static final int
SESSION_READY
Session is ready
public static final int
SESSION_ACTIVE
Session is active (transitory)
public static final int
SESSION_CLOSED
Session is closed
private final int
NUM_STATES
private static final String
TAG
private static final boolean
VERBOSE
private final CameraCaptureSession.StateCallback
mProxy
private final SessionFuture
mSessionFuture
private final com.android.ex.camera2.utils.StateWaiter
mStateWaiter
private final com.android.ex.camera2.utils.StateChangeListener
mStateChangeListener
private static final String[]
sStateNames
Constructors Summary
public BlockingSessionCallback()
Create a blocking session listener without forwarding the session listener invocations to another session listener.


                        
      
        mProxy = null;
    
public BlockingSessionCallback(CameraCaptureSession.StateCallback listener)
Create a blocking session listener; forward original listener invocations into {@code listener}.

param
listener a non-{@code null} listener to forward invocations into
throws
NullPointerException if {@code listener} was {@code null}

        if (listener == null) {
            throw new NullPointerException("listener must not be null");
        }
        mProxy = listener;
    
Methods Summary
public com.android.ex.camera2.utils.StateWaitergetStateWaiter()
Acquire the state waiter; can be used to block until a set of state transitions have been reached.

Only one thread should wait at a time.

        return mStateWaiter;
    
public voidonActive(android.hardware.camera2.CameraCaptureSession session)

        mSessionFuture.setSession(session);
        if (mProxy != null) mProxy.onActive(session);
        mStateChangeListener.onStateChanged(SESSION_ACTIVE);
    
public voidonClosed(android.hardware.camera2.CameraCaptureSession session)

        mSessionFuture.setSession(session);
        if (mProxy != null) mProxy.onClosed(session);
        mStateChangeListener.onStateChanged(SESSION_CLOSED);
    
public voidonConfigureFailed(android.hardware.camera2.CameraCaptureSession session)

        mSessionFuture.setSession(session);
        if (mProxy != null) mProxy.onConfigureFailed(session);
        mStateChangeListener.onStateChanged(SESSION_CONFIGURE_FAILED);
    
public voidonConfigured(android.hardware.camera2.CameraCaptureSession session)

        mSessionFuture.setSession(session);
        if (mProxy != null) mProxy.onConfigured(session);
        mStateChangeListener.onStateChanged(SESSION_CONFIGURED);
    
public voidonReady(android.hardware.camera2.CameraCaptureSession session)

        mSessionFuture.setSession(session);
        if (mProxy != null) mProxy.onReady(session);
        mStateChangeListener.onStateChanged(SESSION_READY);
    
public android.hardware.camera2.CameraCaptureSessionwaitAndGetSession(long timeoutMs)
Return session if already have it; otherwise wait until any of the session listener invocations fire and the session is available.

Does not consume any of the states from the state waiter.

param
timeoutMs how many milliseconds to wait for
return
a non-{@code null} {@link CameraCaptureSession} instance
throws
TimeoutRuntimeException if waiting for more than {@long timeoutMs}

        try {
            return mSessionFuture.get(timeoutMs, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            throw new TimeoutRuntimeException(
                    String.format("Failed to get session after %s milliseconds", timeoutMs), e);
        }