• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.cts.verifier.camera.its;
18 
19 import android.hardware.camera2.CaptureResult;
20 import android.hardware.camera2.TotalCaptureResult;
21 import android.os.Build;
22 
23 import androidx.annotation.RequiresApi;
24 
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Set;
28 
29 /** Convenience class to record certain fields of a CaptureResult. */
30 public class RecordingResult {
31     public static final List<CaptureResult.Key<?>> PREVIEW_RESULT_TRACKED_KEYS = List.of(
32             CaptureResult.CONTROL_ZOOM_RATIO,
33             CaptureResult.LENS_FOCAL_LENGTH,
34             CaptureResult.LENS_FOCUS_DISTANCE,
35             CaptureResult.SCALER_CROP_REGION,
36             CaptureResult.LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID,
37             CaptureResult.LENS_INTRINSIC_CALIBRATION,
38             CaptureResult.SENSOR_TIMESTAMP,
39             CaptureResult.CONTROL_AE_STATE,
40             CaptureResult.CONTROL_AF_STATE,
41             CaptureResult.CONTROL_AWB_STATE,
42             CaptureResult.STATISTICS_FACES,
43             CaptureResult.STATISTICS_FACE_DETECT_MODE
44     );
45 
46     HashMap<CaptureResult.Key<?>, Object> mMap;
47 
RecordingResult()48     public RecordingResult() {
49         mMap = new HashMap<>();
50     }
addKey(TotalCaptureResult result, CaptureResult.Key<?> key)51     public void addKey(TotalCaptureResult result, CaptureResult.Key<?> key) {
52         mMap.put(key, result.get(key));
53     }
addKeys(TotalCaptureResult result, Iterable<CaptureResult.Key<?>> keys)54     public void addKeys(TotalCaptureResult result,
55             Iterable<CaptureResult.Key<?>> keys) {
56         for (CaptureResult.Key<?> k : keys) {
57             this.addKey(result, k);
58         }
59     }
60     @RequiresApi(Build.VERSION_CODES.VANILLA_ICE_CREAM)
addVKeys(TotalCaptureResult result)61     public void addVKeys(TotalCaptureResult result) {
62         // TODO: b/332581106 - Evaluate if data added by samples surpasses socket limit
63         this.addKey(result, CaptureResult.STATISTICS_LENS_INTRINSICS_SAMPLES);
64     }
getKeys()65     public Set<CaptureResult.Key<?>> getKeys() {
66         return mMap.keySet();
67     }
getResult(CaptureResult.Key<T> key)68     public <T> T getResult(CaptureResult.Key<T> key) {
69         return (T) mMap.get(key);
70     }
71 }
72