blob: 4c50041cadefca12d091a86c53fc51b4f45a1422 [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&
42 configuration);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010043
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 Sebechlebsky3b478c42023-11-23 13:15:56 +010064 bool isStreamCombinationSupported(
65 const ::aidl::android::hardware::camera::device::StreamConfiguration&
66 in_streams) const;
67
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010068 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 Pal68137fc2023-11-24 18:06:54 +000097 uint32_t getCameraId() const { return mCameraId; }
98
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010099 const std::vector<
100 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>&
101 getInputConfigs() const;
102
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +0100103 // Returns largest supported input resolution.
104 Resolution getMaxInputResolution() const;
105
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100106 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100107 static constexpr int32_t kMaxNumberOfRawStreams = 0;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100108
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 Sebechlebsky4ce32082024-02-14 16:02:11 +0100112 static constexpr int32_t kMaxNumberOfProcessedStreams = 3;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100113
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 Sebechlebsky4ce32082024-02-14 16:02:11 +0100117 static constexpr int32_t kMaxNumberOfStallStreams = 1;
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100118
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000119 // Focal length for full frame sensor.
Jan Sebechlebsky4ce32082024-02-14 16:02:11 +0100120 static constexpr float kFocalLength = 43.0;
121
122 // Default JPEG compression quality.
123 static constexpr uint8_t kDefaultJpegQuality = 80;
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000124
Vadim Caen11dfd932024-03-05 09:57:20 +0100125 static constexpr camera_metadata_enum_android_control_capture_intent_t
126 kDefaultCaptureIntent = ANDROID_CONTROL_CAPTURE_INTENT_PREVIEW;
127
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100128 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100129 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
130
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100131 const uint32_t mCameraId;
132 const std::shared_ptr<
133 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
134 mVirtualCameraClientCallback;
135
136 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100137
138 const std::vector<
139 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
140 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100141};
142
143} // namespace virtualcamera
144} // namespace companion
145} // namespace android
146
147#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H