Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H |
| 18 | #define ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H |
| 19 | |
| 20 | #include <cstdint> |
| 21 | #include <memory> |
| 22 | |
| 23 | #include "aidl/android/companion/virtualcamera/IVirtualCameraCallback.h" |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 24 | #include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 25 | #include "aidl/android/hardware/camera/device/BnCameraDevice.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace companion { |
| 29 | namespace virtualcamera { |
| 30 | |
| 31 | // Representation of single virtual camera device, implements |
| 32 | // ICameraDevice AIDL to expose camera to camera framework. |
| 33 | class VirtualCameraDevice |
| 34 | : public ::aidl::android::hardware::camera::device::BnCameraDevice { |
| 35 | public: |
| 36 | explicit VirtualCameraDevice( |
| 37 | uint32_t cameraId, |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 38 | const std::vector< |
| 39 | aidl::android::companion::virtualcamera::SupportedStreamConfiguration>& |
| 40 | supportedInputConfig, |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 41 | std::shared_ptr< |
| 42 | ::aidl::android::companion::virtualcamera::IVirtualCameraCallback> |
| 43 | virtualCameraClientCallback = nullptr); |
| 44 | |
| 45 | virtual ~VirtualCameraDevice() override = default; |
| 46 | |
| 47 | ndk::ScopedAStatus getCameraCharacteristics( |
| 48 | ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return) |
| 49 | override; |
| 50 | |
| 51 | ndk::ScopedAStatus getPhysicalCameraCharacteristics( |
| 52 | const std::string& in_physicalCameraId, |
| 53 | ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return) |
| 54 | override; |
| 55 | |
| 56 | ndk::ScopedAStatus getResourceCost( |
| 57 | ::aidl::android::hardware::camera::common::CameraResourceCost* |
| 58 | _aidl_return) override; |
| 59 | |
| 60 | ndk::ScopedAStatus isStreamCombinationSupported( |
| 61 | const ::aidl::android::hardware::camera::device::StreamConfiguration& |
| 62 | in_streams, |
| 63 | bool* _aidl_return) override; |
| 64 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 65 | bool isStreamCombinationSupported( |
| 66 | const ::aidl::android::hardware::camera::device::StreamConfiguration& |
| 67 | in_streams) const; |
| 68 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 69 | ndk::ScopedAStatus open( |
| 70 | const std::shared_ptr< |
| 71 | ::aidl::android::hardware::camera::device::ICameraDeviceCallback>& |
| 72 | in_callback, |
| 73 | std::shared_ptr< |
| 74 | ::aidl::android::hardware::camera::device::ICameraDeviceSession>* |
| 75 | _aidl_return) override; |
| 76 | |
| 77 | ndk::ScopedAStatus openInjectionSession( |
| 78 | const std::shared_ptr< |
| 79 | ::aidl::android::hardware::camera::device::ICameraDeviceCallback>& |
| 80 | in_callback, |
| 81 | std::shared_ptr< |
| 82 | ::aidl::android::hardware::camera::device::ICameraInjectionSession>* |
| 83 | _aidl_return) override; |
| 84 | |
| 85 | ndk::ScopedAStatus setTorchMode(bool in_on) override; |
| 86 | |
| 87 | ndk::ScopedAStatus turnOnTorchWithStrengthLevel( |
| 88 | int32_t in_torchStrength) override; |
| 89 | |
| 90 | ndk::ScopedAStatus getTorchStrengthLevel(int32_t* _aidl_return) override; |
| 91 | |
| 92 | binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; |
| 93 | |
| 94 | // Returns unique virtual camera name in form |
| 95 | // "device@{major}.{minor}/virtual/{numerical_id}" |
| 96 | std::string getCameraName() const; |
| 97 | |
Biswarup Pal | 68137fc | 2023-11-24 18:06:54 +0000 | [diff] [blame] | 98 | uint32_t getCameraId() const { return mCameraId; } |
| 99 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 100 | private: |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame^] | 101 | std::shared_ptr<VirtualCameraDevice> sharedFromThis(); |
| 102 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 103 | const uint32_t mCameraId; |
| 104 | const std::shared_ptr< |
| 105 | ::aidl::android::companion::virtualcamera::IVirtualCameraCallback> |
| 106 | mVirtualCameraClientCallback; |
| 107 | |
| 108 | ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 109 | |
| 110 | const std::vector< |
| 111 | aidl::android::companion::virtualcamera::SupportedStreamConfiguration> |
| 112 | mSupportedInputConfigurations; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | } // namespace virtualcamera |
| 116 | } // namespace companion |
| 117 | } // namespace android |
| 118 | |
| 119 | #endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H |