blob: 32bdd13e6331dd82f44086d2a2c426648b42a84c [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"
27
28namespace android {
29namespace companion {
30namespace virtualcamera {
31
32// Representation of single virtual camera device, implements
33// ICameraDevice AIDL to expose camera to camera framework.
34class VirtualCameraDevice
35 : public ::aidl::android::hardware::camera::device::BnCameraDevice {
36 public:
37 explicit VirtualCameraDevice(
38 uint32_t cameraId,
Biswarup Pal6152a302023-12-19 12:44:09 +000039 const aidl::android::companion::virtualcamera::VirtualCameraConfiguration&
40 configuration);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010041
42 virtual ~VirtualCameraDevice() override = default;
43
44 ndk::ScopedAStatus getCameraCharacteristics(
45 ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return)
46 override;
47
48 ndk::ScopedAStatus getPhysicalCameraCharacteristics(
49 const std::string& in_physicalCameraId,
50 ::aidl::android::hardware::camera::device::CameraMetadata* _aidl_return)
51 override;
52
53 ndk::ScopedAStatus getResourceCost(
54 ::aidl::android::hardware::camera::common::CameraResourceCost*
55 _aidl_return) override;
56
57 ndk::ScopedAStatus isStreamCombinationSupported(
58 const ::aidl::android::hardware::camera::device::StreamConfiguration&
59 in_streams,
60 bool* _aidl_return) override;
61
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +010062 bool isStreamCombinationSupported(
63 const ::aidl::android::hardware::camera::device::StreamConfiguration&
64 in_streams) const;
65
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010066 ndk::ScopedAStatus open(
67 const std::shared_ptr<
68 ::aidl::android::hardware::camera::device::ICameraDeviceCallback>&
69 in_callback,
70 std::shared_ptr<
71 ::aidl::android::hardware::camera::device::ICameraDeviceSession>*
72 _aidl_return) override;
73
74 ndk::ScopedAStatus openInjectionSession(
75 const std::shared_ptr<
76 ::aidl::android::hardware::camera::device::ICameraDeviceCallback>&
77 in_callback,
78 std::shared_ptr<
79 ::aidl::android::hardware::camera::device::ICameraInjectionSession>*
80 _aidl_return) override;
81
82 ndk::ScopedAStatus setTorchMode(bool in_on) override;
83
84 ndk::ScopedAStatus turnOnTorchWithStrengthLevel(
85 int32_t in_torchStrength) override;
86
87 ndk::ScopedAStatus getTorchStrengthLevel(int32_t* _aidl_return) override;
88
89 binder_status_t dump(int fd, const char** args, uint32_t numArgs) override;
90
91 // Returns unique virtual camera name in form
92 // "device@{major}.{minor}/virtual/{numerical_id}"
93 std::string getCameraName() const;
94
Biswarup Pal68137fc2023-11-24 18:06:54 +000095 uint32_t getCameraId() const { return mCameraId; }
96
Jan Sebechlebskyc3e1a632024-02-06 14:19:05 +010097 const std::vector<
98 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>&
99 getInputConfigs() const;
100
Jan Sebechlebsky8ae23592024-02-02 16:08:18 +0100101 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
102 static const int32_t kMaxNumberOfRawStreams = 0;
103
104 // Maximal number of non-jpeg streams configured concurrently in single
105 // session. This should be at least 3 and can be increased at the potential
106 // cost of more CPU/GPU load if there are many concurrent streams.
107 static const int32_t kMaxNumberOfProcessedStreams = 3;
108
109 // Maximal number of stalling (in case of virtual camera only jpeg for now)
110 // streams. Can be increaed at the cost of potential cost of more GPU/CPU
111 // load.
112 static const int32_t kMaxNumberOfStallStreams = 1;
113
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100114 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100115 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
116
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100117 const uint32_t mCameraId;
118 const std::shared_ptr<
119 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
120 mVirtualCameraClientCallback;
121
122 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100123
124 const std::vector<
125 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
126 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100127};
128
129} // namespace virtualcamera
130} // namespace companion
131} // namespace android
132
133#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H