FileDocCategorySizeDatePackage
CameraAgent.javaAPI DocAndroid 5.1 API38600Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.portability

CameraAgent

public abstract class CameraAgent extends Object
An interface which provides possible camera device operations. The client should call {@code CameraAgent.openCamera} to get an instance of {@link CameraAgent.CameraProxy} to control the camera. Classes implementing this interface should have its own one unique {@code Thread} other than the main thread for camera operations. Camera device callbacks are wrapped since the client should not deal with {@code android.hardware.Camera} directly. TODO: provide callback interfaces for: {@code android.hardware.Camera.ErrorCallback}, {@code android.hardware.Camera.OnZoomChangeListener}, and

Fields Summary
public static final long
CAMERA_OPERATION_TIMEOUT_MS
private static final Log.Tag
TAG
Constructors Summary
Methods Summary
public voidcloseCamera(com.android.ex.camera2.portability.CameraAgent$CameraProxy camera, boolean synced)
Closes the camera device.

param
camera The camera to close. {@code null} means all.
param
synced Whether this call should be synchronous.

        try {
            if (synced) {
                // Don't bother to wait since camera is in bad state.
                if (getCameraState().isInvalid()) {
                    return;
                }
                final WaitDoneBundle bundle = new WaitDoneBundle();

                getDispatchThread().runJobSync(new Runnable() {
                    @Override
                    public void run() {
                        getCameraHandler().obtainMessage(CameraActions.RELEASE).sendToTarget();
                        getCameraHandler().post(bundle.mUnlockRunnable);
                    }}, bundle.mWaitLock, CAMERA_OPERATION_TIMEOUT_MS, "camera release");
            } else {
                getDispatchThread().runJob(new Runnable() {
                    @Override
                    public void run() {
                        getCameraHandler().removeCallbacksAndMessages(null);
                        getCameraHandler().obtainMessage(CameraActions.RELEASE).sendToTarget();
                    }});
            }
        } catch (final RuntimeException ex) {
            getCameraExceptionHandler().onDispatchThreadException(ex);
        }
    
public abstract CameraDeviceInfogetCameraDeviceInfo()

return
The camera devices info.

protected abstract CameraExceptionHandlergetCameraExceptionHandler()

return
The exception handler.

protected abstract android.os.HandlergetCameraHandler()

return
The handler to which camera tasks should be posted.

protected abstract CameraStateHoldergetCameraState()

return
The state machine tracking the camera API's current status.

protected abstract DispatchThreadgetDispatchThread()

return
The thread used on which client callbacks are served.

public voidopenCamera(android.os.Handler handler, int cameraId, com.android.ex.camera2.portability.CameraAgent$CameraOpenCallback callback)
Opens the camera of the specified ID asynchronously. The camera device will be opened in the camera handler thread and will be returned through the {@link CameraAgent.CameraOpenCallback# onCameraOpened(com.android.camera.cameradevice.CameraAgent.CameraProxy)}.

param
handler The {@link android.os.Handler} in which the callback was handled.
param
callback The callback for the result.
param
cameraId The camera ID to open.

        try {
            getDispatchThread().runJob(new Runnable() {
                @Override
                public void run() {
                    getCameraHandler().obtainMessage(CameraActions.OPEN_CAMERA, cameraId, 0,
                            CameraOpenCallbackForward.getNewInstance(handler, callback)).sendToTarget();
                }
            });
        } catch (final RuntimeException ex) {
            getCameraExceptionHandler().onDispatchThreadException(ex);
        }
    
public abstract voidrecycle()
Recycles the resources used by this instance. CameraAgent will be in an unusable state after calling this.

public abstract voidsetCameraExceptionHandler(CameraExceptionHandler exceptionHandler)
Sets a callback for handling camera api runtime exceptions on a handler.