1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.camera.one.v2.camera2proxy; 18 19 import java.util.List; 20 21 import android.hardware.camera2.CameraAccessException; 22 import android.hardware.camera2.CameraCaptureSession; 23 import android.hardware.camera2.CameraDevice; 24 import android.hardware.camera2.CaptureRequest; 25 import android.os.Handler; 26 import android.view.Surface; 27 28 import javax.annotation.Nullable; 29 import javax.annotation.ParametersAreNonnullByDefault; 30 31 @ParametersAreNonnullByDefault 32 public class AndroidCameraDeviceProxy implements CameraDeviceProxy { 33 private static class AndroidCaptureSessionStateCallback extends 34 CameraCaptureSession.StateCallback { 35 private final CameraCaptureSessionProxy.StateCallback mStateCallback; 36 AndroidCaptureSessionStateCallback( CameraCaptureSessionProxy.StateCallback stateCallback)37 private AndroidCaptureSessionStateCallback( 38 CameraCaptureSessionProxy.StateCallback stateCallback) { 39 mStateCallback = stateCallback; 40 } 41 42 @Override onConfigured(CameraCaptureSession session)43 public void onConfigured(CameraCaptureSession session) { 44 mStateCallback.onConfigured(new AndroidCameraCaptureSessionProxy(session)); 45 } 46 47 @Override onConfigureFailed(CameraCaptureSession session)48 public void onConfigureFailed(CameraCaptureSession session) { 49 mStateCallback.onConfigureFailed(new AndroidCameraCaptureSessionProxy(session)); 50 } 51 52 @Override onReady(CameraCaptureSession session)53 public void onReady(CameraCaptureSession session) { 54 mStateCallback.onReady(new AndroidCameraCaptureSessionProxy(session)); 55 } 56 57 @Override onActive(CameraCaptureSession session)58 public void onActive(CameraCaptureSession session) { 59 mStateCallback.onActive(new AndroidCameraCaptureSessionProxy(session)); 60 } 61 62 @Override onClosed(CameraCaptureSession session)63 public void onClosed(CameraCaptureSession session) { 64 mStateCallback.onClosed(new AndroidCameraCaptureSessionProxy(session)); 65 } 66 } 67 68 private final CameraDevice mCameraDevice; 69 AndroidCameraDeviceProxy(CameraDevice cameraDevice)70 public AndroidCameraDeviceProxy(CameraDevice cameraDevice) { 71 mCameraDevice = cameraDevice; 72 } 73 74 @Override getId()75 public String getId() { 76 return mCameraDevice.getId(); 77 } 78 79 @Override createCaptureSession(List<Surface> list, CameraCaptureSessionProxy.StateCallback stateCallback, @Nullable Handler handler)80 public void createCaptureSession(List<Surface> list, 81 CameraCaptureSessionProxy.StateCallback stateCallback, 82 @Nullable Handler handler) 83 throws CameraAccessException { 84 mCameraDevice.createCaptureSession(list, new AndroidCaptureSessionStateCallback( 85 stateCallback), handler); 86 } 87 88 @Override createCaptureRequest(int i)89 public CaptureRequest.Builder createCaptureRequest(int i) throws CameraAccessException { 90 return mCameraDevice.createCaptureRequest(i); 91 } 92 93 @Override close()94 public void close() { 95 mCameraDevice.close(); 96 } 97 } 98