summaryrefslogtreecommitdiff
path: root/core/java/android/hardware/camera2/params/MultiResolutionStreamInfo.java
blob: e2e61ad4d31a950212f5a1acb958ef33ca1e9bf9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.camera2.params;

import android.annotation.NonNull;
import android.annotation.IntRange;

import java.util.Objects;

/**
 * A utility class describing the properties of one stream of fixed-size image buffers
 * backing a multi-resolution image stream.
 *
 * <p>A group of {@link MultiResolutionStreamInfo} are used to describe the properties of a
 * multi-resolution image stream for a particular format. The
 * {@link android.hardware.camera2.MultiResolutionImageReader} class represents a
 * multi-resolution output stream, and is constructed using a group of
 * {@link MultiResolutionStreamInfo}. A group of {@link MultiResolutionStreamInfo} can also be used
 * to create a multi-resolution reprocessable camera capture session. See
 * {@link android.hardware.camera2.params.InputConfiguration} for details.</p>
 *
 * @see InputConfiguration
 * @see android.hardware.camera2.MultiResolutionImageReader
 */
public class MultiResolutionStreamInfo {
    private int mStreamWidth;
    private int mStreamHeight;
    private String mPhysicalCameraId;

    /**
     * Create a new {@link MultiResolutionStreamInfo}.
     *
     * <p>This class creates a {@link MultiResolutionStreamInfo} using image width, image height,
     * and the physical camera Id images originate from.</p>
     *
     * <p>Normally applications do not need to create these directly. Use {@link
     * MultiResolutionStreamConfigurationMap#getOutputInfo} or {@link
     * MultiResolutionStreamConfigurationMap#getInputInfo} to obtain them for a particular format
     * instead.</p>
     *
     * @param streamWidth The width in pixels of the camera stream
     * @param streamHeight The height in pixels of the camera stream
     * @param physicalCameraId The physical camera Id the camera stream is associated with
     * @throws IllegalArgumentException if the streamWidth or streamHeight is invalid (either zero
     *                                  or negative).
     */
    public MultiResolutionStreamInfo(@IntRange(from = 1) int streamWidth,
            @IntRange(from = 1) int streamHeight,
            @NonNull String physicalCameraId) {
        if (streamWidth <= 0) {
            throw new IllegalArgumentException("Invalid stream width " + streamWidth);
        }
        if (streamHeight <= 0) {
            throw new IllegalArgumentException("Invalid stream height " + streamHeight);
        }
        mStreamWidth = streamWidth;
        mStreamHeight = streamHeight;
        mPhysicalCameraId = physicalCameraId;
    }

    /**
     * The width of this particular image buffer stream in pixels.
     */
    public @IntRange(from = 1) int getWidth() {
        return mStreamWidth;
    }

    /**
     * The height of this particular image buffer stream in pixels.
     */
    public @IntRange(from = 1) int getHeight() {
        return mStreamHeight;
    }

    /**
     * The physical camera Id of this particular image buffer stream.
     */
    public @NonNull String getPhysicalCameraId() {
        return mPhysicalCameraId;
    }

    /**
     * Check if this {@link MultiResolutionStreamInfo} is equal to another
     * {@link MultiResolutionStreamInfo}.
     *
     * @return {@code true} if the objects were equal, {@code false} otherwise
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (this == obj) {
            return true;
        }
        if (obj instanceof MultiResolutionStreamInfo) {
            final MultiResolutionStreamInfo other = (MultiResolutionStreamInfo) obj;
            return mStreamWidth == other.mStreamWidth &&
                    mStreamHeight == other.mStreamHeight &&
                    mPhysicalCameraId.equals(other.mPhysicalCameraId);
        }
        return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return Objects.hash(
                mStreamWidth, mStreamHeight, mPhysicalCameraId);
    }
}