blob: 720f02e215be234958f63b0bb820f8883ce0a310 [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"
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +010027#include "util/Util.h"
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010028
29namespace android {
30namespace companion {
31namespace virtualcamera {
32
33// Representation of single virtual camera device, implements
34// ICameraDevice AIDL to expose camera to camera framework.
35class VirtualCameraDevice
36 : public ::aidl::android::hardware::camera::device::BnCameraDevice {
37 public:
38 explicit VirtualCameraDevice(
39 uint32_t cameraId,
Biswarup Pal6152a302023-12-19 12:44:09 +000040 const aidl::android::companion::virtualcamera::VirtualCameraConfiguration&
41 configuration);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010042
43 virtual ~VirtualCameraDevice() override = default;
44
45 ndk::ScopedAStatus getCameraCharacteristics(
46 ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return)
47 override;
48
49 ndk::ScopedAStatus getPhysicalCameraCharacteristics(
50 const std::string& in_physicalCameraId,
51 ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return)
52 override;
53
54 ndk::ScopedAStatus getResourceCost(
55 ::aidl::android::hardware::camera::common::CameraResourceCost*
56 _aidl_return) override;
57
58 ndk::ScopedAStatus isStreamCombinationSupported(
59 const ::aidl::android::hardware::camera::device::StreamConfiguration&
60 in_streams,
61 bool* _aidl_return) override;
62
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010063 bool isStreamCombinationSupported(
64 const ::aidl::android::hardware::camera::device::StreamConfiguration&
65 in_streams) const;
66
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010067 ndk::ScopedAStatus open(
68 const std::shared_ptr<
69 ::aidl::android::hardware::camera::device::ICameraDeviceCallback>&
70 in_callback,
71 std::shared_ptr<
72 ::aidl::android::hardware::camera::device::ICameraDeviceSession>*
73 _aidl_return) override;
74
75 ndk::ScopedAStatus openInjectionSession(
76 const std::shared_ptr<
77 ::aidl::android::hardware::camera::device::ICameraDeviceCallback>&
78 in_callback,
79 std::shared_ptr<
80 ::aidl::android::hardware::camera::device::ICameraInjectionSession>*
81 _aidl_return) override;
82
83 ndk::ScopedAStatus setTorchMode(bool in_on) override;
84
85 ndk::ScopedAStatus turnOnTorchWithStrengthLevel(
86 int32_t in_torchStrength) override;
87
88 ndk::ScopedAStatus getTorchStrengthLevel(int32_t* _aidl_return) override;
89
90 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
91
92 // Returns unique virtual camera name in form
93 // "device@{major}.{minor}/virtual/{numerical_id}"
94 std::string getCameraName() const;
95
Biswarup Pal68137fc2023-11-24 18:06:54 +000096 uint32_t getCameraId() const { return mCameraId; }
97
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010098 const std::vector<
99 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>&
100 getInputConfigs() const;
101
Jan Sebechlebskybb01c1d2024-02-12 11:41:37 +0100102 // Returns largest supported input resolution.
103 Resolution getMaxInputResolution() const;
104
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100105 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
106 static const int32_t kMaxNumberOfRawStreams = 0;
107
108 // Maximal number of non-jpeg streams configured concurrently in single
109 // session. This should be at least 3 and can be increased at the potential
110 // cost of more CPU/GPU load if there are many concurrent streams.
111 static const int32_t kMaxNumberOfProcessedStreams = 3;
112
113 // Maximal number of stalling (in case of virtual camera only jpeg for now)
114 // streams. Can be increaed at the cost of potential cost of more GPU/CPU
115 // load.
116 static const int32_t kMaxNumberOfStallStreams = 1;
117
Biswarup Pal8ad8bc52024-02-08 13:41:44 +0000118 // Focal length for full frame sensor.
119 constexpr static const float kFocalLength = 43.0;
120
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100121 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100122 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
123
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100124 const uint32_t mCameraId;
125 const std::shared_ptr<
126 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
127 mVirtualCameraClientCallback;
128
129 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100130
131 const std::vector<
132 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
133 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100134};
135
136} // namespace virtualcamera
137} // namespace companion
138} // namespace android
139
140#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H