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.core; 18 19 import android.hardware.camera2.CameraAccessException; 20 21 import com.android.camera.async.SafeCloseable; 22 import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException; 23 24 import java.util.List; 25 26 import javax.annotation.Nonnull; 27 import javax.annotation.Nullable; 28 import javax.annotation.concurrent.ThreadSafe; 29 30 /** 31 * Provides thread-safe access to a camera. 32 */ 33 @ThreadSafe 34 public interface FrameServer { 35 /** 36 * A Session enables submitting multiple Requests for frames. 37 */ 38 @ThreadSafe 39 public interface Session extends SafeCloseable { 40 /** 41 * Submits the given request, blocking until resources are allocated for 42 * the request. 43 * 44 * @param burstRequests The request to submit to the camera device. 45 * @throws java.lang.InterruptedException if interrupted before the 46 * request is be submitted. 47 */ submitRequest(List<Request> burstRequests, RequestType type)48 public void submitRequest(List<Request> burstRequests, RequestType type) 49 throws CameraAccessException, InterruptedException, 50 CameraCaptureSessionClosedException, ResourceAcquisitionFailedException; 51 52 @Override close()53 public void close(); 54 } 55 56 /** 57 * Indicates that a session has been closed already, via 58 * {@link FrameServer.Session#close} and no more requests may be submitted. 59 */ 60 public static class SessionClosedException extends RuntimeException { 61 } 62 63 public static enum RequestType { 64 REPEATING, NON_REPEATING 65 } 66 67 /** 68 * Creates an exclusive session. Blocks, if necessary, until any existing 69 * exclusive session is closed. 70 * 71 * @return A new session which may be used to interact with the underlying 72 * camera. 73 */ 74 @Nonnull createExclusiveSession()75 public Session createExclusiveSession() throws InterruptedException; 76 77 /** 78 * Like {@link #createExclusiveSession}, but returns null instead of 79 * blocking if the session cannot be created immediately. 80 */ 81 @Nullable tryCreateExclusiveSession()82 public Session tryCreateExclusiveSession(); 83 } 84