blob: fb4370863a21069e606f26f132c0ecc9de69e298 [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>
26
27namespace android {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080028namespace hardware {
29namespace camera2 {
Igor Murashkine7ee7632013-06-11 18:10:18 -070030
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080031status_t CaptureRequest::readFromParcel(const Parcel* parcel) {
Igor Murashkine7ee7632013-06-11 18:10:18 -070032 if (parcel == NULL) {
33 ALOGE("%s: Null parcel", __FUNCTION__);
34 return BAD_VALUE;
35 }
36
37 mMetadata.clear();
38 mSurfaceList.clear();
39
40 status_t err;
41
42 if ((err = mMetadata.readFromParcel(parcel)) != OK) {
43 ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__);
44 return err;
45 }
46 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
47
48 int32_t size;
49 if ((err = parcel->readInt32(&size)) != OK) {
50 ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__);
51 return err;
52 }
53 ALOGV("%s: Read surface list size = %d", __FUNCTION__, size);
54
55 // Do not distinguish null arrays from 0-sized arrays.
56 for (int i = 0; i < size; ++i) {
57 // Parcel.writeParcelableArray
58 size_t len;
59 const char16_t* className = parcel->readString16Inplace(&len);
60 ALOGV("%s: Read surface class = %s", __FUNCTION__,
61 className != NULL ? String8(className).string() : "<null>");
62
63 if (className == NULL) {
64 continue;
65 }
66
67 // Surface.writeToParcel
Chien-Yu Chen7bc4fc82014-11-20 10:36:22 -080068 const char16_t* name = parcel->readString16Inplace(&len);
69 ALOGV("%s: Read surface name = %s", __FUNCTION__,
70 name != NULL ? String8(name).string() : "<null>");
Igor Murashkine7ee7632013-06-11 18:10:18 -070071 sp<IBinder> binder(parcel->readStrongBinder());
72 ALOGV("%s: Read surface binder = %p",
73 __FUNCTION__, binder.get());
74
75 sp<Surface> surface;
76
77 if (binder != NULL) {
78 sp<IGraphicBufferProducer> gbp =
79 interface_cast<IGraphicBufferProducer>(binder);
80 surface = new Surface(gbp);
81 }
82
83 mSurfaceList.push_back(surface);
84 }
85
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -070086 int isReprocess = 0;
87 if ((err = parcel->readInt32(&isReprocess)) != OK) {
88 ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__);
89 return err;
90 }
91 mIsReprocess = (isReprocess != 0);
92
Igor Murashkine7ee7632013-06-11 18:10:18 -070093 return OK;
94}
95
96status_t CaptureRequest::writeToParcel(Parcel* parcel) const {
97 if (parcel == NULL) {
98 ALOGE("%s: Null parcel", __FUNCTION__);
99 return BAD_VALUE;
100 }
101
102 status_t err;
103
104 if ((err = mMetadata.writeToParcel(parcel)) != OK) {
105 return err;
106 }
107
108 int32_t size = static_cast<int32_t>(mSurfaceList.size());
109
110 // Send 0-sized arrays when it's empty. Do not send null arrays.
111 parcel->writeInt32(size);
112
113 for (int32_t i = 0; i < size; ++i) {
114 sp<Surface> surface = mSurfaceList[i];
115
116 sp<IBinder> binder;
117 if (surface != 0) {
Marco Nelissenf8880202014-11-14 07:58:25 -0800118 binder = IInterface::asBinder(surface->getIGraphicBufferProducer());
Igor Murashkine7ee7632013-06-11 18:10:18 -0700119 }
120
121 // not sure if readParcelableArray does this, hard to tell from source
122 parcel->writeString16(String16("android.view.Surface"));
123
124 // Surface.writeToParcel
125 parcel->writeString16(String16("unknown_name"));
126 // Surface.nativeWriteToParcel
127 parcel->writeStrongBinder(binder);
128 }
129
Chien-Yu Chen618ff8a2015-03-13 11:27:17 -0700130 parcel->writeInt32(mIsReprocess ? 1 : 0);
131
Igor Murashkine7ee7632013-06-11 18:10:18 -0700132 return OK;
133}
134
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800135} // namespace camera2
136} // namespace hardware
137} // namespace android