1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
|
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.camera2.params;
import static com.android.internal.R.string.hardware;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.graphics.ImageFormat;
import android.graphics.ImageFormat.Format;
import android.graphics.PixelFormat;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.util.ArraySet;
import android.util.Range;
import android.util.Size;
import android.view.Surface;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Collections;
import java.util.Set;
/**
* Immutable class to store the recommended stream configurations to set up
* {@link android.view.Surface Surfaces} for creating a
* {@link android.hardware.camera2.CameraCaptureSession capture session} with
* {@link android.hardware.camera2.CameraDevice#createCaptureSession}.
*
* <p>The recommended list does not replace or deprecate the exhaustive complete list found in
* {@link StreamConfigurationMap}. It is a suggestion about available power and performance
* efficient stream configurations for a specific use case. Per definition it is only a subset
* of {@link StreamConfigurationMap} and can be considered by developers for optimization
* purposes.</p>
*
* <p>This also duplicates the minimum frame durations and stall durations from the
* {@link StreamConfigurationMap} for each format/size combination that can be used to calculate
* effective frame rate when submitting multiple captures.
* </p>
*
* <p>An instance of this object is available by invoking
* {@link CameraCharacteristics#getRecommendedStreamConfigurationMap} and passing a respective
* usecase id. For more information about supported use case constants see
* {@link #USECASE_PREVIEW}.</p>
*
* <pre><code>{@code
* CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
* RecommendedStreamConfigurationMap configs = characteristics.getRecommendedStreamConfigurationMap(
* RecommendedStreamConfigurationMap.USECASE_PREVIEW);
* }</code></pre>
*
* @see CameraCharacteristics#getRecommendedStreamConfigurationMap
* @see CameraDevice#createCaptureSession
*/
public final class RecommendedStreamConfigurationMap {
private static final String TAG = "RecommendedStreamConfigurationMap";
private int mUsecase;
private boolean mSupportsPrivate;
private StreamConfigurationMap mRecommendedMap;
/** @hide */
public static final int MAX_USECASE_COUNT = 32;
/**
* The recommended stream configuration map for use case preview must contain a subset of
* efficient, non-stalling configurations that must include both
* {@link android.graphics.ImageFormat#PRIVATE} and
* {@link android.graphics.ImageFormat#YUV_420_888} output formats. Even if available for the
* camera device, high speed or input configurations will be absent.
*/
public static final int USECASE_PREVIEW = 0x0;
/**
* The recommended stream configuration map for recording must contain a subset of efficient
* video configurations that include {@link android.graphics.ImageFormat#PRIVATE}
* output format for at least all supported {@link android.media.CamcorderProfile profiles}.
* High speed configurations if supported will be available as well. Even if available for the
* camera device, input configurations will be absent.
*/
public static final int USECASE_RECORD = 0x1;
/**
* The recommended stream configuration map for use case video snapshot must only contain a
* subset of efficient liveshot configurations that include
* {@link android.graphics.ImageFormat#JPEG} output format. The sizes will match at least
* the maximum resolution of usecase record and will not cause any preview glitches. Even
* if available for the camera device, high speed or input configurations will be absent.
*/
public static final int USECASE_VIDEO_SNAPSHOT = 0x2;
/**
* The recommended stream configuration map for use case snapshot must contain a subset of
* efficient still capture configurations that must include
* {@link android.graphics.ImageFormat#JPEG} output format and at least one configuration with
* size approximately equal to the sensor pixel array size
* {@link CameraCharacteristics#SENSOR_INFO_ACTIVE_ARRAY_SIZE}.
* Even if available for the camera device, high speed or input configurations will be absent.
*/
public static final int USECASE_SNAPSHOT = 0x3;
/**
* In case the device supports
* {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_YUV_REPROCESSING} and/or
* {@link CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_PRIVATE_REPROCESSING},
* the recommended stream configuration map for use case ZSL must contain a subset of efficient
* configurations that include the suggested input and output format mappings. Even if
* available for the camera device, high speed configurations will be absent.
*/
public static final int USECASE_ZSL = 0x4;
/**
* In case the device supports
* {@link android.hardware.camera2.CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_RAW}, the
* recommended stream configuration map for use case RAW must contain a subset of efficient
* configurations that include the {@link android.graphics.ImageFormat#RAW_SENSOR} and other
* RAW output formats. Even if available for the camera device, high speed and input
* configurations will be absent.
*/
public static final int USECASE_RAW = 0x5;
/**
* The recommended stream configuration map for use case low latency snapshot must contain
* subset of configurations with end-to-end latency that does not exceed 200 ms. under standard
* operating conditions (reasonable light levels, not loaded system). The expected output format
* will be primarily {@link android.graphics.ImageFormat#JPEG} however other image formats can
* be present as well. Even if available for the camera device, high speed and input
* configurations will be absent. This suggested configuration map may be absent on some devices
* that can not support any low latency requests.
*/
public static final int USECASE_LOW_LATENCY_SNAPSHOT = 0x6;
/**
* If supported, the recommended 10-bit output stream configurations must include
* a subset of the advertised {@link android.graphics.ImageFormat#YCBCR_P010} and
* {@link android.graphics.ImageFormat#PRIVATE} outputs that are optimized for power
* and performance when registered along with a supported 10-bit dynamic range profile.
* {@see android.hardware.camera2.params.OutputConfiguration#setDynamicRangeProfile} for
* details.
*/
public static final int USECASE_10BIT_OUTPUT = 0x8;
/**
* Device specific use cases.
* @hide
*/
public static final int USECASE_VENDOR_START = 0x18;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef(prefix = {"USECASE_"}, value =
{USECASE_PREVIEW,
USECASE_RECORD,
USECASE_VIDEO_SNAPSHOT,
USECASE_SNAPSHOT,
USECASE_ZSL,
USECASE_RAW,
USECASE_LOW_LATENCY_SNAPSHOT,
USECASE_10BIT_OUTPUT})
public @interface RecommendedUsecase {};
/**
* Create a new {@link RecommendedStreamConfigurationMap}.
*
* @param recommendedMap stream configuration map that contains for the specific use case
* @param usecase Recommended use case
* @param supportsPrivate Flag indicating private format support.
*
* @hide
*/
public RecommendedStreamConfigurationMap(StreamConfigurationMap recommendedMap, int usecase,
boolean supportsPrivate) {
mRecommendedMap = recommendedMap;
mUsecase = usecase;
mSupportsPrivate = supportsPrivate;
}
/**
* Get the use case value for the recommended stream configurations.
*
* @return Use case id.
*/
public @RecommendedUsecase int getRecommendedUseCase() {
return mUsecase;
}
private Set<Integer> getUnmodifiableIntegerSet(int[] intArray) {
if ((intArray != null) && (intArray.length > 0)) {
ArraySet<Integer> integerSet = new ArraySet<Integer>();
integerSet.ensureCapacity(intArray.length);
for (int intEntry : intArray) {
integerSet.add(intEntry);
}
return Collections.unmodifiableSet(integerSet);
}
return null;
}
/**
* Get the image {@code format} output formats in this stream configuration.
*
* <p>
* For more information refer to {@link StreamConfigurationMap#getOutputFormats}.
* </p>
*
* @return a non-modifiable set of Integer formats
*/
public @NonNull Set<Integer> getOutputFormats() {
return getUnmodifiableIntegerSet(mRecommendedMap.getOutputFormats());
}
/**
* Get the image {@code format} output formats for a reprocessing input format.
*
* <p>
* For more information refer to {@link StreamConfigurationMap#getValidOutputFormatsForInput}.
* </p>
*
* @return a non-modifiable set of Integer formats
*/
public @Nullable Set<Integer> getValidOutputFormatsForInput(@Format int inputFormat) {
return getUnmodifiableIntegerSet(mRecommendedMap.getValidOutputFormatsForInput(
inputFormat));
}
/**
* Get the image {@code format} input formats in this stream configuration.
*
* <p>All image formats returned by this function will be defined in either {@link ImageFormat}
* or in {@link PixelFormat} (and there is no possibility of collision).</p>
*
* @return a non-modifiable set of Integer formats
*/
public @Nullable Set<Integer> getInputFormats() {
return getUnmodifiableIntegerSet(mRecommendedMap.getInputFormats());
}
private Set<Size> getUnmodifiableSizeSet(Size[] sizeArray) {
if ((sizeArray != null) && (sizeArray.length > 0)) {
ArraySet<Size> sizeSet = new ArraySet<Size>();
sizeSet.addAll(Arrays.asList(sizeArray));
return Collections.unmodifiableSet(sizeSet);
}
return null;
}
/**
* Get the supported input sizes for this input format.
*
* <p>The format must have come from {@link #getInputFormats}; otherwise
* {@code null} is returned.</p>
*
* @param format a format from {@link #getInputFormats}
* @return a non-modifiable set of sizes, or {@code null} if the format was not available.
*/
public @Nullable Set<Size> getInputSizes(@Format int format) {
return getUnmodifiableSizeSet(mRecommendedMap.getInputSizes(format));
}
/**
* Determine whether or not output surfaces with a particular user-defined format can be passed
* {@link CameraDevice#createCaptureSession createCaptureSession}.
*
* <p>
* For further information refer to {@link StreamConfigurationMap#isOutputSupportedFor}.
* </p>
*
*
* @param format an image format from either {@link ImageFormat} or {@link PixelFormat}
* @return
* {@code true} if using a {@code surface} with this {@code format} will be
* supported with {@link CameraDevice#createCaptureSession}
*
* @throws IllegalArgumentException
* if the image format was not a defined named constant
* from either {@link ImageFormat} or {@link PixelFormat}
*/
public boolean isOutputSupportedFor(@Format int format) {
return mRecommendedMap.isOutputSupportedFor(format);
}
/**
* Get a list of sizes compatible with the requested image {@code format}.
*
* <p>
* For more information refer to {@link StreamConfigurationMap#getOutputSizes}.
* </p>
*
*
* @param format an image format from {@link ImageFormat} or {@link PixelFormat}
* @return a non-modifiable set of supported sizes,
* or {@code null} if the {@code format} is not a supported output
*/
public @Nullable Set<Size> getOutputSizes(@Format int format) {
return getUnmodifiableSizeSet(mRecommendedMap.getOutputSizes(format));
}
/**
* Get a list of supported high speed video recording sizes.
* <p>
* For more information refer to {@link StreamConfigurationMap#getHighSpeedVideoSizes}.
* </p>
*
* @return a non-modifiable set of supported high speed video recording sizes
*/
public @Nullable Set<Size> getHighSpeedVideoSizes() {
return getUnmodifiableSizeSet(mRecommendedMap.getHighSpeedVideoSizes());
}
private Set<Range<Integer>> getUnmodifiableRangeSet(Range<Integer>[] rangeArray) {
if ((rangeArray != null) && (rangeArray.length > 0)) {
ArraySet<Range<Integer>> rangeSet = new ArraySet<Range<Integer>>();
rangeSet.addAll(Arrays.asList(rangeArray));
return Collections.unmodifiableSet(rangeSet);
}
return null;
}
/**
* Get the frame per second ranges (fpsMin, fpsMax) for input high speed video size.
*
* <p>
* For further information refer to
* {@link StreamConfigurationMap#getHighSpeedVideoFpsRangesFor}.
* </p>
* @param size one of the sizes returned by {@link #getHighSpeedVideoSizes()}
* @return a non-modifiable set of supported high speed video recording FPS ranges The upper
* bound of returned ranges is guaranteed to be greater than or equal to 120.
* @throws IllegalArgumentException if input size does not exist in the return value of
* getHighSpeedVideoSizes
*/
public @Nullable Set<Range<Integer>> getHighSpeedVideoFpsRangesFor(@NonNull Size size) {
return getUnmodifiableRangeSet(mRecommendedMap.getHighSpeedVideoFpsRangesFor(size));
}
/**
* Get a list of supported high speed video recording FPS ranges.
* <p>
* For further information refer to {@link StreamConfigurationMap#getHighSpeedVideoFpsRanges}.
* </p>
* @return a non-modifiable set of supported high speed video recording FPS ranges The upper
* bound of returned ranges is guaranteed to be larger or equal to 120.
*/
public @Nullable Set<Range<Integer>> getHighSpeedVideoFpsRanges() {
return getUnmodifiableRangeSet(mRecommendedMap.getHighSpeedVideoFpsRanges());
}
/**
* Get the supported video sizes for an input high speed FPS range.
*
* <p>
* For further information refer to {@link StreamConfigurationMap#getHighSpeedVideoSizesFor}.
* </p>
*
* @param fpsRange one of the FPS ranges returned by {@link #getHighSpeedVideoFpsRanges()}
* @return A non-modifiable set of video sizes to create high speed capture sessions for high
* speed streaming use cases.
*
* @throws IllegalArgumentException if input FPS range does not exist in the return value of
* getHighSpeedVideoFpsRanges
*/
public @Nullable Set<Size> getHighSpeedVideoSizesFor(@NonNull Range<Integer> fpsRange) {
return getUnmodifiableSizeSet(mRecommendedMap.getHighSpeedVideoSizesFor(fpsRange));
}
/**
* Get a list of supported high resolution sizes, which cannot operate at full BURST_CAPTURE
* rate.
*
* <p>
* For further information refer to {@link StreamConfigurationMap#getHighResolutionOutputSizes}.
* </p>
*
* @return a non-modifiable set of supported slower high-resolution sizes, or {@code null} if
* the BURST_CAPTURE capability is not supported
*/
public @Nullable Set<Size> getHighResolutionOutputSizes(@Format int format) {
return getUnmodifiableSizeSet(mRecommendedMap.getHighResolutionOutputSizes(format));
}
/**
* Get the minimum
* {@link android.hardware.camera2.CaptureRequest#SENSOR_FRAME_DURATION frame duration}
* for the format/size combination (in nanoseconds).
*
* <p>
* For further information refer to {@link StreamConfigurationMap#getOutputMinFrameDuration}.
* </p>
*
* @param format an image format from {@link ImageFormat} or {@link PixelFormat}
* @param size an output-compatible size
* @return a minimum frame duration {@code >} 0 in nanoseconds, or
* 0 if the minimum frame duration is not available.
*
* @throws IllegalArgumentException if {@code format} or {@code size} was not supported
*/
public @IntRange(from = 0) long getOutputMinFrameDuration(@Format int format,
@NonNull Size size) {
return mRecommendedMap.getOutputMinFrameDuration(format, size);
}
/**
* Get the stall duration for the format/size combination (in nanoseconds).
*
* <p>
* For further information refer to {@link StreamConfigurationMap#getOutputStallDuration}.
* </p>
*
* @param format an image format from {@link ImageFormat} or {@link PixelFormat}
* @param size an output-compatible size
* @return a stall duration {@code >=} 0 in nanoseconds
*
* @throws IllegalArgumentException if {@code format} or {@code size} was not supported
*/
public @IntRange(from = 0) long getOutputStallDuration(@Format int format, @NonNull Size size) {
return mRecommendedMap.getOutputStallDuration(format, size);
}
/**
* Get a list of sizes compatible with {@code klass} to use as an output.
*
* <p>For further information refer to {@link StreamConfigurationMap#getOutputSizes(Class)}.
* </p>
*
* @param klass
* a {@link Class} object reference
* @return
* a non-modifiable set of supported sizes for {@link ImageFormat#PRIVATE} format,
* or {@code null} if the {@code klass} is not a supported output.
*/
public @Nullable <T> Set<Size> getOutputSizes(@NonNull Class<T> klass) {
if (mSupportsPrivate) {
return getUnmodifiableSizeSet(mRecommendedMap.getOutputSizes(klass));
}
return null;
}
/**
* Get the minimum {@link CaptureRequest#SENSOR_FRAME_DURATION frame duration}
* for the class/size combination (in nanoseconds).
*
* <p>For more information refer to
* {@link StreamConfigurationMap#getOutputMinFrameDuration(Class, Size)}.</p>
*
* @param klass
* a class which has a non-empty array returned by {@link #getOutputSizes(Class)}
* @param size an output-compatible size
* @return a minimum frame duration {@code >} 0 in nanoseconds, or
* 0 if the minimum frame duration is not available.
*
* @throws IllegalArgumentException if {@code klass} or {@code size} was not supported
*/
public @IntRange(from = 0) <T> long getOutputMinFrameDuration(@NonNull final Class<T> klass,
@NonNull final Size size) {
if (mSupportsPrivate) {
return mRecommendedMap.getOutputMinFrameDuration(klass, size);
}
return 0;
}
/**
* Get the stall duration for the class/size combination (in nanoseconds).
*
* <p>For more information refer to
* {@link StreamConfigurationMap#getOutputStallDuration(Class, Size)}.
*
* @param klass
* a class which has a non-empty array returned by {@link #getOutputSizes(Class)}.
* @param size an output-compatible size
* @return a minimum frame duration {@code >} 0 in nanoseconds, or 0 if the stall duration is
* not available.
*
* @throws IllegalArgumentException if {@code klass} or {@code size} was not supported
*/
public @IntRange(from = 0) <T> long getOutputStallDuration(@NonNull final Class<T> klass,
@NonNull final Size size) {
if (mSupportsPrivate) {
return mRecommendedMap.getOutputStallDuration(klass, size);
}
return 0;
}
/**
* Determine whether or not the {@code surface} in its current state is suitable to be included
* in a {@link CameraDevice#createCaptureSession capture session} as an output.
*
* <p>For more information refer to {@link StreamConfigurationMap#isOutputSupportedFor}.
* </p>
*
* @param surface a {@link Surface} object reference
* @return {@code true} if this is supported, {@code false} otherwise
*
* @throws IllegalArgumentException if the Surface endpoint is no longer valid
*
*/
public boolean isOutputSupportedFor(@NonNull Surface surface) {
return mRecommendedMap.isOutputSupportedFor(surface);
}
}
|