1 /*
2 * Copyright (C) 2019 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 #define LOG_TAG "GCH_HidlUtils"
18 //#define LOG_NDEBUG 0
19 #include <log/log.h>
20 #include <regex>
21
22 #include "hidl_camera_device.h"
23 #include "hidl_utils.h"
24
25 namespace android {
26 namespace hardware {
27 namespace camera {
28 namespace implementation {
29 namespace hidl_utils {
30
31 using ::android::hardware::camera::device::V3_2::ErrorCode;
32 using ::android::hardware::camera::device::V3_2::ErrorMsg;
33 using ::android::hardware::camera::device::V3_2::MsgType;
34 using ::android::hardware::camera::device::V3_2::ShutterMsg;
35 using ::android::hardware::camera::device::V3_7::implementation::HidlCameraDevice;
36 using android::hardware::camera::metadata::V3_6::
37 CameraMetadataEnumAndroidSensorPixelMode;
38 using ::android::hardware::camera::provider::V2_7::implementation::HidlCameraProvider;
39
ConvertToHidlVendorTagType(google_camera_hal::CameraMetadataType hal_type,CameraMetadataType * hidl_type)40 status_t ConvertToHidlVendorTagType(
41 google_camera_hal::CameraMetadataType hal_type,
42 CameraMetadataType* hidl_type) {
43 if (hidl_type == nullptr) {
44 ALOGE("%s: hidl_type is nullptr.", __FUNCTION__);
45 return BAD_VALUE;
46 }
47
48 switch (hal_type) {
49 case google_camera_hal::CameraMetadataType::kByte:
50 *hidl_type = CameraMetadataType::BYTE;
51 break;
52 case google_camera_hal::CameraMetadataType::kInt32:
53 *hidl_type = CameraMetadataType::INT32;
54 break;
55 case google_camera_hal::CameraMetadataType::kFloat:
56 *hidl_type = CameraMetadataType::FLOAT;
57 break;
58 case google_camera_hal::CameraMetadataType::kInt64:
59 *hidl_type = CameraMetadataType::INT64;
60 break;
61 case google_camera_hal::CameraMetadataType::kDouble:
62 *hidl_type = CameraMetadataType::DOUBLE;
63 break;
64 case google_camera_hal::CameraMetadataType::kRational:
65 *hidl_type = CameraMetadataType::RATIONAL;
66 break;
67 default:
68 ALOGE("%s: Unknown google_camera_hal::CameraMetadataType: %u",
69 __FUNCTION__, hal_type);
70 return BAD_VALUE;
71 }
72
73 return OK;
74 }
75
ConvertToHidlResourceCost(const google_camera_hal::CameraResourceCost & hal_cost,CameraResourceCost * hidl_cost)76 status_t ConvertToHidlResourceCost(
77 const google_camera_hal::CameraResourceCost& hal_cost,
78 CameraResourceCost* hidl_cost) {
79 if (hidl_cost == nullptr) {
80 ALOGE("%s: hidl_cost is nullptr.", __FUNCTION__);
81 return BAD_VALUE;
82 }
83
84 hidl_cost->resourceCost = hal_cost.resource_cost;
85 hidl_cost->conflictingDevices.resize(hal_cost.conflicting_devices.size());
86
87 for (uint32_t i = 0; i < hal_cost.conflicting_devices.size(); i++) {
88 hidl_cost->conflictingDevices[i] =
89 "device@" + HidlCameraDevice::kDeviceVersion + "/" +
90 HidlCameraProvider::kProviderName + "/" +
91 std::to_string(hal_cost.conflicting_devices[i]);
92 }
93
94 return OK;
95 }
96
ConvertToHidlVendorTagSections(const std::vector<google_camera_hal::VendorTagSection> & hal_sections,hidl_vec<VendorTagSection> * hidl_sections)97 status_t ConvertToHidlVendorTagSections(
98 const std::vector<google_camera_hal::VendorTagSection>& hal_sections,
99 hidl_vec<VendorTagSection>* hidl_sections) {
100 if (hidl_sections == nullptr) {
101 ALOGE("%s: hidl_sections is nullptr.", __FUNCTION__);
102 return BAD_VALUE;
103 }
104
105 hidl_sections->resize(hal_sections.size());
106 for (uint32_t i = 0; i < hal_sections.size(); i++) {
107 (*hidl_sections)[i].sectionName = hal_sections[i].section_name;
108 (*hidl_sections)[i].tags.resize(hal_sections[i].tags.size());
109
110 for (uint32_t j = 0; j < hal_sections[i].tags.size(); j++) {
111 (*hidl_sections)[i].tags[j].tagId = hal_sections[i].tags[j].tag_id;
112 (*hidl_sections)[i].tags[j].tagName = hal_sections[i].tags[j].tag_name;
113 status_t res =
114 ConvertToHidlVendorTagType(hal_sections[i].tags[j].tag_type,
115 &(*hidl_sections)[i].tags[j].tagType);
116 if (res != OK) {
117 ALOGE("%s: Converting to hidl vendor tag type failed. ", __FUNCTION__);
118 return res;
119 }
120 }
121 }
122
123 return OK;
124 }
125
ConvertToHidlStatus(status_t hal_status)126 Status ConvertToHidlStatus(status_t hal_status) {
127 switch (hal_status) {
128 case OK:
129 return Status::OK;
130 case BAD_VALUE:
131 return Status::ILLEGAL_ARGUMENT;
132 case -EBUSY:
133 return Status::CAMERA_IN_USE;
134 case -EUSERS:
135 return Status::MAX_CAMERAS_IN_USE;
136 case UNKNOWN_TRANSACTION:
137 return Status::METHOD_NOT_SUPPORTED;
138 case INVALID_OPERATION:
139 return Status::OPERATION_NOT_SUPPORTED;
140 case DEAD_OBJECT:
141 return Status::CAMERA_DISCONNECTED;
142 default:
143 return Status::INTERNAL_ERROR;
144 }
145 }
146
ConvertToHalTemplateType(RequestTemplate hidl_template,google_camera_hal::RequestTemplate * hal_template)147 status_t ConvertToHalTemplateType(
148 RequestTemplate hidl_template,
149 google_camera_hal::RequestTemplate* hal_template) {
150 if (hal_template == nullptr) {
151 ALOGE("%s: hal_template is nullptr.", __FUNCTION__);
152 return BAD_VALUE;
153 }
154
155 switch (hidl_template) {
156 case RequestTemplate::PREVIEW:
157 *hal_template = google_camera_hal::RequestTemplate::kPreview;
158 break;
159 case RequestTemplate::STILL_CAPTURE:
160 *hal_template = google_camera_hal::RequestTemplate::kStillCapture;
161 break;
162 case RequestTemplate::VIDEO_RECORD:
163 *hal_template = google_camera_hal::RequestTemplate::kVideoRecord;
164 break;
165 case RequestTemplate::VIDEO_SNAPSHOT:
166 *hal_template = google_camera_hal::RequestTemplate::kVideoSnapshot;
167 break;
168 case RequestTemplate::ZERO_SHUTTER_LAG:
169 *hal_template = google_camera_hal::RequestTemplate::kZeroShutterLag;
170 break;
171 case RequestTemplate::MANUAL:
172 *hal_template = google_camera_hal::RequestTemplate::kManual;
173 break;
174 default:
175 ALOGE("%s: Unknown HIDL RequestTemplate: %u", __FUNCTION__,
176 hidl_template);
177 return BAD_VALUE;
178 }
179
180 return OK;
181 }
182
ConvertToHidlHalStreamConfig(const std::vector<google_camera_hal::HalStream> & hal_configured_streams,HalStreamConfiguration * hidl_hal_stream_config)183 status_t ConvertToHidlHalStreamConfig(
184 const std::vector<google_camera_hal::HalStream>& hal_configured_streams,
185 HalStreamConfiguration* hidl_hal_stream_config) {
186 if (hidl_hal_stream_config == nullptr) {
187 ALOGE("%s: hidl_hal_stream_config is nullptr.", __FUNCTION__);
188 return BAD_VALUE;
189 }
190
191 hidl_hal_stream_config->streams.resize(hal_configured_streams.size());
192
193 for (uint32_t i = 0; i < hal_configured_streams.size(); i++) {
194 hidl_hal_stream_config->streams[i].supportOffline = false;
195 if (hal_configured_streams[i].is_physical_camera_stream) {
196 hidl_hal_stream_config->streams[i].v3_4.physicalCameraId =
197 std::to_string(hal_configured_streams[i].physical_camera_id);
198 }
199
200 hidl_hal_stream_config->streams[i].v3_4.v3_3.overrideDataSpace =
201 hal_configured_streams[i].override_data_space;
202
203 hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.id =
204 hal_configured_streams[i].id;
205
206 hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.overrideFormat =
207 (::android::hardware::graphics::common::V1_0::PixelFormat)
208 hal_configured_streams[i]
209 .override_format;
210
211 hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.producerUsage =
212 hal_configured_streams[i].producer_usage;
213
214 hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.consumerUsage =
215 hal_configured_streams[i].consumer_usage;
216
217 hidl_hal_stream_config->streams[i].v3_4.v3_3.v3_2.maxBuffers =
218 hal_configured_streams[i].max_buffers;
219 }
220
221 return OK;
222 }
223
WriteToResultMetadataQueue(camera_metadata_t * metadata,MessageQueue<uint8_t,kSynchronizedReadWrite> * result_metadata_queue)224 status_t WriteToResultMetadataQueue(
225 camera_metadata_t* metadata,
226 MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue) {
227 if (result_metadata_queue == nullptr) {
228 return BAD_VALUE;
229 }
230
231 if (result_metadata_queue->availableToWrite() <= 0) {
232 ALOGW("%s: result_metadata_queue is not available to write", __FUNCTION__);
233 return BAD_VALUE;
234 }
235
236 uint32_t size = get_camera_metadata_size(metadata);
237 bool success = result_metadata_queue->write(
238 reinterpret_cast<const uint8_t*>(metadata), size);
239 if (!success) {
240 ALOGW("%s: Writing to result metadata queue failed. (size=%u)",
241 __FUNCTION__, size);
242 return INVALID_OPERATION;
243 }
244
245 return OK;
246 }
247
248 // Try writing result metadata to result metadata queue. If failed, return
249 // the metadata to the caller in out_hal_metadata.
TryWritingToResultMetadataQueue(std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,MessageQueue<uint8_t,kSynchronizedReadWrite> * result_metadata_queue,uint64_t * fmq_result_size,std::unique_ptr<google_camera_hal::HalCameraMetadata> * out_hal_metadata)250 status_t TryWritingToResultMetadataQueue(
251 std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
252 MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
253 uint64_t* fmq_result_size,
254 std::unique_ptr<google_camera_hal::HalCameraMetadata>* out_hal_metadata) {
255 if (out_hal_metadata == nullptr) {
256 ALOGE("%s: out_hal_metadata is nullptr.", __FUNCTION__);
257 return BAD_VALUE;
258 }
259
260 *out_hal_metadata = std::move(hal_metadata);
261
262 if (fmq_result_size == nullptr) {
263 ALOGE("%s: fmq_result_size is nullptr", __FUNCTION__);
264 return BAD_VALUE;
265 }
266
267 *fmq_result_size = 0;
268 if (*out_hal_metadata == nullptr) {
269 return OK;
270 }
271
272 camera_metadata_t* metadata = (*out_hal_metadata)->ReleaseCameraMetadata();
273 // Temporarily use the raw metadata to write to metadata queue.
274 status_t res = WriteToResultMetadataQueue(metadata, result_metadata_queue);
275 *out_hal_metadata = google_camera_hal::HalCameraMetadata::Create(metadata);
276
277 if (res != OK) {
278 ALOGW("%s: Writing to result metadata queue failed: %s(%d)", __FUNCTION__,
279 strerror(-res), res);
280 return res;
281 }
282
283 *fmq_result_size = (*out_hal_metadata)->GetCameraMetadataSize();
284 *out_hal_metadata = nullptr;
285 return OK;
286 }
287
ConverToHidlResultMetadata(MessageQueue<uint8_t,kSynchronizedReadWrite> * result_metadata_queue,std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,CameraMetadata * hidl_metadata,uint64_t * fmq_result_size)288 status_t ConverToHidlResultMetadata(
289 MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
290 std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_metadata,
291 CameraMetadata* hidl_metadata, uint64_t* fmq_result_size) {
292 if (TryWritingToResultMetadataQueue(std::move(hal_metadata),
293 result_metadata_queue, fmq_result_size,
294 &hal_metadata) == OK) {
295 return OK;
296 }
297
298 // If writing to metadata queue failed, attach the metadata to hidl_metadata.
299 if (hidl_metadata == nullptr) {
300 ALOGE("%s: hidl_metadata is nullptr", __FUNCTION__);
301 return BAD_VALUE;
302 }
303
304 uint32_t metadata_size = hal_metadata->GetCameraMetadataSize();
305 hidl_metadata->setToExternal(
306 reinterpret_cast<uint8_t*>(hal_metadata->ReleaseCameraMetadata()),
307 metadata_size, /*shouldOwn=*/true);
308
309 return OK;
310 }
311
ConvertToHidlBufferStatus(google_camera_hal::BufferStatus hal_status,BufferStatus * hidl_status)312 status_t ConvertToHidlBufferStatus(google_camera_hal::BufferStatus hal_status,
313 BufferStatus* hidl_status) {
314 if (hidl_status == nullptr) {
315 ALOGE("%s: hidl_status is nullptr.", __FUNCTION__);
316 return BAD_VALUE;
317 }
318
319 switch (hal_status) {
320 case google_camera_hal::BufferStatus::kOk:
321 *hidl_status = BufferStatus::OK;
322 break;
323 case google_camera_hal::BufferStatus::kError:
324 *hidl_status = BufferStatus::ERROR;
325 break;
326 default:
327 ALOGE("%s: Unknown HAL buffer status: %u", __FUNCTION__, hal_status);
328 return BAD_VALUE;
329 }
330
331 return OK;
332 }
333
ConvertToHidlStreamBuffer(const google_camera_hal::StreamBuffer & hal_buffer,StreamBuffer * hidl_buffer)334 status_t ConvertToHidlStreamBuffer(
335 const google_camera_hal::StreamBuffer& hal_buffer,
336 StreamBuffer* hidl_buffer) {
337 if (hidl_buffer == nullptr) {
338 ALOGE("%s: hidl_buffer is nullptr", __FUNCTION__);
339 return BAD_VALUE;
340 }
341
342 hidl_buffer->streamId = hal_buffer.stream_id;
343 hidl_buffer->bufferId = hal_buffer.buffer_id;
344 hidl_buffer->buffer = nullptr;
345
346 status_t res =
347 ConvertToHidlBufferStatus(hal_buffer.status, &hidl_buffer->status);
348 if (res != OK) {
349 ALOGE("%s: Converting to HIDL buffer status failed: %s(%d)", __FUNCTION__,
350 strerror(-res), res);
351 return res;
352 }
353
354 hidl_buffer->acquireFence = nullptr;
355 hidl_buffer->releaseFence = hal_buffer.release_fence;
356 return OK;
357 }
358
ConvertToHidlCaptureResult_V3_2(MessageQueue<uint8_t,kSynchronizedReadWrite> * result_metadata_queue,google_camera_hal::CaptureResult * hal_result,device::V3_2::CaptureResult * hidl_result)359 status_t ConvertToHidlCaptureResult_V3_2(
360 MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
361 google_camera_hal::CaptureResult* hal_result,
362 device::V3_2::CaptureResult* hidl_result) {
363 if (hidl_result == nullptr) {
364 ALOGE("%s: hidl_result is nullptr.", __FUNCTION__);
365 return BAD_VALUE;
366 }
367
368 if (hal_result == nullptr) {
369 ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
370 return BAD_VALUE;
371 }
372
373 hidl_result->frameNumber = hal_result->frame_number;
374
375 status_t res = ConverToHidlResultMetadata(
376 result_metadata_queue, std::move(hal_result->result_metadata),
377 &hidl_result->result, &hidl_result->fmqResultSize);
378 if (res != OK) {
379 ALOGE("%s: Converting to HIDL result metadata failed: %s(%d).",
380 __FUNCTION__, strerror(-res), res);
381 return res;
382 }
383
384 hidl_result->outputBuffers.resize(hal_result->output_buffers.size());
385 for (uint32_t i = 0; i < hidl_result->outputBuffers.size(); i++) {
386 res = ConvertToHidlStreamBuffer(hal_result->output_buffers[i],
387 &hidl_result->outputBuffers[i]);
388 if (res != OK) {
389 ALOGE("%s: Converting to HIDL output stream buffer failed: %s(%d)",
390 __FUNCTION__, strerror(-res), res);
391 return res;
392 }
393 }
394
395 uint32_t num_input_buffers = hal_result->input_buffers.size();
396 if (num_input_buffers > 0) {
397 if (num_input_buffers > 1) {
398 ALOGW("%s: HAL result should not have more than 1 input buffer. (=%u)",
399 __FUNCTION__, num_input_buffers);
400 }
401
402 res = ConvertToHidlStreamBuffer(hal_result->input_buffers[0],
403 &hidl_result->inputBuffer);
404 if (res != OK) {
405 ALOGE("%s: Converting to HIDL input stream buffer failed: %s(%d)",
406 __FUNCTION__, strerror(-res), res);
407 return res;
408 }
409 } else {
410 hidl_result->inputBuffer.streamId = -1;
411 }
412
413 hidl_result->partialResult = hal_result->partial_result;
414 return OK;
415 }
416
ConvertToHidlCaptureResult(MessageQueue<uint8_t,kSynchronizedReadWrite> * result_metadata_queue,std::unique_ptr<google_camera_hal::CaptureResult> hal_result,CaptureResult * hidl_result)417 status_t ConvertToHidlCaptureResult(
418 MessageQueue<uint8_t, kSynchronizedReadWrite>* result_metadata_queue,
419 std::unique_ptr<google_camera_hal::CaptureResult> hal_result,
420 CaptureResult* hidl_result) {
421 if (hidl_result == nullptr) {
422 ALOGE("%s: hidl_result is nullptr.", __FUNCTION__);
423 return BAD_VALUE;
424 }
425
426 if (hal_result == nullptr) {
427 ALOGE("%s: hal_result is nullptr.", __FUNCTION__);
428 return BAD_VALUE;
429 }
430
431 status_t res = ConvertToHidlCaptureResult_V3_2(
432 result_metadata_queue, hal_result.get(), &hidl_result->v3_2);
433 if (res != OK) {
434 ALOGE("%s: Converting to V3.2 HIDL result failed: %s(%d).", __FUNCTION__,
435 strerror(-res), res);
436 return res;
437 }
438
439 uint32_t num_physical_metadata = hal_result->physical_metadata.size();
440 hidl_result->physicalCameraMetadata.resize(num_physical_metadata);
441
442 for (uint32_t i = 0; i < num_physical_metadata; i++) {
443 hidl_result->physicalCameraMetadata[i].physicalCameraId =
444 std::to_string(hal_result->physical_metadata[i].physical_camera_id);
445
446 res = ConverToHidlResultMetadata(
447 result_metadata_queue,
448 std::move(hal_result->physical_metadata[i].metadata),
449 &hidl_result->physicalCameraMetadata[i].metadata,
450 &hidl_result->physicalCameraMetadata[i].fmqMetadataSize);
451 if (res != OK) {
452 ALOGE("%s: Converting to HIDL physical metadata failed: %s(%d).",
453 __FUNCTION__, strerror(-res), res);
454 return res;
455 }
456 }
457
458 return OK;
459 }
460
ConvertToHidlErrorMessage(const google_camera_hal::ErrorMessage & hal_error,ErrorMsg * hidl_error)461 status_t ConvertToHidlErrorMessage(
462 const google_camera_hal::ErrorMessage& hal_error, ErrorMsg* hidl_error) {
463 if (hidl_error == nullptr) {
464 ALOGE("%s: hidl_error is nullptr.", __FUNCTION__);
465 return BAD_VALUE;
466 }
467
468 hidl_error->frameNumber = hal_error.frame_number;
469 hidl_error->errorStreamId = hal_error.error_stream_id;
470
471 switch (hal_error.error_code) {
472 case google_camera_hal::ErrorCode::kErrorDevice:
473 hidl_error->errorCode = ErrorCode::ERROR_DEVICE;
474 break;
475 case google_camera_hal::ErrorCode::kErrorRequest:
476 hidl_error->errorCode = ErrorCode::ERROR_REQUEST;
477 break;
478 case google_camera_hal::ErrorCode::kErrorResult:
479 hidl_error->errorCode = ErrorCode::ERROR_RESULT;
480 break;
481 case google_camera_hal::ErrorCode::kErrorBuffer:
482 hidl_error->errorCode = ErrorCode::ERROR_BUFFER;
483 break;
484 default:
485 ALOGE("%s: Unknown error code: %u", __FUNCTION__, hal_error.error_code);
486 return BAD_VALUE;
487 }
488
489 return OK;
490 }
491
ConvertToHidlShutterMessage(const google_camera_hal::ShutterMessage & hal_shutter,ShutterMsg * hidl_shutter)492 status_t ConvertToHidlShutterMessage(
493 const google_camera_hal::ShutterMessage& hal_shutter,
494 ShutterMsg* hidl_shutter) {
495 if (hidl_shutter == nullptr) {
496 ALOGE("%s: hidl_shutter is nullptr.", __FUNCTION__);
497 return BAD_VALUE;
498 }
499
500 hidl_shutter->frameNumber = hal_shutter.frame_number;
501 hidl_shutter->timestamp = hal_shutter.timestamp_ns;
502 return OK;
503 }
504
ConverToHidlNotifyMessage(const google_camera_hal::NotifyMessage & hal_message,NotifyMsg * hidl_message)505 status_t ConverToHidlNotifyMessage(
506 const google_camera_hal::NotifyMessage& hal_message,
507 NotifyMsg* hidl_message) {
508 if (hidl_message == nullptr) {
509 ALOGE("%s: hidl_message is nullptr.", __FUNCTION__);
510 return BAD_VALUE;
511 }
512
513 status_t res;
514 switch (hal_message.type) {
515 case google_camera_hal::MessageType::kError:
516 hidl_message->type = MsgType::ERROR;
517 res = ConvertToHidlErrorMessage(hal_message.message.error,
518 &hidl_message->msg.error);
519 if (res != OK) {
520 ALOGE("%s: Converting to HIDL error message failed: %s(%d)",
521 __FUNCTION__, strerror(-res), res);
522 return res;
523 }
524 break;
525 case google_camera_hal::MessageType::kShutter:
526 hidl_message->type = MsgType::SHUTTER;
527 res = ConvertToHidlShutterMessage(hal_message.message.shutter,
528 &hidl_message->msg.shutter);
529 if (res != OK) {
530 ALOGE("%s: Converting to HIDL shutter message failed: %s(%d)",
531 __FUNCTION__, strerror(-res), res);
532 return res;
533 }
534 break;
535 default:
536 ALOGE("%s: Unknown message type: %u", __FUNCTION__, hal_message.type);
537 return BAD_VALUE;
538 }
539
540 return OK;
541 }
542
ConvertToHidlCameraDeviceStatus(google_camera_hal::CameraDeviceStatus hal_camera_device_status,CameraDeviceStatus * hidl_camera_device_status)543 status_t ConvertToHidlCameraDeviceStatus(
544 google_camera_hal::CameraDeviceStatus hal_camera_device_status,
545 CameraDeviceStatus* hidl_camera_device_status) {
546 if (hidl_camera_device_status == nullptr) {
547 ALOGE("%s: hidl_camera_device_status is nullptr.", __FUNCTION__);
548 return BAD_VALUE;
549 }
550
551 switch (hal_camera_device_status) {
552 case google_camera_hal::CameraDeviceStatus::kNotPresent:
553 *hidl_camera_device_status = CameraDeviceStatus::NOT_PRESENT;
554 break;
555 case google_camera_hal::CameraDeviceStatus::kPresent:
556 *hidl_camera_device_status = CameraDeviceStatus::PRESENT;
557 break;
558 case google_camera_hal::CameraDeviceStatus::kEnumerating:
559 *hidl_camera_device_status = CameraDeviceStatus::ENUMERATING;
560 break;
561 default:
562 ALOGE("%s: Unknown HAL camera device status: %u", __FUNCTION__,
563 hal_camera_device_status);
564 return BAD_VALUE;
565 }
566
567 return OK;
568 }
569
ConvertToHidlTorchModeStatus(google_camera_hal::TorchModeStatus hal_torch_status,TorchModeStatus * hidl_torch_status)570 status_t ConvertToHidlTorchModeStatus(
571 google_camera_hal::TorchModeStatus hal_torch_status,
572 TorchModeStatus* hidl_torch_status) {
573 if (hidl_torch_status == nullptr) {
574 ALOGE("%s: hidl_torch_status is nullptr.", __FUNCTION__);
575 return BAD_VALUE;
576 }
577
578 switch (hal_torch_status) {
579 case google_camera_hal::TorchModeStatus::kNotAvailable:
580 *hidl_torch_status = TorchModeStatus::NOT_AVAILABLE;
581 break;
582 case google_camera_hal::TorchModeStatus::kAvailableOff:
583 *hidl_torch_status = TorchModeStatus::AVAILABLE_OFF;
584 break;
585 case google_camera_hal::TorchModeStatus::kAvailableOn:
586 *hidl_torch_status = TorchModeStatus::AVAILABLE_ON;
587 break;
588 default:
589 ALOGE("%s: Unknown HAL torch mode status: %u", __FUNCTION__,
590 hal_torch_status);
591 return BAD_VALUE;
592 }
593
594 return OK;
595 }
596
ConvertToHidlBufferRequest(const std::vector<google_camera_hal::BufferRequest> & hal_buffer_requests,hidl_vec<BufferRequest> * hidl_buffer_requests)597 status_t ConvertToHidlBufferRequest(
598 const std::vector<google_camera_hal::BufferRequest>& hal_buffer_requests,
599 hidl_vec<BufferRequest>* hidl_buffer_requests) {
600 if (hidl_buffer_requests == nullptr) {
601 ALOGE("%s: hidl_buffer_request is nullptr.", __FUNCTION__);
602 return BAD_VALUE;
603 }
604
605 hidl_buffer_requests->resize(hal_buffer_requests.size());
606 for (uint32_t i = 0; i < hal_buffer_requests.size(); i++) {
607 (*hidl_buffer_requests)[i].streamId = hal_buffer_requests[i].stream_id;
608 (*hidl_buffer_requests)[i].numBuffersRequested =
609 hal_buffer_requests[i].num_buffers_requested;
610 }
611 return OK;
612 }
613
ConvertToHalBufferStatus(BufferStatus hidl_status,google_camera_hal::BufferStatus * hal_status)614 status_t ConvertToHalBufferStatus(BufferStatus hidl_status,
615 google_camera_hal::BufferStatus* hal_status) {
616 if (hal_status == nullptr) {
617 ALOGE("%s: hal_status is nullptr.", __FUNCTION__);
618 return BAD_VALUE;
619 }
620
621 switch (hidl_status) {
622 case BufferStatus::OK:
623 *hal_status = google_camera_hal::BufferStatus::kOk;
624 break;
625 case BufferStatus::ERROR:
626 *hal_status = google_camera_hal::BufferStatus::kError;
627 break;
628 default:
629 ALOGE("%s: Unknown HIDL buffer status: %u", __FUNCTION__, hidl_status);
630 return BAD_VALUE;
631 }
632
633 return OK;
634 }
635
ConvertToHalStreamBuffer(const StreamBuffer & hidl_buffer,google_camera_hal::StreamBuffer * hal_buffer)636 status_t ConvertToHalStreamBuffer(const StreamBuffer& hidl_buffer,
637 google_camera_hal::StreamBuffer* hal_buffer) {
638 if (hal_buffer == nullptr) {
639 ALOGE("%s: hal_buffer is nullptr.", __FUNCTION__);
640 return BAD_VALUE;
641 }
642
643 hal_buffer->stream_id = hidl_buffer.streamId;
644 hal_buffer->buffer_id = hidl_buffer.bufferId;
645 hal_buffer->buffer = hidl_buffer.buffer.getNativeHandle();
646
647 status_t res =
648 ConvertToHalBufferStatus(hidl_buffer.status, &hal_buffer->status);
649 if (res != OK) {
650 ALOGE("%s: Converting to HAL buffer status failed: %s(%d)", __FUNCTION__,
651 strerror(-res), res);
652 return res;
653 }
654
655 hal_buffer->acquire_fence = hidl_buffer.acquireFence.getNativeHandle();
656 hal_buffer->release_fence = hidl_buffer.releaseFence.getNativeHandle();
657
658 return OK;
659 }
660
ConvertToHalMetadata(uint32_t message_queue_setting_size,MessageQueue<uint8_t,kSynchronizedReadWrite> * request_metadata_queue,const CameraMetadata & request_settings,std::unique_ptr<google_camera_hal::HalCameraMetadata> * hal_metadata)661 status_t ConvertToHalMetadata(
662 uint32_t message_queue_setting_size,
663 MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
664 const CameraMetadata& request_settings,
665 std::unique_ptr<google_camera_hal::HalCameraMetadata>* hal_metadata) {
666 if (hal_metadata == nullptr) {
667 ALOGE("%s: hal_metadata is nullptr.", __FUNCTION__);
668 return BAD_VALUE;
669 }
670
671 const camera_metadata_t* metadata = nullptr;
672 CameraMetadata metadata_queue_settings;
673
674 if (message_queue_setting_size == 0) {
675 // Use the settings in the request.
676 if (request_settings.size() != 0) {
677 metadata =
678 reinterpret_cast<const camera_metadata_t*>(request_settings.data());
679 }
680 } else {
681 // Read the settings from request metadata queue.
682 if (request_metadata_queue == nullptr) {
683 ALOGE("%s: request_metadata_queue is nullptr", __FUNCTION__);
684 return BAD_VALUE;
685 }
686
687 metadata_queue_settings.resize(message_queue_setting_size);
688 bool success = request_metadata_queue->read(metadata_queue_settings.data(),
689 message_queue_setting_size);
690 if (!success) {
691 ALOGE("%s: Failed to read from request metadata queue.", __FUNCTION__);
692 return BAD_VALUE;
693 }
694
695 metadata = reinterpret_cast<const camera_metadata_t*>(
696 metadata_queue_settings.data());
697 }
698
699 if (metadata == nullptr) {
700 *hal_metadata = nullptr;
701 return OK;
702 }
703
704 *hal_metadata = google_camera_hal::HalCameraMetadata::Clone(metadata);
705 return OK;
706 }
707
ConvertToHalCaptureRequest(const CaptureRequest & hidl_request,MessageQueue<uint8_t,kSynchronizedReadWrite> * request_metadata_queue,google_camera_hal::CaptureRequest * hal_request)708 status_t ConvertToHalCaptureRequest(
709 const CaptureRequest& hidl_request,
710 MessageQueue<uint8_t, kSynchronizedReadWrite>* request_metadata_queue,
711 google_camera_hal::CaptureRequest* hal_request) {
712 if (hal_request == nullptr) {
713 ALOGE("%s: hal_request is nullptr.", __FUNCTION__);
714 return BAD_VALUE;
715 }
716
717 hal_request->frame_number = hidl_request.v3_4.v3_2.frameNumber;
718
719 status_t res = ConvertToHalMetadata(
720 hidl_request.v3_4.v3_2.fmqSettingsSize, request_metadata_queue,
721 hidl_request.v3_4.v3_2.settings, &hal_request->settings);
722 if (res != OK) {
723 ALOGE("%s: Converting metadata failed: %s(%d)", __FUNCTION__,
724 strerror(-res), res);
725 return res;
726 }
727
728 google_camera_hal::StreamBuffer hal_buffer = {};
729 if (hidl_request.v3_4.v3_2.inputBuffer.buffer != nullptr) {
730 res = ConvertToHalStreamBuffer(hidl_request.v3_4.v3_2.inputBuffer,
731 &hal_buffer);
732 if (res != OK) {
733 ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
734 strerror(-res), res);
735 return res;
736 }
737
738 hal_request->input_buffers.push_back(hal_buffer);
739 hal_request->input_width = hidl_request.inputWidth;
740 hal_request->input_height = hidl_request.inputHeight;
741 }
742
743 for (auto& buffer : hidl_request.v3_4.v3_2.outputBuffers) {
744 hal_buffer = {};
745 status_t res = ConvertToHalStreamBuffer(buffer, &hal_buffer);
746 if (res != OK) {
747 ALOGE("%s: Converting hal stream buffer failed: %s(%d)", __FUNCTION__,
748 strerror(-res), res);
749 return res;
750 }
751
752 hal_request->output_buffers.push_back(hal_buffer);
753 }
754
755 for (auto hidl_physical_settings : hidl_request.v3_4.physicalCameraSettings) {
756 std::unique_ptr<google_camera_hal::HalCameraMetadata> hal_physical_settings;
757 res = ConvertToHalMetadata(
758 hidl_physical_settings.fmqSettingsSize, request_metadata_queue,
759 hidl_physical_settings.settings, &hal_physical_settings);
760 if (res != OK) {
761 ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
762 strerror(-res), res);
763 return res;
764 }
765
766 uint32_t camera_id = std::stoul(hidl_physical_settings.physicalCameraId);
767 hal_request->physical_camera_settings.emplace(
768 camera_id, std::move(hal_physical_settings));
769 }
770
771 return OK;
772 }
773
ConvertToHalBufferCaches(const hidl_vec<BufferCache> & hidl_buffer_caches,std::vector<google_camera_hal::BufferCache> * hal_buffer_caches)774 status_t ConvertToHalBufferCaches(
775 const hidl_vec<BufferCache>& hidl_buffer_caches,
776 std::vector<google_camera_hal::BufferCache>* hal_buffer_caches) {
777 if (hal_buffer_caches == nullptr) {
778 ALOGE("%s: hal_buffer_caches is nullptr.", __FUNCTION__);
779 return BAD_VALUE;
780 }
781
782 for (auto hidl_cache : hidl_buffer_caches) {
783 google_camera_hal::BufferCache hal_cache;
784 hal_cache.stream_id = hidl_cache.streamId;
785 hal_cache.buffer_id = hidl_cache.bufferId;
786
787 hal_buffer_caches->push_back(hal_cache);
788 }
789
790 return OK;
791 }
792
ConvertToHalStreamConfigurationMode(StreamConfigurationMode hidl_mode,google_camera_hal::StreamConfigurationMode * hal_mode)793 status_t ConvertToHalStreamConfigurationMode(
794 StreamConfigurationMode hidl_mode,
795 google_camera_hal::StreamConfigurationMode* hal_mode) {
796 if (hal_mode == nullptr) {
797 ALOGE("%s: hal_mode is nullptr.", __FUNCTION__);
798 return BAD_VALUE;
799 }
800
801 switch (hidl_mode) {
802 case StreamConfigurationMode::NORMAL_MODE:
803 *hal_mode = google_camera_hal::StreamConfigurationMode::kNormal;
804 break;
805 case StreamConfigurationMode::CONSTRAINED_HIGH_SPEED_MODE:
806 *hal_mode =
807 google_camera_hal::StreamConfigurationMode::kConstrainedHighSpeed;
808 break;
809 default:
810 ALOGE("%s: Unknown configuration mode %u", __FUNCTION__, hidl_mode);
811 return BAD_VALUE;
812 }
813
814 return OK;
815 }
816
sensorPixelModeContains(const device::V3_7::Stream & hidl_stream,uint32_t key)817 static bool sensorPixelModeContains(const device::V3_7::Stream& hidl_stream,
818 uint32_t key) {
819 for (auto& i : hidl_stream.sensorPixelModesUsed) {
820 if (i == static_cast<CameraMetadataEnumAndroidSensorPixelMode>(key)) {
821 return true;
822 }
823 }
824 return false;
825 }
826
ConverToHalStreamConfig(const StreamConfiguration & hidl_stream_config,google_camera_hal::StreamConfiguration * hal_stream_config)827 status_t ConverToHalStreamConfig(
828 const StreamConfiguration& hidl_stream_config,
829 google_camera_hal::StreamConfiguration* hal_stream_config) {
830 if (hal_stream_config == nullptr) {
831 ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
832 return BAD_VALUE;
833 }
834
835 status_t res;
836
837 for (auto hidl_stream : hidl_stream_config.streams) {
838 google_camera_hal::Stream hal_stream;
839 res = ConvertToHalStream(hidl_stream.v3_4, &hal_stream);
840 if (res != OK) {
841 ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
842 strerror(-res), res);
843 return res;
844 }
845 hal_stream.group_id = hidl_stream.groupId;
846
847 hal_stream.used_in_max_resolution_mode = sensorPixelModeContains(
848 hidl_stream, ANDROID_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION);
849 hal_stream.used_in_default_resolution_mode =
850 hidl_stream.sensorPixelModesUsed.size() > 0
851 ? sensorPixelModeContains(hidl_stream,
852 ANDROID_SENSOR_PIXEL_MODE_DEFAULT)
853 : true;
854 hal_stream_config->streams.push_back(hal_stream);
855 }
856
857 res = ConvertToHalStreamConfigurationMode(hidl_stream_config.operationMode,
858 &hal_stream_config->operation_mode);
859 if (res != OK) {
860 ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
861 strerror(-res), res);
862 return res;
863 }
864
865 res = ConvertToHalMetadata(0, nullptr, hidl_stream_config.sessionParams,
866 &hal_stream_config->session_params);
867 if (res != OK) {
868 ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
869 strerror(-res), res);
870 return res;
871 }
872
873 hal_stream_config->stream_config_counter =
874 hidl_stream_config.streamConfigCounter;
875 hal_stream_config->multi_resolution_input_image =
876 hidl_stream_config.multiResolutionInputImage;
877
878 return OK;
879 }
880
ConverToHalStreamConfig(const device::V3_4::StreamConfiguration & hidl_stream_config,google_camera_hal::StreamConfiguration * hal_stream_config)881 status_t ConverToHalStreamConfig(
882 const device::V3_4::StreamConfiguration& hidl_stream_config,
883 google_camera_hal::StreamConfiguration* hal_stream_config) {
884 if (hal_stream_config == nullptr) {
885 ALOGE("%s: hal_stream_config is nullptr.", __FUNCTION__);
886 return BAD_VALUE;
887 }
888
889 status_t res;
890 for (auto hidl_stream : hidl_stream_config.streams) {
891 google_camera_hal::Stream hal_stream;
892 res = ConvertToHalStream(hidl_stream, &hal_stream);
893 if (res != OK) {
894 ALOGE("%s: Converting to HAL stream failed: %s(%d)", __FUNCTION__,
895 strerror(-res), res);
896 return res;
897 }
898 hal_stream_config->streams.push_back(hal_stream);
899 }
900
901 res = ConvertToHalStreamConfigurationMode(hidl_stream_config.operationMode,
902 &hal_stream_config->operation_mode);
903 if (res != OK) {
904 ALOGE("%s: Converting to HAL opeation mode failed: %s(%d)", __FUNCTION__,
905 strerror(-res), res);
906 return res;
907 }
908
909 res = ConvertToHalMetadata(0, nullptr, hidl_stream_config.sessionParams,
910 &hal_stream_config->session_params);
911 if (res != OK) {
912 ALOGE("%s: Converting to HAL metadata failed: %s(%d)", __FUNCTION__,
913 strerror(-res), res);
914 return res;
915 }
916
917 return OK;
918 }
919
ConvertToHalStreamType(StreamType hidl_stream_type,google_camera_hal::StreamType * hal_stream_type)920 status_t ConvertToHalStreamType(StreamType hidl_stream_type,
921 google_camera_hal::StreamType* hal_stream_type) {
922 if (hal_stream_type == nullptr) {
923 ALOGE("%s: hal_stream_type is nullptr.", __FUNCTION__);
924 return BAD_VALUE;
925 }
926
927 switch (hidl_stream_type) {
928 case StreamType::OUTPUT:
929 *hal_stream_type = google_camera_hal::StreamType::kOutput;
930 break;
931 case StreamType::INPUT:
932 *hal_stream_type = google_camera_hal::StreamType::kInput;
933 break;
934 default:
935 ALOGE("%s: Unknown stream type: %u", __FUNCTION__, hidl_stream_type);
936 return BAD_VALUE;
937 }
938
939 return OK;
940 }
941
ConvertToHalStreamRotation(StreamRotation hidl_stream_rotation,google_camera_hal::StreamRotation * hal_stream_rotation)942 status_t ConvertToHalStreamRotation(
943 StreamRotation hidl_stream_rotation,
944 google_camera_hal::StreamRotation* hal_stream_rotation) {
945 if (hal_stream_rotation == nullptr) {
946 ALOGE("%s: hal_stream_rotation is nullptr.", __FUNCTION__);
947 return BAD_VALUE;
948 }
949
950 switch (hidl_stream_rotation) {
951 case StreamRotation::ROTATION_0:
952 *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation0;
953 break;
954 case StreamRotation::ROTATION_90:
955 *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation90;
956 break;
957 case StreamRotation::ROTATION_180:
958 *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation180;
959 break;
960 case StreamRotation::ROTATION_270:
961 *hal_stream_rotation = google_camera_hal::StreamRotation::kRotation270;
962 break;
963 default:
964 ALOGE("%s: Unknown stream rotation: %u", __FUNCTION__,
965 hidl_stream_rotation);
966 return BAD_VALUE;
967 }
968
969 return OK;
970 }
971
ConvertToHalStream(const Stream & hidl_stream,google_camera_hal::Stream * hal_stream)972 status_t ConvertToHalStream(const Stream& hidl_stream,
973 google_camera_hal::Stream* hal_stream) {
974 if (hal_stream == nullptr) {
975 ALOGE("%s: hal_stream is nullptr.", __FUNCTION__);
976 return BAD_VALUE;
977 }
978
979 *hal_stream = {};
980
981 hal_stream->id = hidl_stream.v3_2.id;
982
983 status_t res = ConvertToHalStreamType(hidl_stream.v3_2.streamType,
984 &hal_stream->stream_type);
985 if (res != OK) {
986 ALOGE("%s: Converting to HAL stream type failed: %s(%d)", __FUNCTION__,
987 strerror(-res), res);
988 return res;
989 }
990
991 hal_stream->width = hidl_stream.v3_2.width;
992 hal_stream->height = hidl_stream.v3_2.height;
993 hal_stream->format = (android_pixel_format_t)hidl_stream.v3_2.format;
994 hal_stream->usage = (uint64_t)hidl_stream.v3_2.usage;
995 hal_stream->data_space = (android_dataspace_t)hidl_stream.v3_2.dataSpace;
996
997 res = ConvertToHalStreamRotation(hidl_stream.v3_2.rotation,
998 &hal_stream->rotation);
999 if (res != OK) {
1000 ALOGE("%s: Converting to HAL stream rotation failed: %s(%d)", __FUNCTION__,
1001 strerror(-res), res);
1002 return res;
1003 }
1004
1005 if (hidl_stream.physicalCameraId.empty()) {
1006 hal_stream->is_physical_camera_stream = false;
1007 } else {
1008 hal_stream->is_physical_camera_stream = true;
1009 hal_stream->physical_camera_id = std::stoul(hidl_stream.physicalCameraId);
1010 }
1011
1012 hal_stream->buffer_size = hidl_stream.bufferSize;
1013
1014 return OK;
1015 }
1016
ConvertToHalTorchMode(TorchMode hidl_torch_mode,google_camera_hal::TorchMode * hal_torch_mode)1017 status_t ConvertToHalTorchMode(TorchMode hidl_torch_mode,
1018 google_camera_hal::TorchMode* hal_torch_mode) {
1019 if (hal_torch_mode == nullptr) {
1020 ALOGE("%s: hal_torch_mode is nullptr.", __FUNCTION__);
1021 return BAD_VALUE;
1022 }
1023
1024 switch (hidl_torch_mode) {
1025 case TorchMode::ON:
1026 *hal_torch_mode = google_camera_hal::TorchMode::kOn;
1027 break;
1028 case TorchMode::OFF:
1029 *hal_torch_mode = google_camera_hal::TorchMode::kOff;
1030 break;
1031 default:
1032 ALOGE("%s: Unknown torch mode: %u", __FUNCTION__, hidl_torch_mode);
1033 return BAD_VALUE;
1034 }
1035
1036 return OK;
1037 }
1038
ConvertToHalBufferRequestStatus(const BufferRequestStatus & hidl_buffer_request_status,google_camera_hal::BufferRequestStatus * hal_buffer_request_status)1039 status_t ConvertToHalBufferRequestStatus(
1040 const BufferRequestStatus& hidl_buffer_request_status,
1041 google_camera_hal::BufferRequestStatus* hal_buffer_request_status) {
1042 if (hal_buffer_request_status == nullptr) {
1043 ALOGE("%s: hal_buffer_request_status is nullptr.", __FUNCTION__);
1044 return BAD_VALUE;
1045 }
1046
1047 switch (hidl_buffer_request_status) {
1048 case BufferRequestStatus::OK:
1049 *hal_buffer_request_status = google_camera_hal::BufferRequestStatus::kOk;
1050 break;
1051 case BufferRequestStatus::FAILED_PARTIAL:
1052 *hal_buffer_request_status =
1053 google_camera_hal::BufferRequestStatus::kFailedPartial;
1054 break;
1055 case BufferRequestStatus::FAILED_CONFIGURING:
1056 *hal_buffer_request_status =
1057 google_camera_hal::BufferRequestStatus::kFailedConfiguring;
1058 break;
1059 case BufferRequestStatus::FAILED_ILLEGAL_ARGUMENTS:
1060 *hal_buffer_request_status =
1061 google_camera_hal::BufferRequestStatus::kFailedIllegalArgs;
1062 break;
1063 case BufferRequestStatus::FAILED_UNKNOWN:
1064 *hal_buffer_request_status =
1065 google_camera_hal::BufferRequestStatus::kFailedUnknown;
1066 break;
1067 default:
1068 ALOGE("%s: Failed unknown buffer request error code %d", __FUNCTION__,
1069 hidl_buffer_request_status);
1070 return BAD_VALUE;
1071 }
1072
1073 return OK;
1074 }
1075
ConvertToHalBufferReturnStatus(const StreamBufferRet & hidl_stream_buffer_return,google_camera_hal::BufferReturn * hal_buffer_return)1076 status_t ConvertToHalBufferReturnStatus(
1077 const StreamBufferRet& hidl_stream_buffer_return,
1078 google_camera_hal::BufferReturn* hal_buffer_return) {
1079 if (hal_buffer_return == nullptr) {
1080 ALOGE("%s: hal_buffer_return is nullptr.", __FUNCTION__);
1081 return BAD_VALUE;
1082 }
1083
1084 if (hidl_stream_buffer_return.val.getDiscriminator() ==
1085 StreamBuffersVal::hidl_discriminator::error) {
1086 switch (hidl_stream_buffer_return.val.error()) {
1087 case StreamBufferRequestError::NO_BUFFER_AVAILABLE:
1088 hal_buffer_return->val.error =
1089 google_camera_hal::StreamBufferRequestError::kNoBufferAvailable;
1090 break;
1091 case StreamBufferRequestError::MAX_BUFFER_EXCEEDED:
1092 hal_buffer_return->val.error =
1093 google_camera_hal::StreamBufferRequestError::kMaxBufferExceeded;
1094 break;
1095 case StreamBufferRequestError::STREAM_DISCONNECTED:
1096 hal_buffer_return->val.error =
1097 google_camera_hal::StreamBufferRequestError::kStreamDisconnected;
1098 break;
1099 case StreamBufferRequestError::UNKNOWN_ERROR:
1100 hal_buffer_return->val.error =
1101 google_camera_hal::StreamBufferRequestError::kUnknownError;
1102 break;
1103 default:
1104 ALOGE("%s: Unknown StreamBufferRequestError %d", __FUNCTION__,
1105 hidl_stream_buffer_return.val.error());
1106 return BAD_VALUE;
1107 }
1108 } else {
1109 hal_buffer_return->val.error =
1110 google_camera_hal::StreamBufferRequestError::kOk;
1111 }
1112
1113 return OK;
1114 }
1115
ConvertStreamConfigurationV34ToV37(const device::V3_4::StreamConfiguration & config_3_4,StreamConfiguration * config_3_7)1116 status_t ConvertStreamConfigurationV34ToV37(
1117 const device::V3_4::StreamConfiguration& config_3_4,
1118 StreamConfiguration* config_3_7) {
1119 if (config_3_7 == nullptr) {
1120 ALOGE("%s: config_3_7 is nullptr.", __FUNCTION__);
1121 return BAD_VALUE;
1122 }
1123
1124 config_3_7->streams.resize(config_3_4.streams.size());
1125 for (size_t i = 0; i < config_3_4.streams.size(); i++) {
1126 config_3_7->streams[i].v3_4 = config_3_4.streams[i];
1127 config_3_7->streams[i].groupId = -1;
1128 }
1129 config_3_7->operationMode = config_3_4.operationMode;
1130 config_3_7->sessionParams = config_3_4.sessionParams;
1131 config_3_7->multiResolutionInputImage = false;
1132
1133 return OK;
1134 }
1135
ConvertToHalDeviceState(const hardware::hidl_bitfield<DeviceState> hidl_device_state,google_camera_hal::DeviceState & hal_device_state)1136 status_t ConvertToHalDeviceState(
1137 const hardware::hidl_bitfield<DeviceState> hidl_device_state,
1138 google_camera_hal::DeviceState& hal_device_state) {
1139 switch (static_cast<DeviceState>(hidl_device_state)) {
1140 case DeviceState::NORMAL:
1141 hal_device_state = google_camera_hal::DeviceState::kNormal;
1142 break;
1143 case DeviceState::BACK_COVERED:
1144 hal_device_state = google_camera_hal::DeviceState::kBackCovered;
1145 break;
1146 case DeviceState::FRONT_COVERED:
1147 hal_device_state = google_camera_hal::DeviceState::kFrontCovered;
1148 break;
1149 case DeviceState::FOLDED:
1150 hal_device_state = google_camera_hal::DeviceState::kFolded;
1151 break;
1152 default:
1153 ALOGE("%s: Failed unknown device state", __FUNCTION__);
1154 return BAD_VALUE;
1155 }
1156
1157 return OK;
1158 }
1159 } // namespace hidl_utils
1160 } // namespace implementation
1161 } // namespace camera
1162 } // namespace hardware
1163 } // namespace android
1164