blob: 53dcc4d46c6d218569f336e4b2f74b9dc2e94c53 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
Biswarup Pal6152a302023-12-19 12:44:09 +00002 * Copyright 2023 The Android Open Source Project
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01003 *
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 Sebechlebsky3b478c42023-11-23 13:15:56 +010024#include "aidl/android/companion/virtualcamera/SupportedStreamConfiguration.h"
Biswarup Pal6152a302023-12-19 12:44:09 +000025#include "aidl/android/companion/virtualcamera/VirtualCameraConfiguration.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010026#include "aidl/android/hardware/camera/device/BnCameraDevice.h"
Vadim Caen11dfd932024-03-05 09:57:20 +010027#include "system/camera_metadata.h"
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +010028#include "util/Util.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010029
30namespace android {
31namespace companion {
32namespace virtualcamera {
33
34// Representation of single virtual camera device, implements
35// ICameraDevice AIDL to expose camera to camera framework.
36class VirtualCameraDevice
37 : public ::aidl::android::hardware::camera::device::BnCameraDevice {
38 public:
39 explicit VirtualCameraDevice(
40 uint32_t cameraId,
Biswarup Pal6152a302023-12-19 12:44:09 +000041 const aidl::android::companion::virtualcamera::VirtualCameraConfiguration&
Biswarup Pal37a75182024-01-16 15:53:35 +000042 configuration,
43 int32_t deviceId);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010044
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 Sebechlebsky3b478c42023-11-23 13:15:56 +010065 bool isStreamCombinationSupported(
66 const ::aidl::android::hardware::camera::device::StreamConfiguration&
67 in_streams) const;
68
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010069 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 Pal68137fc2023-11-24 18:06:54 +000098 uint32_t getCameraId() const { return mCameraId; }
99
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100100 const std::vector<
101 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>&
102 getInputConfigs() const;
103
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +0100104 // Returns largest supported input resolution.
105 Resolution getMaxInputResolution() const;
106
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100107 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100108 static constexpr int32_t kMaxNumberOfRawStreams = 0;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100109
110 // Maximal number of non-jpeg streams configured concurrently in single
111 // session. This should be at least 3 and can be increased at the potential
112 // cost of more CPU/GPU load if there are many concurrent streams.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100113 static constexpr int32_t kMaxNumberOfProcessedStreams = 3;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100114
115 // Maximal number of stalling (in case of virtual camera only jpeg for now)
116 // streams. Can be increaed at the cost of potential cost of more GPU/CPU
117 // load.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100118 static constexpr int32_t kMaxNumberOfStallStreams = 1;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100119
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000120 // Focal length for full frame sensor.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100121 static constexpr float kFocalLength = 43.0;
122
123 // Default JPEG compression quality.
124 static constexpr uint8_t kDefaultJpegQuality = 80;
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000125
Vadim Caenc0aff132024-03-12 17:20:07 +0100126 // Default JPEG orientation.
127 static constexpr uint8_t kDefaultJpegOrientation = 0;
128
Jan Sebechlebsky15a0a3b2024-05-29 13:05:25 +0200129 // Lowest min fps advertised in supported fps ranges.
130 static constexpr int kMinFps = 1;
Jan Sebechlebskyb8282672024-05-22 10:43:37 +0200131
Vadim Caenc0aff132024-03-12 17:20:07 +0100132 // Default Make and Model for Exif
133 static constexpr char kDefaultMakeAndModel[] = "Android Virtual Camera";
134
Vadim Caen11dfd932024-03-05 09:57:20 +0100135 static constexpr camera_metadata_enum_android_control_capture_intent_t
136 kDefaultCaptureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
137
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100138 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100139 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
140
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100141 const uint32_t mCameraId;
142 const std::shared_ptr<
143 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
144 mVirtualCameraClientCallback;
145
146 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100147
148 const std::vector<
149 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
150 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100151};
152
153} // namespace virtualcamera
154} // namespace companion
155} // namespace android
156
157#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H