blob: 370062590f40ab76e812da49700bd8346ae96fee [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 Sebechlebsky8ae23592024-02-02 16:08:18 +010097 // Maximal number of RAW streams - virtual camera doesn't support RAW streams.
98 static const int32_t kMaxNumberOfRawStreams = 0;
99
100 // Maximal number of non-jpeg streams configured concurrently in single
101 // session. This should be at least 3 and can be increased at the potential
102 // cost of more CPU/GPU load if there are many concurrent streams.
103 static const int32_t kMaxNumberOfProcessedStreams = 3;
104
105 // Maximal number of stalling (in case of virtual camera only jpeg for now)
106 // streams. Can be increaed at the cost of potential cost of more GPU/CPU
107 // load.
108 static const int32_t kMaxNumberOfStallStreams = 1;
109
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100110 private:
Jan Sebechlebsky0bb5e092023-12-08 16:17:54 +0100111 std::shared_ptr<VirtualCameraDevice> sharedFromThis();
112
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100113 const uint32_t mCameraId;
114 const std::shared_ptr<
115 ::aidl::android::companion::virtualcamera::IVirtualCameraCallback>
116 mVirtualCameraClientCallback;
117
118 ::aidl::android::hardware::camera::device::CameraMetadata mCameraCharacteristics;
Jan Sebechlebsky3b478c42023-11-23 13:15:56 +0100119
120 const std::vector<
121 aidl::android::companion::virtualcamera::SupportedStreamConfiguration>
122 mSupportedInputConfigurations;
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +0100123};
124
125} // namespace virtualcamera
126} // namespace companion
127} // namespace android
128
129#endif // ANDROID_COMPANION_VIRTUALCAMERA_VIRTUALCAMERADEVICE_H