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