CaptureRequest.cpp revision 032845cc878f538e3336c96e1c24668953eab971
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 22#include <camera/camera2/CaptureRequest.h> 23 24#include <binder/Parcel.h> 25#include <gui/Surface.h> 26#include <gui/view/Surface.h> 27 28namespace android { 29namespace hardware { 30namespace camera2 { 31 32// 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 39status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) { 40 if (parcel == NULL) { 41 ALOGE("%s: Null parcel", __FUNCTION__); 42 return BAD_VALUE; 43 } 44 45 mMetadata.clear(); 46 mSurfaceList.clear(); 47 48 status_t err = OK; 49 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 76 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 } 82 83 sp<Surface> surface; 84 if (surfaceShim.graphicBufferProducer != NULL) { 85 surface = new Surface(surfaceShim.graphicBufferProducer); 86 } 87 88 mSurfaceList.push_back(surface); 89 } 90 91 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 98 return OK; 99} 100 101status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const { 102 if (parcel == NULL) { 103 ALOGE("%s: Null parcel", __FUNCTION__); 104 return BAD_VALUE; 105 } 106 107 status_t err = OK; 108 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) { 119 // not sure if readParcelableArray does this, hard to tell from source 120 parcel->writeString16(String16("android.view.Surface")); 121 122 // Surface.writeToParcel 123 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 } 131 } 132 133 parcel->writeInt32(mIsReprocess ? 1 : 0); 134 135 return OK; 136} 137 138} // namespace camera2 139} // namespace hardware 140} // namespace android 141