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 #ifndef ANDROID_HARDWARE_CAPTURERESULT_H
18 #define ANDROID_HARDWARE_CAPTURERESULT_H
19 
20 #include <utils/RefBase.h>
21 #include <binder/Parcelable.h>
22 #include <camera/CameraMetadata.h>
23 
24 
25 namespace android {
26 
27 namespace hardware {
28 namespace camera2 {
29 namespace impl {
30 
31 /**
32  * CaptureResultExtras is a structure to encapsulate various indices for a capture result.
33  * These indices are framework-internal and not sent to the HAL.
34  */
35 struct CaptureResultExtras : public android::Parcelable {
36     /**
37      * An integer to index the request sequence that this result belongs to.
38      */
39     int32_t requestId;
40 
41     /**
42      * An integer to index this result inside a request sequence, starting from 0.
43      */
44     int32_t burstId;
45 
46     /**
47      * TODO: Add documentation for this field.
48      */
49     int32_t afTriggerId;
50 
51     /**
52      * TODO: Add documentation for this field.
53      */
54     int32_t precaptureTriggerId;
55 
56     /**
57      * A 64bit integer to index the frame number associated with this result.
58      */
59     int64_t frameNumber;
60 
61     /**
62      * The partial result count (index) for this capture result.
63      */
64     int32_t partialResultCount;
65 
66     /**
67      * For buffer drop errors, the stream ID for the stream that lost a buffer.
68      * Otherwise -1.
69      */
70     int32_t errorStreamId;
71 
72     /**
73      * For capture result errors, the physical camera ID in case the respective request contains
74      * a reference to physical camera device.
75      * Empty otherwise.
76      */
77     std::string errorPhysicalCameraId;
78 
79     // The last completed frame numbers shouldn't be checked in onResultReceived() and notifyError()
80     // because the output buffers could be arriving after onResultReceived() and
81     // notifyError(). Given this constraint, we check it for each
82     // onCaptureStarted, and if there is no further onCaptureStarted(),
83     // check for onDeviceIdle() to clear out all pending frame numbers.
84 
85     /**
86      * The latest regular request frameNumber for which all buffers and capture result have been
87      * returned or notified as an BUFFER_ERROR/RESULT_ERROR/REQUEST_ERROR. -1 if
88      * none has completed.
89      */
90     int64_t lastCompletedRegularFrameNumber;
91 
92     /**
93      * The latest reprocess request frameNumber for which all buffers and capture result have been
94      * returned or notified as an BUFFER_ERROR/RESULT_ERROR/REQUEST_ERROR. -1 if
95      * none has completed.
96      */
97     int64_t lastCompletedReprocessFrameNumber;
98 
99     /**
100      * The latest Zsl request frameNumber for which all buffers and capture result have been
101      * returned or notified as an BUFFER_ERROR/RESULT_ERROR/REQUEST_ERROR. -1 if
102      * none has completed.
103      */
104     int64_t lastCompletedZslFrameNumber;
105 
106     /**
107      * Whether the readoutTimestamp variable is valid and should be used.
108      */
109     bool hasReadoutTimestamp;
110 
111     /**
112      * The readout timestamp of the capture. Its value is equal to the
113      * start-of-exposure timestamp plus the exposure time (and a possible fixed
114      * offset due to sensor crop).
115      */
116     int64_t readoutTimestamp;
117 
118     /**
119      * Constructor initializes object as invalid by setting requestId to be -1.
120      */
CaptureResultExtrasCaptureResultExtras121     CaptureResultExtras()
122         : requestId(-1),
123           burstId(0),
124           afTriggerId(0),
125           precaptureTriggerId(0),
126           frameNumber(0),
127           partialResultCount(0),
128           errorStreamId(-1),
129           errorPhysicalCameraId(),
130           lastCompletedRegularFrameNumber(-1),
131           lastCompletedReprocessFrameNumber(-1),
132           lastCompletedZslFrameNumber(-1),
133           hasReadoutTimestamp(false),
134           readoutTimestamp(0) {
135     }
136 
137     /**
138      * This function returns true if it's a valid CaptureResultExtras object.
139      * Otherwise, returns false. It is valid only when requestId is non-negative.
140      */
141     bool isValid();
142 
143     virtual status_t                readFromParcel(const android::Parcel* parcel) override;
144     virtual status_t                writeToParcel(android::Parcel* parcel) const override;
145 };
146 
147 struct PhysicalCaptureResultInfo : public android::Parcelable {
148 
PhysicalCaptureResultInfoPhysicalCaptureResultInfo149     PhysicalCaptureResultInfo()
150         : mPhysicalCameraId(),
151           mPhysicalCameraMetadata() {
152     }
PhysicalCaptureResultInfoPhysicalCaptureResultInfo153     PhysicalCaptureResultInfo(const std::string& cameraId,
154             const CameraMetadata& cameraMetadata)
155             : mPhysicalCameraId(cameraId),
156               mPhysicalCameraMetadata(cameraMetadata) {
157     }
158 
159     std::string mPhysicalCameraId;
160     CameraMetadata mPhysicalCameraMetadata;
161 
162     virtual status_t                readFromParcel(const android::Parcel* parcel) override;
163     virtual status_t                writeToParcel(android::Parcel* parcel) const override;
164 };
165 
166 } // namespace impl
167 } // namespace camera2
168 } // namespace hardware
169 
170 using hardware::camera2::impl::CaptureResultExtras;
171 using hardware::camera2::impl::PhysicalCaptureResultInfo;
172 
173 struct CaptureResult : public virtual LightRefBase<CaptureResult> {
174     CameraMetadata          mMetadata;
175     std::vector<PhysicalCaptureResultInfo> mPhysicalMetadatas;
176     CaptureResultExtras     mResultExtras;
177 
178     CaptureResult();
179 
180     CaptureResult(const CaptureResult& otherResult);
181 
182     CaptureResult(CaptureResult &&captureResult);
183 
184     status_t                readFromParcel(android::Parcel* parcel);
185     status_t                writeToParcel(android::Parcel* parcel) const;
186 };
187 
188 }
189 
190 #endif /* ANDROID_HARDWARE_CAPTURERESULT_H */
191