blob: 1843ec4869bf25cbb39d731c9d3b44d3c1866b0b [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
97 size_t len;
98 const char16_t* className = parcel->readString16Inplace(&len);
99 ALOGV("%s: Read surface class = %s", __FUNCTION__,
100 className != NULL ? String8(className).string() : "<null>");
101
102 if (className == NULL) {
103 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
Igor Murashkine7ee7632013-06-11 18:10:18 -0700149 return OK;
150}
151
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800152status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700153 if (parcel == NULL) {
154 ALOGE("%s: Null parcel", __FUNCTION__);
155 return BAD_VALUE;
156 }
157
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700158 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700159
Emilian Peevaebbe412018-01-15 13:53:24 +0000160 int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size());
161
162 if ((err = parcel->writeInt32(settingsCount)) != OK) {
163 ALOGE("%s: Failed to write settings count!", __FUNCTION__);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700164 return err;
165 }
166
Emilian Peevaebbe412018-01-15 13:53:24 +0000167 for (const auto &it : mPhysicalCameraSettings) {
168 if ((err = parcel->writeString16(String16(it.id.c_str()))) != OK) {
169 ALOGE("%s: Failed to camera id!", __FUNCTION__);
170 return err;
171 }
172
173 if ((err = it.settings.writeToParcel(parcel)) != OK) {
174 ALOGE("%s: Failed to write settings!", __FUNCTION__);
175 return err;
176 }
177 }
178
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800179 parcel->writeInt32(mIsReprocess ? 1 : 0);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700180
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800181 if (mSurfaceConverted) {
182 parcel->writeInt32(0); // 0-sized array
183 } else {
184 int32_t size = static_cast<int32_t>(mSurfaceList.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700185
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800186 // Send 0-sized arrays when it's empty. Do not send null arrays.
187 parcel->writeInt32(size);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700188
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800189 for (int32_t i = 0; i < size; ++i) {
190 // not sure if readParcelableArray does this, hard to tell from source
191 parcel->writeString16(String16("android.view.Surface"));
192
193 // Surface.writeToParcel
194 view::Surface surfaceShim;
195 surfaceShim.name = String16("unknown_name");
196 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
197 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
198 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
199 __FUNCTION__, i, strerror(-err), err);
200 return err;
201 }
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700202 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700203 }
204
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800205 parcel->writeInt32(mStreamIdxList.size());
206 for (size_t i = 0; i < mStreamIdxList.size(); ++i) {
207 if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) {
208 ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__);
209 return err;
210 }
211 if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) {
212 ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__);
213 return err;
214 }
215 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700216 return OK;
217}
218
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800219} // namespace camera2
220} // namespace hardware
221} // namespace android