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     String16  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     /**
108      * Constructor initializes object as invalid by setting requestId to be -1.
109      */
CaptureResultExtrasCaptureResultExtras110     CaptureResultExtras()
111         : requestId(-1),
112           burstId(0),
113           afTriggerId(0),
114           precaptureTriggerId(0),
115           frameNumber(0),
116           partialResultCount(0),
117           errorStreamId(-1),
118           errorPhysicalCameraId(),
119           lastCompletedRegularFrameNumber(-1),
120           lastCompletedReprocessFrameNumber(-1),
121           lastCompletedZslFrameNumber(-1) {
122     }
123 
124     /**
125      * This function returns true if it's a valid CaptureResultExtras object.
126      * Otherwise, returns false. It is valid only when requestId is non-negative.
127      */
128     bool isValid();
129 
130     virtual status_t                readFromParcel(const android::Parcel* parcel) override;
131     virtual status_t                writeToParcel(android::Parcel* parcel) const override;
132 };
133 
134 struct PhysicalCaptureResultInfo : public android::Parcelable {
135 
PhysicalCaptureResultInfoPhysicalCaptureResultInfo136     PhysicalCaptureResultInfo()
137         : mPhysicalCameraId(),
138           mPhysicalCameraMetadata() {
139     }
PhysicalCaptureResultInfoPhysicalCaptureResultInfo140     PhysicalCaptureResultInfo(const String16& cameraId,
141             const CameraMetadata& cameraMetadata)
142             : mPhysicalCameraId(cameraId),
143               mPhysicalCameraMetadata(cameraMetadata) {
144     }
145 
146     String16  mPhysicalCameraId;
147     CameraMetadata mPhysicalCameraMetadata;
148 
149     virtual status_t                readFromParcel(const android::Parcel* parcel) override;
150     virtual status_t                writeToParcel(android::Parcel* parcel) const override;
151 };
152 
153 } // namespace impl
154 } // namespace camera2
155 } // namespace hardware
156 
157 using hardware::camera2::impl::CaptureResultExtras;
158 using hardware::camera2::impl::PhysicalCaptureResultInfo;
159 
160 struct CaptureResult : public virtual LightRefBase<CaptureResult> {
161     CameraMetadata          mMetadata;
162     std::vector<PhysicalCaptureResultInfo> mPhysicalMetadatas;
163     CaptureResultExtras     mResultExtras;
164 
165     CaptureResult();
166 
167     CaptureResult(const CaptureResult& otherResult);
168 
169     CaptureResult(CaptureResult &&captureResult);
170 
171     status_t                readFromParcel(android::Parcel* parcel);
172     status_t                writeToParcel(android::Parcel* parcel) const;
173 };
174 
175 }
176 
177 #endif /* ANDROID_HARDWARE_CAPTURERESULT_H */
178