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 "CamDev@3.5-impl"
18 #include <log/log.h>
19
20 #include "CameraModule.h"
21 #include "CameraDevice_3_5.h"
22
23 namespace android {
24 namespace hardware {
25 namespace camera {
26 namespace device {
27 namespace V3_5 {
28 namespace implementation {
29
30 using namespace ::android::hardware::camera::device;
31 using ::android::hardware::camera::common::V1_0::Status;
32 using ::android::hardware::camera::device::V3_2::CameraMetadata;
33
CameraDevice(sp<CameraModule> module,const std::string & cameraId,const SortedVector<std::pair<std::string,std::string>> & cameraDeviceNames)34 CameraDevice::CameraDevice(sp<CameraModule> module, const std::string& cameraId,
35 const SortedVector<std::pair<std::string, std::string>>& cameraDeviceNames) :
36 V3_4::implementation::CameraDevice(module, cameraId, cameraDeviceNames) {
37 }
38
~CameraDevice()39 CameraDevice::~CameraDevice() {
40 }
41
createSession(camera3_device_t * device,const camera_metadata_t * deviceInfo,const sp<V3_2::ICameraDeviceCallback> & callback)42 sp<V3_2::implementation::CameraDeviceSession> CameraDevice::createSession(camera3_device_t* device,
43 const camera_metadata_t* deviceInfo,
44 const sp<V3_2::ICameraDeviceCallback>& callback) {
45 sp<CameraDeviceSession> session = new CameraDeviceSession(device, deviceInfo, callback);
46 IF_ALOGV() {
47 session->getInterface()->interfaceChain([](
48 ::android::hardware::hidl_vec<::android::hardware::hidl_string> interfaceChain) {
49 ALOGV("Session interface chain:");
50 for (auto iface : interfaceChain) {
51 ALOGV(" %s", iface.c_str());
52 }
53 });
54 }
55 return session;
56 }
57
getPhysicalCameraCharacteristics(const hidl_string & physicalCameraId,V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb)58 Return<void> CameraDevice::getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId,
59 V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) {
60 Status status = initStatus();
61 CameraMetadata cameraCharacteristics;
62 if (status == Status::OK) {
63 // Require module 2.5+ version.
64 if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_5) {
65 ALOGE("%s: get_physical_camera_info must be called on camera module 2.5 or newer",
66 __FUNCTION__);
67 status = Status::INTERNAL_ERROR;
68 } else {
69 char *end;
70 errno = 0;
71 long id = strtol(physicalCameraId.c_str(), &end, 0);
72 if (id > INT_MAX || (errno == ERANGE && id == LONG_MAX) ||
73 id < INT_MIN || (errno == ERANGE && id == LONG_MIN) ||
74 *end != '\0') {
75 ALOGE("%s: Invalid physicalCameraId %s", __FUNCTION__, physicalCameraId.c_str());
76 status = Status::ILLEGAL_ARGUMENT;
77 } else {
78 camera_metadata_t *physicalInfo = nullptr;
79 int ret = mModule->getPhysicalCameraInfo((int)id, &physicalInfo);
80 if (ret == OK) {
81 V3_2::implementation::convertToHidl(physicalInfo, &cameraCharacteristics);
82 } else if (ret == -EINVAL) {
83 ALOGE("%s: %s is not a valid physical camera Id outside of getCameraIdList()",
84 __FUNCTION__, physicalCameraId.c_str());
85 status = Status::ILLEGAL_ARGUMENT;
86 } else {
87 ALOGE("%s: Failed to get physical camera %s info: %s (%d)!", __FUNCTION__,
88 physicalCameraId.c_str(), strerror(-ret), ret);
89 status = Status::INTERNAL_ERROR;
90 }
91 }
92 }
93 }
94 _hidl_cb(status, cameraCharacteristics);
95 return Void();
96 }
97
isStreamCombinationSupported(const V3_4::StreamConfiguration & streams,V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb)98 Return<void> CameraDevice::isStreamCombinationSupported(const V3_4::StreamConfiguration& streams,
99 V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) {
100 Status status;
101 bool streamsSupported = false;
102
103 // Require module 2.5+ version.
104 if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_5) {
105 ALOGE("%s: is_stream_combination_supported must be called on camera module 2.5 or "\
106 "newer", __FUNCTION__);
107 status = Status::INTERNAL_ERROR;
108 } else {
109 camera_stream_combination_t streamComb{};
110 streamComb.operation_mode = static_cast<uint32_t> (streams.operationMode);
111 streamComb.num_streams = streams.streams.size();
112 camera_stream_t *streamBuffer = new camera_stream_t[streamComb.num_streams];
113
114 size_t i = 0;
115 for (const auto &it : streams.streams) {
116 streamBuffer[i].stream_type = static_cast<int> (it.v3_2.streamType);
117 streamBuffer[i].width = it.v3_2.width;
118 streamBuffer[i].height = it.v3_2.height;
119 streamBuffer[i].format = static_cast<int> (it.v3_2.format);
120 streamBuffer[i].data_space = static_cast<android_dataspace_t> (it.v3_2.dataSpace);
121 streamBuffer[i].usage = static_cast<uint32_t> (it.v3_2.usage);
122 streamBuffer[i].physical_camera_id = it.physicalCameraId.c_str();
123 streamBuffer[i++].rotation = static_cast<int> (it.v3_2.rotation);
124 }
125 streamComb.streams = streamBuffer;
126 auto res = mModule->isStreamCombinationSupported(mCameraIdInt, &streamComb);
127 switch (res) {
128 case NO_ERROR:
129 streamsSupported = true;
130 status = Status::OK;
131 break;
132 case BAD_VALUE:
133 status = Status::OK;
134 break;
135 case INVALID_OPERATION:
136 status = Status::METHOD_NOT_SUPPORTED;
137 break;
138 default:
139 ALOGE("%s: Unexpected error: %d", __FUNCTION__, res);
140 status = Status::INTERNAL_ERROR;
141 };
142 delete [] streamBuffer;
143 }
144
145 _hidl_cb(status, streamsSupported);
146 return Void();
147 }
148
149 // End of methods from ::android::hardware::camera::device::V3_2::ICameraDevice.
150
151 } // namespace implementation
152 } // namespace V3_5
153 } // namespace device
154 } // namespace camera
155 } // namespace hardware
156 } // namespace android
157
158