Avichal Rakesh | e1857f8 | 2022-06-08 17:47:23 -0700 | [diff] [blame] | 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 | #define LOG_TAG "android.hardware.camera.device@3.4-convert-impl" |
| 18 | #include <log/log.h> |
| 19 | |
| 20 | #include "convert.h" |
| 21 | |
| 22 | #include <aidl/android/hardware/graphics/common/BufferUsage.h> |
| 23 | #include <aidl/android/hardware/graphics/common/PixelFormat.h> |
| 24 | #include <hardware/camera_common.h> |
| 25 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace camera { |
| 29 | namespace device { |
| 30 | namespace implementation { |
| 31 | |
| 32 | using ::aidl::android::hardware::camera::device::ErrorCode; |
| 33 | using ::aidl::android::hardware::camera::device::ErrorMsg; |
| 34 | using ::aidl::android::hardware::camera::device::ShutterMsg; |
| 35 | using ::aidl::android::hardware::graphics::common::BufferUsage; |
| 36 | using ::aidl::android::hardware::graphics::common::PixelFormat; |
| 37 | |
| 38 | void convertToAidl(const camera_metadata_t* src, CameraMetadata* dest) { |
| 39 | if (src == nullptr) { |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | size_t size = get_camera_metadata_size(src); |
| 44 | auto* src_start = (uint8_t*)src; |
| 45 | uint8_t* src_end = src_start + size; |
| 46 | dest->metadata.assign(src_start, src_end); |
| 47 | } |
| 48 | |
| 49 | bool convertFromAidl(const CameraMetadata& src, const camera_metadata_t** dst) { |
| 50 | const std::vector<uint8_t>& metadata = src.metadata; |
| 51 | if (metadata.empty()) { |
| 52 | // Special case for null metadata |
| 53 | *dst = nullptr; |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | const uint8_t* data = metadata.data(); |
| 58 | // check that the size of CameraMetadata match underlying camera_metadata_t |
| 59 | if (get_camera_metadata_size((camera_metadata_t*)data) != metadata.size()) { |
| 60 | ALOGE("%s: input CameraMetadata is corrupt!", __FUNCTION__); |
| 61 | return false; |
| 62 | } |
| 63 | *dst = (camera_metadata_t*)data; |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | } // namespace implementation |
| 68 | } // namespace device |
| 69 | } // namespace camera |
| 70 | } // namespace hardware |
| 71 | } // namespace android |