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_5_EXTCAMERADEVICE_H 18 #define ANDROID_HARDWARE_CAMERA_DEVICE_V3_5_EXTCAMERADEVICE_H 19 20 #include "utils/Mutex.h" 21 #include "CameraMetadata.h" 22 23 #include <android/hardware/camera/device/3.5/ICameraDevice.h> 24 #include <android/hardware/camera/device/3.5/ICameraDeviceCallback.h> 25 #include <hidl/Status.h> 26 #include <hidl/MQDescriptor.h> 27 #include "ExternalCameraDeviceSession.h" 28 #include <../../../../3.4/default/include/ext_device_v3_4_impl/ExternalCameraDevice_3_4.h> 29 30 namespace android { 31 namespace hardware { 32 namespace camera { 33 namespace device { 34 namespace V3_5 { 35 namespace implementation { 36 37 using namespace ::android::hardware::camera::device; 38 using ::android::hardware::camera::device::V3_5::ICameraDevice; 39 using ::android::hardware::camera::common::V1_0::CameraResourceCost; 40 using ::android::hardware::camera::common::V1_0::TorchMode; 41 using ::android::hardware::camera::common::V1_0::Status; 42 using ::android::hardware::camera::external::common::ExternalCameraConfig; 43 using ::android::hardware::camera::external::common::Size; 44 using ::android::hardware::Return; 45 using ::android::hardware::Void; 46 using ::android::hardware::hidl_vec; 47 using ::android::hardware::hidl_string; 48 using ::android::sp; 49 50 /* 51 * The camera device HAL implementation is opened lazily (via the open call) 52 */ 53 struct ExternalCameraDevice : public V3_4::implementation::ExternalCameraDevice { 54 55 // Called by external camera provider HAL. 56 // Provider HAL must ensure the uniqueness of CameraDevice object per cameraId, or there could 57 // be multiple CameraDevice trying to access the same physical camera. Also, provider will have 58 // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying 59 // camera is detached. 60 ExternalCameraDevice(const std::string& cameraId, const ExternalCameraConfig& cfg); 61 virtual ~ExternalCameraDevice(); 62 getInterfaceExternalCameraDevice63 virtual sp<V3_2::ICameraDevice> getInterface() override { 64 return new TrampolineDeviceInterface_3_5(this); 65 } 66 67 Return<void> getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, 68 V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb); 69 70 Return<void> isStreamCombinationSupported( 71 const V3_4::StreamConfiguration& streams, 72 V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb); 73 74 protected: 75 virtual sp<V3_4::implementation::ExternalCameraDeviceSession> createSession( 76 const sp<V3_2::ICameraDeviceCallback>&, 77 const ExternalCameraConfig& cfg, 78 const std::vector<SupportedV4L2Format>& sortedFormats, 79 const CroppingType& croppingType, 80 const common::V1_0::helper::CameraMetadata& chars, 81 const std::string& cameraId, 82 unique_fd v4l2Fd) override; 83 84 virtual status_t initDefaultCharsKeys( 85 ::android::hardware::camera::common::V1_0::helper::CameraMetadata*) override; 86 87 const std::vector<int32_t> EXTRA_CHARACTERISTICS_KEYS_3_5 = { 88 ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION 89 }; 90 91 private: 92 struct TrampolineDeviceInterface_3_5 : public ICameraDevice { TrampolineDeviceInterface_3_5ExternalCameraDevice::TrampolineDeviceInterface_3_593 TrampolineDeviceInterface_3_5(sp<ExternalCameraDevice> parent) : 94 mParent(parent) {} 95 getResourceCostExternalCameraDevice::TrampolineDeviceInterface_3_596 virtual Return<void> getResourceCost(V3_2::ICameraDevice::getResourceCost_cb _hidl_cb) 97 override { 98 return mParent->getResourceCost(_hidl_cb); 99 } 100 getCameraCharacteristicsExternalCameraDevice::TrampolineDeviceInterface_3_5101 virtual Return<void> getCameraCharacteristics( 102 V3_2::ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override { 103 return mParent->getCameraCharacteristics(_hidl_cb); 104 } 105 setTorchModeExternalCameraDevice::TrampolineDeviceInterface_3_5106 virtual Return<Status> setTorchMode(TorchMode mode) override { 107 return mParent->setTorchMode(mode); 108 } 109 openExternalCameraDevice::TrampolineDeviceInterface_3_5110 virtual Return<void> open(const sp<V3_2::ICameraDeviceCallback>& callback, 111 V3_2::ICameraDevice::open_cb _hidl_cb) override { 112 return mParent->open(callback, _hidl_cb); 113 } 114 dumpStateExternalCameraDevice::TrampolineDeviceInterface_3_5115 virtual Return<void> dumpState(const hidl_handle& fd) override { 116 return mParent->dumpState(fd); 117 } 118 getPhysicalCameraCharacteristicsExternalCameraDevice::TrampolineDeviceInterface_3_5119 virtual Return<void> getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, 120 V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) override { 121 return mParent->getPhysicalCameraCharacteristics(physicalCameraId, _hidl_cb); 122 } 123 isStreamCombinationSupportedExternalCameraDevice::TrampolineDeviceInterface_3_5124 virtual Return<void> isStreamCombinationSupported( 125 const V3_4::StreamConfiguration& streams, 126 V3_5::ICameraDevice::isStreamCombinationSupported_cb _hidl_cb) override { 127 return mParent->isStreamCombinationSupported(streams, _hidl_cb); 128 } 129 130 private: 131 sp<ExternalCameraDevice> mParent; 132 }; 133 }; 134 135 } // namespace implementation 136 } // namespace V3_5 137 } // namespace device 138 } // namespace camera 139 } // namespace hardware 140 } // namespace android 141 142 #endif // ANDROID_HARDWARE_CAMERA_DEVICE_V3_5_EXTCAMERADEVICE_H 143