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 "ExtCamDev@3.5"
18 //#define LOG_NDEBUG 0
19 #include <log/log.h>
20 
21 #include "ExternalCameraDevice_3_5.h"
22 
23 namespace android {
24 namespace hardware {
25 namespace camera {
26 namespace device {
27 namespace V3_5 {
28 namespace implementation {
29 
ExternalCameraDevice(const std::string & cameraId,const ExternalCameraConfig & cfg)30 ExternalCameraDevice::ExternalCameraDevice(
31         const std::string& cameraId, const ExternalCameraConfig& cfg) :
32         V3_4::implementation::ExternalCameraDevice(cameraId, cfg) {}
33 
~ExternalCameraDevice()34 ExternalCameraDevice::~ExternalCameraDevice() {}
35 
getPhysicalCameraCharacteristics(const hidl_string &,V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb)36 Return<void> ExternalCameraDevice::getPhysicalCameraCharacteristics(const hidl_string&,
37         V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) {
38     CameraMetadata cameraCharacteristics;
39     // External camera HAL doesn't support physical camera functions
40     _hidl_cb(Status::ILLEGAL_ARGUMENT, cameraCharacteristics);
41     return Void();
42 }
43 
createSession(const sp<V3_2::ICameraDeviceCallback> & cb,const ExternalCameraConfig & cfg,const std::vector<SupportedV4L2Format> & sortedFormats,const CroppingType & croppingType,const common::V1_0::helper::CameraMetadata & chars,const std::string & cameraId,unique_fd v4l2Fd)44 sp<V3_4::implementation::ExternalCameraDeviceSession> ExternalCameraDevice::createSession(
45         const sp<V3_2::ICameraDeviceCallback>& cb,
46         const ExternalCameraConfig& cfg,
47         const std::vector<SupportedV4L2Format>& sortedFormats,
48         const CroppingType& croppingType,
49         const common::V1_0::helper::CameraMetadata& chars,
50         const std::string& cameraId,
51         unique_fd v4l2Fd) {
52     return new ExternalCameraDeviceSession(
53             cb, cfg, sortedFormats, croppingType, chars, cameraId, std::move(v4l2Fd));
54 }
55 
56 #define UPDATE(tag, data, size)                    \
57 do {                                               \
58   if (metadata->update((tag), (data), (size))) {   \
59     ALOGE("Update " #tag " failed!");              \
60     return -EINVAL;                                \
61   }                                                \
62 } while (0)
63 
initDefaultCharsKeys(::android::hardware::camera::common::V1_0::helper::CameraMetadata * metadata)64 status_t ExternalCameraDevice::initDefaultCharsKeys(
65         ::android::hardware::camera::common::V1_0::helper::CameraMetadata* metadata) {
66     status_t res =
67             V3_4::implementation::ExternalCameraDevice::initDefaultCharsKeys(metadata);
68 
69     if (res != OK) {
70         return res;
71     }
72 
73     const uint8_t bufMgrVer = ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION_HIDL_DEVICE_3_5;
74     UPDATE(ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION, &bufMgrVer, 1);
75 
76     std::vector<int> availableCharacteristicsKeys = AVAILABLE_CHARACTERISTICS_KEYS_3_4;
77     availableCharacteristicsKeys.reserve(availableCharacteristicsKeys.size() +
78             EXTRA_CHARACTERISTICS_KEYS_3_5.size());
79     for (const auto& key : EXTRA_CHARACTERISTICS_KEYS_3_5) {
80         availableCharacteristicsKeys.push_back(key);
81     }
82     UPDATE(ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS,
83            availableCharacteristicsKeys.data(),
84            availableCharacteristicsKeys.size());
85 
86     return OK;
87 }
88 
isStreamCombinationSupported(const V3_4::StreamConfiguration & streams,V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb)89 Return<void> ExternalCameraDevice::isStreamCombinationSupported(
90         const V3_4::StreamConfiguration& streams,
91         V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) {
92 
93     if (isInitFailed()) {
94         ALOGE("%s: camera %s. camera init failed!", __FUNCTION__, mCameraId.c_str());
95         _hidl_cb(Status::INTERNAL_ERROR, false);
96         return Void();
97     }
98 
99     hidl_vec<V3_2::Stream> streamsV3_2(streams.streams.size());
100     size_t i = 0;
101     for (const auto& it : streams.streams) {
102         streamsV3_2[i++] = it.v3_2;
103     }
104     V3_2::StreamConfiguration streamConfig = {streamsV3_2, streams.operationMode};
105     auto status = ExternalCameraDeviceSession::isStreamCombinationSupported(streamConfig,
106             mSupportedFormats, mCfg);
107     _hidl_cb(Status::OK, Status::OK == status);
108     return Void();
109 }
110 #undef UPDATE
111 
112 }  // namespace implementation
113 }  // namespace V3_5
114 }  // namespace device
115 }  // namespace camera
116 }  // namespace hardware
117 }  // namespace android
118 
119