1 /*
2  * Copyright (C) 2020 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 package android.hardware.camera2.params;
17 
18 import android.annotation.NonNull;
19 import android.annotation.Nullable;
20 
21 import android.hardware.camera2.CameraExtensionCharacteristics.Extension;
22 import android.hardware.camera2.CameraExtensionSession;
23 
24 import java.util.List;
25 import java.util.concurrent.Executor;
26 
27 /**
28  * A class that aggregates all supported arguments for
29  * {@link CameraExtensionSession} initialization.
30  */
31 public final class ExtensionSessionConfiguration {
32     private static final String TAG = "ExtensionSessionConfiguration";
33 
34     private int mExtensionType;
35     private List<OutputConfiguration> mOutputs;
36     private OutputConfiguration mPostviewOutput = null;
37     private Executor mExecutor = null;
38     private CameraExtensionSession.StateCallback mCallback = null;
39 
40     /**
41      * Create a new ExtensionSessionConfiguration
42      *
43      * @param extension to be used for processing
44      * @param outputs   a list of output configurations for the capture session
45      * @param executor  the executor which will be used for invoking the callbacks
46      * @param listener  callbacks to be invoked when the state of the
47      *                  CameraExtensionSession changes
48      */
ExtensionSessionConfiguration(@xtension int extension, @NonNull List<OutputConfiguration> outputs, @NonNull Executor executor, @NonNull CameraExtensionSession.StateCallback listener)49     public ExtensionSessionConfiguration(@Extension int extension,
50             @NonNull List<OutputConfiguration> outputs, @NonNull Executor executor,
51             @NonNull CameraExtensionSession.StateCallback listener) {
52         mExtensionType = extension;
53         mOutputs = outputs;
54         mExecutor = executor;
55         mCallback = listener;
56     }
57 
58     /**
59      * Retrieve the extension type.
60      *
61      * @return the extension type.
62      */
63     public @Extension
getExtension()64     int getExtension() {
65         return mExtensionType;
66     }
67 
68     /**
69      * Set the postview for still capture output configuration.
70      *
71      * @param postviewOutput output configuration for postview
72      * @see android.hardware.camera2.CameraExtensionCharacteristics#isPostviewAvailable
73      */
74     public
setPostviewOutputConfiguration(@ullable OutputConfiguration postviewOutput)75     void setPostviewOutputConfiguration(@Nullable OutputConfiguration postviewOutput) {
76         mPostviewOutput = postviewOutput;
77     }
78 
79     /**
80      * Get the postview for still capture output configuration.
81      *
82      * @return output configuration for postview
83      * @see android.hardware.camera2.CameraExtensionCharacteristics#isPostviewAvailable
84      */
85     public @Nullable // Postview output is optional
getPostviewOutputConfiguration()86     OutputConfiguration getPostviewOutputConfiguration() {
87         return mPostviewOutput;
88     }
89 
90     /**
91      * Retrieve the {@link OutputConfiguration} list for the capture
92      * session.
93      *
94      * @return A list of output configurations for the capture session.
95      */
96     public @NonNull
getOutputConfigurations()97     List<OutputConfiguration> getOutputConfigurations() {
98         return mOutputs;
99     }
100 
101     /**
102      * Retrieve the CameraCaptureSession.StateCallback
103      * listener.
104      *
105      * @return A state callback interface implementation.
106      */
107     public @NonNull
getStateCallback()108     CameraExtensionSession.StateCallback getStateCallback() {
109         return mCallback;
110     }
111 
112     /**
113      * Retrieve the Executor for the CameraExtensionSession instance.
114      *
115      * @return The Executor on which the callback will be invoked.
116      */
117     public @NonNull
getExecutor()118     Executor getExecutor() {
119         return mExecutor;
120     }
121 }
122