1 /*
2  * Copyright 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 
17 package androidx.camera.extensions;
18 
19 import androidx.camera.core.impl.CameraConfig;
20 import androidx.camera.core.impl.Config;
21 import androidx.camera.core.impl.Identifier;
22 import androidx.camera.core.impl.MutableOptionsBundle;
23 import androidx.camera.core.impl.SessionProcessor;
24 import androidx.camera.core.impl.UseCaseConfigFactory;
25 
26 import org.jspecify.annotations.NonNull;
27 
28 /**
29  * Implementation of CameraConfig which provides the extensions capability.
30  */
31 class ExtensionsConfig implements CameraConfig {
32     // Option Declarations:
33     // *********************************************************************************************
34     public static final Option<Integer> OPTION_EXTENSION_MODE =
35             Option.create(
36                     "camerax.extensions.extensionMode", int.class);
37 
38     private final Config mConfig;
39 
ExtensionsConfig(Config config)40     ExtensionsConfig(Config config) {
41         mConfig = config;
42     }
43 
44     @Override
getConfig()45     public @NonNull Config getConfig() {
46         return mConfig;
47     }
48 
49     @ExtensionMode.Mode
getExtensionMode()50     public int getExtensionMode() {
51         return retrieveOption(OPTION_EXTENSION_MODE);
52     }
53 
54     @Override
getCompatibilityId()55     public @NonNull Identifier getCompatibilityId() {
56         return retrieveOption(OPTION_COMPATIBILITY_ID);
57     }
58 
59     static final class Builder implements CameraConfig.Builder<Builder> {
60         private final MutableOptionsBundle mConfig = MutableOptionsBundle.create();
61 
build()62         ExtensionsConfig build() {
63             return new ExtensionsConfig(mConfig);
64         }
65 
setExtensionMode(@xtensionMode.Mode int mode)66         public Builder setExtensionMode(@ExtensionMode.Mode int mode) {
67             mConfig.insertOption(OPTION_EXTENSION_MODE, mode);
68             return this;
69         }
70 
71         @Override
setUseCaseConfigFactory(@onNull UseCaseConfigFactory factory)72         public @NonNull Builder setUseCaseConfigFactory(@NonNull UseCaseConfigFactory factory) {
73             mConfig.insertOption(OPTION_USECASE_CONFIG_FACTORY, factory);
74             return this;
75         }
76 
77         @Override
setCompatibilityId(@onNull Identifier identifier)78         public @NonNull Builder setCompatibilityId(@NonNull Identifier identifier) {
79             mConfig.insertOption(OPTION_COMPATIBILITY_ID, identifier);
80             return this;
81         }
82 
83         @Override
setUseCaseCombinationRequiredRule( int useCaseCombinationRequiredRule)84         public @NonNull Builder setUseCaseCombinationRequiredRule(
85                 int useCaseCombinationRequiredRule) {
86             mConfig.insertOption(OPTION_USE_CASE_COMBINATION_REQUIRED_RULE,
87                     useCaseCombinationRequiredRule);
88             return this;
89         }
90 
91         @Override
setSessionProcessor(@onNull SessionProcessor sessionProcessor)92         public @NonNull Builder setSessionProcessor(@NonNull SessionProcessor sessionProcessor) {
93             mConfig.insertOption(OPTION_SESSION_PROCESSOR, sessionProcessor);
94             return this;
95         }
96 
97         @Override
setZslDisabled(boolean disabled)98         public @NonNull Builder setZslDisabled(boolean disabled) {
99             mConfig.insertOption(OPTION_ZSL_DISABLED, disabled);
100             return this;
101         }
102 
103         @Override
setPostviewSupported(boolean supported)104         public @NonNull Builder setPostviewSupported(boolean supported) {
105             mConfig.insertOption(OPTION_POSTVIEW_SUPPORTED, supported);
106             return this;
107         }
108 
109         @Override
setCaptureProcessProgressSupported(boolean supported)110         public @NonNull Builder setCaptureProcessProgressSupported(boolean supported) {
111             mConfig.insertOption(OPTION_CAPTURE_PROCESS_PROGRESS_SUPPORTED, supported);
112             return this;
113         }
114     }
115 }
116