OutputConfiguration.java revision 49ea6ae76d78ff8d179c0957d4bc55f08cb98d0f
1/* 2 * Copyright (C) 2015 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 18package android.hardware.camera2.params; 19 20import android.hardware.camera2.CameraDevice; 21import android.view.Surface; 22 23import static com.android.internal.util.Preconditions.*; 24 25/** 26 * Immutable class for describing camera output, which contains a {@link Surface} and its specific 27 * configuration for creating capture session. 28 * 29 * @see CameraDevice#createCaptureSession 30 * 31 * @hide 32 */ 33public final class OutputConfiguration { 34 35 /** 36 * Rotation constant: 0 degree rotation (no rotation) 37 */ 38 public static final int ROTATION_0 = 0; 39 40 /** 41 * Rotation constant: 90 degree counterclockwise rotation. 42 */ 43 public static final int ROTATION_90 = 1; 44 45 /** 46 * Rotation constant: 180 degree counterclockwise rotation. 47 */ 48 public static final int ROTATION_180 = 2; 49 50 /** 51 * Rotation constant: 270 degree counterclockwise rotation. 52 */ 53 public static final int ROTATION_270 = 3; 54 55 /** 56 * Create a new immutable SurfaceConfiguration instance. 57 * 58 * @param surface 59 * A Surface for camera to output to. 60 * 61 * <p>This constructor creates a default configuration</p> 62 * 63 */ 64 public OutputConfiguration(Surface surface) { 65 checkNotNull(surface, "Surface must not be null"); 66 mSurface = surface; 67 mRotation = ROTATION_0; 68 } 69 70 /** 71 * Create a new immutable SurfaceConfiguration instance. 72 * 73 * <p>This constructor takes an argument for desired camera rotation</p> 74 * 75 * @param surface 76 * A Surface for camera to output to. 77 * @param rotation 78 * The desired rotation to be applied on camera output. Value must be one of 79 * ROTATION_[0, 90, 180, 270]. Note that when the rotation is 90 or 270 degree, 80 * application should make sure corresponding surface size has width and height 81 * transposed corresponding to the width and height without rotation. For example, 82 * if application needs camera to capture 1280x720 picture and rotate it by 90 degree, 83 * application should set rotation to {@code ROTATION_90} and make sure the 84 * corresponding Surface size is 720x1280. Note that {@link CameraDevice} might 85 * throw {@code IllegalArgumentException} if device cannot perform such rotation. 86 * 87 */ 88 public OutputConfiguration(Surface surface, int rotation) { 89 checkNotNull(surface, "Surface must not be null"); 90 checkArgumentInRange(rotation, ROTATION_0, ROTATION_270, "Rotation constant"); 91 mSurface = surface; 92 mRotation = rotation; 93 } 94 95 /** 96 * Get the {@link Surface} associated with this {@link OutputConfiguration}. 97 * 98 * @return the {@link Surface} associated with this {@link OutputConfiguration}. 99 */ 100 public Surface getSurface() { 101 return mSurface; 102 } 103 104 /** 105 * Get the rotation associated with this {@link OutputConfiguration}. 106 * 107 * @return the rotation associated with this {@link OutputConfiguration}. 108 * Value will be one of ROTATION_[0, 90, 180, 270] 109 */ 110 public int getRotation() { 111 return mRotation; 112 } 113 114 private final Surface mSurface; 115 private final int mRotation; 116} 117