OutputConfiguration.cpp revision b97babb8c08969b55af3b6456d15f764c8873d3f
1b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh/* 2b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** 3b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** Copyright 2015, The Android Open Source Project 4b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** 5b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** Licensed under the Apache License, Version 2.0 (the "License"); 6b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** you may not use this file except in compliance with the License. 7b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** You may obtain a copy of the License at 8b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** 9b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** http://www.apache.org/licenses/LICENSE-2.0 10b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** 11b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** Unless required by applicable law or agreed to in writing, software 12b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** distributed under the License is distributed on an "AS IS" BASIS, 13b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** See the License for the specific language governing permissions and 15b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh** limitations under the License. 16b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh*/ 17b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 18b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh#define LOG_TAG "OutputConfiguration" 19b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh#include <utils/Log.h> 20b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 21b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh#include <camera/camera2/OutputConfiguration.h> 22b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh#include <binder/Parcel.h> 23b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 24b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yehnamespace android { 25b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 26b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 27b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yehconst int OutputConfiguration::INVALID_ROTATION = -1; 28b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 29b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh// Read empty strings without printing a false error message. 30b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia YehString16 OutputConfiguration::readMaybeEmptyString16(const Parcel& parcel) { 31b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh size_t len; 32b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh const char16_t* str = parcel.readString16Inplace(&len); 33b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh if (str != NULL) { 34b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return String16(str, len); 35b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh } else { 36b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return String16(); 37b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh } 38b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh} 39b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 40b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yehsp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const { 41b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return mGbp; 42b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh} 43b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 44b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yehint OutputConfiguration::getRotation() const { 45b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return mRotation; 46b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh} 47b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 48b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia YehOutputConfiguration::OutputConfiguration(const Parcel& parcel) { 49b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh status_t err; 50b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh int rotation = 0; 51b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh if ((err = parcel.readInt32(&rotation)) != OK) { 52b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); 53b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh mGbp = NULL; 54b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh mRotation = INVALID_ROTATION; 55b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return; 56b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh } 57b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 58b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh String16 name = readMaybeEmptyString16(parcel); 59b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh const sp<IGraphicBufferProducer>& gbp = 60b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder()); 61b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh mGbp = gbp; 62b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh mRotation = rotation; 63b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 64b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__, 65b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh gbp.get(), String8(name).string()); 66b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh} 67b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 68b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yehstatus_t OutputConfiguration::writeToParcel(Parcel& parcel) const { 69b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 70b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh parcel.writeInt32(mRotation); 71b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh parcel.writeString16(String16("unknown_name")); // name of surface 72b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh sp<IBinder> b(IInterface::asBinder(mGbp)); 73b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh parcel.writeStrongBinder(b); 74b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 75b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh return OK; 76b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh} 77b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 78b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh}; // namespace android 79b97babb8c08969b55af3b6456d15f764c8873d3fYin-Chia Yeh 80