blob: 907c80799229d1c9c6e446b63d801c592ce5b78c [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);
52 bool isOpenLegacyDefined();
53 int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
54 int setCallbacks(const camera_module_callbacks_t *callbacks);
55 bool isVendorTagDefined();
56 void getVendorTagOps(vendor_tag_ops_t* ops);
57 int setTorchMode(const char* camera_id, bool enable);
58 uint16_t getModuleApiVersion();
59 const char* getModuleName();
60 uint16_t getHalApiVersion();
61 const char* getModuleAuthor();
62 // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
63 void *getDso();
64
65private:
66 // Derive camera characteristics keys defined after HAL device version
67 static void deriveCameraCharacteristicsKeys(uint32_t deviceVersion, CameraMetadata &chars);
68 // Helper function to append available[request|result|chars]Keys
69 static void appendAvailableKeys(CameraMetadata &chars,
70 int32_t keyTag, const Vector<int32_t>& appendKeys);
71 status_t filterOpenErrorCode(status_t err);
72 camera_module_t *mModule;
73 KeyedVector<int, camera_info> mCameraInfoMap;
74 KeyedVector<int, int> mDeviceVersionMap;
75 Mutex mCameraInfoLock;
76};
77
78} // namespace helper
79} // namespace V1_0
80} // namespace common
81} // namespace camera
82} // namespace hardware
83} // namespace android
84
85#endif