blob: d0de1a40b10f734140188c78938e991248ca0b34 [file] [log] [blame]
Yin-Chia Yehee238402018-11-04 16:30:11 -08001/*
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
23namespace android {
24namespace hardware {
25namespace camera {
26namespace device {
27namespace V3_5 {
28namespace implementation {
29
30ExternalCameraDevice::ExternalCameraDevice(
31 const std::string& cameraId, const ExternalCameraConfig& cfg) :
32 V3_4::implementation::ExternalCameraDevice(cameraId, cfg) {}
33
34ExternalCameraDevice::~ExternalCameraDevice() {}
35
36Return<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
44sp<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) \
57do { \
58 if (metadata->update((tag), (data), (size))) { \
59 ALOGE("Update " #tag " failed!"); \
60 return -EINVAL; \
61 } \
62} while (0)
63
64status_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
Emilian Peev40a8c6e2018-10-29 09:35:21 +000089Return<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,
Emil Jahshaneed00402018-12-11 15:15:17 +0200106 mSupportedFormats, mCfg);
Emilian Peev40a8c6e2018-10-29 09:35:21 +0000107 _hidl_cb(Status::OK, Status::OK == status);
108 return Void();
109}
Yin-Chia Yehee238402018-11-04 16:30:11 -0800110#undef UPDATE
111
112} // namespace implementation
113} // namespace V3_5
114} // namespace device
115} // namespace camera
116} // namespace hardware
117} // namespace android
118