1 /* 2 * Copyright (C) 2014 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 static com.android.internal.util.Preconditions.*; 20 21 import android.hardware.camera2.CameraCharacteristics; 22 import android.hardware.camera2.utils.HashCodeHelpers; 23 import android.util.Range; 24 import android.util.Size; 25 26 /** 27 * Immutable class to store the available 28 * {@link CameraCharacteristics#CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS high speed video 29 * configurations} 30 * 31 * @see CameraCharacteristics#CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS 32 * 33 * @hide 34 */ 35 public final class HighSpeedVideoConfiguration { 36 static final private int HIGH_SPEED_MAX_MINIMAL_FPS = 120; 37 38 /** 39 * Create a new {@link HighSpeedVideoConfiguration}. 40 * 41 * @param width image width, in pixels (positive) 42 * @param height image height, in pixels (positive) 43 * @param fpsMin minimum frames per second for the configuration (positive) 44 * @param fpsMax maximum frames per second for the configuration (larger or equal to 60) 45 * 46 * @throws IllegalArgumentException 47 * if width/height/fpsMin were not positive or fpsMax less than 60 48 * 49 * @hide 50 */ HighSpeedVideoConfiguration( final int width, final int height, final int fpsMin, final int fpsMax, final int batchSizeMax)51 public HighSpeedVideoConfiguration( 52 final int width, final int height, final int fpsMin, final int fpsMax, 53 final int batchSizeMax) { 54 if (fpsMax < HIGH_SPEED_MAX_MINIMAL_FPS) { 55 throw new IllegalArgumentException("fpsMax must be at least " + 56 HIGH_SPEED_MAX_MINIMAL_FPS); 57 } 58 mFpsMax = fpsMax; 59 mWidth = checkArgumentPositive(width, "width must be positive"); 60 mHeight = checkArgumentPositive(height, "height must be positive"); 61 mFpsMin = checkArgumentPositive(fpsMin, "fpsMin must be positive"); 62 mSize = new Size(mWidth, mHeight); 63 mBatchSizeMax = checkArgumentPositive(batchSizeMax, "batchSizeMax must be positive"); 64 mFpsRange = new Range<Integer>(mFpsMin, mFpsMax); 65 } 66 67 /** 68 * Return the width of the high speed video configuration. 69 * 70 * @return width > 0 71 */ getWidth()72 public int getWidth() { 73 return mWidth; 74 } 75 76 /** 77 * Return the height of the high speed video configuration. 78 * 79 * @return height > 0 80 */ getHeight()81 public int getHeight() { 82 return mHeight; 83 } 84 85 /** 86 * Return the minimum frame per second of the high speed video configuration. 87 * 88 * @return fpsMin > 0 89 */ getFpsMin()90 public int getFpsMin() { 91 return mFpsMin; 92 } 93 94 /** 95 * Return the maximum frame per second of the high speed video configuration. 96 * 97 * @return fpsMax >= 60 98 */ getFpsMax()99 public int getFpsMax() { 100 return mFpsMax; 101 } 102 103 /** 104 * Convenience method to return the size of this high speed video configuration. 105 * 106 * @return a Size with positive width and height 107 */ getSize()108 public Size getSize() { 109 return mSize; 110 } 111 112 /** 113 * Convenience method to return the max batch size of this high speed video configuration. 114 * 115 * @return the maximal batch size for this high speed video configuration 116 */ getBatchSizeMax()117 public int getBatchSizeMax() { 118 return mBatchSizeMax; 119 } 120 121 /** 122 * Convenience method to return the FPS range of this high speed video configuration. 123 * 124 * @return a Range with high bound >= {@value #HIGH_SPEED_MAX_MINIMAL_FPS} 125 */ getFpsRange()126 public Range<Integer> getFpsRange() { 127 return mFpsRange; 128 } 129 130 /** 131 * Check if this {@link HighSpeedVideoConfiguration} is equal to another 132 * {@link HighSpeedVideoConfiguration}. 133 * 134 * <p>Two configurations are equal if and only if each of the respective elements is equal.</p> 135 * 136 * @return {@code true} if the objects were equal, {@code false} otherwise 137 */ 138 @Override equals(final Object obj)139 public boolean equals(final Object obj) { 140 if (obj == null) { 141 return false; 142 } 143 if (this == obj) { 144 return true; 145 } 146 if (obj instanceof HighSpeedVideoConfiguration) { 147 final HighSpeedVideoConfiguration other = (HighSpeedVideoConfiguration) obj; 148 return mWidth == other.mWidth && 149 mHeight == other.mHeight && 150 mFpsMin == other.mFpsMin && 151 mFpsMax == other.mFpsMax && 152 mBatchSizeMax == other.mBatchSizeMax; 153 } 154 return false; 155 } 156 157 /** 158 * {@inheritDoc} 159 */ 160 @Override hashCode()161 public int hashCode() { 162 return HashCodeHelpers.hashCode(mWidth, mHeight, mFpsMin, mFpsMax); 163 } 164 165 private final int mWidth; 166 private final int mHeight; 167 private final int mFpsMin; 168 private final int mFpsMax; 169 private final int mBatchSizeMax; 170 private final Size mSize; 171 private final Range<Integer> mFpsRange; 172 } 173