1 /* 2 * Copyright (C) 2019 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 HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_ 18 #define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_ 19 20 #include <android/hardware/camera/provider/2.6/ICameraProviderCallback.h> 21 #include <android/hardware/camera/provider/2.7/ICameraProvider.h> 22 #include <regex> 23 #include "camera_provider.h" 24 25 namespace android { 26 namespace hardware { 27 namespace camera { 28 namespace provider { 29 namespace V2_7 { 30 namespace implementation { 31 32 using ::android::sp; 33 using ::android::hardware::hidl_string; 34 using ::android::hardware::hidl_vec; 35 using ::android::hardware::Return; 36 using ::android::hardware::camera::common::V1_0::Status; 37 using ::android::hardware::camera::provider::V2_4::ICameraProviderCallback; 38 using ::android::hardware::camera::provider::V2_5::DeviceState; 39 using ::android::hardware::camera::provider::V2_7::CameraIdAndStreamCombination; 40 using ::android::hardware::camera::provider::V2_7::ICameraProvider; 41 42 using ::android::google_camera_hal::CameraProvider; 43 44 // HidlCameraProvider implements the HIDL camera provider interface, 45 // ICameraProvider, to enumerate the available individual camera devices 46 // in the system, and provide updates about changes to device status. 47 class HidlCameraProvider : public ICameraProvider { 48 public: 49 static const std::string kProviderName; 50 static android::sp<HidlCameraProvider> Create(); 51 virtual ~HidlCameraProvider() = default; 52 53 // Override functions in ICameraProvider. 54 Return<Status> setCallback( 55 const sp<ICameraProviderCallback>& callback) override; 56 57 Return<void> getVendorTags(getVendorTags_cb _hidl_cb) override; 58 59 Return<void> getCameraIdList(getCameraIdList_cb _hidl_cb) override; 60 61 Return<void> isSetTorchModeSupported( 62 isSetTorchModeSupported_cb _hidl_cb) override; 63 64 Return<void> getConcurrentStreamingCameraIds( 65 getConcurrentStreamingCameraIds_cb _hidl_cb) override; 66 67 Return<void> isConcurrentStreamCombinationSupported( 68 const hidl_vec<V2_6::CameraIdAndStreamCombination>& configs, 69 isConcurrentStreamCombinationSupported_cb _hidl_cb) override; 70 71 Return<void> isConcurrentStreamCombinationSupported_2_7( 72 const hidl_vec<CameraIdAndStreamCombination>& configs, 73 isConcurrentStreamCombinationSupported_cb _hidl_cb) override; 74 75 Return<void> getCameraDeviceInterface_V1_x( 76 const hidl_string& cameraDeviceName, 77 getCameraDeviceInterface_V1_x_cb _hidl_cb) override; 78 79 Return<void> getCameraDeviceInterface_V3_x( 80 const hidl_string& cameraDeviceName, 81 getCameraDeviceInterface_V3_x_cb _hidl_cb) override; 82 83 Return<void> notifyDeviceStateChange( 84 hardware::hidl_bitfield<DeviceState> newState) override; 85 // End of override functions in ICameraProvider. 86 87 protected: 88 HidlCameraProvider() = default; 89 90 private: 91 static const std::regex kDeviceNameRegex; 92 93 status_t Initialize(); 94 95 // Parse device version and camera ID. 96 bool ParseDeviceName(const hidl_string& device_name, 97 std::string* device_version, std::string* camera_id); 98 99 std::mutex callbacks_lock_; 100 sp<ICameraProviderCallback> callbacks_; 101 102 std::unique_ptr<CameraProvider> google_camera_provider_; 103 google_camera_hal::CameraProviderCallback camera_provider_callback_; 104 }; 105 106 } // namespace implementation 107 } // namespace V2_7 108 } // namespace provider 109 } // namespace camera 110 } // namespace hardware 111 } // namespace android 112 113 #endif // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_CAMERA_PROVIDER_H_ 114