blob: 983d29b20b85ad135bba1fb9857304579aff2cb1 [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>
21
Eino-Ville Talvala7b82efe2013-07-25 17:12:35 -070022#include <camera/camera2/CaptureRequest.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070023
24#include <binder/Parcel.h>
25#include <gui/Surface.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080026#include <gui/view/Surface.h>
Igor Murashkine7ee7632013-06-11 18:10:18 -070027
28namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080029namespace hardware {
30namespace camera2 {
Igor Murashkine7ee7632013-06-11 18:10:18 -070031
Mathias Agopian032845c2017-02-08 17:05:02 -080032// These must be in the .cpp (to avoid inlining)
33CaptureRequest::CaptureRequest() = default;
34CaptureRequest::~CaptureRequest() = default;
35CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default;
36CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default;
37
38
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080039status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070040 if (parcel == NULL) {
41 ALOGE("%s: Null parcel", __FUNCTION__);
42 return BAD_VALUE;
43 }
44
45 mMetadata.clear();
46 mSurfaceList.clear();
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080047 mStreamIdxList.clear();
48 mSurfaceIdxList.clear();
Igor Murashkine7ee7632013-06-11 18:10:18 -070049
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070050 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -070051
52 if ((err = mMetadata.readFromParcel(parcel)) != OK) {
53 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
54 return err;
55 }
56 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
57
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080058 int isReprocess = 0;
59 if ((err = parcel->readInt32(&isReprocess)) != OK) {
60 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
61 return err;
62 }
63 mIsReprocess = (isReprocess != 0);
64
Igor Murashkine7ee7632013-06-11 18:10:18 -070065 int32_t size;
66 if ((err = parcel->readInt32(&size)) != OK) {
67 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
68 return err;
69 }
70 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
71
72 // Do not distinguish null arrays from 0-sized arrays.
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -080073 for (int32_t i = 0; i < size; ++i) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070074 // Parcel.writeParcelableArray
75 size_t len;
76 const char16_t* className = parcel->readString16Inplace(&len);
77 ALOGV("%s: Read surface class = %s", __FUNCTION__,
78 className != NULL ? String8(className).string() : "<null>");
79
80 if (className == NULL) {
81 continue;
82 }
83
84 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070085 view::Surface surfaceShim;
86 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
87 ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)",
88 __FUNCTION__, i, strerror(-err), err);
89 return err;
90 }
Igor Murashkine7ee7632013-06-11 18:10:18 -070091
92 sp<Surface> surface;
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070093 if (surfaceShim.graphicBufferProducer != NULL) {
94 surface = new Surface(surfaceShim.graphicBufferProducer);
Igor Murashkine7ee7632013-06-11 18:10:18 -070095 }
96
97 mSurfaceList.push_back(surface);
98 }
99
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800100 int32_t streamSurfaceSize;
101 if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) {
102 ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__);
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700103 return err;
104 }
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800105
106 if (streamSurfaceSize < 0) {
107 ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize);
108 return BAD_VALUE;
109 }
110
111 for (int32_t i = 0; i < streamSurfaceSize; ++i) {
112 int streamIdx;
113 if ((err = parcel->readInt32(&streamIdx)) != OK) {
114 ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__);
115 return err;
116 }
117 mStreamIdxList.push_back(streamIdx);
118
119 int surfaceIdx;
120 if ((err = parcel->readInt32(&surfaceIdx)) != OK) {
121 ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__);
122 return err;
123 }
124 mSurfaceIdxList.push_back(surfaceIdx);
125 }
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700126
Igor Murashkine7ee7632013-06-11 18:10:18 -0700127 return OK;
128}
129
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800130status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700131 if (parcel == NULL) {
132 ALOGE("%s: Null parcel", __FUNCTION__);
133 return BAD_VALUE;
134 }
135
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700136 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700137
138 if ((err = mMetadata.writeToParcel(parcel)) != OK) {
139 return err;
140 }
141
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800142 parcel->writeInt32(mIsReprocess ? 1 : 0);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700143
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800144 if (mSurfaceConverted) {
145 parcel->writeInt32(0); // 0-sized array
146 } else {
147 int32_t size = static_cast<int32_t>(mSurfaceList.size());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700148
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800149 // Send 0-sized arrays when it's empty. Do not send null arrays.
150 parcel->writeInt32(size);
Igor Murashkine7ee7632013-06-11 18:10:18 -0700151
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800152 for (int32_t i = 0; i < size; ++i) {
153 // not sure if readParcelableArray does this, hard to tell from source
154 parcel->writeString16(String16("android.view.Surface"));
155
156 // Surface.writeToParcel
157 view::Surface surfaceShim;
158 surfaceShim.name = String16("unknown_name");
159 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
160 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
161 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
162 __FUNCTION__, i, strerror(-err), err);
163 return err;
164 }
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700165 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700166 }
167
Yin-Chia Yeh4dfa4cc2017-11-10 20:00:09 -0800168 parcel->writeInt32(mStreamIdxList.size());
169 for (size_t i = 0; i < mStreamIdxList.size(); ++i) {
170 if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) {
171 ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__);
172 return err;
173 }
174 if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) {
175 ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__);
176 return err;
177 }
178 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700179 return OK;
180}
181
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800182} // namespace camera2
183} // namespace hardware
184} // namespace android