1cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei/*
2cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * Copyright (C) 2014 The Android Open Source Project
3cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei *
4cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * Licensed under the Apache License, Version 2.0 (the "License");
5cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * you may not use this file except in compliance with the License.
6cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * You may obtain a copy of the License at
7cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei *
8cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei *      http://www.apache.org/licenses/LICENSE-2.0
9cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei *
10cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * Unless required by applicable law or agreed to in writing, software
11cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * distributed under the License is distributed on an "AS IS" BASIS,
12cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * See the License for the specific language governing permissions and
14cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei * limitations under the License.
15cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei */
16cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
17cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#define LOG_TAG "Camera-CaptureResult"
18cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#include <utils/Log.h>
19cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
20cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#include <camera/CaptureResult.h>
21cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei#include <binder/Parcel.h>
22cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
23cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weinamespace android {
24cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
25cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weibool CaptureResultExtras::isValid() {
26cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    return requestId >= 0;
27cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
28cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
29cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weistatus_t CaptureResultExtras::readFromParcel(Parcel *parcel) {
30cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (parcel == NULL) {
31cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Null parcel", __FUNCTION__);
32cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return BAD_VALUE;
33cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
34cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
35cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->readInt32(&requestId);
36cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->readInt32(&burstId);
37cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->readInt32(&afTriggerId);
38cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->readInt32(&precaptureTriggerId);
39cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->readInt64(&frameNumber);
40204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He    parcel->readInt32(&partialResultCount);
41cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
42cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    return OK;
43cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
44cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
45cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weistatus_t CaptureResultExtras::writeToParcel(Parcel *parcel) const {
46cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (parcel == NULL) {
47cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Null parcel", __FUNCTION__);
48cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return BAD_VALUE;
49cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
50cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
51cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->writeInt32(requestId);
52cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->writeInt32(burstId);
53cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->writeInt32(afTriggerId);
54cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->writeInt32(precaptureTriggerId);
55cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    parcel->writeInt64(frameNumber);
56204e3295e2814052aef7e45ee9edd60128efbbd0Zhijun He    parcel->writeInt32(partialResultCount);
57cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
58cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    return OK;
59cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
60cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
61cb0652e5a850b2fcd919e977247e87239efaf70eJianing WeiCaptureResult::CaptureResult() :
62cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        mMetadata(), mResultExtras() {
63cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
64cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
65cb0652e5a850b2fcd919e977247e87239efaf70eJianing WeiCaptureResult::CaptureResult(const CaptureResult &otherResult) {
66cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    mResultExtras = otherResult.mResultExtras;
67cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    mMetadata = otherResult.mMetadata;
68cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
69cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
70cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weistatus_t CaptureResult::readFromParcel(Parcel *parcel) {
71cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
72cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
73cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
74cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (parcel == NULL) {
75cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: parcel is null", __FUNCTION__);
76cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return BAD_VALUE;
77cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
78cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
79cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    mMetadata.clear();
80cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
81cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    status_t res = OK;
82cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    res = mMetadata.readFromParcel(parcel);
83cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (res != OK) {
84cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Failed to read metadata from parcel.",
85cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei              __FUNCTION__);
86cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return res;
87cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
88cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: Read metadata from parcel", __FUNCTION__);
89cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
90cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    res = mResultExtras.readFromParcel(parcel);
91cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (res != OK) {
92cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Failed to read result extras from parcel.",
93cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei                __FUNCTION__);
94cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return res;
95cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
96cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: Read result extras from parcel", __FUNCTION__);
97cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
98cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    return OK;
99cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
100cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
101cb0652e5a850b2fcd919e977247e87239efaf70eJianing Weistatus_t CaptureResult::writeToParcel(Parcel *parcel) const {
102cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
103cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
104cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
105cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (parcel == NULL) {
106cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: parcel is null", __FUNCTION__);
107cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return BAD_VALUE;
108cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
109cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
110cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    status_t res;
111cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
112cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    res = mMetadata.writeToParcel(parcel);
113cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (res != OK) {
114cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Failed to write metadata to parcel", __FUNCTION__);
115cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return res;
116cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
117cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: Wrote metadata to parcel", __FUNCTION__);
118cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
119cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    res = mResultExtras.writeToParcel(parcel);
120cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    if (res != OK) {
121cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        ALOGE("%s: Failed to write result extras to parcel", __FUNCTION__);
122cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei        return res;
123cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    }
124cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    ALOGV("%s: Wrote result extras to parcel", __FUNCTION__);
125cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
126cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei    return OK;
127cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
128cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei
129cb0652e5a850b2fcd919e977247e87239efaf70eJianing Wei}
130