/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.hardware.camera2.params; import static com.android.internal.util.Preconditions.*; import android.annotation.CallbackExecutor; import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SuppressLint; import android.graphics.ColorSpace; import android.hardware.camera2.CameraCaptureSession; import android.hardware.camera2.CameraCharacteristics; import android.hardware.camera2.CameraDevice; import android.hardware.camera2.CameraDevice.CameraDeviceSetup; import android.hardware.camera2.CaptureRequest; import android.hardware.camera2.impl.CameraMetadataNative; import android.hardware.camera2.params.InputConfiguration; import android.hardware.camera2.params.OutputConfiguration; import android.hardware.camera2.utils.HashCodeHelpers; import android.media.ImageReader; import android.os.Parcel; import android.os.Parcelable; import com.android.internal.camera.flags.Flags; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.Executor; /** * A helper class that aggregates all supported arguments for capture session initialization. */ public final class SessionConfiguration implements Parcelable { private static final String TAG = "SessionConfiguration"; /** * A regular session type containing instances of {@link OutputConfiguration} running * at regular non high speed FPS ranges and optionally {@link InputConfiguration} for * reprocessable sessions. * * @see CameraDevice#createCaptureSession(SessionConfiguration) * @see CameraDevice#createReprocessableCaptureSession */ public static final int SESSION_REGULAR = CameraDevice.SESSION_OPERATION_MODE_NORMAL; /** * A high speed session type that can only contain instances of {@link OutputConfiguration}. * The outputs can run using high speed FPS ranges. Calls to {@link #setInputConfiguration} * are not supported. *
* When using this type, the CameraCaptureSession returned by * {@link android.hardware.camera2.CameraCaptureSession.StateCallback} can be cast to a * {@link android.hardware.camera2.CameraConstrainedHighSpeedCaptureSession} to access the extra * methods for constrained high speed recording. *
* * @see CameraDevice#createConstrainedHighSpeedCaptureSession */ public static final int SESSION_HIGH_SPEED = CameraDevice.SESSION_OPERATION_MODE_CONSTRAINED_HIGH_SPEED; /** * First vendor-specific session mode * @hide */ public static final int SESSION_VENDOR_START = CameraDevice.SESSION_OPERATION_MODE_VENDOR_START; /** @hide */ @Retention(RetentionPolicy.SOURCE) @IntDef(prefix = {"SESSION_"}, value = {SESSION_REGULAR, SESSION_HIGH_SPEED }) public @interface SessionMode {}; // Camera capture session related parameters. private ListThe SessionConfiguration objects created by this constructor can be used by * {@link CameraDeviceSetup.isSessionConfigurationSupported} and {@link * CameraDeviceSetup.getSessionCharacteristics} to query a camera device's feature * combination support and session specific characteristics. For the SessionConfiguration * object to be used to create a capture session, {@link #setStateCallback} must be called to * specify the state callback function, and any incomplete OutputConfigurations must be * completed via {@link OutputConfiguration#addSurface} or * {@link OutputConfiguration#setSurfacesForMultiResolutionOutput} as appropriate.
* * @param sessionType The session type. * @param outputs A list of output configurations for the capture session. * * @see #SESSION_REGULAR * @see #SESSION_HIGH_SPEED * @see CameraDevice#createCaptureSession(SessionConfiguration) * @see CameraDeviceSetup#isSessionConfigurationSupported * @see CameraDeviceSetup#getSessionCharacteristics */ @FlaggedApi(Flags.FLAG_CAMERA_DEVICE_SETUP) public SessionConfiguration(@SessionMode int sessionType, @NonNull ListTwo output session configurations are only equal if and only if the underlying input * configuration, output configurations, and session type are equal.
* * @return {@code true} if the objects were equal, {@code false} otherwise */ @Override public boolean equals(@Nullable Object obj) { if (obj == null) { return false; } else if (this == obj) { return true; } else if (obj instanceof SessionConfiguration) { final SessionConfiguration other = (SessionConfiguration) obj; if (mInputConfig != other.mInputConfig || mSessionType != other.mSessionType || mOutputConfigurations.size() != other.mOutputConfigurations.size()) { return false; } for (int i = 0; i < mOutputConfigurations.size(); i++) { if (!mOutputConfigurations.get(i).equals(other.mOutputConfigurations.get(i))) return false; } return true; } return false; } /** * {@inheritDoc} */ @Override public int hashCode() { return HashCodeHelpers.hashCode(mOutputConfigurations.hashCode(), mInputConfig.hashCode(), mSessionType); } /** * Retrieve the type of the capture session. * * @return The capture session type. */ public @SessionMode int getSessionType() { return mSessionType; } /** * Retrieve the {@link OutputConfiguration} list for the capture session. * * @return A list of output configurations for the capture session. */ public ListClients can choose from any profile advertised as supported in * {@link CameraCharacteristics#REQUEST_AVAILABLE_COLOR_SPACE_PROFILES} * queried using {@link ColorSpaceProfiles#getSupportedColorSpaces}. * When set, the colorSpace will override the default color spaces of the output targets, * or the color space implied by the dataSpace passed into an {@link ImageReader}'s * constructor.
*/ public void setColorSpace(@NonNull ColorSpace.Named colorSpace) { mColorSpace = colorSpace.ordinal(); for (OutputConfiguration outputConfiguration : mOutputConfigurations) { outputConfiguration.setColorSpace(colorSpace); } } /** * Clear the color space, such that the default color space will be used. */ public void clearColorSpace() { mColorSpace = ColorSpaceProfiles.UNSPECIFIED; for (OutputConfiguration outputConfiguration : mOutputConfigurations) { outputConfiguration.clearColorSpace(); } } /** * Return the current color space. * * @return the currently set color space */ @SuppressLint("MethodNameUnits") public @Nullable ColorSpace getColorSpace() { if (mColorSpace != ColorSpaceProfiles.UNSPECIFIED) { return ColorSpace.get(ColorSpace.Named.values()[mColorSpace]); } else { return null; } } /** * Set the state callback and executor. * *This function must be called for the SessionConfiguration object created via {@link * #SessionConfiguration(int, List) SessionConfiguration(int, List<OutputConfiguration>)} * before it's used to create a capture session.
* * @param executor The executor which should be used to invoke the callback. In general it is * recommended that camera operations are not done on the main (UI) thread. * @param cb A state callback interface implementation. */ @FlaggedApi(Flags.FLAG_CAMERA_DEVICE_SETUP) public void setStateCallback( @NonNull @CallbackExecutor Executor executor, @NonNull CameraCaptureSession.StateCallback cb) { mStateCallback = cb; mExecutor = executor; } }