• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "ACameraVendorUtils"
18 
19 #include "utils.h"
20 
21 #include <utils/Log.h>
22 
23 namespace android {
24 namespace acam {
25 namespace utils {
26 
27 // Convert CaptureRequest wrappable by sp<> to aidl CaptureRequest.
convertToAidl(const CaptureRequest * captureRequest)28 AidlCaptureRequest convertToAidl(const CaptureRequest *captureRequest) {
29     AidlCaptureRequest aidlCaptureRequest;
30     aidlCaptureRequest.physicalCameraSettings =
31             captureRequest->mCaptureRequest.physicalCameraSettings;
32     aidlCaptureRequest.streamAndWindowIds = captureRequest->mCaptureRequest.streamAndWindowIds;
33     return aidlCaptureRequest;
34 }
35 
convertToAidl(int rotation)36 OutputConfiguration::Rotation convertToAidl(int rotation) {
37     using AidlRotation = OutputConfiguration::Rotation;
38 
39     AidlRotation aRot = AidlRotation ::R0;
40     switch(rotation) {
41         case CAMERA3_STREAM_ROTATION_90:
42             aRot = AidlRotation::R90;
43             break;
44         case CAMERA3_STREAM_ROTATION_180:
45             aRot = AidlRotation::R180;
46             break;
47         case CAMERA3_STREAM_ROTATION_270:
48             aRot = AidlRotation::R270;
49             break;
50         default:
51             break;
52     }
53     return aRot;
54 }
55 
cloneFromAidl(const AidlCameraMetadata & srcMetadata,camera_metadata_t ** dst)56 bool cloneFromAidl(const AidlCameraMetadata& srcMetadata, camera_metadata_t** dst) {
57     const camera_metadata *buffer = (camera_metadata_t*)(srcMetadata.metadata.data());
58     size_t expectedSize = srcMetadata.metadata.size();
59     int ret = validate_camera_metadata_structure(buffer, &expectedSize);
60     if (ret != OK && ret != CAMERA_METADATA_VALIDATION_SHIFTED) {
61         ALOGE("%s: Malformed camera srcMetadata received from caller", __FUNCTION__);
62         return false;
63     }
64 
65     camera_metadata_t* clonedBuffer = clone_camera_metadata(buffer);
66     if (clonedBuffer != nullptr) {
67         *dst = clonedBuffer;
68         return true;
69     }
70 
71     ALOGE("%s: Failed to clone srcMetadata buffer.", __FUNCTION__);
72     return false;
73 }
74 
75 // Note: existing data in dst will be gone.
convertToAidl(const camera_metadata_t * src,AidlCameraMetadata * dst)76 void convertToAidl(const camera_metadata_t *src, AidlCameraMetadata* dst) {
77     if (src == nullptr) {
78         return;
79     }
80     size_t size = get_camera_metadata_size(src);
81     uint8_t* metadataStart = (uint8_t*)src;
82     uint8_t* metadataEnd = metadataStart + size;
83     dst->metadata.assign(metadataStart, metadataEnd);
84 }
85 
convertToAidl(ACameraDevice_request_template templateId)86 TemplateId convertToAidl(ACameraDevice_request_template templateId) {
87     switch(templateId) {
88         case TEMPLATE_STILL_CAPTURE:
89             return TemplateId::STILL_CAPTURE;
90         case TEMPLATE_RECORD:
91             return TemplateId::RECORD;
92         case TEMPLATE_VIDEO_SNAPSHOT:
93             return TemplateId::VIDEO_SNAPSHOT;
94         case TEMPLATE_ZERO_SHUTTER_LAG:
95             return TemplateId::ZERO_SHUTTER_LAG;
96         case TEMPLATE_MANUAL:
97             return TemplateId::MANUAL;
98         default:
99             return TemplateId::PREVIEW;
100     }
101 }
102 
convertFromAidl(Status status)103 camera_status_t convertFromAidl(Status status) {
104     camera_status_t ret = ACAMERA_OK;
105     switch(status) {
106         case Status::NO_ERROR:
107             break;
108         case Status::DISCONNECTED:
109             ret = ACAMERA_ERROR_CAMERA_DISCONNECTED;
110             break;
111         case Status::CAMERA_IN_USE:
112             ret = ACAMERA_ERROR_CAMERA_IN_USE;
113             break;
114         case Status::MAX_CAMERAS_IN_USE:
115             ret = ACAMERA_ERROR_MAX_CAMERA_IN_USE;
116             break;
117         case Status::ILLEGAL_ARGUMENT:
118             ret = ACAMERA_ERROR_INVALID_PARAMETER;
119             break;
120         case Status::DEPRECATED_HAL:
121             // Should not reach here since we filtered legacy HALs earlier
122             ret = ACAMERA_ERROR_INVALID_PARAMETER;
123             break;
124         case Status::DISABLED:
125             ret = ACAMERA_ERROR_CAMERA_DISABLED;
126             break;
127         case Status::PERMISSION_DENIED:
128             ret = ACAMERA_ERROR_PERMISSION_DENIED;
129             break;
130         case Status::INVALID_OPERATION:
131             ret = ACAMERA_ERROR_INVALID_OPERATION;
132             break;
133         default:
134             ret = ACAMERA_ERROR_UNKNOWN;
135             break;
136     }
137     return ret;
138 }
139 
140 } // namespace utils
141 } // namespace acam
142 } // namespace android
143