blob: 68d4f9051ca5ad2edcf3c849ddd65d676b1acc79 [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>
23
24#include "CameraMetadata.h"
25
26namespace android {
27namespace hardware {
28namespace camera {
29namespace common {
30namespace V1_0 {
31namespace helper {
32/**
33 * A wrapper class for HAL camera module.
34 *
35 * This class wraps camera_module_t returned from HAL to provide a wrapped
36 * get_camera_info implementation which CameraService generates some
37 * camera characteristics keys defined in newer HAL version on an older HAL.
38 */
39class CameraModule : public RefBase {
40public:
41 explicit CameraModule(camera_module_t *module);
42 virtual ~CameraModule();
43
44 // Must be called after construction
45 // Returns OK on success, NO_INIT on failure
46 int init();
47
48 int getCameraInfo(int cameraId, struct camera_info *info);
49 int getDeviceVersion(int cameraId);
50 int getNumberOfCameras(void);
51 int open(const char* id, struct hw_device_t** device);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080052 bool isOpenLegacyDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070053 int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
54 int setCallbacks(const camera_module_callbacks_t *callbacks);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080055 bool isVendorTagDefined() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070056 void getVendorTagOps(vendor_tag_ops_t* ops);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080057 bool isSetTorchModeSupported() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070058 int setTorchMode(const char* camera_id, bool enable);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080059 uint16_t getModuleApiVersion() const;
60 const char* getModuleName() const;
61 uint16_t getHalApiVersion() const;
62 const char* getModuleAuthor() const;
Yin-Chia Yehfaef8f92016-10-31 12:53:56 -070063 // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
64 void *getDso();
65
66private:
67 // Derive camera characteristics keys defined after HAL device version
68 static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars);
69 // Helper function to append available[request|result|chars]Keys
70 static void appendAvailableKeys(CameraMetadata &chars,
71 int32_t keyTag, const Vector<int32_t>& appendKeys);
72 status_t filterOpenErrorCode(status_t err);
73 camera_module_t *mModule;
74 KeyedVector<int, camera_info> mCameraInfoMap;
75 KeyedVector<int, int> mDeviceVersionMap;
76 Mutex mCameraInfoLock;
77};
78
79} // namespace helper
80} // namespace V1_0
81} // namespace common
82} // namespace camera
83} // namespace hardware
84} // namespace android
85
86#endif