Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 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; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 28 | const int OutputConfiguration::INVALID_SET_ID = -1; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 29 | |
| 30 | // Read empty strings without printing a false error message. |
| 31 | String16 OutputConfiguration::readMaybeEmptyString16(const Parcel& parcel) { |
| 32 | size_t len; |
| 33 | const char16_t* str = parcel.readString16Inplace(&len); |
| 34 | if (str != NULL) { |
| 35 | return String16(str, len); |
| 36 | } else { |
| 37 | return String16(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const { |
| 42 | return mGbp; |
| 43 | } |
| 44 | |
| 45 | int OutputConfiguration::getRotation() const { |
| 46 | return mRotation; |
| 47 | } |
| 48 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 49 | int OutputConfiguration::getSurfaceSetID() const { |
| 50 | return mSurfaceSetID; |
| 51 | } |
| 52 | |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 53 | OutputConfiguration::OutputConfiguration(const Parcel& parcel) { |
| 54 | status_t err; |
| 55 | int rotation = 0; |
| 56 | if ((err = parcel.readInt32(&rotation)) != OK) { |
| 57 | ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); |
| 58 | mGbp = NULL; |
| 59 | mRotation = INVALID_ROTATION; |
| 60 | return; |
| 61 | } |
| 62 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 63 | int setID = INVALID_SET_ID; |
| 64 | if ((err = parcel.readInt32(&setID)) != OK) { |
| 65 | ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__); |
| 66 | mGbp = NULL; |
| 67 | mSurfaceSetID = INVALID_SET_ID; |
| 68 | return; |
| 69 | } |
| 70 | |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 71 | String16 name = readMaybeEmptyString16(parcel); |
| 72 | const sp<IGraphicBufferProducer>& gbp = |
| 73 | interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder()); |
| 74 | mGbp = gbp; |
| 75 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 76 | mSurfaceSetID = setID; |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 77 | |
| 78 | ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__, |
| 79 | gbp.get(), String8(name).string()); |
| 80 | } |
| 81 | |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 82 | OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation, |
| 83 | int surfaceSetID) { |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 84 | mGbp = gbp; |
| 85 | mRotation = rotation; |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 86 | mSurfaceSetID = surfaceSetID; |
Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 89 | status_t OutputConfiguration::writeToParcel(Parcel& parcel) const { |
| 90 | |
| 91 | parcel.writeInt32(mRotation); |
Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame^] | 92 | parcel.writeInt32(mSurfaceSetID); |
Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 93 | parcel.writeString16(String16("unknown_name")); // name of surface |
| 94 | sp<IBinder> b(IInterface::asBinder(mGbp)); |
| 95 | parcel.writeStrongBinder(b); |
| 96 | |
| 97 | return OK; |
| 98 | } |
| 99 | |
| 100 | }; // namespace android |
| 101 | |