1 /* 2 * Copyright (C) 2023 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 android.hardware.camera2.extension; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.hardware.camera2.CameraDevice; 24 import android.hardware.camera2.CaptureRequest; 25 import android.hardware.camera2.params.ColorSpaceProfiles; 26 import android.os.IBinder; 27 28 import com.android.internal.camera.flags.Flags; 29 30 import java.util.ArrayList; 31 import java.util.List; 32 33 /** 34 * Helper class used to guide the camera framework when 35 * initializing the internal camera capture session. 36 * It contains all required internal outputs, parameters, 37 * modes and settings. 38 * 39 * <p>Extension must decide the final set of output surfaces 40 * and pass an instance of ExtensionConfiguration as part 41 * of the result during calls to {@link SessionProcessor#initSession}.</p> 42 * 43 * @hide 44 */ 45 @SystemApi 46 public class ExtensionConfiguration { 47 private final int mSessionType; 48 private final int mSessionTemplateId; 49 private final List<ExtensionOutputConfiguration> mOutputs; 50 private final CaptureRequest mSessionParameters; 51 private int mColorSpace; 52 53 /** 54 * Initialize an extension configuration instance 55 * 56 * @param sessionType The type of camera capture session 57 * operating mode to be used 58 * @param sessionTemplateId The request template id to be used 59 * for generating the session parameter 60 * capture request 61 * @param outputs List of {@link ExtensionOutputConfiguration} 62 * camera outputs to be configured 63 * as part of the capture session 64 * @param sessionParams An optional set of camera capture 65 * session parameter values 66 */ ExtensionConfiguration(@ameraDevice.SessionOperatingMode int sessionType, @CameraDevice.RequestTemplate int sessionTemplateId, @NonNull List<ExtensionOutputConfiguration> outputs, @Nullable CaptureRequest sessionParams)67 public ExtensionConfiguration(@CameraDevice.SessionOperatingMode int sessionType, 68 @CameraDevice.RequestTemplate int sessionTemplateId, 69 @NonNull List<ExtensionOutputConfiguration> outputs, 70 @Nullable CaptureRequest sessionParams) { 71 mSessionType = sessionType; 72 mSessionTemplateId = sessionTemplateId; 73 mOutputs = outputs; 74 mSessionParameters = sessionParams; 75 mColorSpace = ColorSpaceProfiles.UNSPECIFIED; 76 } 77 78 /** 79 * Set the color space using the ordinal value of a 80 * {@link android.graphics.ColorSpace.Named}. 81 * The default will be -1, indicating an unspecified ColorSpace, 82 * unless explicitly set using this method. 83 */ setColorSpace(int colorSpace)84 public void setColorSpace(int colorSpace) { 85 mColorSpace = colorSpace; 86 } 87 getCameraSessionConfig()88 CameraSessionConfig getCameraSessionConfig() { 89 if (mOutputs.isEmpty()) { 90 return null; 91 } 92 93 CameraSessionConfig ret = new CameraSessionConfig(); 94 ret.sessionTemplateId = mSessionTemplateId; 95 ret.sessionType = mSessionType; 96 ret.outputConfigs = new ArrayList<>(mOutputs.size()); 97 ret.colorSpace = mColorSpace; 98 for (ExtensionOutputConfiguration outputConfig : mOutputs) { 99 ret.outputConfigs.add(outputConfig.getOutputConfig()); 100 } 101 if (mSessionParameters != null) { 102 ret.sessionParameter = mSessionParameters.getNativeCopy(); 103 } 104 105 return ret; 106 } 107 } 108