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 #include "AidlCamera.h"
18
19 #include "HidlDisplay.h"
20 #include "utils/include/Utils.h"
21
22 #include <android-base/logging.h>
23
24 namespace aidl::android::automotive::evs::implementation {
25
26 namespace hidlevs = ::android::hardware::automotive::evs;
27
28 using ::aidl::android::hardware::automotive::evs::BufferDesc;
29 using ::aidl::android::hardware::automotive::evs::CameraDesc;
30 using ::aidl::android::hardware::automotive::evs::CameraParam;
31 using ::aidl::android::hardware::automotive::evs::DisplayState;
32 using ::aidl::android::hardware::automotive::evs::EvsEventDesc;
33 using ::aidl::android::hardware::automotive::evs::EvsEventType;
34 using ::aidl::android::hardware::automotive::evs::EvsResult;
35 using ::aidl::android::hardware::automotive::evs::IEvsCameraStream;
36 using ::aidl::android::hardware::automotive::evs::IEvsDisplay;
37 using ::aidl::android::hardware::automotive::evs::ParameterRange;
38 using ::android::hardware::hidl_vec;
39 using ::ndk::ScopedAStatus;
40
AidlCamera(const::android::sp<hidlevs::V1_0::IEvsCamera> & hidlCamera,bool forceV1_0)41 AidlCamera::AidlCamera(const ::android::sp<hidlevs::V1_0::IEvsCamera>& hidlCamera, bool forceV1_0) {
42 auto hidlCameraV1 = hidlevs::V1_1::IEvsCamera::castFrom(hidlCamera).withDefault(nullptr);
43 if (forceV1_0 || !hidlCameraV1) {
44 // AidlCamera is initialized in V1_0::IEvsCamera support mode in below
45 // three conditions:
46 // 1. A given camera object is an implementation of V1_0::IEvsCamera
47 // (fails to upcast as V1_1::IEvsCamera).
48 // 2. A caller explicitly creates AidlCamera object in V1_0::IEvsCamera
49 // mode by setting forceV1_0 as true.
50 // 3. Or, A given camera object is invalid (nullptr).
51 mImpl = std::make_shared<ImplV0>(hidlCamera);
52 } else {
53 mImpl = std::make_shared<ImplV1>(hidlCameraV1);
54 }
55 }
56
getHidlCamera() const57 const ::android::sp<hidlevs::V1_0::IEvsCamera> AidlCamera::getHidlCamera() const {
58 return mImpl->getHidlCamera();
59 }
60
doneWithFrame(const std::vector<BufferDesc> & buffers)61 ScopedAStatus AidlCamera::doneWithFrame(const std::vector<BufferDesc>& buffers) {
62 return mImpl->doneWithFrame(buffers);
63 }
64
forcePrimaryClient(const std::shared_ptr<IEvsDisplay> & display)65 ScopedAStatus AidlCamera::forcePrimaryClient(const std::shared_ptr<IEvsDisplay>& display) {
66 return mImpl->forcePrimaryClient(display);
67 }
68
getCameraInfo(CameraDesc * _aidl_return)69 ScopedAStatus AidlCamera::getCameraInfo(CameraDesc* _aidl_return) {
70 return mImpl->getCameraInfo(_aidl_return);
71 }
72
getExtendedInfo(int32_t opaqueIdentifier,std::vector<uint8_t> * value)73 ScopedAStatus AidlCamera::getExtendedInfo(int32_t opaqueIdentifier, std::vector<uint8_t>* value) {
74 return mImpl->getExtendedInfo(opaqueIdentifier, value);
75 }
76
getIntParameter(CameraParam id,std::vector<int32_t> * value)77 ScopedAStatus AidlCamera::getIntParameter(CameraParam id, std::vector<int32_t>* value) {
78 return mImpl->getIntParameter(id, value);
79 }
80
getIntParameterRange(CameraParam id,ParameterRange * _aidl_return)81 ScopedAStatus AidlCamera::getIntParameterRange(CameraParam id, ParameterRange* _aidl_return) {
82 return mImpl->getIntParameterRange(id, _aidl_return);
83 }
84
getParameterList(std::vector<CameraParam> * _aidl_return)85 ScopedAStatus AidlCamera::getParameterList(std::vector<CameraParam>* _aidl_return) {
86 return mImpl->getParameterList(_aidl_return);
87 }
88
getPhysicalCameraInfo(const std::string & deviceId,CameraDesc * _aidl_return)89 ScopedAStatus AidlCamera::getPhysicalCameraInfo(const std::string& deviceId,
90 CameraDesc* _aidl_return) {
91 return mImpl->getPhysicalCameraInfo(deviceId, _aidl_return);
92 }
93
importExternalBuffers(const std::vector<BufferDesc> & buffers,int32_t * _aidl_return)94 ScopedAStatus AidlCamera::importExternalBuffers(const std::vector<BufferDesc>& buffers,
95 int32_t* _aidl_return) {
96 return mImpl->importExternalBuffers(buffers, _aidl_return);
97 }
98
pauseVideoStream()99 ScopedAStatus AidlCamera::pauseVideoStream() {
100 return mImpl->pauseVideoStream();
101 }
102
resumeVideoStream()103 ScopedAStatus AidlCamera::resumeVideoStream() {
104 return mImpl->resumeVideoStream();
105 }
106
setExtendedInfo(int32_t opaqueIdentifier,const std::vector<uint8_t> & opaqueValue)107 ScopedAStatus AidlCamera::setExtendedInfo(int32_t opaqueIdentifier,
108 const std::vector<uint8_t>& opaqueValue) {
109 return mImpl->setExtendedInfo(opaqueIdentifier, opaqueValue);
110 }
111
setIntParameter(CameraParam id,int32_t value,std::vector<int32_t> * effectiveValue)112 ScopedAStatus AidlCamera::setIntParameter(CameraParam id, int32_t value,
113 std::vector<int32_t>* effectiveValue) {
114 return mImpl->setIntParameter(id, value, effectiveValue);
115 }
116
setPrimaryClient()117 ScopedAStatus AidlCamera::setPrimaryClient() {
118 return mImpl->setPrimaryClient();
119 }
120
setMaxFramesInFlight(int32_t bufferCount)121 ScopedAStatus AidlCamera::setMaxFramesInFlight(int32_t bufferCount) {
122 return mImpl->setMaxFramesInFlight(bufferCount);
123 }
124
startVideoStream(const std::shared_ptr<IEvsCameraStream> & listener)125 ScopedAStatus AidlCamera::startVideoStream(const std::shared_ptr<IEvsCameraStream>& listener) {
126 return mImpl->startVideoStream(listener);
127 }
128
stopVideoStream()129 ScopedAStatus AidlCamera::stopVideoStream() {
130 return mImpl->stopVideoStream();
131 }
132
unsetPrimaryClient()133 ScopedAStatus AidlCamera::unsetPrimaryClient() {
134 return mImpl->unsetPrimaryClient();
135 }
136
ImplV0(const::android::sp<hidlevs::V1_0::IEvsCamera> & camera)137 AidlCamera::ImplV0::ImplV0(const ::android::sp<hidlevs::V1_0::IEvsCamera>& camera) :
138 IHidlCamera(camera) {
139 if (!camera) {
140 LOG(WARNING) << "AidlCamera object is instantiated with an invalid IEvsCamera object.";
141 return;
142 }
143
144 // Because android::hardware::automotive::evs::V1_0::BufferDesc does not
145 // contain a device id while it is required to handle received frames
146 // properly, we are retrieving it from the camera descriptor and store
147 // locally.
148 camera->getCameraInfo([this](const auto& read) { mId = read.cameraId; });
149 }
150
doneWithFrame(const std::vector<BufferDesc> & buffers)151 ScopedAStatus AidlCamera::ImplV0::doneWithFrame(const std::vector<BufferDesc>& buffers) {
152 if (!mHidlStream) {
153 LOG(WARNING) << "Ignores a request to return a buffer of an invalid HIDL camera stream";
154 return ScopedAStatus::ok();
155 }
156
157 hidlevs::V1_0::BufferDesc hidlBuffer;
158 if (mHidlStream->getHidlBuffer(buffers[0].bufferId, &hidlBuffer)) {
159 mHidlCamera->doneWithFrame(hidlBuffer);
160 }
161
162 return ScopedAStatus::ok();
163 }
164
forcePrimaryClient(const std::shared_ptr<IEvsDisplay> & display)165 ScopedAStatus AidlCamera::ImplV0::forcePrimaryClient(
166 [[maybe_unused]] const std::shared_ptr<IEvsDisplay>& display) {
167 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
168 }
169
getCameraInfo(CameraDesc * _aidl_return)170 ScopedAStatus AidlCamera::ImplV0::getCameraInfo(CameraDesc* _aidl_return) {
171 if (!mHidlCamera) {
172 LOG(ERROR) << "HIDL camera is not valid";
173 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
174 }
175
176 (void)mHidlCamera->getCameraInfo(
177 [_aidl_return](auto& desc) { *_aidl_return = std::move(Utils::makeFromHidl(desc)); });
178
179 return ScopedAStatus::ok();
180 }
181
getExtendedInfo(int32_t opaqueIdentifier,std::vector<uint8_t> * value)182 ScopedAStatus AidlCamera::ImplV0::getExtendedInfo(int32_t opaqueIdentifier,
183 std::vector<uint8_t>* value) {
184 if (!mHidlCamera) {
185 LOG(ERROR) << "HIDL camera is not valid";
186 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
187 }
188
189 int32_t hidlValue = mHidlCamera->getExtendedInfo(opaqueIdentifier);
190 value->resize(sizeof(hidlValue));
191 int* p = reinterpret_cast<int*>(value->data());
192 *p = hidlValue;
193 return ScopedAStatus::ok();
194 }
195
getIntParameter(CameraParam,std::vector<int32_t> *)196 ScopedAStatus AidlCamera::ImplV0::getIntParameter(CameraParam /*id*/,
197 std::vector<int32_t>* /*value*/) {
198 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
199 }
200
getIntParameterRange(CameraParam,ParameterRange *)201 ScopedAStatus AidlCamera::ImplV0::getIntParameterRange(CameraParam /*id*/,
202 ParameterRange* /*_aidl_return*/) {
203 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
204 }
205
getParameterList(std::vector<CameraParam> *)206 ScopedAStatus AidlCamera::ImplV0::getParameterList(std::vector<CameraParam>* /*_aidl_return*/) {
207 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
208 }
209
getPhysicalCameraInfo(const std::string &,CameraDesc *)210 ScopedAStatus AidlCamera::ImplV0::getPhysicalCameraInfo(const std::string& /*deviceId*/,
211 CameraDesc* /*_aidl_return*/) {
212 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
213 }
214
importExternalBuffers(const std::vector<BufferDesc> &,int32_t *)215 ScopedAStatus AidlCamera::ImplV0::importExternalBuffers(const std::vector<BufferDesc>& /*buffers*/,
216 int32_t* /*_aidl_return*/) {
217 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
218 }
219
pauseVideoStream()220 ScopedAStatus AidlCamera::ImplV0::pauseVideoStream() {
221 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
222 }
223
resumeVideoStream()224 ScopedAStatus AidlCamera::ImplV0::resumeVideoStream() {
225 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
226 }
227
setExtendedInfo(int32_t opaqueIdentifier,const std::vector<uint8_t> & opaqueValue)228 ScopedAStatus AidlCamera::ImplV0::setExtendedInfo(int32_t opaqueIdentifier,
229 const std::vector<uint8_t>& opaqueValue) {
230 if (opaqueValue.size() < sizeof(int32_t)) {
231 return Utils::buildScopedAStatusFromEvsResult(EvsResult::INVALID_ARG);
232 }
233
234 int32_t v = *(reinterpret_cast<const int32_t*>(opaqueValue.data()));
235 return Utils::buildScopedAStatusFromEvsResult(
236 mHidlCamera->setExtendedInfo(opaqueIdentifier, v));
237 }
238
setIntParameter(CameraParam,int32_t,std::vector<int32_t> *)239 ScopedAStatus AidlCamera::ImplV0::setIntParameter(CameraParam /*id*/, int32_t /*value*/,
240 std::vector<int32_t>* /*effectiveValue*/) {
241 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
242 }
243
setPrimaryClient()244 ScopedAStatus AidlCamera::ImplV0::setPrimaryClient() {
245 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
246 }
247
setMaxFramesInFlight(int32_t bufferCount)248 ScopedAStatus AidlCamera::ImplV0::setMaxFramesInFlight(int32_t bufferCount) {
249 if (!mHidlCamera) {
250 LOG(ERROR) << "HIDL camera is not valid";
251 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
252 }
253
254 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->setMaxFramesInFlight(bufferCount));
255 }
256
startVideoStream(const std::shared_ptr<IEvsCameraStream> & listener)257 ScopedAStatus AidlCamera::ImplV0::startVideoStream(
258 const std::shared_ptr<IEvsCameraStream>& listener) {
259 if (!listener) {
260 return Utils::buildScopedAStatusFromEvsResult(EvsResult::INVALID_ARG);
261 } else if (mHidlStream) {
262 return Utils::buildScopedAStatusFromEvsResult(EvsResult::STREAM_ALREADY_RUNNING);
263 }
264
265 // Creates a wrapper object and requests a video stream
266 mHidlStream = new (std::nothrow) HidlCameraStream(mId, listener);
267 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->startVideoStream(mHidlStream));
268 }
269
stopVideoStream()270 ScopedAStatus AidlCamera::ImplV0::stopVideoStream() {
271 if (!mHidlStream) {
272 return ScopedAStatus::ok();
273 }
274
275 mHidlCamera->stopVideoStream();
276 mHidlStream = nullptr;
277 return ScopedAStatus::ok();
278 }
279
unsetPrimaryClient()280 ScopedAStatus AidlCamera::ImplV0::unsetPrimaryClient() {
281 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
282 }
283
ImplV1(const::android::sp<hidlevs::V1_1::IEvsCamera> & camera)284 AidlCamera::ImplV1::ImplV1(const ::android::sp<hidlevs::V1_1::IEvsCamera>& camera) :
285 IHidlCamera(camera), mHidlCamera(camera) {
286 if (!camera) {
287 LOG(WARNING) << "AidlCamera object is instantiated with an invalid IEvsCamera object.";
288 return;
289 }
290
291 camera->getCameraInfo_1_1([this](const auto& read) { mId = read.v1.cameraId; });
292 }
293
doneWithFrame(const std::vector<BufferDesc> & buffers)294 ScopedAStatus AidlCamera::ImplV1::doneWithFrame(const std::vector<BufferDesc>& buffers) {
295 if (!mHidlStream) {
296 LOG(WARNING) << "Ignores a request to return a buffer of an invalid HIDL camera stream";
297 return ScopedAStatus::ok();
298 }
299
300 const auto n = buffers.size();
301 hidl_vec<hidlevs::V1_1::BufferDesc> hidlBuffers(n);
302 for (auto i = 0; i < n; ++i) {
303 hidlevs::V1_1::BufferDesc buffer;
304 if (mHidlStream->getHidlBuffer(buffers[i].bufferId, &buffer)) {
305 hidlBuffers[i] = std::move(buffer);
306 }
307 }
308
309 mHidlCamera->doneWithFrame_1_1(hidlBuffers);
310 return ScopedAStatus::ok();
311 }
312
forcePrimaryClient(const std::shared_ptr<IEvsDisplay> & display)313 ScopedAStatus AidlCamera::ImplV1::forcePrimaryClient(const std::shared_ptr<IEvsDisplay>& display) {
314 if (!mHidlCamera) {
315 return Utils::buildScopedAStatusFromEvsResult(EvsResult::NOT_SUPPORTED);
316 }
317
318 return Utils::buildScopedAStatusFromEvsResult(
319 mHidlCamera->forceMaster(new HidlDisplay(display)));
320 }
321
getCameraInfo(CameraDesc * _aidl_return)322 ScopedAStatus AidlCamera::ImplV1::getCameraInfo(CameraDesc* _aidl_return) {
323 if (!mHidlCamera) {
324 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
325 }
326
327 (void)mHidlCamera->getCameraInfo_1_1(
328 [_aidl_return](auto& desc) { *_aidl_return = std::move(Utils::makeFromHidl(desc)); });
329
330 return ScopedAStatus::ok();
331 }
332
getExtendedInfo(int32_t opaqueIdentifier,std::vector<uint8_t> * value)333 ScopedAStatus AidlCamera::ImplV1::getExtendedInfo(int32_t opaqueIdentifier,
334 std::vector<uint8_t>* value) {
335 if (!mHidlCamera) {
336 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
337 }
338
339 hidlevs::V1_0::EvsResult hidlStatus = hidlevs::V1_0::EvsResult::OK;
340 (void)mHidlCamera->getExtendedInfo_1_1(opaqueIdentifier,
341 [&hidlStatus, value](auto status,
342 const hidl_vec<uint8_t>& hwValue) {
343 hidlStatus = status;
344 *value = hwValue;
345 });
346 return Utils::buildScopedAStatusFromEvsResult(hidlStatus);
347 }
348
getIntParameter(CameraParam id,std::vector<int32_t> * value)349 ScopedAStatus AidlCamera::ImplV1::getIntParameter(CameraParam id, std::vector<int32_t>* value) {
350 if (!mHidlCamera) {
351 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
352 }
353
354 hidlevs::V1_0::EvsResult hidlStatus = hidlevs::V1_0::EvsResult::OK;
355 (void)mHidlCamera->getIntParameter(Utils::makeToHidl(id),
356 [&hidlStatus, value](auto status,
357 const hidl_vec<int32_t>& hidlValues) {
358 hidlStatus = status;
359 *value = hidlValues;
360 });
361 return Utils::buildScopedAStatusFromEvsResult(hidlStatus);
362 }
363
getIntParameterRange(CameraParam id,ParameterRange * _aidl_return)364 ScopedAStatus AidlCamera::ImplV1::getIntParameterRange(CameraParam id,
365 ParameterRange* _aidl_return) {
366 if (!mHidlCamera) {
367 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
368 }
369
370 (void)mHidlCamera->getIntParameterRange(Utils::makeToHidl(id),
371 [_aidl_return](auto min, auto max, auto step) {
372 _aidl_return->min = min;
373 _aidl_return->max = max;
374 _aidl_return->step = step;
375 });
376 return ScopedAStatus::ok();
377 }
378
getParameterList(std::vector<CameraParam> * _aidl_return)379 ScopedAStatus AidlCamera::ImplV1::getParameterList(std::vector<CameraParam>* _aidl_return) {
380 if (!mHidlCamera) {
381 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
382 }
383
384 (void)mHidlCamera->getParameterList(
385 [_aidl_return](const hidl_vec<hidlevs::V1_1::CameraParam>& list) {
386 _aidl_return->reserve(list.size());
387 for (auto i = 0; i < list.size(); ++i) {
388 _aidl_return->push_back(std::move(Utils::makeFromHidl(list[i])));
389 }
390 });
391 return ScopedAStatus::ok();
392 }
393
getPhysicalCameraInfo(const std::string & deviceId,CameraDesc * _aidl_return)394 ScopedAStatus AidlCamera::ImplV1::getPhysicalCameraInfo(const std::string& deviceId,
395 CameraDesc* _aidl_return) {
396 if (!mHidlCamera) {
397 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
398 }
399
400 (void)mHidlCamera->getPhysicalCameraInfo(deviceId, [_aidl_return](const auto& hidlDesc) {
401 *_aidl_return = std::move(Utils::makeFromHidl(hidlDesc));
402 });
403 return ScopedAStatus::ok();
404 }
405
importExternalBuffers(const std::vector<BufferDesc> & buffers,int32_t * _aidl_return)406 ScopedAStatus AidlCamera::ImplV1::importExternalBuffers(const std::vector<BufferDesc>& buffers,
407 int32_t* _aidl_return) {
408 if (!mHidlCamera) {
409 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
410 }
411
412 hidl_vec<hidlevs::V1_1::BufferDesc> hidlBuffers;
413 hidlBuffers.resize(buffers.size());
414 for (auto i = 0; i < buffers.size(); ++i) {
415 hidlBuffers[i] = std::move(Utils::makeToHidlV1_1(buffers[i]));
416 }
417 hidlevs::V1_0::EvsResult hidlStatus = hidlevs::V1_0::EvsResult::OK;
418 (void)mHidlCamera->importExternalBuffers(hidlBuffers,
419 [&hidlStatus, _aidl_return](auto status, auto delta) {
420 hidlStatus = status;
421 *_aidl_return = delta;
422 });
423 return Utils::buildScopedAStatusFromEvsResult(hidlStatus);
424 }
425
pauseVideoStream()426 ScopedAStatus AidlCamera::ImplV1::pauseVideoStream() {
427 if (!mHidlCamera) {
428 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
429 }
430 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->pauseVideoStream());
431 }
432
resumeVideoStream()433 ScopedAStatus AidlCamera::ImplV1::resumeVideoStream() {
434 if (!mHidlCamera) {
435 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
436 }
437 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->resumeVideoStream());
438 }
439
setExtendedInfo(int32_t opaqueIdentifier,const std::vector<uint8_t> & opaqueValue)440 ScopedAStatus AidlCamera::ImplV1::setExtendedInfo(int32_t opaqueIdentifier,
441 const std::vector<uint8_t>& opaqueValue) {
442 if (!mHidlCamera) {
443 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
444 }
445
446 hidl_vec<uint8_t> value = opaqueValue;
447 hidlevs::V1_0::EvsResult hidlStatus = mHidlCamera->setExtendedInfo_1_1(opaqueIdentifier, value);
448
449 return Utils::buildScopedAStatusFromEvsResult(hidlStatus);
450 }
451
setIntParameter(CameraParam id,int32_t value,std::vector<int32_t> * effectiveValue)452 ScopedAStatus AidlCamera::ImplV1::setIntParameter(CameraParam id, int32_t value,
453 std::vector<int32_t>* effectiveValue) {
454 if (!mHidlCamera) {
455 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
456 }
457
458 hidlevs::V1_0::EvsResult hidlStatus = hidlevs::V1_0::EvsResult::OK;
459 (void)mHidlCamera->setIntParameter(Utils::makeToHidl(id), value,
460 [&hidlStatus,
461 &effectiveValue](auto status,
462 const hidl_vec<int32_t>& values) {
463 hidlStatus = status;
464 *effectiveValue = values;
465 });
466 return Utils::buildScopedAStatusFromEvsResult(hidlStatus);
467 }
468
setPrimaryClient()469 ScopedAStatus AidlCamera::ImplV1::setPrimaryClient() {
470 if (!mHidlCamera) {
471 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
472 }
473
474 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->setMaster());
475 }
476
setMaxFramesInFlight(int32_t bufferCount)477 ScopedAStatus AidlCamera::ImplV1::setMaxFramesInFlight(int32_t bufferCount) {
478 if (!mHidlCamera) {
479 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
480 }
481
482 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->setMaxFramesInFlight(bufferCount));
483 }
484
startVideoStream(const std::shared_ptr<IEvsCameraStream> & listener)485 ScopedAStatus AidlCamera::ImplV1::startVideoStream(
486 const std::shared_ptr<IEvsCameraStream>& listener) {
487 if (!listener) {
488 return Utils::buildScopedAStatusFromEvsResult(EvsResult::INVALID_ARG);
489 } else if (mHidlStream) {
490 return Utils::buildScopedAStatusFromEvsResult(EvsResult::STREAM_ALREADY_RUNNING);
491 }
492
493 // Creates a wrapper object and requests a video stream
494 mHidlStream = new (std::nothrow) HidlCameraStream(mId, listener);
495 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->startVideoStream(mHidlStream));
496 }
497
stopVideoStream()498 ScopedAStatus AidlCamera::ImplV1::stopVideoStream() {
499 if (!mHidlStream) {
500 return ScopedAStatus::ok();
501 }
502
503 mHidlCamera->stopVideoStream();
504 mHidlStream = nullptr;
505 return ScopedAStatus::ok();
506 }
507
unsetPrimaryClient()508 ScopedAStatus AidlCamera::ImplV1::unsetPrimaryClient() {
509 if (!mHidlCamera) {
510 return Utils::buildScopedAStatusFromEvsResult(EvsResult::RESOURCE_NOT_AVAILABLE);
511 }
512
513 return Utils::buildScopedAStatusFromEvsResult(mHidlCamera->unsetMaster());
514 }
515
516 } // namespace aidl::android::automotive::evs::implementation
517