1 /* 2 ** 3 ** Copyright 2015, 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_TAG "OutputConfiguration" 19 #include <utils/Log.h> 20 21 #include <camera/camera2/OutputConfiguration.h> 22 #include <binder/Parcel.h> 23 24 namespace android { 25 26 27 const int OutputConfiguration::INVALID_ROTATION = -1; 28 29 // Read empty strings without printing a false error message. 30 String16 OutputConfiguration::readMaybeEmptyString16(const Parcel& parcel) { 31 size_t len; 32 const char16_t* str = parcel.readString16Inplace(&len); 33 if (str != NULL) { 34 return String16(str, len); 35 } else { 36 return String16(); 37 } 38 } 39 40 sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const { 41 return mGbp; 42 } 43 44 int OutputConfiguration::getRotation() const { 45 return mRotation; 46 } 47 48 OutputConfiguration::OutputConfiguration(const Parcel& parcel) { 49 status_t err; 50 int rotation = 0; 51 if ((err = parcel.readInt32(&rotation)) != OK) { 52 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); 53 mGbp = NULL; 54 mRotation = INVALID_ROTATION; 55 return; 56 } 57 58 String16 name = readMaybeEmptyString16(parcel); 59 const sp<IGraphicBufferProducer>& gbp = 60 interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder()); 61 mGbp = gbp; 62 mRotation = rotation; 63 64 ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__, 65 gbp.get(), String8(name).string()); 66 } 67 68 OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation) { 69 mGbp = gbp; 70 mRotation = rotation; 71 } 72 73 status_t OutputConfiguration::writeToParcel(Parcel& parcel) const { 74 75 parcel.writeInt32(mRotation); 76 parcel.writeString16(String16("unknown_name")); // name of surface 77 sp<IBinder> b(IInterface::asBinder(mGbp)); 78 parcel.writeStrongBinder(b); 79 80 return OK; 81 } 82 83 }; // namespace android 84 85