Tanmay Patil | b2897b4 | 2020-06-08 17:55:02 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2020 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 SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_ |
| 18 | #define SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include "core_lib.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace hardware { |
| 26 | namespace automotive { |
| 27 | namespace sv { |
| 28 | namespace V1_0 { |
| 29 | namespace implementation { |
| 30 | |
| 31 | // Struct for camera related configurations. |
| 32 | // Note: Does not camera intrinsics and extrinsics, these are specified in EVS metadata. |
| 33 | struct CameraConfig { |
| 34 | // Id of logical group containing surronnd view cameras. |
| 35 | std::string evsGroupId; |
| 36 | |
| 37 | // List of evs camera Ids in order: front, right, rear, left. |
| 38 | std::vector<std::string> evsCameraIds; |
| 39 | |
| 40 | // In order: front, right, rear, left. |
| 41 | std::vector<std::string> maskFilenames; |
| 42 | }; |
| 43 | |
| 44 | struct SvConfig2d { |
| 45 | // Bool flag for surround view 2d. |
| 46 | bool sv2dEnabled; |
| 47 | |
| 48 | // Surround view 2d params. |
| 49 | android_auto::surround_view::SurroundView2dParams sv2dParams; |
| 50 | |
| 51 | // Car model bounding box for 2d surround view. |
| 52 | // To be moved into sv 2d params. |
| 53 | android_auto::surround_view::BoundingBox carBoundingBox; |
| 54 | }; |
| 55 | |
| 56 | struct SvConfig3d { |
| 57 | // Bool flag for enabling/disabling surround view 3d. |
| 58 | bool sv3dEnabled; |
| 59 | |
| 60 | // Bool flag for enabling/disabling animations. |
| 61 | bool sv3dAnimationsEnabled; |
| 62 | |
| 63 | // Car model config file. |
| 64 | std::string carModelConfigFile; |
| 65 | |
| 66 | // Car model obj file. |
| 67 | std::string carModelObjFile; |
| 68 | |
| 69 | // Surround view 3d params. |
| 70 | android_auto::surround_view::SurroundView3dParams sv3dParams; |
| 71 | }; |
| 72 | |
| 73 | // Main struct in which surround view config is parsed into. |
| 74 | struct SurroundViewConfig { |
| 75 | // Version info. |
| 76 | std::string version; |
| 77 | |
| 78 | // Camera config. |
| 79 | CameraConfig cameraConfig; |
| 80 | |
| 81 | // Surround view 2d config. |
| 82 | SvConfig2d sv2dConfig; |
| 83 | |
| 84 | // Surround view 3d config. |
| 85 | SvConfig3d sv3dConfig; |
| 86 | }; |
| 87 | |
| 88 | struct Range { |
| 89 | // Range start. |
| 90 | // Start value may be greater than end value. |
| 91 | float start; |
| 92 | |
| 93 | // Range end. |
| 94 | float end; |
| 95 | }; |
| 96 | |
| 97 | // Rotation axis |
| 98 | struct RotationAxis { |
| 99 | // Unit axis direction vector. |
| 100 | std::array<float, 3> axisVector; |
| 101 | |
| 102 | // Rotate about this point. |
| 103 | std::array<float, 3> rotationPoint; |
| 104 | }; |
| 105 | |
| 106 | enum AnimationType { |
| 107 | // Rotate a part about an axis from a start to end angle. |
| 108 | ROTATION_ANGLE = 0, |
| 109 | |
| 110 | // Continuously rotate a part about an axis by a specified angular speed. |
| 111 | ROTATION_SPEED = 1, |
| 112 | |
| 113 | // Linearly translates a part from one point to another. |
| 114 | TRANSLATION = 2, |
| 115 | |
| 116 | // Switch to another texture once. |
| 117 | SWITCH_TEXTURE_ONCE = 3, |
| 118 | |
| 119 | // Adjust the brightness of the texture once. |
| 120 | ADJUST_GAMMA_ONCE = 4, |
| 121 | |
| 122 | // Repeatedly toggle between two textures. |
| 123 | SWITCH_TEXTURE_REPEAT = 5, |
| 124 | |
| 125 | // Repeatedly toggle between two gamma values. |
| 126 | ADJUST_GAMMA_REPEAT = 6, |
| 127 | }; |
| 128 | |
| 129 | // Rotation operation |
| 130 | struct RotationOp { |
| 131 | // VHAL signal to trigger operation. |
| 132 | uint64_t vhalProperty; |
| 133 | |
| 134 | // Rotation operation type. |
| 135 | AnimationType type; |
| 136 | |
| 137 | // Rotation axis. |
| 138 | RotationAxis axis; |
| 139 | |
| 140 | // Default rotation (angle/speed) value. |
| 141 | // It is used for default rotation when the signal is on while vhal_range is |
| 142 | // not provided. |
| 143 | float defaultRotationValue; |
| 144 | |
| 145 | // Default animation time elapsed to finish the rotation operation. |
| 146 | // It is ignored if VHAL provides continuous signal value. |
| 147 | float animationTime; |
| 148 | |
| 149 | // physical rotation range with start mapped to vhal_range start and |
| 150 | // end mapped to vhal_range end. |
| 151 | Range rotationRange; |
| 152 | |
| 153 | // VHAL signal range. |
| 154 | // Un-supported types: STRING, BYTES and VEC |
| 155 | // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal |
| 156 | // VehiclePropertyType |
| 157 | Range vhalRange; |
| 158 | }; |
| 159 | |
| 160 | // Translation operation. |
| 161 | struct TranslationOp { |
| 162 | // VHAL signal to trigger operation. |
| 163 | uint64_t vhalProperty; |
| 164 | |
| 165 | // Translation operation type. |
| 166 | AnimationType type; |
| 167 | |
| 168 | // Unit direction vector. |
| 169 | std::array<float, 3> direction; |
| 170 | |
| 171 | // Default translation value. |
| 172 | // It is used for default translation when the signal is on while vhal_range |
| 173 | // is not provided. |
| 174 | float defaultTranslationValue; |
| 175 | |
| 176 | // Default animation time elapsed to finish the texture operation. |
| 177 | // It is ignored if VHAL provides continuous signal value. |
| 178 | float animationTime; |
| 179 | |
| 180 | // Physical translation range with start mapped to vhal_range start and |
| 181 | // end mapped to vhal_range end. |
| 182 | Range translationRange; |
| 183 | |
| 184 | // VHAL signal range. |
| 185 | // Un-supported types: STRING, BYTES and VEC |
| 186 | // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal |
| 187 | // VehiclePropertyType |
| 188 | Range vhalRange; |
| 189 | }; |
| 190 | |
| 191 | // Texture operation. |
| 192 | struct TextureOp { |
| 193 | // VHAL signal to trigger operation. |
| 194 | uint64_t vhalProperty; |
| 195 | |
| 196 | // Texture operation type. |
| 197 | AnimationType type; |
| 198 | |
| 199 | // Default texture id. |
| 200 | // It is used as default texture when the signal is on while vhal_range is |
| 201 | // not provided. |
| 202 | std::string defaultTexture; |
| 203 | |
| 204 | // Default animation time elapsed to finish the texture operation. |
| 205 | // Unit is milliseconds. |
| 206 | // If the animation time is specified, the vhal_property is assumed to be |
| 207 | // on/off type. |
| 208 | // It is ignored if it is equal or less than zero and vhal_property is |
| 209 | // assumed to provide continuous value. |
| 210 | int animationTime; |
| 211 | |
| 212 | // texture range mapped to texture_ids[i].first. |
| 213 | Range textureRange; |
| 214 | |
| 215 | // VHAL signal range. |
| 216 | // Un-supported types: STRING, BYTES and VEC |
| 217 | // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal |
| 218 | // VehiclePropertyType |
| 219 | Range vhalRange; |
| 220 | |
| 221 | // Texture ids for switching textures. |
| 222 | // Applicable for animation types: kSwitchTextureOnce and |
| 223 | // kSwitchTextureRepeated |
| 224 | // 0 - n-1 |
| 225 | std::vector<std::pair<float, std::string>> textureIds; |
| 226 | }; |
| 227 | |
| 228 | // Gamma operation. |
| 229 | struct GammaOp { |
| 230 | // VHAL signal to trigger operation. |
| 231 | uint64_t vhalProperty; |
| 232 | |
| 233 | // Texture operation type. |
| 234 | // Applicable for animation types: kAdjustGammaOnce and kAdjustGammaRepeat. |
| 235 | AnimationType type; |
| 236 | |
| 237 | // Default animation time elapsed to finish the gamma operation. |
| 238 | // Unit is milliseconds. |
| 239 | // If the animation time is specified, the vhal_property is assumed to be |
| 240 | // on/off type. |
| 241 | // It is ignored if it is equal or less than zero and vhal_property is |
| 242 | // assumed to provide continuous value. |
| 243 | int animationTime; |
| 244 | |
| 245 | // Gamma range with start mapped to vhal_range start and |
| 246 | // end mapped to vhal_range end. |
| 247 | Range gammaRange; |
| 248 | |
| 249 | // VHAL signal range. |
| 250 | // Un-supported types: STRING, BYTES and VEC |
| 251 | // Refer: hardware/interfaces/automotive/vehicle/2.0/types.hal |
| 252 | // VehiclePropertyType |
| 253 | Range vhalRange; |
| 254 | }; |
| 255 | |
| 256 | // Animation info of a car part |
| 257 | struct AnimationInfo { |
| 258 | // Car animation part id(name). It is a unique id. |
| 259 | std::string partId; |
| 260 | |
| 261 | // Car part parent name. |
| 262 | std::string parentId; |
| 263 | |
| 264 | // List of child Ids. |
| 265 | std::vector<std::string> childIds; |
| 266 | |
| 267 | // Car part pose w.r.t parent's coordinate. |
| 268 | android_auto::surround_view::Mat4x4 pose; |
| 269 | |
| 270 | // VHAL priority from high [0] to low [n-1]. Only VHALs specified in the |
| 271 | // vector have priority. |
| 272 | std::vector<uint64_t> vhalPriority; |
| 273 | |
| 274 | // TODO(b/158245554): simplify xxOpsMap data structs. |
| 275 | // Map of gamma operations. Key value is VHAL property. |
| 276 | std::map<uint64_t, std::vector<GammaOp>> gammaOpsMap; |
| 277 | |
| 278 | // Map of texture operations. Key value is VHAL property. |
| 279 | std::map<uint64_t, std::vector<TextureOp>> textureOpsMap; |
| 280 | |
| 281 | // Map of rotation operations. Key value is VHAL property. |
| 282 | // Multiple rotation ops are supported and will be simultaneously animated in |
| 283 | // order if their rotation axis are different and rotation points are the |
| 284 | // same. |
| 285 | std::map<uint64_t, std::vector<RotationOp>> rotationOpsMap; |
| 286 | |
| 287 | // Map of translation operations. Key value is VHAL property. |
| 288 | std::map<uint64_t, std::vector<TranslationOp>> translationOpsMap; |
| 289 | }; |
| 290 | |
| 291 | // Main struct in which surround view car model config is parsed into. |
| 292 | struct AnimationConfig { |
| 293 | std::string version; |
| 294 | |
| 295 | std::vector<AnimationInfo> animations; |
| 296 | }; |
| 297 | |
| 298 | // Car model. |
| 299 | struct CarModel { |
| 300 | // Car model parts map. |
| 301 | std::map<std::string, android_auto::surround_view::CarPart> partsMap; |
| 302 | |
| 303 | // Car testures map. |
| 304 | std::map<std::string, android_auto::surround_view::CarTexture> texturesMap; |
| 305 | }; |
| 306 | |
| 307 | struct CarModelConfig { |
| 308 | CarModel carModel; |
| 309 | |
| 310 | AnimationConfig animationConfig; |
| 311 | }; |
| 312 | |
| 313 | struct IOModuleConfig { |
| 314 | // Camera config. |
| 315 | CameraConfig cameraConfig; |
| 316 | |
| 317 | // Surround view 2d config. |
| 318 | SvConfig2d sv2dConfig; |
| 319 | |
| 320 | // Surround view 3d config. |
| 321 | SvConfig3d sv3dConfig; |
| 322 | |
| 323 | // Car model config. |
| 324 | CarModelConfig carModelConfig; |
| 325 | }; |
| 326 | |
| 327 | enum IOStatus : uint8_t { |
| 328 | // OK ststus. ALL fields read and parsed. |
| 329 | OK = 0, |
| 330 | |
| 331 | // Error status. Cannot read the config file (config file missing or not |
| 332 | // accessible) |
| 333 | ERROR_READ_CONFIG_FILE = 1, |
| 334 | |
| 335 | // Error ststus. Config file format doesn't match. |
| 336 | ERROR_CONFIG_FILE_FORMAT = 2, |
| 337 | |
| 338 | // Warning status. Read car model (obj, mtl) error. Either the files are |
| 339 | // missing or wrong format. |
| 340 | ERROR_READ_CAR_MODEL = 3, |
| 341 | |
| 342 | // Warning status. Read animation config file error. Either the file is |
| 343 | // missing or wrong format. |
| 344 | ERROR_READ_ANIMATION = 4, |
| 345 | }; |
| 346 | |
| 347 | } // namespace implementation |
| 348 | } // namespace V1_0 |
| 349 | } // namespace sv |
| 350 | } // namespace automotive |
| 351 | } // namespace hardware |
| 352 | } // namespace android |
| 353 | |
| 354 | #endif // SURROUND_VIEW_SERVICE_IMPL_IOMODULECOMMON_H_ |