blob: d2fcde6a34c315414b9ea466a5e011e60a336d9e [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>
Austin Borger1c1bee02023-06-01 16:51:35 -070024#include <camera/StringUtils.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070025
26#include <binder/Parcel.h>
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -070027#include <gui/Flags.h> // remove with WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
Igor Murashkine7ee7632013-06-11 18:10:18 -070028#include <gui/Surface.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080029#include <gui/view/Surface.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070030
31namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080032namespace hardware {
33namespace camera2 {
Igor Murashkine7ee7632013-06-11 18:10:18 -070034
Mathias Agopian032845c2017-02-08 17:05:02 -080035// These must be in the .cpp (to avoid inlining)
36CaptureRequest::CaptureRequest() = default;
37CaptureRequest::~CaptureRequest() = default;
38CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default;
39CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default;
40
41
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080042status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070043 if (parcel == NULL) {
44 ALOGE("%s: Null parcel", __FUNCTION__);
45 return BAD_VALUE;
46 }
47
Igor Murashkine7ee7632013-06-11 18:10:18 -070048 mSurfaceList.clear();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080049 mStreamIdxList.clear();
50 mSurfaceIdxList.clear();
Emilian Peevaebbe412018-01-15 13:53:24 +000051 mPhysicalCameraSettings.clear();
Igor Murashkine7ee7632013-06-11 18:10:18 -070052
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070053 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -070054
Emilian Peevaebbe412018-01-15 13:53:24 +000055 int32_t settingsCount;
56 if ((err = parcel->readInt32(&settingsCount)) != OK) {
57 ALOGE("%s: Failed to read the settings count from parcel: %d", __FUNCTION__, err);
Igor Murashkine7ee7632013-06-11 18:10:18 -070058 return err;
59 }
Emilian Peevaebbe412018-01-15 13:53:24 +000060
61 if (settingsCount <= 0) {
62 ALOGE("%s: Settings count %d should always be positive!", __FUNCTION__, settingsCount);
63 return BAD_VALUE;
64 }
65
66 for (int32_t i = 0; i < settingsCount; i++) {
67 String16 id;
68 if ((err = parcel->readString16(&id)) != OK) {
69 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
70 return BAD_VALUE;
71 }
72
73 CameraMetadata settings;
74 if ((err = settings.readFromParcel(parcel)) != OK) {
75 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
76 return err;
77 }
78 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
Austin Borger1c1bee02023-06-01 16:51:35 -070079 mPhysicalCameraSettings.push_back({toStdString(id), settings});
Emilian Peevaebbe412018-01-15 13:53:24 +000080 }
Igor Murashkine7ee7632013-06-11 18:10:18 -070081
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080082 int isReprocess = 0;
83 if ((err = parcel->readInt32(&isReprocess)) != OK) {
84 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
85 return err;
86 }
87 mIsReprocess = (isReprocess != 0);
88
Igor Murashkine7ee7632013-06-11 18:10:18 -070089 int32_t size;
90 if ((err = parcel->readInt32(&size)) != OK) {
91 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
92 return err;
93 }
94 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
95
96 // Do not distinguish null arrays from 0-sized arrays.
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080097 for (int32_t i = 0; i < size; ++i) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070098 // Parcel.writeParcelableArray
Steven Moreland6faf8ed2020-11-04 23:55:40 +000099 std::optional<std::string> className;
100 parcel->readUtf8FromUtf16(&className);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700101 ALOGV("%s: Read surface class = %s", __FUNCTION__,
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000102 className.value_or("<null>").c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700103
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000104 if (className == std::nullopt) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700105 continue;
106 }
107
108 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700109 view::Surface surfaceShim;
110 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
111 ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)",
112 __FUNCTION__, i, strerror(-err), err);
113 return err;
114 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700115
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700116#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
117 sp<Surface> surface = surfaceShim.toSurface();
118#else
Igor Murashkine7ee7632013-06-11 18:10:18 -0700119 sp<Surface> surface;
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700120 if (surfaceShim.graphicBufferProducer != NULL) {
121 surface = new Surface(surfaceShim.graphicBufferProducer);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700122 }
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700123#endif
Igor Murashkine7ee7632013-06-11 18:10:18 -0700124 mSurfaceList.push_back(surface);
125 }
126
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800127 int32_t streamSurfaceSize;
128 if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) {
129 ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700130 return err;
131 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800132
133 if (streamSurfaceSize < 0) {
134 ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize);
135 return BAD_VALUE;
136 }
137
138 for (int32_t i = 0; i < streamSurfaceSize; ++i) {
139 int streamIdx;
140 if ((err = parcel->readInt32(&streamIdx)) != OK) {
141 ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__);
142 return err;
143 }
144 mStreamIdxList.push_back(streamIdx);
145
146 int surfaceIdx;
147 if ((err = parcel->readInt32(&surfaceIdx)) != OK) {
148 ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__);
149 return err;
150 }
151 mSurfaceIdxList.push_back(surfaceIdx);
152 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700153
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800154 int32_t hasUserTag;
155 if ((err = parcel->readInt32(&hasUserTag)) != OK) {
156 ALOGE("%s: Failed to read user tag availability flag", __FUNCTION__);
157 return BAD_VALUE;
158 }
159 if (hasUserTag) {
160 String16 userTag;
161 if ((err = parcel->readString16(&userTag)) != OK) {
162 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
163 return BAD_VALUE;
164 }
Austin Borger1c1bee02023-06-01 16:51:35 -0700165 mUserTag = toStdString(userTag);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800166 }
167
Igor Murashkine7ee7632013-06-11 18:10:18 -0700168 return OK;
169}
170
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800171status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700172 if (parcel == NULL) {
173 ALOGE("%s: Null parcel", __FUNCTION__);
174 return BAD_VALUE;
175 }
176
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700177 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700178
Emilian Peevaebbe412018-01-15 13:53:24 +0000179 int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size());
180
181 if ((err = parcel->writeInt32(settingsCount)) != OK) {
182 ALOGE("%s: Failed to write settings count!", __FUNCTION__);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700183 return err;
184 }
185
Emilian Peevaebbe412018-01-15 13:53:24 +0000186 for (const auto &it : mPhysicalCameraSettings) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700187 if ((err = parcel->writeString16(toString16(it.id))) != OK) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000188 ALOGE("%s: Failed to camera id!", __FUNCTION__);
189 return err;
190 }
191
192 if ((err = it.settings.writeToParcel(parcel)) != OK) {
193 ALOGE("%s: Failed to write settings!", __FUNCTION__);
194 return err;
195 }
196 }
197
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800198 parcel->writeInt32(mIsReprocess ? 1 : 0);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700199
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800200 if (mSurfaceConverted) {
201 parcel->writeInt32(0); // 0-sized array
202 } else {
203 int32_t size = static_cast<int32_t>(mSurfaceList.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700204
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800205 // Send 0-sized arrays when it's empty. Do not send null arrays.
206 parcel->writeInt32(size);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700207
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800208 for (int32_t i = 0; i < size; ++i) {
209 // not sure if readParcelableArray does this, hard to tell from source
210 parcel->writeString16(String16("android.view.Surface"));
211
212 // Surface.writeToParcel
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700213#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
214 view::Surface surfaceShim = view::Surface::fromSurface(mSurfaceList[i]);
215#else
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800216 view::Surface surfaceShim;
217 surfaceShim.name = String16("unknown_name");
218 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700219#endif
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
221 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
222 __FUNCTION__, i, strerror(-err), err);
223 return err;
224 }
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700225 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700226 }
227
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800228 parcel->writeInt32(mStreamIdxList.size());
229 for (size_t i = 0; i < mStreamIdxList.size(); ++i) {
230 if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) {
231 ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__);
232 return err;
233 }
234 if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) {
235 ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__);
236 return err;
237 }
238 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800239
240 if (mUserTag.empty()) {
241 parcel->writeInt32(0);
242 } else {
243 parcel->writeInt32(1);
Austin Borger1c1bee02023-06-01 16:51:35 -0700244 parcel->writeString16(toString16(mUserTag));
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800245 }
246
Igor Murashkine7ee7632013-06-11 18:10:18 -0700247 return OK;
248}
249
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800250} // namespace camera2
251} // namespace hardware
252} // namespace android