1 /* 2 * Copyright (C) 2021 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.params; 18 19 import android.annotation.NonNull; 20 import android.annotation.IntRange; 21 22 import java.util.Objects; 23 24 /** 25 * A utility class describing the properties of one stream of fixed-size image buffers 26 * backing a multi-resolution image stream. 27 * 28 * <p>A group of {@link MultiResolutionStreamInfo} are used to describe the properties of a 29 * multi-resolution image stream for a particular format. The 30 * {@link android.hardware.camera2.MultiResolutionImageReader} class represents a 31 * multi-resolution output stream, and is constructed using a group of 32 * {@link MultiResolutionStreamInfo}. A group of {@link MultiResolutionStreamInfo} can also be used 33 * to create a multi-resolution reprocessable camera capture session. See 34 * {@link android.hardware.camera2.params.InputConfiguration} for details.</p> 35 * 36 * @see InputConfiguration 37 * @see android.hardware.camera2.MultiResolutionImageReader 38 */ 39 public class MultiResolutionStreamInfo { 40 private int mStreamWidth; 41 private int mStreamHeight; 42 private String mPhysicalCameraId; 43 44 /** 45 * Create a new {@link MultiResolutionStreamInfo}. 46 * 47 * <p>This class creates a {@link MultiResolutionStreamInfo} using image width, image height, 48 * and the physical camera Id images originate from.</p> 49 * 50 * <p>Normally applications do not need to create these directly. Use {@link 51 * MultiResolutionStreamConfigurationMap#getOutputInfo} or {@link 52 * MultiResolutionStreamConfigurationMap#getInputInfo} to obtain them for a particular format 53 * instead.</p> 54 * 55 * @param streamWidth The width in pixels of the camera stream 56 * @param streamHeight The height in pixels of the camera stream 57 * @param physicalCameraId The physical camera Id the camera stream is associated with 58 * @throws IllegalArgumentException if the streamWidth or streamHeight is invalid (either zero 59 * or negative). 60 */ MultiResolutionStreamInfo(@ntRangefrom = 1) int streamWidth, @IntRange(from = 1) int streamHeight, @NonNull String physicalCameraId)61 public MultiResolutionStreamInfo(@IntRange(from = 1) int streamWidth, 62 @IntRange(from = 1) int streamHeight, 63 @NonNull String physicalCameraId) { 64 if (streamWidth <= 0) { 65 throw new IllegalArgumentException("Invalid stream width " + streamWidth); 66 } 67 if (streamHeight <= 0) { 68 throw new IllegalArgumentException("Invalid stream height " + streamHeight); 69 } 70 mStreamWidth = streamWidth; 71 mStreamHeight = streamHeight; 72 mPhysicalCameraId = physicalCameraId; 73 } 74 75 /** 76 * The width of this particular image buffer stream in pixels. 77 */ getWidth()78 public @IntRange(from = 1) int getWidth() { 79 return mStreamWidth; 80 } 81 82 /** 83 * The height of this particular image buffer stream in pixels. 84 */ getHeight()85 public @IntRange(from = 1) int getHeight() { 86 return mStreamHeight; 87 } 88 89 /** 90 * The physical camera Id of this particular image buffer stream. 91 */ getPhysicalCameraId()92 public @NonNull String getPhysicalCameraId() { 93 return mPhysicalCameraId; 94 } 95 96 /** 97 * Check if this {@link MultiResolutionStreamInfo} is equal to another 98 * {@link MultiResolutionStreamInfo}. 99 * 100 * @return {@code true} if the objects were equal, {@code false} otherwise 101 */ 102 @Override equals(final Object obj)103 public boolean equals(final Object obj) { 104 if (obj == null) { 105 return false; 106 } 107 if (this == obj) { 108 return true; 109 } 110 if (obj instanceof MultiResolutionStreamInfo) { 111 final MultiResolutionStreamInfo other = (MultiResolutionStreamInfo) obj; 112 return mStreamWidth == other.mStreamWidth && 113 mStreamHeight == other.mStreamHeight && 114 mPhysicalCameraId.equals(other.mPhysicalCameraId); 115 } 116 return false; 117 } 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override hashCode()123 public int hashCode() { 124 return Objects.hash( 125 mStreamWidth, mStreamHeight, mPhysicalCameraId); 126 } 127 } 128