Home | History | Annotate | Download | only in ext_device_v3_4_impl
      1 /*
      2  * Copyright (C) 2018 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 ANDROID_HARDWARE_CAMERA_DEVICE_V3_4_EXTCAMERADEVICE_H
     18 #define ANDROID_HARDWARE_CAMERA_DEVICE_V3_4_EXTCAMERADEVICE_H
     19 
     20 #include "utils/Mutex.h"
     21 #include "CameraMetadata.h"
     22 
     23 #include <android/hardware/camera/device/3.2/ICameraDevice.h>
     24 #include <hidl/Status.h>
     25 #include <hidl/MQDescriptor.h>
     26 #include "ExternalCameraDeviceSession.h"
     27 
     28 namespace android {
     29 namespace hardware {
     30 namespace camera {
     31 namespace device {
     32 namespace V3_4 {
     33 namespace implementation {
     34 
     35 using namespace ::android::hardware::camera::device;
     36 using ::android::hardware::camera::device::V3_2::ICameraDevice;
     37 using ::android::hardware::camera::device::V3_2::ICameraDeviceCallback;
     38 using ::android::hardware::camera::common::V1_0::CameraResourceCost;
     39 using ::android::hardware::camera::common::V1_0::TorchMode;
     40 using ::android::hardware::camera::common::V1_0::Status;
     41 using ::android::hardware::camera::external::common::ExternalCameraConfig;
     42 using ::android::hardware::camera::external::common::Size;
     43 using ::android::hardware::Return;
     44 using ::android::hardware::Void;
     45 using ::android::hardware::hidl_vec;
     46 using ::android::hardware::hidl_string;
     47 using ::android::sp;
     48 
     49 /*
     50  * The camera device HAL implementation is opened lazily (via the open call)
     51  */
     52 struct ExternalCameraDevice : public ICameraDevice {
     53 
     54     // Called by external camera provider HAL.
     55     // Provider HAL must ensure the uniqueness of CameraDevice object per cameraId, or there could
     56     // be multiple CameraDevice trying to access the same physical camera.  Also, provider will have
     57     // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying
     58     // camera is detached.
     59     ExternalCameraDevice(const std::string& cameraId, const ExternalCameraConfig& cfg);
     60     ~ExternalCameraDevice();
     61 
     62     // Caller must use this method to check if CameraDevice ctor failed
     63     bool isInitFailed();
     64 
     65     /* Methods from ::android::hardware::camera::device::V3_2::ICameraDevice follow. */
     66     // The following method can be called without opening the actual camera device
     67     Return<void> getResourceCost(getResourceCost_cb _hidl_cb) override;
     68 
     69     Return<void> getCameraCharacteristics(getCameraCharacteristics_cb _hidl_cb) override;
     70 
     71     Return<Status> setTorchMode(TorchMode) override;
     72 
     73     // Open the device HAL and also return a default capture session
     74     Return<void> open(const sp<ICameraDeviceCallback>&, open_cb) override;
     75 
     76     // Forward the dump call to the opened session, or do nothing
     77     Return<void> dumpState(const ::android::hardware::hidl_handle&) override;
     78     /* End of Methods from ::android::hardware::camera::device::V3_2::ICameraDevice */
     79 
     80 protected:
     81     // Init supported w/h/format/fps in mSupportedFormats. Caller still owns fd
     82     void initSupportedFormatsLocked(int fd);
     83 
     84     status_t initCameraCharacteristics();
     85     // Init non-device dependent keys
     86     status_t initDefaultCharsKeys(::android::hardware::camera::common::V1_0::helper::CameraMetadata*);
     87     // Init camera control chars keys. Caller still owns fd
     88     status_t initCameraControlsCharsKeys(int fd,
     89             ::android::hardware::camera::common::V1_0::helper::CameraMetadata*);
     90     // Init camera output configuration related keys.  Caller still owns fd
     91     status_t initOutputCharsKeys(int fd,
     92             ::android::hardware::camera::common::V1_0::helper::CameraMetadata*);
     93 
     94     static void getFrameRateList(int fd, double fpsUpperBound, SupportedV4L2Format* format);
     95 
     96     // Get candidate supported formats list of input cropping type.
     97     static std::vector<SupportedV4L2Format> getCandidateSupportedFormatsLocked(
     98             int fd, CroppingType cropType,
     99             const std::vector<ExternalCameraConfig::FpsLimitation>& fpsLimits);
    100     // Trim supported format list by the cropping type. Also sort output formats by width/height
    101     static void trimSupportedFormats(CroppingType cropType,
    102             /*inout*/std::vector<SupportedV4L2Format>* pFmts);
    103 
    104     Mutex mLock;
    105     bool mInitFailed = false;
    106     std::string mCameraId;
    107     const ExternalCameraConfig& mCfg;
    108     std::vector<SupportedV4L2Format> mSupportedFormats;
    109     CroppingType mCroppingType;
    110 
    111     wp<ExternalCameraDeviceSession> mSession = nullptr;
    112 
    113     ::android::hardware::camera::common::V1_0::helper::CameraMetadata mCameraCharacteristics;
    114 };
    115 
    116 }  // namespace implementation
    117 }  // namespace V3_4
    118 }  // namespace device
    119 }  // namespace camera
    120 }  // namespace hardware
    121 }  // namespace android
    122 
    123 #endif  // ANDROID_HARDWARE_CAMERA_DEVICE_V3_4_EXTCAMERADEVICE_H
    124