Home | History | Annotate | Download | only in include
      1 /*
      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 <string>
     21 #include <unordered_set>
     22 
     23 #include <hardware/camera.h>
     24 #include <utils/Mutex.h>
     25 #include <utils/KeyedVector.h>
     26 #include <utils/RefBase.h>
     27 
     28 #include "CameraMetadata.h"
     29 
     30 namespace android {
     31 namespace hardware {
     32 namespace camera {
     33 namespace common {
     34 namespace V1_0 {
     35 namespace 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  */
     43 class CameraModule : public RefBase {
     44 public:
     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);
     56     bool isOpenLegacyDefined() const;
     57     int openLegacy(const char* id, uint32_t halVersion, struct hw_device_t** device);
     58     int setCallbacks(const camera_module_callbacks_t *callbacks);
     59     bool isVendorTagDefined() const;
     60     void getVendorTagOps(vendor_tag_ops_t* ops);
     61     bool isSetTorchModeSupported() const;
     62     int setTorchMode(const char* camera_id, bool enable);
     63     uint16_t getModuleApiVersion() const;
     64     const char* getModuleName() const;
     65     uint16_t getHalApiVersion() const;
     66     const char* getModuleAuthor() const;
     67     // Only used by CameraModuleFixture native test. Do NOT use elsewhere.
     68     void *getDso();
     69     // Only used by CameraProvider
     70     void removeCamera(int cameraId);
     71     int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo);
     72     int isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams);
     73     void notifyDeviceStateChange(uint64_t deviceState);
     74 
     75     static bool isLogicalMultiCamera(
     76             const common::V1_0::helper::CameraMetadata& metadata,
     77             std::unordered_set<std::string>* physicalCameraIds);
     78 
     79 private:
     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;
     87     int mNumberOfCameras;
     88     KeyedVector<int, camera_info> mCameraInfoMap;
     89     KeyedVector<int, int> mDeviceVersionMap;
     90     KeyedVector<int, camera_metadata_t*> mPhysicalCameraInfoMap;
     91     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
    102