• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
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 CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_HIDLHWCAMERA_H
18 #define CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_HIDLHWCAMERA_H
19 
20 #include "HidlCameraStream.h"
21 
22 #include <aidl/android/hardware/automotive/evs/BnEvsCamera.h>
23 #include <aidl/android/hardware/automotive/evs/BufferDesc.h>
24 #include <aidl/android/hardware/automotive/evs/CameraDesc.h>
25 #include <aidl/android/hardware/automotive/evs/CameraParam.h>
26 #include <aidl/android/hardware/automotive/evs/EvsEventDesc.h>
27 #include <aidl/android/hardware/automotive/evs/EvsResult.h>
28 #include <aidl/android/hardware/automotive/evs/IEvsCameraStream.h>
29 #include <aidl/android/hardware/automotive/evs/IEvsDisplay.h>
30 #include <aidl/android/hardware/automotive/evs/ParameterRange.h>
31 #include <aidl/android/hardware/automotive/evs/Stream.h>
32 #include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
33 
34 #include <unordered_map>
35 
36 namespace aidl::android::automotive::evs::implementation {
37 
38 namespace aidlevs = ::aidl::android::hardware::automotive::evs;
39 namespace hidlevs = ::android::hardware::automotive::evs;
40 
41 class AidlCamera : public ::aidl::android::hardware::automotive::evs::BnEvsCamera {
42 public:
43     // Methods from ::android::hardware::automotive::evs::IEvsCamera follow.
44     ::ndk::ScopedAStatus doneWithFrame(const std::vector<aidlevs::BufferDesc>& buffers) override;
45     ::ndk::ScopedAStatus forcePrimaryClient(
46             const std::shared_ptr<aidlevs::IEvsDisplay>& display) override;
47     ::ndk::ScopedAStatus getCameraInfo(aidlevs::CameraDesc* _aidl_return) override;
48     ::ndk::ScopedAStatus getExtendedInfo(int32_t opaqueIdentifier,
49                                          std::vector<uint8_t>* value) override;
50     ::ndk::ScopedAStatus getIntParameter(aidlevs::CameraParam id,
51                                          std::vector<int32_t>* value) override;
52     ::ndk::ScopedAStatus getIntParameterRange(aidlevs::CameraParam id,
53                                               aidlevs::ParameterRange* _aidl_return) override;
54     ::ndk::ScopedAStatus getParameterList(std::vector<aidlevs::CameraParam>* _aidl_return) override;
55     ::ndk::ScopedAStatus getPhysicalCameraInfo(const std::string& deviceId,
56                                                aidlevs::CameraDesc* _aidl_return) override;
57     ::ndk::ScopedAStatus importExternalBuffers(const std::vector<aidlevs::BufferDesc>& buffers,
58                                                int32_t* _aidl_return) override;
59     ::ndk::ScopedAStatus pauseVideoStream() override;
60     ::ndk::ScopedAStatus resumeVideoStream() override;
61     ::ndk::ScopedAStatus setExtendedInfo(int32_t opaqueIdentifier,
62                                          const std::vector<uint8_t>& opaqueValue) override;
63     ::ndk::ScopedAStatus setIntParameter(aidlevs::CameraParam id, int32_t value,
64                                          std::vector<int32_t>* effectiveValue) override;
65     ::ndk::ScopedAStatus setPrimaryClient() override;
66     ::ndk::ScopedAStatus setMaxFramesInFlight(int32_t bufferCount) override;
67     ::ndk::ScopedAStatus startVideoStream(
68             const std::shared_ptr<aidlevs::IEvsCameraStream>& receiver) override;
69     ::ndk::ScopedAStatus stopVideoStream() override;
70     ::ndk::ScopedAStatus unsetPrimaryClient() override;
71 
72     explicit AidlCamera(const ::android::sp<hidlevs::V1_0::IEvsCamera>& camera);
~AidlCamera()73     virtual ~AidlCamera() { mImpl = nullptr; }
74 
75     const ::android::sp<hidlevs::V1_0::IEvsCamera> getHidlCamera() const;
76 
77 private:
78     class IHidlCamera;
79     class ImplV0;
80     class ImplV1;
81     std::shared_ptr<IHidlCamera> mImpl;
82 };
83 
84 class AidlCamera::IHidlCamera {
85 public:
86     virtual ::ndk::ScopedAStatus doneWithFrame(const std::vector<aidlevs::BufferDesc>& buffers) = 0;
87     virtual ::ndk::ScopedAStatus forcePrimaryClient(
88             const std::shared_ptr<aidlevs::IEvsDisplay>& display) = 0;
89     virtual ::ndk::ScopedAStatus getCameraInfo(aidlevs::CameraDesc* _aidl_return) = 0;
90     virtual ::ndk::ScopedAStatus getExtendedInfo(int32_t opaqueIdentifier,
91                                                  std::vector<uint8_t>* value) = 0;
92     virtual ::ndk::ScopedAStatus getIntParameter(aidlevs::CameraParam id,
93                                                  std::vector<int32_t>* value) = 0;
94     virtual ::ndk::ScopedAStatus getIntParameterRange(aidlevs::CameraParam id,
95                                                       aidlevs::ParameterRange* _aidl_return) = 0;
96     virtual ::ndk::ScopedAStatus getParameterList(
97             std::vector<aidlevs::CameraParam>* _aidl_return) = 0;
98     virtual ::ndk::ScopedAStatus getPhysicalCameraInfo(const std::string& deviceId,
99                                                        aidlevs::CameraDesc* _aidl_return) = 0;
100     virtual ::ndk::ScopedAStatus importExternalBuffers(
101             const std::vector<aidlevs::BufferDesc>& buffers, int32_t* _aidl_return) = 0;
102     virtual ::ndk::ScopedAStatus pauseVideoStream() = 0;
103     virtual ::ndk::ScopedAStatus resumeVideoStream() = 0;
104     virtual ::ndk::ScopedAStatus setExtendedInfo(int32_t opaqueIdentifier,
105                                                  const std::vector<uint8_t>& opaqueValue) = 0;
106     virtual ::ndk::ScopedAStatus setIntParameter(aidlevs::CameraParam id, int32_t value,
107                                                  std::vector<int32_t>* effectiveValue) = 0;
108     virtual ::ndk::ScopedAStatus setPrimaryClient() = 0;
109     virtual ::ndk::ScopedAStatus setMaxFramesInFlight(int32_t bufferCount) = 0;
110     virtual ::ndk::ScopedAStatus startVideoStream(
111             const std::shared_ptr<aidlevs::IEvsCameraStream>& receiver) = 0;
112     virtual ::ndk::ScopedAStatus stopVideoStream() = 0;
113     virtual ::ndk::ScopedAStatus unsetPrimaryClient() = 0;
114     virtual const ::android::sp<hidlevs::V1_0::IEvsCamera> getHidlCamera() const = 0;
115 
IHidlCamera(const::android::sp<hidlevs::V1_0::IEvsCamera> & camera)116     explicit IHidlCamera(const ::android::sp<hidlevs::V1_0::IEvsCamera>& camera) :
117           mHidlCamera(camera) {}
~IHidlCamera()118     virtual ~IHidlCamera() {
119         mHidlCamera = nullptr;
120         mHidlStream = nullptr;
121     }
122 
123 protected:
124     // The low level camera interface that backs this proxy
125     ::android::sp<hidlevs::V1_0::IEvsCamera> mHidlCamera;
126     ::android::sp<HidlCameraStream> mHidlStream;
127 };
128 
129 class AidlCamera::ImplV0 final : public IHidlCamera {
130 public:
131     ::ndk::ScopedAStatus doneWithFrame(const std::vector<aidlevs::BufferDesc>& buffers) override;
132     ::ndk::ScopedAStatus forcePrimaryClient(
133             const std::shared_ptr<aidlevs::IEvsDisplay>& display) override;
134     ::ndk::ScopedAStatus getCameraInfo(aidlevs::CameraDesc* _aidl_return) override;
135     ::ndk::ScopedAStatus getExtendedInfo(int32_t opaqueIdentifier,
136                                          std::vector<uint8_t>* value) override;
137     ::ndk::ScopedAStatus getIntParameter(aidlevs::CameraParam id,
138                                          std::vector<int32_t>* value) override;
139     ::ndk::ScopedAStatus getIntParameterRange(aidlevs::CameraParam id,
140                                               aidlevs::ParameterRange* _aidl_return) override;
141     ::ndk::ScopedAStatus getParameterList(std::vector<aidlevs::CameraParam>* _aidl_return) override;
142     ::ndk::ScopedAStatus getPhysicalCameraInfo(const std::string& deviceId,
143                                                aidlevs::CameraDesc* _aidl_return) override;
144     ::ndk::ScopedAStatus importExternalBuffers(const std::vector<aidlevs::BufferDesc>& buffers,
145                                                int32_t* _aidl_return) override;
146     ::ndk::ScopedAStatus pauseVideoStream() override;
147     ::ndk::ScopedAStatus resumeVideoStream() override;
148     ::ndk::ScopedAStatus setExtendedInfo(int32_t opaqueIdentifier,
149                                          const std::vector<uint8_t>& opaqueValue) override;
150     ::ndk::ScopedAStatus setIntParameter(aidlevs::CameraParam id, int32_t value,
151                                          std::vector<int32_t>* effectiveValue) override;
152     ::ndk::ScopedAStatus setPrimaryClient() override;
153     ::ndk::ScopedAStatus setMaxFramesInFlight(int32_t bufferCount) override;
154     ::ndk::ScopedAStatus startVideoStream(
155             const std::shared_ptr<aidlevs::IEvsCameraStream>& receiver) override;
156     ::ndk::ScopedAStatus stopVideoStream() override;
157     ::ndk::ScopedAStatus unsetPrimaryClient() override;
158 
159     explicit ImplV0(const ::android::sp<hidlevs::V1_0::IEvsCamera>& camera);
~ImplV0()160     virtual ~ImplV0(){};
161 
getHidlCamera()162     const ::android::sp<hidlevs::V1_0::IEvsCamera> getHidlCamera() const override {
163         return mHidlCamera;
164     }
165 };
166 
167 class AidlCamera::ImplV1 final : public IHidlCamera {
168 public:
169     ::ndk::ScopedAStatus doneWithFrame(const std::vector<aidlevs::BufferDesc>& buffers) override;
170     ::ndk::ScopedAStatus forcePrimaryClient(
171             const std::shared_ptr<aidlevs::IEvsDisplay>& display) override;
172     ::ndk::ScopedAStatus getCameraInfo(aidlevs::CameraDesc* _aidl_return) override;
173     ::ndk::ScopedAStatus getExtendedInfo(int32_t opaqueIdentifier,
174                                          std::vector<uint8_t>* value) override;
175     ::ndk::ScopedAStatus getIntParameter(aidlevs::CameraParam id,
176                                          std::vector<int32_t>* value) override;
177     ::ndk::ScopedAStatus getIntParameterRange(aidlevs::CameraParam id,
178                                               aidlevs::ParameterRange* _aidl_return) override;
179     ::ndk::ScopedAStatus getParameterList(std::vector<aidlevs::CameraParam>* _aidl_return) override;
180     ::ndk::ScopedAStatus getPhysicalCameraInfo(const std::string& deviceId,
181                                                aidlevs::CameraDesc* _aidl_return) override;
182     ::ndk::ScopedAStatus importExternalBuffers(const std::vector<aidlevs::BufferDesc>& buffers,
183                                                int32_t* _aidl_return) override;
184     ::ndk::ScopedAStatus pauseVideoStream() override;
185     ::ndk::ScopedAStatus resumeVideoStream() override;
186     ::ndk::ScopedAStatus setExtendedInfo(int32_t opaqueIdentifier,
187                                          const std::vector<uint8_t>& opaqueValue) override;
188     ::ndk::ScopedAStatus setIntParameter(aidlevs::CameraParam id, int32_t value,
189                                          std::vector<int32_t>* effectiveValue) override;
190     ::ndk::ScopedAStatus setPrimaryClient() override;
191     ::ndk::ScopedAStatus setMaxFramesInFlight(int32_t bufferCount) override;
192     ::ndk::ScopedAStatus startVideoStream(
193             const std::shared_ptr<aidlevs::IEvsCameraStream>& receiver) override;
194     ::ndk::ScopedAStatus stopVideoStream() override;
195     ::ndk::ScopedAStatus unsetPrimaryClient() override;
196 
197     explicit ImplV1(const ::android::sp<hidlevs::V1_1::IEvsCamera>& camera);
~ImplV1()198     virtual ~ImplV1() { mHidlCamera = nullptr; }
199 
getHidlCamera()200     const ::android::sp<hidlevs::V1_0::IEvsCamera> getHidlCamera() const override {
201         return mHidlCamera;
202     }
203 
204 private:
205     ::android::sp<hidlevs::V1_1::IEvsCamera> mHidlCamera;
206 };
207 
208 }  // namespace aidl::android::automotive::evs::implementation
209 
210 #endif  // CPP_EVS_MANAGER_AIDL_WRAPPERS_INCLUDE_HIDLHWCAMERA_H
211