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