Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1 | /* |
| 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 Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 22 | #include <camera/camera2/CaptureRequest.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <gui/Surface.h> |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 26 | #include <gui/view/Surface.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 27 | |
| 28 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 29 | namespace hardware { |
| 30 | namespace camera2 { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 31 | |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 32 | // These must be in the .cpp (to avoid inlining) |
| 33 | CaptureRequest::CaptureRequest() = default; |
| 34 | CaptureRequest::~CaptureRequest() = default; |
| 35 | CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default; |
| 36 | CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default; |
| 37 | |
| 38 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 39 | status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 40 | if (parcel == NULL) { |
| 41 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 42 | return BAD_VALUE; |
| 43 | } |
| 44 | |
| 45 | mMetadata.clear(); |
| 46 | mSurfaceList.clear(); |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 47 | mStreamIdxList.clear(); |
| 48 | mSurfaceIdxList.clear(); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 49 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 50 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 51 | |
| 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 Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 58 | 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 Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 65 | 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 Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 73 | for (int32_t i = 0; i < size; ++i) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 74 | // 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 Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 85 | 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 Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 91 | |
| 92 | sp<Surface> surface; |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 93 | if (surfaceShim.graphicBufferProducer != NULL) { |
| 94 | surface = new Surface(surfaceShim.graphicBufferProducer); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | mSurfaceList.push_back(surface); |
| 98 | } |
| 99 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 100 | int32_t streamSurfaceSize; |
| 101 | if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) { |
| 102 | ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 103 | return err; |
| 104 | } |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 105 | |
| 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 Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 126 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 127 | return OK; |
| 128 | } |
| 129 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 130 | status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 131 | if (parcel == NULL) { |
| 132 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 133 | return BAD_VALUE; |
| 134 | } |
| 135 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 136 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 137 | |
| 138 | if ((err = mMetadata.writeToParcel(parcel)) != OK) { |
| 139 | return err; |
| 140 | } |
| 141 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 142 | parcel->writeInt32(mIsReprocess ? 1 : 0); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 143 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 144 | if (mSurfaceConverted) { |
| 145 | parcel->writeInt32(0); // 0-sized array |
| 146 | } else { |
| 147 | int32_t size = static_cast<int32_t>(mSurfaceList.size()); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 148 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 149 | // Send 0-sized arrays when it's empty. Do not send null arrays. |
| 150 | parcel->writeInt32(size); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 151 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 152 | 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 Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 165 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 168 | 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 Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 179 | return OK; |
| 180 | } |
| 181 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 182 | } // namespace camera2 |
| 183 | } // namespace hardware |
| 184 | } // namespace android |