1 /* 2 * Copyright 2019 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.core.impl; 18 19 import android.content.Context; 20 21 import androidx.camera.core.ImageCapture.CaptureMode; 22 import androidx.camera.core.InitializationException; 23 24 import org.jspecify.annotations.NonNull; 25 import org.jspecify.annotations.Nullable; 26 27 /** 28 * A Repository for generating use case configurations. 29 */ 30 public interface UseCaseConfigFactory { 31 32 enum CaptureType { 33 /** 34 * Capture type for still image capture. A still capture which can be a single or 35 * multiple frames which are combined into a single image. 36 */ 37 IMAGE_CAPTURE, 38 39 /** 40 * Capture type for preview. A use case of this type is consuming a stream of frames. 41 */ 42 PREVIEW, 43 44 /** 45 * Capture type for image analysis. A use case of this type is consuming a stream of frames. 46 */ 47 IMAGE_ANALYSIS, 48 49 /** 50 * Capture type for video capture. A use case of this type is consuming a stream of frames. 51 */ 52 VIDEO_CAPTURE, 53 /** 54 * Capture type for stream sharing. A use case of this type is consuming a stream of frames. 55 */ 56 STREAM_SHARING, 57 /** 58 * Capture type for metering repeating. A use case of this type is consuming a stream of 59 * frames. 60 */ 61 METERING_REPEATING 62 } 63 64 /** 65 * Interface for deferring creation of a UseCaseConfigFactory. 66 */ 67 interface Provider { 68 /** 69 * Creates a new, initialized instance of a UseCaseConfigFactory. 70 * 71 * @param context the android context 72 * @return the factory instance 73 * @throws InitializationException if it fails to create the factory 74 */ newInstance(@onNull Context context)75 @NonNull UseCaseConfigFactory newInstance(@NonNull Context context) 76 throws InitializationException; 77 } 78 79 /** 80 * Returns the configuration for the given capture type, or <code>null</code> if the 81 * configuration cannot be produced. 82 * 83 * @param captureType The {@link CaptureType} for the configuration. 84 * @param captureMode The {@link CaptureMode} for the configuration. 85 * @return The use case configuration. 86 */ getConfig(@onNull CaptureType captureType, @CaptureMode int captureMode)87 @Nullable Config getConfig(@NonNull CaptureType captureType, @CaptureMode int captureMode); 88 89 UseCaseConfigFactory EMPTY_INSTANCE = new UseCaseConfigFactory() { 90 @Override 91 public @Nullable Config getConfig(@NonNull CaptureType captureType, 92 @CaptureMode int captureMode) { 93 return null; 94 } 95 }; 96 } 97