blob: c89e9346550fe1ddf4806dacced3e2bab6fde8cb [file] [log] [blame]
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -07001/*
2 * Copyright (C) 2016 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#ifndef CAMERA_COMMON_1_0_CAMERAMODULE_H
18#define CAMERA_COMMON_1_0_CAMERAMODULE_H
19
Shuzhen Wang892e8262019-02-08 16:12:30 -080020#include <string>
21#include <unordered_set>
22
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070023#include <hardware/camera.h>
24#include <utils/Mutex.h>
25#include <utils/KeyedVector.h>
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080026#include <utils/RefBase.h>
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070027
28#include "CameraMetadata.h"
29
30namespace android {
31namespace hardware {
32namespace camera {
33namespace common {
34namespace V1_0 {
35namespace helper {
36/**
37 * A wrapper class for HAL camera module.
38 *
39 * This class wraps camera_module_t returned from HAL to provide a wrapped
40 * get_camera_info implementation which CameraService generates some
41 * camera characteristics keys defined in newer HAL version on an older HAL.
42 */
43class CameraModule : public RefBase {
44public:
45 explicit CameraModule(camera_module_t *module);
46 virtual ~CameraModule();
47
48 // Must be called after construction
49 // Returns OK on success, NO_INIT on failure
50 int init();
51
52 int getCameraInfo(int cameraId, struct camera_info *info);
53 int getDeviceVersion(int cameraId);
54 int getNumberOfCameras(void);
55 int open(const char* id, struct hw_device_t** device);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080056 bool isOpenLegacyDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070057 int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
58 int setCallbacks(const camera_module_callbacks_t *callbacks);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080059 bool isVendorTagDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070060 void getVendorTagOps(vendor_tag_ops_t* ops);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080061 bool isSetTorchModeSupported() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070062 int setTorchMode(const char* camera_id, bool enable);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080063 uint16_t getModuleApiVersion() const;
64 const char* getModuleName() const;
65 uint16_t getHalApiVersion() const;
66 const char* getModuleAuthor() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070067 // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
68 void *getDso();
Guennadi Liakhovetskieca1d452017-12-07 10:59:35 +010069 // Only used by CameraProvider
70 void removeCamera(int cameraId);
Shuzhen Wangd3feb3d2018-08-17 13:52:40 -070071 int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo);
Emilian Peev40a8c6e2018-10-29 09:35:21 +000072 int isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams);
Eino-Ville Talvala29518042019-01-18 17:32:06 -080073 void notifyDeviceStateChange(uint64_t deviceState);
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070074
Shuzhen Wang892e8262019-02-08 16:12:30 -080075 static bool isLogicalMultiCamera(
76 const common::V1_0::helper::CameraMetadata& metadata,
77 std::unordered_set<std::string>* physicalCameraIds);
78
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070079private:
80 // Derive camera characteristics keys defined after HAL device version
81 static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars);
82 // Helper function to append available[request|result|chars]Keys
83 static void appendAvailableKeys(CameraMetadata &chars,
84 int32_t keyTag, const Vector<int32_t>& appendKeys);
85 status_t filterOpenErrorCode(status_t err);
86 camera_module_t *mModule;
Shuzhen Wang6bdeaf52018-09-05 09:40:00 -070087 int mNumberOfCameras;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070088 KeyedVector<int, camera_info> mCameraInfoMap;
89 KeyedVector<int, int> mDeviceVersionMap;
Shuzhen Wangd3feb3d2018-08-17 13:52:40 -070090 KeyedVector<int, camera_metadata_t*> mPhysicalCameraInfoMap;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070091 Mutex mCameraInfoLock;
92};
93
94} // namespace helper
95} // namespace V1_0
96} // namespace common
97} // namespace camera
98} // namespace hardware
99} // namespace android
100
101#endif