1 /* 2 * Copyright (C) 2020 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_6_EXTCAMERADEVICE_H 18 #define ANDROID_HARDWARE_CAMERA_DEVICE_V3_6_EXTCAMERADEVICE_H 19 20 #include <android/hardware/camera/device/3.6/ICameraDevice.h> 21 22 #include "ExternalCameraDeviceSession.h" 23 #include <../../../../3.5/default/include/ext_device_v3_5_impl/ExternalCameraDevice_3_5.h> 24 25 namespace android { 26 namespace hardware { 27 namespace camera { 28 namespace device { 29 namespace V3_6 { 30 namespace implementation { 31 32 using namespace ::android::hardware::camera::device; 33 using ::android::hardware::camera::device::V3_6::ICameraDevice; 34 using ::android::hardware::camera::common::V1_0::CameraResourceCost; 35 using ::android::hardware::camera::common::V1_0::TorchMode; 36 using ::android::hardware::camera::common::V1_0::Status; 37 using ::android::hardware::camera::external::common::ExternalCameraConfig; 38 using ::android::hardware::camera::external::common::Size; 39 using ::android::hardware::Return; 40 using ::android::hardware::Void; 41 using ::android::hardware::hidl_vec; 42 using ::android::hardware::hidl_string; 43 using ::android::sp; 44 45 /* 46 * The camera device HAL implementation is opened lazily (via the open call) 47 */ 48 struct ExternalCameraDevice : public V3_5::implementation::ExternalCameraDevice { 49 50 // Called by external camera provider HAL. 51 // Provider HAL must ensure the uniqueness of CameraDevice object per cameraId, or there could 52 // be multiple CameraDevice trying to access the same physical camera. Also, provider will have 53 // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying 54 // camera is detached. 55 ExternalCameraDevice(const std::string& cameraId, const ExternalCameraConfig& cfg); 56 virtual ~ExternalCameraDevice(); 57 getInterfaceExternalCameraDevice58 virtual sp<V3_2::ICameraDevice> getInterface() override { 59 return new TrampolineDeviceInterface_3_6(this); 60 } 61 62 protected: 63 virtual sp<V3_4::implementation::ExternalCameraDeviceSession> createSession( 64 const sp<V3_2::ICameraDeviceCallback>&, 65 const ExternalCameraConfig& cfg, 66 const std::vector<SupportedV4L2Format>& sortedFormats, 67 const CroppingType& croppingType, 68 const common::V1_0::helper::CameraMetadata& chars, 69 const std::string& cameraId, 70 unique_fd v4l2Fd) override; 71 72 virtual status_t initAvailableCapabilities( 73 ::android::hardware::camera::common::V1_0::helper::CameraMetadata*) override; 74 75 private: 76 struct TrampolineDeviceInterface_3_6 : public ICameraDevice { TrampolineDeviceInterface_3_6ExternalCameraDevice::TrampolineDeviceInterface_3_677 TrampolineDeviceInterface_3_6(sp<ExternalCameraDevice> parent) : 78 mParent(parent) {} 79 getResourceCostExternalCameraDevice::TrampolineDeviceInterface_3_680 virtual Return<void> getResourceCost(V3_2::ICameraDevice::getResourceCost_cb _hidl_cb) 81 override { 82 return mParent->getResourceCost(_hidl_cb); 83 } 84 getCameraCharacteristicsExternalCameraDevice::TrampolineDeviceInterface_3_685 virtual Return<void> getCameraCharacteristics( 86 V3_2::ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override { 87 return mParent->getCameraCharacteristics(_hidl_cb); 88 } 89 setTorchModeExternalCameraDevice::TrampolineDeviceInterface_3_690 virtual Return<Status> setTorchMode(TorchMode mode) override { 91 return mParent->setTorchMode(mode); 92 } 93 openExternalCameraDevice::TrampolineDeviceInterface_3_694 virtual Return<void> open(const sp<V3_2::ICameraDeviceCallback>& callback, 95 V3_2::ICameraDevice::open_cb _hidl_cb) override { 96 return mParent->open(callback, _hidl_cb); 97 } 98 dumpStateExternalCameraDevice::TrampolineDeviceInterface_3_699 virtual Return<void> dumpState(const hidl_handle& fd) override { 100 return mParent->dumpState(fd); 101 } 102 getPhysicalCameraCharacteristicsExternalCameraDevice::TrampolineDeviceInterface_3_6103 virtual Return<void> getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, 104 V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) override { 105 return mParent->getPhysicalCameraCharacteristics(physicalCameraId, _hidl_cb); 106 } 107 isStreamCombinationSupportedExternalCameraDevice::TrampolineDeviceInterface_3_6108 virtual Return<void> isStreamCombinationSupported( 109 const V3_4::StreamConfiguration& streams, 110 V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override { 111 return mParent->isStreamCombinationSupported(streams, _hidl_cb); 112 } 113 114 private: 115 sp<ExternalCameraDevice> mParent; 116 }; 117 }; 118 119 } // namespace implementation 120 } // namespace V3_6 121 } // namespace device 122 } // namespace camera 123 } // namespace hardware 124 } // namespace android 125 126 #endif // ANDROID_HARDWARE_CAMERA_DEVICE_V3_6_EXTCAMERADEVICE_H 127