blob: 32c387f107f1be481ce8f571bd85a5253d638f6d [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
20#include <hardware/camera.h>
21#include <utils/Mutex.h>
22#include <utils/KeyedVector.h>
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080023#include <utils/RefBase.h>
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070024
25#include "CameraMetadata.h"
26
27namespace android {
28namespace hardware {
29namespace camera {
30namespace common {
31namespace V1_0 {
32namespace helper {
33/**
34 * A wrapper class for HAL camera module.
35 *
36 * This class wraps camera_module_t returned from HAL to provide a wrapped
37 * get_camera_info implementation which CameraService generates some
38 * camera characteristics keys defined in newer HAL version on an older HAL.
39 */
40class CameraModule : public RefBase {
41public:
42 explicit CameraModule(camera_module_t *module);
43 virtual ~CameraModule();
44
45 // Must be called after construction
46 // Returns OK on success, NO_INIT on failure
47 int init();
48
49 int getCameraInfo(int cameraId, struct camera_info *info);
50 int getDeviceVersion(int cameraId);
51 int getNumberOfCameras(void);
52 int open(const char* id, struct hw_device_t** device);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080053 bool isOpenLegacyDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070054 int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
55 int setCallbacks(const camera_module_callbacks_t *callbacks);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080056 bool isVendorTagDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070057 void getVendorTagOps(vendor_tag_ops_t* ops);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080058 bool isSetTorchModeSupported() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070059 int setTorchMode(const char* camera_id, bool enable);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080060 uint16_t getModuleApiVersion() const;
61 const char* getModuleName() const;
62 uint16_t getHalApiVersion() const;
63 const char* getModuleAuthor() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070064 // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
65 void *getDso();
Guennadi Liakhovetskieca1d452017-12-07 10:59:35 +010066 // Only used by CameraProvider
67 void removeCamera(int cameraId);
Shuzhen Wangd3feb3d2018-08-17 13:52:40 -070068 int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo);
Emilian Peev40a8c6e2018-10-29 09:35:21 +000069 int isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams);
Eino-Ville Talvala29518042019-01-18 17:32:06 -080070 void notifyDeviceStateChange(uint64_t deviceState);
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070071
72private:
73 // Derive camera characteristics keys defined after HAL device version
74 static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars);
75 // Helper function to append available[request|result|chars]Keys
76 static void appendAvailableKeys(CameraMetadata &chars,
77 int32_t keyTag, const Vector<int32_t>& appendKeys);
78 status_t filterOpenErrorCode(status_t err);
79 camera_module_t *mModule;
Shuzhen Wang6bdeaf52018-09-05 09:40:00 -070080 int mNumberOfCameras;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070081 KeyedVector<int, camera_info> mCameraInfoMap;
82 KeyedVector<int, int> mDeviceVersionMap;
Shuzhen Wangd3feb3d2018-08-17 13:52:40 -070083 KeyedVector<int, camera_metadata_t*> mPhysicalCameraInfoMap;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070084 Mutex mCameraInfoLock;
85};
86
87} // namespace helper
88} // namespace V1_0
89} // namespace common
90} // namespace camera
91} // namespace hardware
92} // namespace android
93
94#endif