blob: c13dcbd93933bfe5c885e0d207a83938027dcc2f [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(
Biswarup Pal15dcd132024-06-02 14:02:03 +000040 const std::string& 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
Biswarup Pal15dcd132024-06-02 14:02:03 +000095 // "device@{major}.{minor}/virtual/{camera_id}"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010096 std::string getCameraName() const;
97
Biswarup Pal15dcd132024-06-02 14:02:03 +000098 const std::string& getCameraId() const {
99 return mCameraId;
100 }
Biswarup Pal68137fc2023-11-24 18:06:54 +0000101
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +0100102 const std::vector<
103 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>&
104 getInputConfigs() const;
105
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +0100106 // Returns largest supported input resolution.
107 Resolution getMaxInputResolution() const;
108
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100109 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100110 static constexpr int32_t kMaxNumberOfRawStreams = 0;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100111
112 // Maximal number of non-jpeg streams configured concurrently in single
113 // session. This should be at least 3 and can be increased at the potential
114 // cost of more CPU/GPU load if there are many concurrent streams.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100115 static constexpr int32_t kMaxNumberOfProcessedStreams = 3;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100116
117 // Maximal number of stalling (in case of virtual camera only jpeg for now)
118 // streams. Can be increaed at the cost of potential cost of more GPU/CPU
119 // load.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100120 static constexpr int32_t kMaxNumberOfStallStreams = 1;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100121
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000122 // Focal length for full frame sensor.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100123 static constexpr float kFocalLength = 43.0;
124
125 // Default JPEG compression quality.
126 static constexpr uint8_t kDefaultJpegQuality = 80;
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000127
Vadim Caenc0aff132024-03-12 17:20:07 +0100128 // Default JPEG orientation.
129 static constexpr uint8_t kDefaultJpegOrientation = 0;
130
Jan Sebechlebsky15a0a3b2024-05-29 13:05:25 +0200131 // Lowest min fps advertised in supported fps ranges.
132 static constexpr int kMinFps = 1;
Jan Sebechlebskyb8282672024-05-22 10:43:37 +0200133
Vadim Caenc0aff132024-03-12 17:20:07 +0100134 // Default Make and Model for Exif
135 static constexpr char kDefaultMakeAndModel[] = "Android Virtual Camera";
136
Vadim Caen11dfd932024-03-05 09:57:20 +0100137 static constexpr camera_metadata_enum_android_control_capture_intent_t
138 kDefaultCaptureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
139
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100140 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100141 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
142
Biswarup Pal15dcd132024-06-02 14:02:03 +0000143 const std::string mCameraId;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100144 const std::shared_ptr<
145 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
146 mVirtualCameraClientCallback;
147
148 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100149
150 const std::vector<
151 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
152 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100153};
154
155} // namespace virtualcamera
156} // namespace companion
157} // namespace android
158
159#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H