blob: 059795033205d51b4731ec4ef0b6c97774cdebcf [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();
47
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070048 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -070049
50 if ((err = mMetadata.readFromParcel(parcel)) != OK) {
51 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
52 return err;
53 }
54 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
55
56 int32_t size;
57 if ((err = parcel->readInt32(&size)) != OK) {
58 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
59 return err;
60 }
61 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
62
63 // Do not distinguish null arrays from 0-sized arrays.
64 for (int i = 0; i < size; ++i) {
65 // Parcel.writeParcelableArray
66 size_t len;
67 const char16_t* className = parcel->readString16Inplace(&len);
68 ALOGV("%s: Read surface class = %s", __FUNCTION__,
69 className != NULL ? String8(className).string() : "<null>");
70
71 if (className == NULL) {
72 continue;
73 }
74
75 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070076 view::Surface surfaceShim;
77 if ((err = surfaceShim.readFromParcel(parcel)) != OK) {
78 ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)",
79 __FUNCTION__, i, strerror(-err), err);
80 return err;
81 }
Igor Murashkine7ee7632013-06-11 18:10:18 -070082
83 sp<Surface> surface;
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -070084 if (surfaceShim.graphicBufferProducer != NULL) {
85 surface = new Surface(surfaceShim.graphicBufferProducer);
Igor Murashkine7ee7632013-06-11 18:10:18 -070086 }
87
88 mSurfaceList.push_back(surface);
89 }
90
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070091 int isReprocess = 0;
92 if ((err = parcel->readInt32(&isReprocess)) != OK) {
93 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
94 return err;
95 }
96 mIsReprocess = (isReprocess != 0);
97
Igor Murashkine7ee7632013-06-11 18:10:18 -070098 return OK;
99}
100
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800101status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700102 if (parcel == NULL) {
103 ALOGE("%s: Null parcel", __FUNCTION__);
104 return BAD_VALUE;
105 }
106
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700107 status_t err = OK;
Igor Murashkine7ee7632013-06-11 18:10:18 -0700108
109 if ((err = mMetadata.writeToParcel(parcel)) != OK) {
110 return err;
111 }
112
113 int32_t size = static_cast<int32_t>(mSurfaceList.size());
114
115 // Send 0-sized arrays when it's empty. Do not send null arrays.
116 parcel->writeInt32(size);
117
118 for (int32_t i = 0; i < size; ++i) {
Igor Murashkine7ee7632013-06-11 18:10:18 -0700119 // not sure if readParcelableArray does this, hard to tell from source
120 parcel->writeString16(String16("android.view.Surface"));
121
122 // Surface.writeToParcel
Eino-Ville Talvala48932bb2016-08-30 13:45:53 -0700123 view::Surface surfaceShim;
124 surfaceShim.name = String16("unknown_name");
125 surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer();
126 if ((err = surfaceShim.writeToParcel(parcel)) != OK) {
127 ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)",
128 __FUNCTION__, i, strerror(-err), err);
129 return err;
130 }
Igor Murashkine7ee7632013-06-11 18:10:18 -0700131 }
132
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700133 parcel->writeInt32(mIsReprocess ? 1 : 0);
134
Igor Murashkine7ee7632013-06-11 18:10:18 -0700135 return OK;
136}
137
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800138} // namespace camera2
139} // namespace hardware
140} // namespace android