1 /*
2  * Copyright 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 #ifndef ANDROID_COMPANION_VIRTUALCAMERA_METADATAUTIL_H
18 #define ANDROID_COMPANION_VIRTUALCAMERA_METADATAUTIL_H
19 
20 #include <chrono>
21 #include <cstdint>
22 #include <map>
23 #include <memory>
24 #include <variant>
25 #include <vector>
26 
27 #include "aidl/android/hardware/camera/device/CameraMetadata.h"
28 #include "system/camera_metadata.h"
29 #include "util/Util.h"
30 
31 namespace android {
32 namespace companion {
33 namespace virtualcamera {
34 
35 // Convenience builder for the
36 // aidl::android::hardware::camera::device::CameraMetadata.
37 //
38 // Calling the same builder setter multiple will overwrite the value.
39 // This class is not thread-safe.
40 class MetadataBuilder {
41  public:
42   struct StreamConfiguration {
43     int32_t width = 0;
44     int32_t height = 0;
45     int32_t format = 0;
46     // Minimal frame duration - corresponds to maximal FPS for given format.
47     // See ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS in CameraMetadataTag.aidl.
48     std::chrono::nanoseconds minFrameDuration{0};
49     // Minimal stall duration.
50     // See ANDROID_SCALER_AVAILABLE_STALL_DURATIONS in CameraMetadataTag.aidl.
51     std::chrono::nanoseconds minStallDuration{0};
52   };
53 
54   struct ControlRegion {
55     int32_t x0 = 0;
56     int32_t y0 = 0;
57     int32_t x1 = 0;
58     int32_t y1 = 0;
59     int32_t weight = 0;
60   };
61 
62   MetadataBuilder() = default;
63   ~MetadataBuilder() = default;
64 
65   // See ANDROID_INFO_SUPPORTED_HARDWARE_LEVEL in CameraMetadataTag.aidl.
66   MetadataBuilder& setSupportedHardwareLevel(
67       camera_metadata_enum_android_info_supported_hardware_level_t hwLevel);
68 
69   // See ANDROID_INFO_DEVICE_ID in CameraMetadataTag.aidl.
70   MetadataBuilder& setDeviceId(int32_t deviceId);
71 
72   // Whether this camera device has a flash unit
73   // See ANDROID_FLASH_INFO_AVAILABLE in CameraMetadataTag.aidl.
74   MetadataBuilder& setFlashAvailable(bool flashAvailable);
75 
76   // See FLASH_STATE in CaptureResult.java.
77   MetadataBuilder& setFlashState(
78       camera_metadata_enum_android_flash_state_t flashState);
79 
80   // See FLASH_MODE in CaptureRequest.java.
81   MetadataBuilder& setFlashMode(
82       camera_metadata_enum_android_flash_mode_t flashMode);
83 
84   // See ANDROID_LENS_FACING in CameraMetadataTag.aidl.
85   MetadataBuilder& setLensFacing(
86       camera_metadata_enum_android_lens_facing lensFacing);
87 
88   // See ANDROID_SENSOR_READOUT_TIMESTAMP in CameraMetadataTag.aidl.
89   MetadataBuilder& setSensorReadoutTimestamp(
90       camera_metadata_enum_android_sensor_readout_timestamp_t
91           sensorReadoutTimestamp);
92 
93   // See ANDROID_LENS_INFO_AVAILABLE_FOCAL_LENGTHS in CameraMetadataTag.aidl.
94   MetadataBuilder& setAvailableFocalLengths(
95       const std::vector<float>& focalLengths);
96 
97   // See ANDROID_LENS_FOCAL_LENGTH in CameraMetadataTag.aidl.
98   MetadataBuilder& setFocalLength(float focalLength);
99 
100   // See ANDROID_SENSOR_ORIENTATION in CameraMetadataTag.aidl.
101   MetadataBuilder& setSensorOrientation(int32_t sensorOrientation);
102 
103   // Time at start of exposure of first row of the image
104   // sensor active array, in nanoseconds.
105   //
106   // See ANDROID_SENSOR_TIMESTAMP in CameraMetadataTag.aidl.
107   MetadataBuilder& setSensorTimestamp(std::chrono::nanoseconds timestamp);
108 
109   // See SENSOR_INFO_TIMESTAMP_SOURCE in CameraCharacteristic.java.
110   MetadataBuilder& setSensorTimestampSource(
111       camera_metadata_enum_android_sensor_info_timestamp_source_t timestampSource);
112 
113   // See ANDROID_SENSOR_INFO_ACTIVE_ARRAY_SIZE in CameraMetadataTag.aidl.
114   MetadataBuilder& setSensorActiveArraySize(int x0, int y0, int x1, int y1);
115 
116   // See ANDROID_SENSOR_INFO_PIXEL_ARRAY_SIZE in CameraMetadataTag.aidl.
117   MetadataBuilder& setSensorPixelArraySize(int width, int height);
118 
119   // See ANDROID_SENSOR_INFO_PHYSICAL_SIZE in CameraMetadataTag.aidl.
120   MetadataBuilder& setSensorPhysicalSize(float width, float height);
121 
122   // See ANDROID_STATISTICS_FACE_DETECT_MODE in CameraMetadataTag.aidl.
123   MetadataBuilder& setAvailableFaceDetectModes(
124       const std::vector<camera_metadata_enum_android_statistics_face_detect_mode_t>&
125           faceDetectMode);
126 
127   // See SENSOR_AVAILABLE_TEST_PATTERN_MODES in CameraCharacteristics.java.
128   MetadataBuilder& setAvailableTestPatternModes(
129       const std::vector<camera_metadata_enum_android_sensor_test_pattern_mode>&
130           testPatternModes);
131 
132   // See ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES in CameraCharacteristics.java
133   MetadataBuilder& setAvailableStreamUseCases(
134       const std::vector<
135           camera_metadata_enum_android_scaler_available_stream_use_cases>& availableUseCases);
136 
137   // See ANDROID_STATISTICS_FACE_DETECT_MODE in CaptureRequest.java.
138   MetadataBuilder& setFaceDetectMode(
139       camera_metadata_enum_android_statistics_face_detect_mode_t faceDetectMode);
140 
141   // Sets available stream configurations along with corresponding minimal frame
142   // durations (corresponding to max fps) and stall durations.
143   //
144   // See ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
145   // ANDROID_SCALER_AVAILABLE_MIN_FRAME_DURATIONS and
146   // ANDROID_SCALER_AVAILABLE_STALL_DURATIONS in CameraMetadataTag.aidl.
147   MetadataBuilder& setAvailableOutputStreamConfigurations(
148       const std::vector<StreamConfiguration>& streamConfigurations);
149 
150   // See COLOR_CORRECTION_AVAILABLE_ABERRATION_MODES in CameraCharacteristics.java.
151   MetadataBuilder& setAvailableAberrationCorrectionModes(
152       const std::vector<
153           camera_metadata_enum_android_color_correction_aberration_mode>&
154           aberrationCorectionModes);
155 
156   // See COLOR_CORRECTION_ABERRATION_MODE in CaptureRequest.java.
157   MetadataBuilder& setAberrationCorrectionMode(
158       camera_metadata_enum_android_color_correction_aberration_mode
159           aberrationCorrectionMode);
160 
161   // See NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES in CameraCharacteristics.java.
162   MetadataBuilder& setAvailableNoiseReductionModes(
163       const std::vector<camera_metadata_enum_android_noise_reduction_mode>&
164           noiseReductionModes);
165 
166   // See NOISE_REDUCTION_MODE in CaptureRequest.java.
167   MetadataBuilder& setNoiseReductionMode(
168       camera_metadata_enum_android_noise_reduction_mode noiseReductionMode);
169 
170   // See REQUEST_PARTIAL_RESULT_COUNT in CameraCharacteristics.java.
171   MetadataBuilder& setRequestPartialResultCount(int partialResultCount);
172 
173   // See SCALER_CROPPING_TYPE in CameraCharacteristics.java.
174   MetadataBuilder& setCroppingType(
175       camera_metadata_enum_android_scaler_cropping_type croppingType);
176 
177   // See STATISTICS_INFO_MAX_FACE_COUNT in CameraCharacteristic.java.
178   MetadataBuilder& setMaxFaceCount(int maxFaceCount);
179 
180   // See ANDROID_CONTROL_AVAILABLE_MODES in CameraMetadataTag.aidl.
181   MetadataBuilder& setControlAvailableModes(
182       const std::vector<camera_metadata_enum_android_control_mode_t>&
183           availableModes);
184 
185   // See ANDROID_CONTROL_MODE in CaptureRequest.java.
186   MetadataBuilder& setControlMode(
187       camera_metadata_enum_android_control_mode_t mode);
188 
189   // See ANDROID_CONTROL_AVAILABLE_SCENE_MODES in CameraMetadataTag.aidl.
190   MetadataBuilder& setControlAvailableSceneModes(
191       const std::vector<camera_metadata_enum_android_control_scene_mode>&
192           availableSceneModes);
193 
194   // See ANDROID_CONTROL_SCENE_MODE in CameraMetadataTag.aidl
195   MetadataBuilder& setControlSceneMode(
196       camera_metadata_enum_android_control_scene_mode sceneMode);
197 
198   // See ANDROID_CONTROL_AVAILABLE_EFFECTS in CameraMetadataTag.aidl.
199   MetadataBuilder& setControlAvailableEffects(
200       const std::vector<camera_metadata_enum_android_control_effect_mode>&
201           availableEffects);
202 
203   // See CONTROL_EFFECT_MODE in CaptureRequest.java.
204   MetadataBuilder& setControlEffectMode(
205       camera_metadata_enum_android_control_effect_mode_t effectMode);
206 
207   // See ANDROID_CONTROL_AVAILABLE_VIDEO_STABILIZATION_MODES in CameraMetadataTag.aidl.
208   MetadataBuilder& setControlAvailableVideoStabilizationModes(
209       const std::vector<
210           camera_metadata_enum_android_control_video_stabilization_mode_t>&
211           videoStabilizationModes);
212 
213   // See ANDROID_CONTROL_VIDEO_STABILIZATION_MODE in CameraMetadataTag.aidl.
214   MetadataBuilder& setControlVideoStabilizationMode(
215       camera_metadata_enum_android_control_video_stabilization_mode
216           stabilizationMode);
217 
218   // See CONTROL_AE_AVAILABLE_ANTIBANDING_MODES in CameraCharacteristics.java.
219   MetadataBuilder& setControlAeAvailableAntibandingModes(
220       const std::vector<camera_metadata_enum_android_control_ae_antibanding_mode_t>&
221           antibandingModes);
222 
223   // See CONTROL_AE_ANTIBANDING_MODE in CaptureRequest.java.
224   MetadataBuilder& setControlAeAntibandingMode(
225       camera_metadata_enum_android_control_ae_antibanding_mode_t antibandingMode);
226 
227   // See ANDROID_CONTROL_AE_COMPENSATION_RANGE in CameraMetadataTag.aidl.
228   MetadataBuilder& setControlAeCompensationRange(int32_t min, int32_t max);
229 
230   // See ANDROID_CONTROL_AE_COMPENSATION_STEP in CameraMetadataTag.aidl.
231   MetadataBuilder& setControlAeCompensationStep(camera_metadata_rational step);
232 
233   // See ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION in CameraMetadataTag.aidl.
234   MetadataBuilder& setControlAeExposureCompensation(int32_t exposureCompensation);
235 
236   // See ANDROID_CONTROL_AE_AVAILABLE_MODES in CameraCharacteristics.java.
237   MetadataBuilder& setControlAeAvailableModes(
238       const std::vector<camera_metadata_enum_android_control_ae_mode_t>& modes);
239 
240   // See ANDROID_CONTROL_AE_MODE in CaptureRequest.java.
241   MetadataBuilder& setControlAeMode(
242       camera_metadata_enum_android_control_ae_mode_t step);
243 
244   // See ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER in CaptureRequest.java.
245   MetadataBuilder& setControlAePrecaptureTrigger(
246       camera_metadata_enum_android_control_ae_precapture_trigger_t trigger);
247 
248   // See ANDROID_CONTROL_AF_AVAILABLE_MODES in CameraMetadataTag.aidl.
249   MetadataBuilder& setControlAfAvailableModes(
250       const std::vector<camera_metadata_enum_android_control_af_mode_t>&
251           availableModes);
252 
253   // See ANDROID_CONTROL_AF_MODE in CameraMetadataTag.aidl.
254   MetadataBuilder& setControlAfMode(
255       const camera_metadata_enum_android_control_af_mode_t mode);
256 
257   // See ANDROID_CONTROL_AF_TRIGGER_MODE in CameraMetadataTag.aidl.
258   MetadataBuilder& setControlAfTrigger(
259       const camera_metadata_enum_android_control_af_trigger_t trigger);
260 
261   // See ANDROID_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES in CameraMetadataTag.aidl.
262   MetadataBuilder& setControlAeAvailableFpsRanges(
263       const std::vector<FpsRange>& fpsRanges);
264 
265   // See ANDROID_CONTROL_AE_TARGET_FPS_RANGE in CaptureRequest.java.
266   MetadataBuilder& setControlAeTargetFpsRange(FpsRange fpsRange);
267 
268   // See ANDROID_CONTROL_CAPTURE_INTENT in CameraMetadataTag.aidl.
269   MetadataBuilder& setControlCaptureIntent(
270       camera_metadata_enum_android_control_capture_intent_t intent);
271 
272   // See ANDROID_CONTROL_MAX_REGIONS in CameraMetadataTag.aidl.
273   MetadataBuilder& setControlMaxRegions(int32_t maxAeRegions,
274                                         int32_t maxAwbRegions,
275                                         int32_t maxAfRegions);
276 
277   // See ANDROID_CONTROL_AWB_AVAILABLE_MODES in CameraMetadataTag.aidl.
278   MetadataBuilder& setControlAvailableAwbModes(
279       const std::vector<camera_metadata_enum_android_control_awb_mode>& awbModes);
280 
281   // See ANDROID_CONTROL_AWB_AVAILABLE_MODE in CaptureRequest.java.
282   MetadataBuilder& setControlAwbMode(
283       camera_metadata_enum_android_control_awb_mode awb);
284 
285   // See CONTROL_AWB_LOCK_AVAILABLE in CameraMetadataTag.aidl.
286   MetadataBuilder& setControlAwbLockAvailable(bool awbLockAvailable);
287 
288   // See CONTROL_AWB_LOCK in CameraMetadataTag.aidl
289   MetadataBuilder& setControlAwbLock(
290       camera_metadata_enum_android_control_awb_lock awbLock);
291 
292   // See CONTROL_AE_LOCK_AVAILABLE in CameraMetadataTag.aidl.
293   MetadataBuilder& setControlAeLockAvailable(bool aeLockAvailable);
294 
295   // See CONTROL_AE_LOCK in CameraMetadataTag.aidl.
296   MetadataBuilder& setControlAeLock(
297       camera_metadata_enum_android_control_ae_lock aeLock);
298 
299   // See CONTROL_AE_STATE in CameraMetadataTag.aidl
300   MetadataBuilder& setControlAeState(
301       camera_metadata_enum_android_control_ae_state aeState);
302 
303   // See ANDROID_CONTROL_AE_REGIONS in CameraMetadataTag.aidl.
304   MetadataBuilder& setControlAeRegions(
305       const std::vector<ControlRegion>& aeRegions);
306 
307   // See ANDROID_CONTROL_AWB_REGIONS in CameraMetadataTag.aidl.
308   MetadataBuilder& setControlAwbRegions(
309       const std::vector<ControlRegion>& awbRegions);
310 
311   // See ANDROID_CONTROL_AWB_STATE in CameraMetadataTag.aidl.
312   MetadataBuilder& setControlAwbState(
313       camera_metadata_enum_android_control_awb_state awbState);
314 
315   // See ANDROID_SCALER_CROP_REGION in CaptureRequest.java.
316   MetadataBuilder& setCropRegion(int32_t x, int32_t y, int32_t width,
317                                  int32_t height);
318 
319   // See ANDROID_CONTROL_AF_REGIONS in CameraMetadataTag.aidl.
320   MetadataBuilder& setControlAfRegions(
321       const std::vector<ControlRegion>& afRegions);
322 
323   // See ANDROID_CONTROL_AF_STATE in CameraMetadataTag.aidl.
324   MetadataBuilder& setControlAfState(
325       camera_metadata_enum_android_control_af_state aeftate);
326 
327   // The size of the compressed JPEG image, in bytes.
328   //
329   // See ANDROID_JPEG_SIZE in CameraMetadataTag.aidl.
330   MetadataBuilder& setMaxJpegSize(int32_t size);
331 
332   // See SENSOR_INFO_MAX_FRAME_DURATION in CameraCharacteristic.java.
333   MetadataBuilder& setMaxFrameDuration(std::chrono::nanoseconds duration);
334 
335   // See JPEG_AVAILABLE_THUMBNAIL_SIZES in CameraCharacteristic.java.
336   MetadataBuilder& setJpegAvailableThumbnailSizes(
337       const std::vector<Resolution>& thumbnailSizes);
338 
339   // See ANDROID_JPEG_GPS_COORDINATES.
340   MetadataBuilder& setJpegGpsCoordinates(const GpsCoordinates& gpsCoordinates);
341 
342   // See JPEG_ORIENTATION in CaptureRequest.java.
343   MetadataBuilder& setJpegOrientation(int32_t orientation);
344 
345   // See JPEG_QUALITY in CaptureRequest.java.
346   MetadataBuilder& setJpegQuality(uint8_t quality);
347 
348   // See JPEG_THUMBNAIL_SIZE in CaptureRequest.java.
349   MetadataBuilder& setJpegThumbnailSize(int width, int height);
350 
351   // See JPEG_THUMBNAIL_QUALITY in CaptureRequest.java.
352   MetadataBuilder& setJpegThumbnailQuality(uint8_t quality);
353 
354   // The maximum numbers of different types of output streams
355   // that can be configured and used simultaneously by a camera device.
356   //
357   // See ANDROID_REQUEST_MAX_NUM_OUTPUT_STREAMS in CameraMetadataTag.aidl.
358   MetadataBuilder& setMaxNumberOutputStreams(int32_t maxRawStreams,
359                                              int32_t maxProcessedStreams,
360                                              int32_t maxStallStreams);
361 
362   // See ANDROID_SYNC_MAX_LATENCY in CameraMetadataTag.aidl.
363   MetadataBuilder& setSyncMaxLatency(
364       camera_metadata_enum_android_sync_max_latency setSyncMaxLatency);
365 
366   // See REQUEST_PIPELINE_MAX_DEPTH in CameraCharacteristic.java.
367   MetadataBuilder& setPipelineMaxDepth(uint8_t maxDepth);
368 
369   // See REQUEST_PIPELINE_DEPTH in CaptureResult.java.
370   MetadataBuilder& setPipelineDepth(uint8_t depth);
371 
372   // See ANDROID_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM in CameraMetadataTag.aidl.
373   MetadataBuilder& setAvailableMaxDigitalZoom(const float maxZoom);
374 
375   // See ANDROID_CONTROL_ZOOM_RATIO_RANGE in CameraMetadataTag.aidl.
376   MetadataBuilder& setControlZoomRatioRange(float min, float max);
377 
378   // See ANDROID_STATISTICS_SCENE_FLICKER in CameraMetadataTag.aidl.
379   MetadataBuilder& setStatisticsSceneFlicker(
380       camera_metadata_enum_android_statistics_scene_flicker sceneFlicker);
381 
382   // See ANDROID_STATISTICS_HOT_PIXEL_MAP_MODE in CameraMetadataTag.aidl.
383   MetadataBuilder& setStatisticsHotPixelMapMode(
384       camera_metadata_enum_android_statistics_hot_pixel_map_mode mode);
385 
386   // See ANDROID_STATISTICS_LENS_SHADING_MAP_MODE in CameraMetadataTag.aidl.
387   MetadataBuilder& setStatisticsLensShadingMapMode(
388       camera_metadata_enum_android_statistics_lens_shading_map_mode
389           lensShadingMapMode);
390 
391   // See ANDROID_LENS_OPTICAL_STABILIZATION_MODE in CameraMetadataTag.aidl.
392   MetadataBuilder& setLensOpticalStabilizationMode(
393       camera_metadata_enum_android_lens_optical_stabilization_mode_t
394           opticalStabilizationMode);
395 
396   // See ANDROID_REQUEST_AVAILABLE_CAPABILITIES in CameraMetadataTag.aidl.
397   MetadataBuilder& setAvailableRequestCapabilities(
398       const std::vector<
399           camera_metadata_enum_android_request_available_capabilities_t>&
400           requestCapabilities);
401 
402   // A list of all keys that the camera device has available to use with
403   // CaptureRequest.
404   //
405   // See ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS in CameraMetadataTag.aidl.
406   MetadataBuilder& setAvailableRequestKeys(const std::vector<int32_t>& keys);
407 
408   // A list of all keys that the camera device has available to use with
409   // CaptureResult.
410   //
411   // See ANDROID_RESULT_AVAILABLE_REQUEST_KEYS in CameraMetadataTag.aidl.
412   MetadataBuilder& setAvailableResultKeys(const std::vector<int32_t>& keys);
413 
414   // See ANDROID_REQUEST_AVAILABLE_CAPABILITIES in CameraMetadataTag.aidl.
415   MetadataBuilder& setAvailableCapabilities(
416       const std::vector<
417           camera_metadata_enum_android_request_available_capabilities_t>&
418           capabilities);
419 
420   // A list of all keys that the camera device has available to use.
421   //
422   // See ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS in CameraMetadataTag.aidl.
423   MetadataBuilder& setAvailableCharacteristicKeys(
424       const std::vector<camera_metadata_tag_t>& keys);
425 
426   // Extends metadata with ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS
427   // containing all set tags.
428   MetadataBuilder& setAvailableCharacteristicKeys();
429 
430   // Build CameraMetadata instance.
431   //
432   // Returns nullptr in case something went wrong.
433   std::unique_ptr<::aidl::android::hardware::camera::device::CameraMetadata>
434   build();
435 
436  private:
437   // Maps metadata tags to vectors of values for the given tag.
438   std::map<
439       camera_metadata_tag_t,
440       std::variant<std::vector<int64_t>, std::vector<int32_t>,
441                    std::vector<uint8_t>, std::vector<float>,
442                    std::vector<camera_metadata_rational_t>, std::vector<double>>>
443       mEntryMap;
444   // Extend metadata with ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS.
445   bool mExtendWithAvailableCharacteristicsKeys = false;
446 };
447 
448 // Returns JPEG_QUALITY from metadata, or nullopt if the key is not present.
449 std::optional<int32_t> getJpegQuality(
450     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
451 
452 // Return JPEG_ORIENTATION from metadata, or 0 if the key is not present
453 int32_t getJpegOrientation(
454     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
455 
456 // Returns JPEG_THUMBNAIL_SIZE from metadata, or nullopt if the key is not present.
457 std::optional<Resolution> getJpegThumbnailSize(
458     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
459 
460 // Returns JPEG_THUMBNAIL_QUALITY from metadata, or nullopt if the key is not present.
461 std::optional<int32_t> getJpegThumbnailQuality(
462     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
463 
464 // Returns JPEG_AVAILABLE_THUMBNAIL_SIZES from metadata, or nullopt if the key
465 // is not present.
466 std::vector<Resolution> getJpegAvailableThumbnailSizes(
467     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
468 
469 std::optional<FpsRange> getFpsRange(
470     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
471 
472 std::optional<camera_metadata_enum_android_control_capture_intent> getCaptureIntent(
473     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
474 
475 // Returns ANDROID_JPEG_GPS_COORDINATES in a GpsCoordinate object or nullopt if
476 // the key is not present.
477 std::optional<GpsCoordinates> getGpsCoordinates(
478     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
479 
480 std::optional<camera_metadata_enum_android_lens_facing> getLensFacing(
481     const aidl::android::hardware::camera::device::CameraMetadata& metadata);
482 
483 std::optional<camera_metadata_enum_android_control_ae_precapture_trigger>
484 getPrecaptureTrigger(
485     const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata);
486 
487 // Returns the virtual device id. This is not the camera id.
488 std::optional<int32_t> getDeviceId(
489     const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata);
490 
491 // Return the value of ANDROID_SENSOR_ORIENTATION or nullopt if the key is not
492 // present (which is equivalent to a orientation of 0).
493 std::optional<int32_t> getSensorOrientation(
494     const aidl::android::hardware::camera::device::CameraMetadata& cameraMetadata);
495 
496 }  // namespace virtualcamera
497 }  // namespace companion
498 }  // namespace android
499 
500 #endif  // ANDROID_COMPANION_VIRTUALCAMERA_METADATAUTIL_H
501