Home | History | Annotate | Download | only in params
      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 
     37     /**
     38      * Create a new {@link HighSpeedVideoConfiguration}.
     39      *
     40      * @param width image width, in pixels (positive)
     41      * @param height image height, in pixels (positive)
     42      * @param fpsMin minimum frames per second for the configuration (positive)
     43      * @param fpsMax maximum frames per second for the configuration (larger or equal to 60)
     44      *
     45      * @throws IllegalArgumentException
     46      *              if width/height/fpsMin were not positive or fpsMax less than 60
     47      *
     48      * @hide
     49      */
     50     public HighSpeedVideoConfiguration(
     51             final int width, final int height, final int fpsMin, final int fpsMax) {
     52         if (fpsMax < 60) {
     53             throw new IllegalArgumentException("fpsMax must be at least 60");
     54         }
     55         mFpsMax = fpsMax;
     56         mWidth = checkArgumentPositive(width, "width must be positive");
     57         mHeight = checkArgumentPositive(height, "height must be positive");
     58         mFpsMin = checkArgumentPositive(fpsMin, "fpsMin must be positive");
     59         mSize = new Size(mWidth, mHeight);
     60         mFpsRange = new Range<Integer>(mFpsMin, mFpsMax);
     61     }
     62 
     63     /**
     64      * Return the width of the high speed video configuration.
     65      *
     66      * @return width > 0
     67      */
     68     public int getWidth() {
     69         return mWidth;
     70     }
     71 
     72     /**
     73      * Return the height of the high speed video configuration.
     74      *
     75      * @return height > 0
     76      */
     77     public int getHeight() {
     78         return mHeight;
     79     }
     80 
     81     /**
     82      * Return the minimum frame per second of the high speed video configuration.
     83      *
     84      * @return fpsMin > 0
     85      */
     86     public int getFpsMin() {
     87         return mFpsMin;
     88     }
     89 
     90     /**
     91      * Return the maximum frame per second of the high speed video configuration.
     92      *
     93      * @return fpsMax >= 60
     94      */
     95     public int getFpsMax() {
     96         return mFpsMax;
     97     }
     98 
     99     /**
    100      * Convenience method to return the size of this high speed video configuration.
    101      *
    102      * @return a Size with positive width and height
    103      */
    104     public Size getSize() {
    105         return mSize;
    106     }
    107 
    108     /**
    109      * Convenience method to return the FPS range of this high speed video configuration.
    110      *
    111      * @return a Range with high bound >= 60
    112      */
    113     public Range<Integer> getFpsRange() {
    114         return mFpsRange;
    115     }
    116 
    117     /**
    118      * Check if this {@link HighSpeedVideoConfiguration} is equal to another
    119      * {@link HighSpeedVideoConfiguration}.
    120      *
    121      * <p>Two configurations are equal if and only if each of the respective elements is equal.</p>
    122      *
    123      * @return {@code true} if the objects were equal, {@code false} otherwise
    124      */
    125     @Override
    126     public boolean equals(final Object obj) {
    127         if (obj == null) {
    128             return false;
    129         }
    130         if (this == obj) {
    131             return true;
    132         }
    133         if (obj instanceof HighSpeedVideoConfiguration) {
    134             final HighSpeedVideoConfiguration other = (HighSpeedVideoConfiguration) obj;
    135             return mWidth == other.mWidth &&
    136                     mHeight == other.mHeight &&
    137                     mFpsMin == other.mFpsMin &&
    138                     mFpsMax == other.mFpsMax;
    139         }
    140         return false;
    141     }
    142 
    143     /**
    144      * {@inheritDoc}
    145      */
    146     @Override
    147     public int hashCode() {
    148         return HashCodeHelpers.hashCode(mWidth, mHeight, mFpsMin, mFpsMax);
    149     }
    150 
    151     private final int mWidth;
    152     private final int mHeight;
    153     private final int mFpsMin;
    154     private final int mFpsMax;
    155     private final Size mSize;
    156     private final Range<Integer> mFpsRange;
    157 }
    158