blob: 35051546aced83da92cfaeb58ed9f381d2ce9703 [file] [log] [blame]
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07001/*
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
24namespace android {
25
26
27const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080028const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070029
30// Read empty strings without printing a false error message.
31String16 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
41sp<IGraphicBufferProducer> OutputConfiguration::getGraphicBufferProducer() const {
42 return mGbp;
43}
44
45int OutputConfiguration::getRotation() const {
46 return mRotation;
47}
48
Zhijun He018107a2016-01-18 15:32:50 -080049int OutputConfiguration::getSurfaceSetID() const {
50 return mSurfaceSetID;
51}
52
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070053OutputConfiguration::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 He018107a2016-01-18 15:32:50 -080063 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 Yehb97babb2015-03-12 13:42:44 -070071 String16 name = readMaybeEmptyString16(parcel);
72 const sp<IGraphicBufferProducer>& gbp =
73 interface_cast<IGraphicBufferProducer>(parcel.readStrongBinder());
74 mGbp = gbp;
75 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -080076 mSurfaceSetID = setID;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070077
78 ALOGV("%s: OutputConfiguration: bp = %p, name = %s", __FUNCTION__,
79 gbp.get(), String8(name).string());
80}
81
Zhijun He018107a2016-01-18 15:32:50 -080082OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
83 int surfaceSetID) {
Ruben Brunk3450ba72015-06-16 11:00:37 -070084 mGbp = gbp;
85 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -080086 mSurfaceSetID = surfaceSetID;
Ruben Brunk3450ba72015-06-16 11:00:37 -070087}
88
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070089status_t OutputConfiguration::writeToParcel(Parcel& parcel) const {
90
91 parcel.writeInt32(mRotation);
Zhijun He018107a2016-01-18 15:32:50 -080092 parcel.writeInt32(mSurfaceSetID);
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070093 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