1 /* 2 * Copyright (C) 2023 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 #pragma once 18 19 #include <optional> 20 #include <type_traits> 21 #include <unordered_map> 22 #include <vector> 23 24 #include <aidl/android/hardware/camera/device/CameraMetadata.h> 25 26 namespace android { 27 namespace hardware { 28 namespace camera { 29 namespace provider { 30 namespace implementation { 31 32 using aidl::android::hardware::camera::device::CameraMetadata; 33 34 struct CameraMetadataValue { 35 std::vector<uint8_t> data; 36 unsigned count = 0; 37 38 template <class T> CameraMetadataValue& operator=(const T& v) { 39 static_assert(std::is_trivial<T>::value); 40 const uint8_t* v8 = reinterpret_cast<const uint8_t*>(&v); 41 data.assign(v8, v8 + sizeof(v)); 42 count = 1; 43 return *this; 44 } 45 46 template <class T, size_t N> CameraMetadataValue& operator=(const T (&a)[N]) { 47 static_assert(std::is_trivial<T>::value); 48 const uint8_t* v8 = reinterpret_cast<const uint8_t*>(&a[0]); 49 data.assign(v8, v8 + sizeof(a)); 50 count = N; 51 return *this; 52 } 53 addCameraMetadataValue54 template <class T> CameraMetadataValue& add(const T& v) { 55 static_assert(std::is_trivial<T>::value); 56 const uint8_t* v8 = reinterpret_cast<const uint8_t*>(&v); 57 data.insert(data.end(), v8, v8 + sizeof(v)); 58 ++count; 59 return *this; 60 } 61 }; 62 63 using CameraMetadataMap = std::unordered_map<uint32_t, CameraMetadataValue>; 64 65 CameraMetadata metadataCompact(const CameraMetadata&); 66 67 std::optional<CameraMetadata> serializeCameraMetadataMap(const CameraMetadataMap& m); 68 69 CameraMetadataMap parseCameraMetadataMap(const CameraMetadata& m); 70 71 void metadataSetShutterTimestamp(CameraMetadata* metadata, int64_t shutterTimestampNs); 72 73 void prettyPrintCameraMetadata(const CameraMetadata&); 74 75 } // namespace implementation 76 } // namespace provider 77 } // namespace camera 78 } // namespace hardware 79 } // namespace android 80