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> |
| 26 | |
| 27 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 28 | namespace hardware { |
| 29 | namespace camera2 { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 30 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 31 | status_t CaptureRequest::readFromParcel(const Parcel* parcel) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 32 | if (parcel == NULL) { |
| 33 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 34 | return BAD_VALUE; |
| 35 | } |
| 36 | |
| 37 | mMetadata.clear(); |
| 38 | mSurfaceList.clear(); |
| 39 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame^] | 40 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 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 |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame^] | 68 | view::Surface surfaceShim; |
| 69 | if ((err = surfaceShim.readFromParcel(parcel)) != OK) { |
| 70 | ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)", |
| 71 | __FUNCTION__, i, strerror(-err), err); |
| 72 | return err; |
| 73 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 74 | |
| 75 | sp<Surface> surface; |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame^] | 76 | if (surfaceShim.graphicBufferProducer != NULL) { |
| 77 | surface = new Surface(surfaceShim.graphicBufferProducer); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | mSurfaceList.push_back(surface); |
| 81 | } |
| 82 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 83 | int isReprocess = 0; |
| 84 | if ((err = parcel->readInt32(&isReprocess)) != OK) { |
| 85 | ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__); |
| 86 | return err; |
| 87 | } |
| 88 | mIsReprocess = (isReprocess != 0); |
| 89 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 90 | return OK; |
| 91 | } |
| 92 | |
| 93 | status_t CaptureRequest::writeToParcel(Parcel* parcel) const { |
| 94 | if (parcel == NULL) { |
| 95 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 96 | return BAD_VALUE; |
| 97 | } |
| 98 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame^] | 99 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 100 | |
| 101 | if ((err = mMetadata.writeToParcel(parcel)) != OK) { |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | int32_t size = static_cast<int32_t>(mSurfaceList.size()); |
| 106 | |
| 107 | // Send 0-sized arrays when it's empty. Do not send null arrays. |
| 108 | parcel->writeInt32(size); |
| 109 | |
| 110 | for (int32_t i = 0; i < size; ++i) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 111 | // not sure if readParcelableArray does this, hard to tell from source |
| 112 | parcel->writeString16(String16("android.view.Surface")); |
| 113 | |
| 114 | // Surface.writeToParcel |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame^] | 115 | view::Surface surfaceShim; |
| 116 | surfaceShim.name = String16("unknown_name"); |
| 117 | surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer(); |
| 118 | if ((err = surfaceShim.writeToParcel(parcel)) != OK) { |
| 119 | ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)", |
| 120 | __FUNCTION__, i, strerror(-err), err); |
| 121 | return err; |
| 122 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 125 | parcel->writeInt32(mIsReprocess ? 1 : 0); |
| 126 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 127 | return OK; |
| 128 | } |
| 129 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 130 | } // namespace camera2 |
| 131 | } // namespace hardware |
| 132 | } // namespace android |