blob: 071f34ea3781b8f1b0e601a24c5a7b0925798cae [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>
27#include <gui/Surface.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080028#include <gui/view/Surface.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070029
30namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080031namespace hardware {
32namespace camera2 {
Igor Murashkine7ee7632013-06-11 18:10:18 -070033
Mathias Agopian032845c2017-02-08 17:05:02 -080034// These must be in the .cpp (to avoid inlining)
35CaptureRequest::CaptureRequest() = default;
36CaptureRequest::~CaptureRequest() = default;
37CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default;
38CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default;
39
40
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080041status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070042 if (parcel == NULL) {
43 ALOGE("%s: Null parcel", __FUNCTION__);
44 return BAD_VALUE;
45 }
46
Igor Murashkine7ee7632013-06-11 18:10:18 -070047 mSurfaceList.clear();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080048 mStreamIdxList.clear();
49 mSurfaceIdxList.clear();
Emilian Peevaebbe412018-01-15 13:53:24 +000050 mPhysicalCameraSettings.clear();
Igor Murashkine7ee7632013-06-11 18:10:18 -070051
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070052 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -070053
Emilian Peevaebbe412018-01-15 13:53:24 +000054 int32_t settingsCount;
55 if ((err = parcel->readInt32(&settingsCount)) != OK) {
56 ALOGE("%s: Failed to read the settings count from parcel: %d", __FUNCTION__, err);
Igor Murashkine7ee7632013-06-11 18:10:18 -070057 return err;
58 }
Emilian Peevaebbe412018-01-15 13:53:24 +000059
60 if (settingsCount <= 0) {
61 ALOGE("%s: Settings count %d should always be positive!", __FUNCTION__, settingsCount);
62 return BAD_VALUE;
63 }
64
65 for (int32_t i = 0; i < settingsCount; i++) {
66 String16 id;
67 if ((err = parcel->readString16(&id)) != OK) {
68 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
69 return BAD_VALUE;
70 }
71
72 CameraMetadata settings;
73 if ((err = settings.readFromParcel(parcel)) != OK) {
74 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
75 return err;
76 }
77 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
Austin Borger1c1bee02023-06-01 16:51:35 -070078 mPhysicalCameraSettings.push_back({toStdString(id), settings});
Emilian Peevaebbe412018-01-15 13:53:24 +000079 }
Igor Murashkine7ee7632013-06-11 18:10:18 -070080
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080081 int isReprocess = 0;
82 if ((err = parcel->readInt32(&isReprocess)) != OK) {
83 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
84 return err;
85 }
86 mIsReprocess = (isReprocess != 0);
87
Igor Murashkine7ee7632013-06-11 18:10:18 -070088 int32_t size;
89 if ((err = parcel->readInt32(&size)) != OK) {
90 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
91 return err;
92 }
93 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
94
95 // Do not distinguish null arrays from 0-sized arrays.
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080096 for (int32_t i = 0; i < size; ++i) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070097 // Parcel.writeParcelableArray
Steven Moreland6faf8ed2020-11-04 23:55:40 +000098 std::optional<std::string> className;
99 parcel->readUtf8FromUtf16(&className);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700100 ALOGV("%s: Read surface class = %s", __FUNCTION__,
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000101 className.value_or("<null>").c_str());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700102
Steven Moreland6faf8ed2020-11-04 23:55:40 +0000103 if (className == std::nullopt) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700104 continue;
105 }
106
107 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700108 view::Surface surfaceShim;
109 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
110 ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)",
111 __FUNCTION__, i, strerror(-err), err);
112 return err;
113 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700114
115 sp<Surface> surface;
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700116 if (surfaceShim.graphicBufferProducer != NULL) {
117 surface = new Surface(surfaceShim.graphicBufferProducer);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700118 }
119
120 mSurfaceList.push_back(surface);
121 }
122
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800123 int32_t streamSurfaceSize;
124 if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) {
125 ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700126 return err;
127 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800128
129 if (streamSurfaceSize < 0) {
130 ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize);
131 return BAD_VALUE;
132 }
133
134 for (int32_t i = 0; i < streamSurfaceSize; ++i) {
135 int streamIdx;
136 if ((err = parcel->readInt32(&streamIdx)) != OK) {
137 ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__);
138 return err;
139 }
140 mStreamIdxList.push_back(streamIdx);
141
142 int surfaceIdx;
143 if ((err = parcel->readInt32(&surfaceIdx)) != OK) {
144 ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__);
145 return err;
146 }
147 mSurfaceIdxList.push_back(surfaceIdx);
148 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700149
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800150 int32_t hasUserTag;
151 if ((err = parcel->readInt32(&hasUserTag)) != OK) {
152 ALOGE("%s: Failed to read user tag availability flag", __FUNCTION__);
153 return BAD_VALUE;
154 }
155 if (hasUserTag) {
156 String16 userTag;
157 if ((err = parcel->readString16(&userTag)) != OK) {
158 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
159 return BAD_VALUE;
160 }
Austin Borger1c1bee02023-06-01 16:51:35 -0700161 mUserTag = toStdString(userTag);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800162 }
163
Igor Murashkine7ee7632013-06-11 18:10:18 -0700164 return OK;
165}
166
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800167status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700168 if (parcel == NULL) {
169 ALOGE("%s: Null parcel", __FUNCTION__);
170 return BAD_VALUE;
171 }
172
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700173 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700174
Emilian Peevaebbe412018-01-15 13:53:24 +0000175 int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size());
176
177 if ((err = parcel->writeInt32(settingsCount)) != OK) {
178 ALOGE("%s: Failed to write settings count!", __FUNCTION__);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700179 return err;
180 }
181
Emilian Peevaebbe412018-01-15 13:53:24 +0000182 for (const auto &it : mPhysicalCameraSettings) {
Austin Borger1c1bee02023-06-01 16:51:35 -0700183 if ((err = parcel->writeString16(toString16(it.id))) != OK) {
Emilian Peevaebbe412018-01-15 13:53:24 +0000184 ALOGE("%s: Failed to camera id!", __FUNCTION__);
185 return err;
186 }
187
188 if ((err = it.settings.writeToParcel(parcel)) != OK) {
189 ALOGE("%s: Failed to write settings!", __FUNCTION__);
190 return err;
191 }
192 }
193
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800194 parcel->writeInt32(mIsReprocess ? 1 : 0);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700195
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800196 if (mSurfaceConverted) {
197 parcel->writeInt32(0); // 0-sized array
198 } else {
199 int32_t size = static_cast<int32_t>(mSurfaceList.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700200
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800201 // Send 0-sized arrays when it's empty. Do not send null arrays.
202 parcel->writeInt32(size);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700203
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800204 for (int32_t i = 0; i < size; ++i) {
205 // not sure if readParcelableArray does this, hard to tell from source
206 parcel->writeString16(String16("android.view.Surface"));
207
208 // Surface.writeToParcel
209 view::Surface surfaceShim;
210 surfaceShim.name = String16("unknown_name");
211 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
212 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
213 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
214 __FUNCTION__, i, strerror(-err), err);
215 return err;
216 }
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700217 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700218 }
219
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800220 parcel->writeInt32(mStreamIdxList.size());
221 for (size_t i = 0; i < mStreamIdxList.size(); ++i) {
222 if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) {
223 ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__);
224 return err;
225 }
226 if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) {
227 ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__);
228 return err;
229 }
230 }
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800231
232 if (mUserTag.empty()) {
233 parcel->writeInt32(0);
234 } else {
235 parcel->writeInt32(1);
Austin Borger1c1bee02023-06-01 16:51:35 -0700236 parcel->writeString16(toString16(mUserTag));
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800237 }
238
Igor Murashkine7ee7632013-06-11 18:10:18 -0700239 return OK;
240}
241
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800242} // namespace camera2
243} // namespace hardware
244} // namespace android