Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.photography; |
| 18 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 21 | import android.view.Surface; |
| 22 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 23 | import java.util.HashSet; |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 24 | |
| 25 | |
| 26 | /** |
| 27 | * <p>All the settings required to capture a single image from the image sensor.</p> |
| 28 | * |
| 29 | * <p>Contains the configuration for the capture hardware (sensor, lens, flash), |
| 30 | * the processing pipeline, the control algorithms, and the output buffers.</p> |
| 31 | * |
| 32 | * <p>CaptureRequests can be created by calling |
| 33 | * {@link CameraDevice#createCaptureRequest}</p> |
| 34 | * |
| 35 | * <p>CaptureRequests are given to {@link CameraDevice#capture} or |
| 36 | * {@link CameraDevice#setRepeatingRequest} to capture images from a camera.</p> |
| 37 | * |
| 38 | * <p>Each request can specify a different subset of target Surfaces for the |
| 39 | * camera to send the captured data to. All the surfaces used in a request must |
| 40 | * be part of the surface list given to the last call to |
| 41 | * {@link CameraDevice#configureOutputs}.</p> |
| 42 | * |
| 43 | * <p>For example, a request meant for repeating preview might only include the |
| 44 | * Surface for the preview SurfaceView or SurfaceTexture, while a |
| 45 | * high-resolution still capture would also include a Surface from a ImageReader |
| 46 | * configured for high-resolution JPEG images.</p> |
| 47 | * |
| 48 | * @see CameraDevice#capture |
| 49 | * @see CameraDevice#setRepeatingRequest |
| 50 | * @see CameraDevice#createRequest |
| 51 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 52 | public final class CaptureRequest extends CameraMetadata implements Parcelable { |
| 53 | |
| 54 | private final Object mLock = new Object(); |
| 55 | private final HashSet<Surface> mSurfaceSet = new HashSet<Surface>(); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * The exposure time for this capture, in nanoseconds. |
| 59 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 60 | public static final Key<Long> SENSOR_EXPOSURE_TIME = |
Igor Murashkin | b519cc5 | 2013-07-02 11:23:44 -0700 | [diff] [blame] | 61 | new Key<Long>("android.sensor.exposureTime", Long.TYPE); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
| 64 | * The sensor sensitivity (gain) setting for this camera. |
| 65 | * This is represented as an ISO sensitivity value |
| 66 | */ |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 67 | public static final Key<Integer> SENSOR_SENSITIVITY = |
Igor Murashkin | b519cc5 | 2013-07-02 11:23:44 -0700 | [diff] [blame] | 68 | new Key<Integer>("android.sensor.sensitivity", Integer.TYPE); |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 69 | |
| 70 | // Many more settings |
| 71 | |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 72 | /** |
| 73 | * @hide |
| 74 | */ |
| 75 | public CaptureRequest() { |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
| 79 | * <p>Add a surface to the list of targets for this request</p> |
| 80 | * |
| 81 | * <p>The Surface added must be one of the surfaces included in the last |
| 82 | * call to {@link CameraDevice#configureOutputs}.</p> |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 83 | * |
| 84 | * <p>Adding a target more than once has no effect.</p> |
| 85 | * |
| 86 | * @param outputTarget surface to use as an output target for this request |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 87 | */ |
| 88 | public void addTarget(Surface outputTarget) { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 89 | synchronized (mLock) { |
| 90 | mSurfaceSet.add(outputTarget); |
| 91 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * <p>Remove a surface from the list of targets for this request.</p> |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 96 | * |
| 97 | * <p>Removing a target that is not currently added has no effect.</p> |
| 98 | * |
| 99 | * @param outputTarget surface to use as an output target for this request |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 100 | */ |
| 101 | public void removeTarget(Surface outputTarget) { |
Igor Murashkin | 7072550 | 2013-06-25 20:27:06 +0000 | [diff] [blame] | 102 | synchronized (mLock) { |
| 103 | mSurfaceSet.remove(outputTarget); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | public static final Parcelable.Creator<CaptureRequest> CREATOR = |
| 108 | new Parcelable.Creator<CaptureRequest>() { |
| 109 | @Override |
| 110 | public CaptureRequest createFromParcel(Parcel in) { |
| 111 | CaptureRequest request = new CaptureRequest(); |
| 112 | request.readFromParcel(in); |
| 113 | return request; |
| 114 | } |
| 115 | |
| 116 | @Override |
| 117 | public CaptureRequest[] newArray(int size) { |
| 118 | return new CaptureRequest[size]; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * Expand this object from a Parcel. |
| 124 | * @param in The parcel from which the object should be read |
| 125 | */ |
| 126 | @Override |
| 127 | public void readFromParcel(Parcel in) { |
| 128 | synchronized (mLock) { |
| 129 | super.readFromParcel(in); |
| 130 | |
| 131 | mSurfaceSet.clear(); |
| 132 | |
| 133 | Parcelable[] parcelableArray = in.readParcelableArray(Surface.class.getClassLoader()); |
| 134 | |
| 135 | if (parcelableArray == null) { |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | for (Parcelable p : parcelableArray) { |
| 140 | Surface s = (Surface) p; |
| 141 | mSurfaceSet.add(s); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | @Override |
| 147 | public void writeToParcel(Parcel dest, int flags) { |
| 148 | synchronized (mLock) { |
| 149 | super.writeToParcel(dest, flags); |
| 150 | |
| 151 | dest.writeParcelableArray(mSurfaceSet.toArray(new Surface[mSurfaceSet.size()]), flags); |
| 152 | } |
Eino-Ville Talvala | b267554 | 2012-12-12 13:29:45 -0800 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | } |