149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh/* 249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Copyright (C) 2015 The Android Open Source Project 349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Licensed under the Apache License, Version 2.0 (the "License"); 549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * you may not use this file except in compliance with the License. 649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * You may obtain a copy of the License at 749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * http://www.apache.org/licenses/LICENSE-2.0 949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 1049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Unless required by applicable law or agreed to in writing, software 1149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * distributed under the License is distributed on an "AS IS" BASIS, 1249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * See the License for the specific language governing permissions and 1449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * limitations under the License. 1549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 1649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 1749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 1849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yehpackage android.hardware.camera2.params; 1949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 20fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvalaimport android.annotation.NonNull; 21fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvalaimport android.annotation.Nullable; 22445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun Heimport android.annotation.SystemApi; 23c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun Heimport android.graphics.ImageFormat; 24c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun Heimport android.hardware.camera2.CameraCaptureSession; 2549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yehimport android.hardware.camera2.CameraDevice; 2661f15366127752258aea05398c40182c5b174a29Yin-Chia Yehimport android.hardware.camera2.utils.HashCodeHelpers; 27828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chenimport android.hardware.camera2.utils.SurfaceUtils; 285d2d7788f1759b0f3d2c057af0b3ea61b0354feeEino-Ville Talvalaimport android.os.Parcel; 295d2d7788f1759b0f3d2c057af0b3ea61b0354feeEino-Ville Talvalaimport android.os.Parcelable; 30bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yehimport android.util.Log; 31828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chenimport android.util.Size; 3249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yehimport android.view.Surface; 3349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 3449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yehimport static com.android.internal.util.Preconditions.*; 3549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 3623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wangimport java.util.ArrayList; 3723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wangimport java.util.Collections; 3823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wangimport java.util.List; 3923d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang 4049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh/** 41bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh * A class for describing camera output, which contains a {@link Surface} and its specific 4249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * configuration for creating capture session. 4349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 44032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <p>There are several ways to instantiate, modify and use OutputConfigurations. The most common 45032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * and recommended usage patterns are summarized in the following list:</p> 46032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev *<ul> 47032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <li>Passing a {@link Surface} to the constructor and using the OutputConfiguration instance as 48032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * argument to {@link CameraDevice#createCaptureSessionByOutputConfigurations}. This is the most 49032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * frequent usage and clients should consider it first before other more complicated alternatives. 50032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * </li> 51032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 52032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <li>Passing only a surface source class as an argument to the constructor. This is usually 53032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * followed by a call to create a capture session 54032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * (see {@link CameraDevice#createCaptureSessionByOutputConfigurations} and a {@link Surface} add 55032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * call {@link #addSurface} with a valid {@link Surface}. The sequence completes with 56032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#finalizeOutputConfigurations}. This is the deferred usage case which 57032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * aims to enhance performance by allowing the resource-intensive capture session create call to 58032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * execute in parallel with any {@link Surface} initialization, such as waiting for a 59032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link android.view.SurfaceView} to be ready as part of the UI initialization.</li> 60032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 61032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <li>The third and most complex usage pattern inlvolves surface sharing. Once instantiated an 62032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * OutputConfiguration can be enabled for surface sharing via {@link #enableSurfaceSharing}. This 63032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * must be done before creating a new capture session and enables calls to 64032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#updateOutputConfiguration}. An OutputConfiguration with enabled 65032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * surface sharing can be modified via {@link #addSurface} or {@link #removeSurface}. The updates 66032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * to this OutputConfiguration will only come into effect after 67032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#updateOutputConfiguration} returns without throwing exceptions. 68032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * Such updates can be done as long as the session is active. Clients should always consider the 69032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * additional requirements and limitations placed on the output surfaces (for more details see 70032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link #enableSurfaceSharing}, {@link #addSurface}, {@link #removeSurface}, 71032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#updateOutputConfiguration}). A trade-off exists between additional 72032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * complexity and flexibility. If exercised correctly surface sharing can switch between different 73032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * output surfaces without interrupting any ongoing repeating capture requests. This saves time and 74032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * can significantly improve the user experience.</li> 75032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 76032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <li>Surface sharing can be used in combination with deferred surfaces. The rules from both cases 77032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * are combined and clients must call {@link #enableSurfaceSharing} before creating a capture 78032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * session. Attach and/or remove output surfaces via {@link #addSurface}/{@link #removeSurface} and 79032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * finalize the configuration using {@link CameraCaptureSession#finalizeOutputConfigurations}. 80032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#updateOutputConfiguration} can be called after the configuration 81032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * finalize method returns without exceptions.</li> 82032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 83032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * </ul> 84032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 855c19a99a88bf825af2be0883c425e002c45c65f5Emilian Peev * <p> As of {@link android.os.Build.VERSION_CODES#P Android P}, all formats can be used for 865c19a99a88bf825af2be0883c425e002c45c65f5Emilian Peev * sharing, subject to device support. On prior API levels, only {@link ImageFormat#PRIVATE} 875c19a99a88bf825af2be0883c425e002c45c65f5Emilian Peev * format may be used.</p> 88032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 899c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * @see CameraDevice#createCaptureSessionByOutputConfigurations 9049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 9149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 92bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yehpublic final class OutputConfiguration implements Parcelable { 9349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 9449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 9549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Rotation constant: 0 degree rotation (no rotation) 96445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 97445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 9849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 99445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 10049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh public static final int ROTATION_0 = 0; 10149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 10249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 10349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Rotation constant: 90 degree counterclockwise rotation. 104445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 105445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 10649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 107445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 10849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh public static final int ROTATION_90 = 1; 10949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 11049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 11149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Rotation constant: 180 degree counterclockwise rotation. 112445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 113445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 11449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 115445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 11649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh public static final int ROTATION_180 = 2; 11749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 11849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 11949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Rotation constant: 270 degree counterclockwise rotation. 120445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 121445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 12249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 123445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 12449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh public static final int ROTATION_270 = 3; 12549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 12649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 127fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * Invalid surface group ID. 128445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 129445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He *<p>An {@link OutputConfiguration} with this value indicates that the included surface 130fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala *doesn't belong to any surface group.</p> 131445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He */ 132fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public static final int SURFACE_GROUP_ID_NONE = -1; 133445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He 134445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He /** 135445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * Create a new {@link OutputConfiguration} instance with a {@link Surface}. 13649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 13749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * @param surface 13849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * A Surface for camera to output to. 13949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 140fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * <p>This constructor creates a default configuration, with a surface group ID of 141fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * {@value #SURFACE_GROUP_ID_NONE}.</p> 14249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 14349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 144fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public OutputConfiguration(@NonNull Surface surface) { 145fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala this(SURFACE_GROUP_ID_NONE, surface, ROTATION_0); 146fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala } 147fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala 148fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala /** 149c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * Unknown surface source type. 150c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 151c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final int SURFACE_TYPE_UNKNOWN = -1; 152c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 153c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 154c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * The surface is obtained from {@link android.view.SurfaceView}. 155c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 156c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final int SURFACE_TYPE_SURFACE_VIEW = 0; 157c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 158c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 159c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * The surface is obtained from {@link android.graphics.SurfaceTexture}. 160c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 161c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final int SURFACE_TYPE_SURFACE_TEXTURE = 1; 162c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 163c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 1644bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * Maximum number of surfaces supported by one {@link OutputConfiguration}. 1654bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 1664bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p>The combined number of surfaces added by the constructor and 1674bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * {@link OutputConfiguration#addSurface} should not exceed this value.</p> 1684bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 1694bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang */ 170032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev private static final int MAX_SURFACES_COUNT = 4; 1714bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang 1724bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang /** 173fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * Create a new {@link OutputConfiguration} instance with a {@link Surface}, 174fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * with a surface group ID. 175fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 176fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * <p> 177fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * A surface group ID is used to identify which surface group this output surface belongs to. A 178fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * surface group is a group of output surfaces that are not intended to receive camera output 179fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * buffer streams simultaneously. The {@link CameraDevice} may be able to share the buffers used 180fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * by all the surfaces from the same surface group, therefore may reduce the overall memory 181fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * footprint. The application should only set the same set ID for the streams that are not 182fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * simultaneously streaming. A negative ID indicates that this surface doesn't belong to any 183fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * surface group. The default value is {@value #SURFACE_GROUP_ID_NONE}.</p> 184fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 185fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * <p>For example, a video chat application that has an adaptive output resolution feature would 186fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * need two (or more) output resolutions, to switch resolutions without any output glitches. 187fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * However, at any given time, only one output is active to minimize outgoing network bandwidth 188fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * and encoding overhead. To save memory, the application should set the video outputs to have 189fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * the same non-negative group ID, so that the camera device can share the same memory region 190fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * for the alternating outputs.</p> 191fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 192fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * <p>It is not an error to include output streams with the same group ID in the same capture 193fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * request, but the resulting memory consumption may be higher than if the two streams were 194fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * not in the same surface group to begin with, especially if the outputs have substantially 195fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * different dimensions.</p> 196fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 197fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @param surfaceGroupId 198fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * A group ID for this output, used for sharing memory between multiple outputs. 199fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @param surface 200fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * A Surface for camera to output to. 201fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 202fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala */ 203fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public OutputConfiguration(int surfaceGroupId, @NonNull Surface surface) { 204fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala this(surfaceGroupId, surface, ROTATION_0); 20549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh } 20649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 20749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 208445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * Create a new {@link OutputConfiguration} instance. 20949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 21049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * <p>This constructor takes an argument for desired camera rotation</p> 21149ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 21249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * @param surface 21349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * A Surface for camera to output to. 21449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * @param rotation 21549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * The desired rotation to be applied on camera output. Value must be one of 216fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * ROTATION_[0, 90, 180, 270]. Note that when the rotation is 90 or 270 degrees, 217fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * application should make sure corresponding surface size has width and height 218fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * transposed relative to the width and height without rotation. For example, 219fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * if application needs camera to capture 1280x720 picture and rotate it by 90 degree, 220fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * application should set rotation to {@code ROTATION_90} and make sure the 221fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * corresponding Surface size is 720x1280. Note that {@link CameraDevice} might 222fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * throw {@code IllegalArgumentException} if device cannot perform such rotation. 223fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @hide 224fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala */ 225fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala @SystemApi 226fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public OutputConfiguration(@NonNull Surface surface, int rotation) { 227fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala this(SURFACE_GROUP_ID_NONE, surface, rotation); 228fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala } 229fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala 230fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala /** 231fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * Create a new {@link OutputConfiguration} instance, with rotation and a group ID. 232fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 233fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * <p>This constructor takes an argument for desired camera rotation and for the surface group 234fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * ID. See {@link #OutputConfiguration(int, Surface)} for details of the group ID.</p> 235fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * 236fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @param surfaceGroupId 237fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * A group ID for this output, used for sharing memory between multiple outputs. 238fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @param surface 239fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * A Surface for camera to output to. 240fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @param rotation 241fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * The desired rotation to be applied on camera output. Value must be one of 242fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * ROTATION_[0, 90, 180, 270]. Note that when the rotation is 90 or 270 degrees, 24349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * application should make sure corresponding surface size has width and height 244fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * transposed relative to the width and height without rotation. For example, 24549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * if application needs camera to capture 1280x720 picture and rotate it by 90 degree, 24649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * application should set rotation to {@code ROTATION_90} and make sure the 24749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * corresponding Surface size is 720x1280. Note that {@link CameraDevice} might 24849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * throw {@code IllegalArgumentException} if device cannot perform such rotation. 249445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 25049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 251445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 252fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public OutputConfiguration(int surfaceGroupId, @NonNull Surface surface, int rotation) { 25349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh checkNotNull(surface, "Surface must not be null"); 25449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh checkArgumentInRange(rotation, ROTATION_0, ROTATION_270, "Rotation constant"); 255fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala mSurfaceGroupId = surfaceGroupId; 256c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mSurfaceType = SURFACE_TYPE_UNKNOWN; 2574bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaces = new ArrayList<Surface>(); 2584bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaces.add(surface); 25949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh mRotation = rotation; 260828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen mConfiguredSize = SurfaceUtils.getSurfaceSize(surface); 261828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen mConfiguredFormat = SurfaceUtils.getSurfaceFormat(surface); 262828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen mConfiguredDataspace = SurfaceUtils.getSurfaceDataspace(surface); 263fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala mConfiguredGenerationId = surface.getGenerationId(); 264c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mIsDeferredConfig = false; 2654bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsShared = false; 26623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId = null; 267c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 268c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 269c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 270c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * Create a new {@link OutputConfiguration} instance, with desired Surface size and Surface 271c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * source class. 272c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * <p> 273c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * This constructor takes an argument for desired Surface size and the Surface source class 2744bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * without providing the actual output Surface. This is used to setup an output configuration 275c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * with a deferred Surface. The application can use this output configuration to create a 276c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * session. 277c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * </p> 278c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * <p> 2794bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * However, the actual output Surface must be set via {@link #addSurface} and the deferred 2804bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * Surface configuration must be finalized via {@link 2814bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * CameraCaptureSession#finalizeOutputConfigurations} before submitting a request with this 2824bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * Surface target. The deferred Surface can only be obtained either from {@link 2834bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * android.view.SurfaceView} by calling {@link android.view.SurfaceHolder#getSurface}, or from 284c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * {@link android.graphics.SurfaceTexture} via 285c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * {@link android.view.Surface#Surface(android.graphics.SurfaceTexture)}). 286c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * </p> 287c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * 288c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * @param surfaceSize Size for the deferred surface. 289c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * @param klass a non-{@code null} {@link Class} object reference that indicates the source of 290c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * this surface. Only {@link android.view.SurfaceHolder SurfaceHolder.class} and 291c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * {@link android.graphics.SurfaceTexture SurfaceTexture.class} are supported. 29221d63b2836e42133dd8856f260e0854018667780Shuzhen Wang * @throws IllegalArgumentException if the Surface source class is not supported, or Surface 29321d63b2836e42133dd8856f260e0854018667780Shuzhen Wang * size is zero. 294c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 295c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He public <T> OutputConfiguration(@NonNull Size surfaceSize, @NonNull Class<T> klass) { 2964bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang checkNotNull(klass, "surfaceSize must not be null"); 2974bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang checkNotNull(klass, "klass must not be null"); 2984bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (klass == android.view.SurfaceHolder.class) { 2994bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaceType = SURFACE_TYPE_SURFACE_VIEW; 3004bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } else if (klass == android.graphics.SurfaceTexture.class) { 3014bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaceType = SURFACE_TYPE_SURFACE_TEXTURE; 3024bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } else { 3034bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaceType = SURFACE_TYPE_UNKNOWN; 3044bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang throw new IllegalArgumentException("Unknow surface source class type"); 3054bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 306c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 307476bea84959ca6f2a6ef304ab040cb16b4ac97c1Shuzhen Wang if (surfaceSize.getWidth() == 0 || surfaceSize.getHeight() == 0) { 308476bea84959ca6f2a6ef304ab040cb16b4ac97c1Shuzhen Wang throw new IllegalArgumentException("Surface size needs to be non-zero"); 309476bea84959ca6f2a6ef304ab040cb16b4ac97c1Shuzhen Wang } 310476bea84959ca6f2a6ef304ab040cb16b4ac97c1Shuzhen Wang 3114bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaceGroupId = SURFACE_GROUP_ID_NONE; 3124bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaces = new ArrayList<Surface>(); 3134bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mRotation = ROTATION_0; 3144bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredSize = surfaceSize; 3154bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(ImageFormat.PRIVATE); 3164bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredDataspace = StreamConfigurationMap.imageFormatToDataspace(ImageFormat.PRIVATE); 3174bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredGenerationId = 0; 3184bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsDeferredConfig = true; 3194bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsShared = false; 32023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId = null; 3219c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang } 3229c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 3239c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang /** 3244bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * Enable multiple surfaces sharing the same OutputConfiguration 3259c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * 3264bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p>For advanced use cases, a camera application may require more streams than the combination 3274bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * guaranteed by {@link CameraDevice#createCaptureSession}. In this case, more than one 3284bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * compatible surface can be attached to an OutputConfiguration so that they map to one 329032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * camera stream, and the outputs share memory buffers when possible. Due to buffer sharing 330032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * clients should be careful when adding surface outputs that modify their input data. If such 331032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * case exists, camera clients should have an additional mechanism to synchronize read and write 332032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * access between individual consumers.</p> 3339c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * 3344bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p>Two surfaces are compatible in the below cases:</p> 3359c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * 3364bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <li> Surfaces with the same size, format, dataSpace, and Surface source class. In this case, 3374bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * {@link CameraDevice#createCaptureSessionByOutputConfigurations} is guaranteed to succeed. 3384bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 3394bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <li> Surfaces with the same size, format, and dataSpace, but different Surface source classes 3404bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * that are generally not compatible. However, on some devices, the underlying camera device is 3414bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * able to use the same buffer layout for both surfaces. The only way to discover if this is the 3424bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * case is to create a capture session with that output configuration. For example, if the 3434bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * camera device uses the same private buffer format between a SurfaceView/SurfaceTexture and a 3444bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * MediaRecorder/MediaCodec, {@link CameraDevice#createCaptureSessionByOutputConfigurations} 345f02913c4ea495d984cbfcdaa5ab793f8c2710910Shuzhen Wang * will succeed. Otherwise, it fails with {@link 346f02913c4ea495d984cbfcdaa5ab793f8c2710910Shuzhen Wang * CameraCaptureSession.StateCallback#onConfigureFailed}. 3474bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * </ol> 3484bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 3494bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p>To enable surface sharing, this function must be called before {@link 35023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * CameraDevice#createCaptureSessionByOutputConfigurations} or {@link 35123d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * CameraDevice#createReprocessableCaptureSessionByConfigurations}. Calling this function after 35223d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * {@link CameraDevice#createCaptureSessionByOutputConfigurations} has no effect.</p> 3534bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 354032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <p>Up to {@link #getMaxSharedSurfaceCount} surfaces can be shared for an OutputConfiguration. 355032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * The supported surfaces for sharing must be of type SurfaceTexture, SurfaceView, 356032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * MediaRecorder, MediaCodec, or implementation defined ImageReader.</p> 3579c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang */ 3584bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang public void enableSurfaceSharing() { 3594bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsShared = true; 360c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 361c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 362c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 36323d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * Set the id of the physical camera for this OutputConfiguration 36423d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 36523d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * <p>In the case one logical camera is made up of multiple physical cameras, it could be 36623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * desirable for the camera application to request streams from individual physical cameras. 36723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * This call achieves it by mapping the OutputConfiguration to the physical camera id.</p> 36823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 3692d5bbe4b6f4569b0afb14d817e52fb8bb107d9abShuzhen Wang * <p>The valid physical camera ids can be queried by {@link 37023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * android.hardware.camera2.CameraCharacteristics#getPhysicalCameraIds}. 37123d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * </p> 37223d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 37323d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * <p>Passing in a null physicalCameraId means that the OutputConfiguration is for a logical 37423d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * stream.</p> 37523d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 37623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * <p>This function must be called before {@link 37723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * CameraDevice#createCaptureSessionByOutputConfigurations} or {@link 37823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * CameraDevice#createReprocessableCaptureSessionByConfigurations}. Calling this function 37923d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * after {@link CameraDevice#createCaptureSessionByOutputConfigurations} or {@link 38023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * CameraDevice#createReprocessableCaptureSessionByConfigurations} has no effect.</p> 38123d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 38223d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * <p>The surface belonging to a physical camera OutputConfiguration must not be used as input 38323d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * or output of a reprocessing request. </p> 38423d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang */ 38523d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang public void setPhysicalCameraId(@Nullable String physicalCameraId) { 38623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId = physicalCameraId; 38723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang } 38823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang 38923d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang /** 39023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * Check if this configuration is for a physical camera. 39123d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * 39223d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * <p>This returns true if the output configuration was for a physical camera making up a 39323d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * logical multi camera via {@link OutputConfiguration#setPhysicalCameraId}.</p> 39423d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang * @hide 39523d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang */ 39623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang public boolean isForPhysicalCamera() { 39723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang return (mPhysicalCameraId != null); 39823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang } 39923d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang 40023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang /** 401c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * Check if this configuration has deferred configuration. 402c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * 4034bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p>This will return true if the output configuration was constructed with surface deferred by 4044bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * {@link OutputConfiguration#OutputConfiguration(Size, Class)}. It will return true even after 4054bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * the deferred surface is added later by {@link OutputConfiguration#addSurface}.</p> 406c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * 407c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * @return true if this configuration has deferred surface. 408c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * @hide 409c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 410c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He public boolean isDeferredConfiguration() { 411c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He return mIsDeferredConfig; 412c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 413c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 414c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He /** 4154bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * Add a surface to this OutputConfiguration. 416c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * 4174bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p> This function can be called before or after {@link 4184bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * CameraDevice#createCaptureSessionByOutputConfigurations}. If it's called after, 4194bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * the application must finalize the capture session with 420032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#finalizeOutputConfigurations}. It is possible to call this method 421032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * after the output configurations have been finalized only in cases of enabled surface sharing 422032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * see {@link #enableSurfaceSharing}. The modified output configuration must be updated with 423032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link CameraCaptureSession#updateOutputConfiguration}.</p> 424c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He * 4254bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p> If the OutputConfiguration was constructed with a deferred surface by {@link 4264bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * OutputConfiguration#OutputConfiguration(Size, Class)}, the added surface must be obtained 4274bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * from {@link android.view.SurfaceView} by calling {@link android.view.SurfaceHolder#getSurface}, 4284bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * or from {@link android.graphics.SurfaceTexture} via 4294bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * {@link android.view.Surface#Surface(android.graphics.SurfaceTexture)}).</p> 4304bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 4314bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p> If the OutputConfiguration was constructed by other constructors, the added 4324bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * surface must be compatible with the existing surface. See {@link #enableSurfaceSharing} for 4334bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * details of compatible surfaces.</p> 4344bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 4354bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * <p> If the OutputConfiguration already contains a Surface, {@link #enableSurfaceSharing} must 4364bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * be called before calling this function to add a new Surface.</p> 4374bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * 4384bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * @param surface The surface to be added. 4394bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * @throws IllegalArgumentException if the Surface is invalid, the Surface's 44021d63b2836e42133dd8856f260e0854018667780Shuzhen Wang * dataspace/format doesn't match, or adding the Surface would exceed number of 4414bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * shared surfaces supported. 4424bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * @throws IllegalStateException if the Surface was already added to this OutputConfiguration, 4434bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * or if the OutputConfiguration is not shared and it already has a surface associated 4444bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * with it. 445c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He */ 4464bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang public void addSurface(@NonNull Surface surface) { 447c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He checkNotNull(surface, "Surface must not be null"); 4484bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.contains(surface)) { 4494bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang throw new IllegalStateException("Surface is already added!"); 4504bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 4514bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.size() == 1 && !mIsShared) { 4524bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang throw new IllegalStateException("Cannot have 2 surfaces for a non-sharing configuration"); 4534bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 4544bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.size() + 1 > MAX_SURFACES_COUNT) { 4554bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang throw new IllegalArgumentException("Exceeds maximum number of surfaces"); 456c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 457c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 45821d63b2836e42133dd8856f260e0854018667780Shuzhen Wang // This will throw IAE is the surface was abandoned. 45921d63b2836e42133dd8856f260e0854018667780Shuzhen Wang Size surfaceSize = SurfaceUtils.getSurfaceSize(surface); 46021d63b2836e42133dd8856f260e0854018667780Shuzhen Wang if (!surfaceSize.equals(mConfiguredSize)) { 46121d63b2836e42133dd8856f260e0854018667780Shuzhen Wang Log.w(TAG, "Added surface size " + surfaceSize + 46221d63b2836e42133dd8856f260e0854018667780Shuzhen Wang " is different than pre-configured size " + mConfiguredSize + 46321d63b2836e42133dd8856f260e0854018667780Shuzhen Wang ", the pre-configured size will be used."); 4644bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 46521d63b2836e42133dd8856f260e0854018667780Shuzhen Wang 4664bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mConfiguredFormat != SurfaceUtils.getSurfaceFormat(surface)) { 4674bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang throw new IllegalArgumentException("The format of added surface format doesn't match"); 468c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 469c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 47075d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang // If the surface format is PRIVATE, do not enforce dataSpace because camera device may 47175d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang // override it. 47275d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang if (mConfiguredFormat != ImageFormat.PRIVATE && 47375d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang mConfiguredDataspace != SurfaceUtils.getSurfaceDataspace(surface)) { 47475d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang throw new IllegalArgumentException("The dataspace of added surface doesn't match"); 47575d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang } 47675d66023c8107bd803779139aece7f0cf4c7f88dShuzhen Wang 4774bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaces.add(surface); 47849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh } 47949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 48049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 481032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * Remove a surface from this OutputConfiguration. 482032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 483032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * <p> Surfaces added via calls to {@link #addSurface} can also be removed from the 484032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * OutputConfiguration. The only notable exception is the surface associated with 485032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * the OutputConfigration see {@link #getSurface} which was passed as part of the constructor 486032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * or was added first in the deferred case 487032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * {@link OutputConfiguration#OutputConfiguration(Size, Class)}.</p> 488032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 489032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * @param surface The surface to be removed. 490032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 491032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * @throws IllegalArgumentException If the surface is associated with this OutputConfiguration 492032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * (see {@link #getSurface}) or the surface didn't get added 493032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * with {@link #addSurface}. 494032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev */ 495032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev public void removeSurface(@NonNull Surface surface) { 496032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev if (getSurface() == surface) { 497032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev throw new IllegalArgumentException( 498032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev "Cannot remove surface associated with this output configuration"); 499032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev } 500032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev if (!mSurfaces.remove(surface)) { 501032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev throw new IllegalArgumentException("Surface is not part of this output configuration"); 502032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev } 503032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev } 504032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev 505032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev /** 506445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * Create a new {@link OutputConfiguration} instance with another {@link OutputConfiguration} 507445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * instance. 508445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 509445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @param other Another {@link OutputConfiguration} instance to be copied. 510445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 511445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 512445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He */ 513fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public OutputConfiguration(@NonNull OutputConfiguration other) { 514445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He if (other == null) { 515445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He throw new IllegalArgumentException("OutputConfiguration shouldn't be null"); 516445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He } 517445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He 5189c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang this.mSurfaces = other.mSurfaces; 519445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He this.mRotation = other.mRotation; 520fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala this.mSurfaceGroupId = other.mSurfaceGroupId; 521c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He this.mSurfaceType = other.mSurfaceType; 522445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He this.mConfiguredDataspace = other.mConfiguredDataspace; 523445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He this.mConfiguredFormat = other.mConfiguredFormat; 524445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He this.mConfiguredSize = other.mConfiguredSize; 525fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala this.mConfiguredGenerationId = other.mConfiguredGenerationId; 526c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He this.mIsDeferredConfig = other.mIsDeferredConfig; 527b4d0fa3d3f386cc3fa9ad3ba772424986b6dde1fShuzhen Wang this.mIsShared = other.mIsShared; 52823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang this.mPhysicalCameraId = other.mPhysicalCameraId; 529445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He } 530445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He 531445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He /** 532bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh * Create an OutputConfiguration from Parcel. 533bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh */ 534fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala private OutputConfiguration(@NonNull Parcel source) { 535bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh int rotation = source.readInt(); 536445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He int surfaceSetId = source.readInt(); 537c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He int surfaceType = source.readInt(); 538c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He int width = source.readInt(); 539c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He int height = source.readInt(); 5404bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang boolean isDeferred = source.readInt() == 1; 541b4d0fa3d3f386cc3fa9ad3ba772424986b6dde1fShuzhen Wang boolean isShared = source.readInt() == 1; 5424bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang ArrayList<Surface> surfaces = new ArrayList<Surface>(); 5434bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang source.readTypedList(surfaces, Surface.CREATOR); 54423d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang String physicalCameraId = source.readString(); 5459c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 546bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh checkArgumentInRange(rotation, ROTATION_0, ROTATION_270, "Rotation constant"); 5479c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 548fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala mSurfaceGroupId = surfaceSetId; 549bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh mRotation = rotation; 5509c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mSurfaces = surfaces; 5519c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredSize = new Size(width, height); 5524bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsDeferredConfig = isDeferred; 553b4d0fa3d3f386cc3fa9ad3ba772424986b6dde1fShuzhen Wang mIsShared = isShared; 5544bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mSurfaces = surfaces; 5554bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.size() > 0) { 556c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mSurfaceType = SURFACE_TYPE_UNKNOWN; 5574bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredFormat = SurfaceUtils.getSurfaceFormat(mSurfaces.get(0)); 5584bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredDataspace = SurfaceUtils.getSurfaceDataspace(mSurfaces.get(0)); 5594bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mConfiguredGenerationId = mSurfaces.get(0).getGenerationId(); 560c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } else { 561c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mSurfaceType = surfaceType; 562c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mConfiguredFormat = StreamConfigurationMap.imageFormatToInternal(ImageFormat.PRIVATE); 563c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He mConfiguredDataspace = 564c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He StreamConfigurationMap.imageFormatToDataspace(ImageFormat.PRIVATE); 5659c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredGenerationId = 0; 5669c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang } 56723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId = physicalCameraId; 568bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 569bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh 570bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh /** 571032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * Get the maximum supported shared {@link Surface} count. 572032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 573032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * @return the maximum number of surfaces that can be added per each OutputConfiguration. 574032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * 575032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev * @see #enableSurfaceSharing 576032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev */ 57731c11a05a493e18e5c950b3a9d318094ad7525b2Emilian Peev public int getMaxSharedSurfaceCount() { 578032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev return MAX_SURFACES_COUNT; 579032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev } 580032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev 581032331578c78886d2b0a6012dc2a083837c5e79fEmilian Peev /** 58249ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Get the {@link Surface} associated with this {@link OutputConfiguration}. 58349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 5844bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * If more than one surface is associated with this {@link OutputConfiguration}, return the 5854bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * first one as specified in the constructor or {@link OutputConfiguration#addSurface}. 5869c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang */ 5879c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang public @Nullable Surface getSurface() { 5884bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.size() == 0) { 5894bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang return null; 5904bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 5914bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang 5924bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang return mSurfaces.get(0); 5939c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang } 5949c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 5959c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang /** 5969c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * Get the immutable list of surfaces associated with this {@link OutputConfiguration}. 5979c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang * 5984bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * @return the list of surfaces associated with this {@link OutputConfiguration} as specified in 5994bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang * the constructor and {@link OutputConfiguration#addSurface}. The list should not be modified. 60049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 601fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala @NonNull 6029c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang public List<Surface> getSurfaces() { 6034bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang return Collections.unmodifiableList(mSurfaces); 60449ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh } 60549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 60649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh /** 60749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Get the rotation associated with this {@link OutputConfiguration}. 60849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * 60949ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * @return the rotation associated with this {@link OutputConfiguration}. 61049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh * Value will be one of ROTATION_[0, 90, 180, 270] 611445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 612445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * @hide 61349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh */ 614445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He @SystemApi 61549ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh public int getRotation() { 61649ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh return mRotation; 61749ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh } 61849ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh 619445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He /** 620fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * Get the surface group ID associated with this {@link OutputConfiguration}. 621445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He * 622fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * @return the surface group ID associated with this {@link OutputConfiguration}. 623fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala * The default value is {@value #SURFACE_GROUP_ID_NONE}. 624445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He */ 625fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala public int getSurfaceGroupId() { 626fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala return mSurfaceGroupId; 627445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He } 628445b316755923565c3b5b8ebb642db10de5d0ab7Zhijun He 629bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh public static final Parcelable.Creator<OutputConfiguration> CREATOR = 630bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh new Parcelable.Creator<OutputConfiguration>() { 631bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh @Override 632bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh public OutputConfiguration createFromParcel(Parcel source) { 633bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh try { 634bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh OutputConfiguration outputConfiguration = new OutputConfiguration(source); 635bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh return outputConfiguration; 636bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } catch (Exception e) { 637bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh Log.e(TAG, "Exception creating OutputConfiguration from parcel", e); 638bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh return null; 639bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 640bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 641bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh 642bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh @Override 643bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh public OutputConfiguration[] newArray(int size) { 644bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh return new OutputConfiguration[size]; 645bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 646bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh }; 647bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh 648bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh @Override 649bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh public int describeContents() { 650bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh return 0; 651bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 652bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh 653bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh @Override 654bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh public void writeToParcel(Parcel dest, int flags) { 655bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh if (dest == null) { 656bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh throw new IllegalArgumentException("dest must not be null"); 657bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 658bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh dest.writeInt(mRotation); 659fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala dest.writeInt(mSurfaceGroupId); 660c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He dest.writeInt(mSurfaceType); 661c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He dest.writeInt(mConfiguredSize.getWidth()); 662c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He dest.writeInt(mConfiguredSize.getHeight()); 6634bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang dest.writeInt(mIsDeferredConfig ? 1 : 0); 6644bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang dest.writeInt(mIsShared ? 1 : 0); 6654bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang dest.writeTypedList(mSurfaces); 66623d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang dest.writeString(mPhysicalCameraId); 667bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh } 668bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh 66961f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh /** 67061f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh * Check if this {@link OutputConfiguration} is equal to another {@link OutputConfiguration}. 67161f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh * 672828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen * <p>Two output configurations are only equal if and only if the underlying surfaces, surface 673828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen * properties (width, height, format, dataspace) when the output configurations are created, 674828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen * and all other configuration parameters are equal. </p> 67561f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh * 67661f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh * @return {@code true} if the objects were equal, {@code false} otherwise 67761f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh */ 67861f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh @Override 67961f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh public boolean equals(Object obj) { 68061f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh if (obj == null) { 68161f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh return false; 68261f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh } else if (this == obj) { 68361f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh return true; 68461f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh } else if (obj instanceof OutputConfiguration) { 68561f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh final OutputConfiguration other = (OutputConfiguration) obj; 6869c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang if (mRotation != other.mRotation || 6879c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang !mConfiguredSize.equals(other.mConfiguredSize) || 6889c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredFormat != other.mConfiguredFormat || 6899c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mSurfaceGroupId != other.mSurfaceGroupId || 6909c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mSurfaceType != other.mSurfaceType || 6919c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mIsDeferredConfig != other.mIsDeferredConfig || 6924bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mIsShared != other.mIsShared || 6939c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredFormat != other.mConfiguredFormat || 6949c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredDataspace != other.mConfiguredDataspace || 6959c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredGenerationId != other.mConfiguredGenerationId) 6969c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang return false; 6979c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 6984bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang int minLen = Math.min(mSurfaces.size(), other.mSurfaces.size()); 6994bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang for (int i = 0; i < minLen; i++) { 7004bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mSurfaces.get(i) != other.mSurfaces.get(i)) 7019c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang return false; 702c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He } 7039c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang 7049c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang return true; 70561f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh } 70661f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh return false; 70761f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh } 70861f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh 70961f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh /** 71061f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh * {@inheritDoc} 71161f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh */ 71261f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh @Override 71361f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh public int hashCode() { 7144bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang // Need ensure that the hashcode remains unchanged after adding a deferred surface. Otherwise 7159c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang // the deferred output configuration will be lost in the camera streammap after the deferred 716c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He // surface is set. 7174bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang if (mIsDeferredConfig) { 7184bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang return HashCodeHelpers.hashCode( 7194bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mRotation, mConfiguredSize.hashCode(), mConfiguredFormat, mConfiguredDataspace, 72023d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mSurfaceGroupId, mSurfaceType, mIsShared ? 1 : 0, 72123d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId == null ? 0 : mPhysicalCameraId.hashCode()); 7224bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang } 723c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He 724fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala return HashCodeHelpers.hashCode( 7254bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang mRotation, mSurfaces.hashCode(), mConfiguredGenerationId, 7269c663d4415a077230924f40eaf291f51ff37e8b0Shuzhen Wang mConfiguredSize.hashCode(), mConfiguredFormat, 72723d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mConfiguredDataspace, mSurfaceGroupId, mIsShared ? 1 : 0, 72823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang mPhysicalCameraId == null ? 0 : mPhysicalCameraId.hashCode()); 72961f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh } 73061f15366127752258aea05398c40182c5b174a29Yin-Chia Yeh 731bfbbee756663aeeb38706bb1bd4841dcd050f91bYin-Chia Yeh private static final String TAG = "OutputConfiguration"; 7324bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang private ArrayList<Surface> mSurfaces; 73349ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh private final int mRotation; 734c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final int mSurfaceGroupId; 735c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He // Surface source type, this is only used by the deferred surface configuration objects. 736c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final int mSurfaceType; 737828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen 738828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen // The size, format, and dataspace of the surface when OutputConfiguration is created. 739828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen private final Size mConfiguredSize; 740828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen private final int mConfiguredFormat; 741828adbba24c430b09c48092ce05730a54e50756aChien-Yu Chen private final int mConfiguredDataspace; 742fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala // Surface generation ID to distinguish changes to Surface native internals 743fa5e2a156da99322a5e847ab2373c03784060119Eino-Ville Talvala private final int mConfiguredGenerationId; 744c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He // Flag indicating if this config has deferred surface. 745c8b181e95d17c00f9fe4a8338c4cdd0eeac3a0dcZhijun He private final boolean mIsDeferredConfig; 7464bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang // Flag indicating if this config has shared surfaces 7474bd7abe72a647ceb2175a4fe66aa640815c116f8Shuzhen Wang private boolean mIsShared; 74823d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang // The physical camera id that this output configuration is for. 74923d2938f225abfcdb0223d60098be21b9d88d30cShuzhen Wang private String mPhysicalCameraId; 75049ea6ae76d78ff8d179c0957d4bc55f08cb98d0fYin-Chia Yeh} 751