blob: 7a8a4bae411287d19bca7880bb3b94fe21b59f89 [file] [log] [blame]
Igor Murashkine7ee7632013-06-11 18:10:18 -07001/*
2**
3** Copyright 2013, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18// #define LOG_NDEBUG 0
19#define LOG_TAG "CameraRequest"
20#include <utils/Log.h>
Emilian Peevaebbe412018-01-15 13:53:24 +000021#include <utils/String16.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070022
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070023#include <camera/camera2/CaptureRequest.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070024
25#include <binder/Parcel.h>
26#include <gui/Surface.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080027#include <gui/view/Surface.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070028
29namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080030namespace hardware {
31namespace camera2 {
Igor Murashkine7ee7632013-06-11 18:10:18 -070032
Mathias Agopian032845c2017-02-08 17:05:02 -080033// These must be in the .cpp (to avoid inlining)
34CaptureRequest::CaptureRequest() = default;
35CaptureRequest::~CaptureRequest() = default;
36CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default;
37CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default;
38
39
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080040status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070041 if (parcel == NULL) {
42 ALOGE("%s: Null parcel", __FUNCTION__);
43 return BAD_VALUE;
44 }
45
Igor Murashkine7ee7632013-06-11 18:10:18 -070046 mSurfaceList.clear();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080047 mStreamIdxList.clear();
48 mSurfaceIdxList.clear();
Emilian Peevaebbe412018-01-15 13:53:24 +000049 mPhysicalCameraSettings.clear();
Igor Murashkine7ee7632013-06-11 18:10:18 -070050
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070051 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -070052
Emilian Peevaebbe412018-01-15 13:53:24 +000053 int32_t settingsCount;
54 if ((err = parcel->readInt32(&settingsCount)) != OK) {
55 ALOGE("%s: Failed to read the settings count from parcel: %d", __FUNCTION__, err);
Igor Murashkine7ee7632013-06-11 18:10:18 -070056 return err;
57 }
Emilian Peevaebbe412018-01-15 13:53:24 +000058
59 if (settingsCount <= 0) {
60 ALOGE("%s: Settings count %d should always be positive!", __FUNCTION__, settingsCount);
61 return BAD_VALUE;
62 }
63
64 for (int32_t i = 0; i < settingsCount; i++) {
65 String16 id;
66 if ((err = parcel->readString16(&id)) != OK) {
67 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
68 return BAD_VALUE;
69 }
70
71 CameraMetadata settings;
72 if ((err = settings.readFromParcel(parcel)) != OK) {
73 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
74 return err;
75 }
76 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
77 mPhysicalCameraSettings.push_back({std::string(String8(id).string()), settings});
78 }
Igor Murashkine7ee7632013-06-11 18:10:18 -070079
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080080 int isReprocess = 0;
81 if ((err = parcel->readInt32(&isReprocess)) != OK) {
82 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
83 return err;
84 }
85 mIsReprocess = (isReprocess != 0);
86
Igor Murashkine7ee7632013-06-11 18:10:18 -070087 int32_t size;
88 if ((err = parcel->readInt32(&size)) != OK) {
89 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
90 return err;
91 }
92 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
93
94 // Do not distinguish null arrays from 0-sized arrays.
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080095 for (int32_t i = 0; i < size; ++i) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070096 // Parcel.writeParcelableArray
Steven Moreland6faf8ed2020-11-04 23:55:40 +000097 std::optional<std::string> className;
98 parcel->readUtf8FromUtf16(&className);
Igor Murashkine7ee7632013-06-11 18:10:18 -070099 ALOGV("%s: Read surface class = %s", __FUNCTION__,
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000100 className.value_or("<null>").c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700101
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000102 if (className == std::nullopt) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700103 continue;
104 }
105
106 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700107 view::Surface surfaceShim;
108 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
109 ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)",
110 __FUNCTION__, i, strerror(-err), err);
111 return err;
112 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700113
114 sp<Surface> surface;
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700115 if (surfaceShim.graphicBufferProducer != NULL) {
116 surface = new Surface(surfaceShim.graphicBufferProducer);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700117 }
118
119 mSurfaceList.push_back(surface);
120 }
121
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800122 int32_t streamSurfaceSize;
123 if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) {
124 ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700125 return err;
126 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800127
128 if (streamSurfaceSize < 0) {
129 ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize);
130 return BAD_VALUE;
131 }
132
133 for (int32_t i = 0; i < streamSurfaceSize; ++i) {
134 int streamIdx;
135 if ((err = parcel->readInt32(&streamIdx)) != OK) {
136 ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__);
137 return err;
138 }
139 mStreamIdxList.push_back(streamIdx);
140
141 int surfaceIdx;
142 if ((err = parcel->readInt32(&surfaceIdx)) != OK) {
143 ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__);
144 return err;
145 }
146 mSurfaceIdxList.push_back(surfaceIdx);
147 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700148
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800149 int32_t hasUserTag;
150 if ((err = parcel->readInt32(&hasUserTag)) != OK) {
151 ALOGE("%s: Failed to read user tag availability flag", __FUNCTION__);
152 return BAD_VALUE;
153 }
154 if (hasUserTag) {
155 String16 userTag;
156 if ((err = parcel->readString16(&userTag)) != OK) {
157 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
158 return BAD_VALUE;
159 }
160 mUserTag = String8(userTag).c_str();
161 }
162
Igor Murashkine7ee7632013-06-11 18:10:18 -0700163 return OK;
164}
165
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800166status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700167 if (parcel == NULL) {
168 ALOGE("%s: Null parcel", __FUNCTION__);
169 return BAD_VALUE;
170 }
171
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700172 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700173
Emilian Peevaebbe412018-01-15 13:53:24 +0000174 int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size());
175
176 if ((err = parcel->writeInt32(settingsCount)) != OK) {
177 ALOGE("%s: Failed to write settings count!", __FUNCTION__);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700178 return err;
179 }
180
Emilian Peevaebbe412018-01-15 13:53:24 +0000181 for (const auto &it : mPhysicalCameraSettings) {
182 if ((err = parcel->writeString16(String16(it.id.c_str()))) != OK) {
183 ALOGE("%s: Failed to camera id!", __FUNCTION__);
184 return err;
185 }
186
187 if ((err = it.settings.writeToParcel(parcel)) != OK) {
188 ALOGE("%s: Failed to write settings!", __FUNCTION__);
189 return err;
190 }
191 }
192
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800193 parcel->writeInt32(mIsReprocess ? 1 : 0);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700194
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800195 if (mSurfaceConverted) {
196 parcel->writeInt32(0); // 0-sized array
197 } else {
198 int32_t size = static_cast<int32_t>(mSurfaceList.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700199
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800200 // Send 0-sized arrays when it's empty. Do not send null arrays.
201 parcel->writeInt32(size);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700202
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800203 for (int32_t i = 0; i < size; ++i) {
204 // not sure if readParcelableArray does this, hard to tell from source
205 parcel->writeString16(String16("android.view.Surface"));
206
207 // Surface.writeToParcel
208 view::Surface surfaceShim;
209 surfaceShim.name = String16("unknown_name");
210 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
211 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
212 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
213 __FUNCTION__, i, strerror(-err), err);
214 return err;
215 }
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700216 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700217 }
218
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800219 parcel->writeInt32(mStreamIdxList.size());
220 for (size_t i = 0; i < mStreamIdxList.size(); ++i) {
221 if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) {
222 ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__);
223 return err;
224 }
225 if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) {
226 ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__);
227 return err;
228 }
229 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800230
231 if (mUserTag.empty()) {
232 parcel->writeInt32(0);
233 } else {
234 parcel->writeInt32(1);
235 parcel->writeString16(String16(mUserTag.c_str()));
236 }
237
Igor Murashkine7ee7632013-06-11 18:10:18 -0700238 return OK;
239}
240
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800241} // namespace camera2
242} // namespace hardware
243} // namespace android