Debian Codegraph @

core/java/android/hardware/camera2/impl/CaptureCallbackHolder.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2019 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
18 package android.hardware.camera2.impl;
19
20 import android.hardware.camera2.CaptureRequest;
21 import android.view.Surface;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.concurrent.Executor;
27
28 public class CaptureCallbackHolder {
29
30 private final boolean mRepeating;
31 private final CaptureCallback mCallback;
32 private final List<CaptureRequest> mRequestList;
33 private final Executor mExecutor;
34 private final int mSessionId;
35 /**
36 * <p>Determine if the callback holder is for a constrained high speed request list that
37 * expects batched capture results. Capture results will be batched if the request list
38 * is interleaved with preview and video requests. Capture results won't be batched if the
39 * request list only contains preview requests, or if the request doesn't belong to a
40 * constrained high speed list.
41 */
42 private final boolean mHasBatchedOutputs;
43
44 CaptureCallbackHolder(CaptureCallback callback, List<CaptureRequest> requestList,
45 Executor executor, boolean repeating, int sessionId) {
46 if (callback == null || executor == null) {
47 throw new UnsupportedOperationException(
48 "Must have a valid handler and a valid callback");
49 }
50 mRepeating = repeating;
51 mExecutor = executor;
52 mRequestList = new ArrayList<CaptureRequest>(requestList);
53 mCallback = callback;
54 mSessionId = sessionId;
55
56 // Check whether this callback holder is for batched outputs.
57 // The logic here should match createHighSpeedRequestList.
58 boolean hasBatchedOutputs = true;
59 for (int i = 0; i < requestList.size(); i++) {
60 CaptureRequest request = requestList.get(i);
61 if (!request.isPartOfCRequestList()) {
62 hasBatchedOutputs = false;
63 break;
64 }
65 if (i == 0) {
66 Collection<Surface> targets = request.getTargets();
67 if (targets.size() != 2) {
68 hasBatchedOutputs = false;
69 break;
70 }
71 }
72 }
73 mHasBatchedOutputs = hasBatchedOutputs;
74 }
75
76 public boolean isRepeating() {
77 return mRepeating;
78 }
79
80 public CaptureCallback getCallback() {
81 return mCallback;
82 }
83
84 public CaptureRequest getRequest(int subsequenceId) {
85 if (subsequenceId >= mRequestList.size()) {
86 throw new IllegalArgumentException(
87 String.format(
88 "Requested subsequenceId %d is larger than request list size %d.",
89 subsequenceId, mRequestList.size()));
90 } else {
91 if (subsequenceId < 0) {
92 throw new IllegalArgumentException(String.format(
93 "Requested subsequenceId %d is negative", subsequenceId));
94 } else {
95 return mRequestList.get(subsequenceId);
96 }
97 }
98 }
99
100 public CaptureRequest getRequest() {
101 return getRequest(0);
102 }
103
104 public Executor getExecutor() {
105 return mExecutor;
106 }
107
108 public int getSessionId() {
109 return mSessionId;
110 }
111
112 public int getRequestCount() {
113 return mRequestList.size();
114 }
115
116 public boolean hasBatchedOutputs() {
117 return mHasBatchedOutputs;
118 }
119 }