Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 2 | * Copyright 2023 The Android Open Source Project |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 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" |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 25 | #include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h" |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 26 | #include "aidl/android/hardware/camera/device/BnCameraDevice.h" |
| 27 | |
| 28 | namespace android { |
| 29 | namespace companion { |
| 30 | namespace virtualcamera { |
| 31 | |
| 32 | // Representation of single virtual camera device, implements |
| 33 | // ICameraDevice AIDL to expose camera to camera framework. |
| 34 | class VirtualCameraDevice |
| 35 | : public ::aidl::android::hardware::camera::device::BnCameraDevice { |
| 36 | public: |
| 37 | explicit VirtualCameraDevice( |
| 38 | uint32_t cameraId, |
Biswarup Pal | 6152a30 | 2023-12-19 12:44:09 +0000 | [diff] [blame] | 39 | const aidl::android::companion::virtualcamera::VirtualCameraConfiguration& |
| 40 | configuration); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 41 | |
| 42 | virtual ~VirtualCameraDevice() override = default; |
| 43 | |
| 44 | ndk::ScopedAStatus getCameraCharacteristics( |
| 45 | ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return) |
| 46 | override; |
| 47 | |
| 48 | ndk::ScopedAStatus getPhysicalCameraCharacteristics( |
| 49 | const std::string& in_physicalCameraId, |
| 50 | ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return) |
| 51 | override; |
| 52 | |
| 53 | ndk::ScopedAStatus getResourceCost( |
| 54 | ::aidl::android::hardware::camera::common::CameraResourceCost* |
| 55 | _aidl_return) override; |
| 56 | |
| 57 | ndk::ScopedAStatus isStreamCombinationSupported( |
| 58 | const ::aidl::android::hardware::camera::device::StreamConfiguration& |
| 59 | in_streams, |
| 60 | bool* _aidl_return) override; |
| 61 | |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 62 | bool isStreamCombinationSupported( |
| 63 | const ::aidl::android::hardware::camera::device::StreamConfiguration& |
| 64 | in_streams) const; |
| 65 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 66 | ndk::ScopedAStatus open( |
| 67 | const std::shared_ptr< |
| 68 | ::aidl::android::hardware::camera::device::ICameraDeviceCallback>& |
| 69 | in_callback, |
| 70 | std::shared_ptr< |
| 71 | ::aidl::android::hardware::camera::device::ICameraDeviceSession>* |
| 72 | _aidl_return) override; |
| 73 | |
| 74 | ndk::ScopedAStatus openInjectionSession( |
| 75 | const std::shared_ptr< |
| 76 | ::aidl::android::hardware::camera::device::ICameraDeviceCallback>& |
| 77 | in_callback, |
| 78 | std::shared_ptr< |
| 79 | ::aidl::android::hardware::camera::device::ICameraInjectionSession>* |
| 80 | _aidl_return) override; |
| 81 | |
| 82 | ndk::ScopedAStatus setTorchMode(bool in_on) override; |
| 83 | |
| 84 | ndk::ScopedAStatus turnOnTorchWithStrengthLevel( |
| 85 | int32_t in_torchStrength) override; |
| 86 | |
| 87 | ndk::ScopedAStatus getTorchStrengthLevel(int32_t* _aidl_return) override; |
| 88 | |
| 89 | binder_status_t dump(int fd, const char** args, uint32_t numArgs) override; |
| 90 | |
| 91 | // Returns unique virtual camera name in form |
| 92 | // "device@{major}.{minor}/virtual/{numerical_id}" |
| 93 | std::string getCameraName() const; |
| 94 | |
Biswarup Pal | 68137fc | 2023-11-24 18:06:54 +0000 | [diff] [blame] | 95 | uint32_t getCameraId() const { return mCameraId; } |
| 96 | |
Jan Sebechlebsky | c3e1a63 | 2024-02-06 14:19:05 +0100 | [diff] [blame^] | 97 | const std::vector< |
| 98 | aidl::android::companion::virtualcamera::SupportedStreamConfiguration>& |
| 99 | getInputConfigs() const; |
| 100 | |
Jan Sebechlebsky | 8ae2359 | 2024-02-02 16:08:18 +0100 | [diff] [blame] | 101 | // Maximal number of RAW streams - virtual camera doesn't support RAW streams. |
| 102 | static const int32_t kMaxNumberOfRawStreams = 0; |
| 103 | |
| 104 | // Maximal number of non-jpeg streams configured concurrently in single |
| 105 | // session. This should be at least 3 and can be increased at the potential |
| 106 | // cost of more CPU/GPU load if there are many concurrent streams. |
| 107 | static const int32_t kMaxNumberOfProcessedStreams = 3; |
| 108 | |
| 109 | // Maximal number of stalling (in case of virtual camera only jpeg for now) |
| 110 | // streams. Can be increaed at the cost of potential cost of more GPU/CPU |
| 111 | // load. |
| 112 | static const int32_t kMaxNumberOfStallStreams = 1; |
| 113 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 114 | private: |
Jan Sebechlebsky | 0bb5e09 | 2023-12-08 16:17:54 +0100 | [diff] [blame] | 115 | std::shared_ptr<VirtualCameraDevice> sharedFromThis(); |
| 116 | |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 117 | const uint32_t mCameraId; |
| 118 | const std::shared_ptr< |
| 119 | ::aidl::android::companion::virtualcamera::IVirtualCameraCallback> |
| 120 | mVirtualCameraClientCallback; |
| 121 | |
| 122 | ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics; |
Jan Sebechlebsky | 3b478c4 | 2023-11-23 13:15:56 +0100 | [diff] [blame] | 123 | |
| 124 | const std::vector< |
| 125 | aidl::android::companion::virtualcamera::SupportedStreamConfiguration> |
| 126 | mSupportedInputConfigurations; |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } // namespace virtualcamera |
| 130 | } // namespace companion |
| 131 | } // namespace android |
| 132 | |
| 133 | #endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H |