1 /*
2 * Copyright (C) 2022 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 HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_CAMERA_AIDL_TEST_H_
18 #define HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_CAMERA_AIDL_TEST_H_
19
20 // TODO: LOG_TAG should not be in header
21 #ifndef LOG_TAG
22 #define LOG_TAG "camera_aidl_hal_test"
23 #endif
24
25 #include <string>
26 #include <unordered_map>
27 #include <unordered_set>
28
29 #include <CameraMetadata.h>
30 #include <CameraParameters.h>
31 #include <HandleImporter.h>
32 #include <fmq/AidlMessageQueue.h>
33
34 #include <aidl/android/hardware/graphics/common/Dataspace.h>
35
36 #include <aidl/android/hardware/camera/common/Status.h>
37 #include <aidl/android/hardware/camera/common/TorchModeStatus.h>
38 #include <aidl/android/hardware/common/NativeHandle.h>
39
40 #include <aidl/android/hardware/camera/device/CaptureResult.h>
41 #include <aidl/android/hardware/camera/device/ErrorCode.h>
42 #include <aidl/android/hardware/camera/device/HalStream.h>
43 #include <aidl/android/hardware/camera/device/ICameraDevice.h>
44 #include <aidl/android/hardware/camera/device/NotifyMsg.h>
45 #include <aidl/android/hardware/camera/device/PhysicalCameraMetadata.h>
46 #include <aidl/android/hardware/camera/device/Stream.h>
47
48 #include <aidl/android/hardware/camera/provider/ICameraProvider.h>
49
50 #include <aidl/android/hardware/camera/metadata/RequestAvailableColorSpaceProfilesMap.h>
51
52 #include <aidl/android/hardware/graphics/common/PixelFormat.h>
53
54 #include <gtest/gtest.h>
55
56 #include <log/log.h>
57 #include <system/camera_metadata.h>
58 #include <utils/KeyedVector.h>
59 #include <utils/Timers.h>
60
61 using ::aidl::android::hardware::camera::common::Status;
62 using ::aidl::android::hardware::camera::common::TorchModeStatus;
63 using ::aidl::android::hardware::camera::device::BufferRequest;
64 using ::aidl::android::hardware::camera::device::BufferRequestStatus;
65 using ::aidl::android::hardware::camera::device::CameraMetadata;
66 using ::aidl::android::hardware::camera::device::CaptureResult;
67 using ::aidl::android::hardware::camera::device::ConfigureStreamsRet;
68 using ::aidl::android::hardware::camera::device::ErrorCode;
69 using ::aidl::android::hardware::camera::device::HalStream;
70 using ::aidl::android::hardware::camera::device::ICameraDevice;
71 using ::aidl::android::hardware::camera::device::ICameraDeviceSession;
72 using ::aidl::android::hardware::camera::device::ICameraInjectionSession;
73 using ::aidl::android::hardware::camera::device::NotifyMsg;
74 using ::aidl::android::hardware::camera::device::PhysicalCameraMetadata;
75 using ::aidl::android::hardware::camera::device::RequestTemplate;
76 using ::aidl::android::hardware::camera::device::Stream;
77 using ::aidl::android::hardware::camera::device::StreamBuffer;
78 using ::aidl::android::hardware::camera::device::StreamBufferRet;
79 using ::aidl::android::hardware::camera::device::StreamConfiguration;
80 using ::aidl::android::hardware::camera::device::StreamConfigurationMode;
81 using ::aidl::android::hardware::camera::metadata::RequestAvailableColorSpaceProfilesMap;
82 using ::aidl::android::hardware::camera::metadata::RequestAvailableDynamicRangeProfilesMap;
83 using ::aidl::android::hardware::camera::metadata::ScalerAvailableStreamUseCases;
84 using ::aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination;
85 using ::aidl::android::hardware::camera::provider::ICameraProvider;
86
87 using ::aidl::android::hardware::common::NativeHandle;
88 using ::aidl::android::hardware::common::fmq::SynchronizedReadWrite;
89
90 using ::aidl::android::hardware::graphics::common::Dataspace;
91 using ::aidl::android::hardware::graphics::common::PixelFormat;
92
93 using ::android::hardware::camera::common::V1_0::helper::HandleImporter;
94 using ::android::hardware::camera::common::V1_0::helper::Size;
95
96 using ResultMetadataQueue = android::AidlMessageQueue<int8_t, SynchronizedReadWrite>;
97
98 using ::ndk::ScopedAStatus;
99
100 class DeviceCb; // Forward declare to break circular header dependency
101
102 template <typename T>
contains(const std::set<T> & container,T value)103 bool contains(const std::set<T>& container, T value) {
104 return container.find(value) != container.end();
105 }
106
107 class CameraAidlTest : public ::testing::TestWithParam<std::string> {
108 public:
109 enum SystemCameraKind {
110 /**
111 * These camera devices are visible to all apps and system components alike
112 */
113 PUBLIC = 0,
114
115 /**
116 * These camera devices are visible only to processes having the
117 * android.permission.SYSTEM_CAMERA permission. They are not exposed to 3P
118 * apps.
119 */
120 SYSTEM_ONLY_CAMERA,
121
122 /**
123 * These camera devices are visible only to HAL clients (that try to connect
124 * on a hwbinder thread).
125 */
126 HIDDEN_SECURE_CAMERA
127 };
128
129 enum BufferManagerType { FRAMEWORK = 0, HAL, SESSION };
130
131 struct AvailableStream {
132 int32_t width;
133 int32_t height;
134 int32_t format;
135 };
136
137 enum ReprocessType {
138 PRIV_REPROCESS,
139 YUV_REPROCESS,
140 };
141
142 // Copied from ColorSpace.java (see Named)
143 enum ColorSpaceNamed {
144 SRGB,
145 LINEAR_SRGB,
146 EXTENDED_SRGB,
147 LINEAR_EXTENDED_SRGB,
148 BT709,
149 BT2020,
150 DCI_P3,
151 DISPLAY_P3,
152 NTSC_1953,
153 SMPTE_C,
154 ADOBE_RGB,
155 PRO_PHOTO_RGB,
156 ACES,
157 ACESCG,
158 CIE_XYZ,
159 CIE_LAB,
160 BT2020_HLG,
161 BT2020_PQ
162 };
163
164 struct AvailableZSLInputOutput {
165 int32_t inputFormat;
166 int32_t outputFormat;
167 };
168
169 virtual void SetUp() override;
170 virtual void TearDown() override;
171
172 std::vector<std::string> getCameraDeviceNames(std::shared_ptr<ICameraProvider>& provider,
173 bool addSecureOnly = false);
174
175 static bool isSecureOnly(const std::shared_ptr<ICameraProvider>& provider,
176 const std::string& name);
177
178 std::map<std::string, std::string> getCameraDeviceIdToNameMap(
179 std::shared_ptr<ICameraProvider> provider);
180
181 static std::vector<ConcurrentCameraIdCombination> getConcurrentDeviceCombinations(
182 std::shared_ptr<ICameraProvider>& provider);
183
184 void notifyDeviceState(int64_t state);
185
186 static void allocateGraphicBuffer(uint32_t width, uint32_t height, uint64_t usage,
187 PixelFormat format, buffer_handle_t* buffer_handle /*out*/);
188
189 static void openEmptyDeviceSession(const std::string& name,
190 const std::shared_ptr<ICameraProvider>& provider,
191 std::shared_ptr<ICameraDeviceSession>* session /*out*/,
192 CameraMetadata* staticMeta /*out*/,
193 std::shared_ptr<ICameraDevice>* device /*out*/);
194 static void openEmptyInjectionSession(const std::string& name,
195 const std::shared_ptr<ICameraProvider>& provider,
196 std::shared_ptr<ICameraInjectionSession>* session /*out*/,
197 CameraMetadata* staticMeta /*out*/,
198 std::shared_ptr<ICameraDevice>* device /*out*/);
199
200 static void createStreamConfiguration(std::vector<Stream>& streams,
201 StreamConfigurationMode configMode,
202 StreamConfiguration* config, int32_t jpegBufferSize = 0);
203
204 void configureOfflineStillStream(
205 const std::string& name, const std::shared_ptr<ICameraProvider>& provider,
206 const AvailableStream* threshold,
207 std::shared_ptr<ICameraDeviceSession>* session /*out*/, Stream* stream /*out*/,
208 std::vector<HalStream>* halStreams, bool* supportsPartialResults /*out*/,
209 int32_t* partialResultCount /*out*/, std::shared_ptr<DeviceCb>* outCb /*out*/,
210 int32_t* jpegBufferSize /*out*/, std::set<int32_t>* halBufManagedStreamIds /*out*/);
211
212 ndk::ScopedAStatus configureStreams(std::shared_ptr<ICameraDeviceSession>& session,
213 const StreamConfiguration& config,
214 BufferManagerType bufferManagerType,
215 std::set<int32_t>* halBufManagedStreamIds,
216 std::vector<HalStream>* halStreams);
217
218 void configureStreams(
219 const std::string& name, const std::shared_ptr<ICameraProvider>& provider,
220 PixelFormat format, std::shared_ptr<ICameraDeviceSession>* session /*out*/,
221 Stream* previewStream /*out*/, std::vector<HalStream>* halStreams /*out*/,
222 bool* supportsPartialResults /*out*/, int32_t* partialResultCount /*out*/,
223 std::set<int32_t>* halBufManagedStreamIds /*out*/,
224 std::shared_ptr<DeviceCb>* outCb /*out*/, uint32_t streamConfigCounter,
225 bool maxResolution,
226 RequestAvailableDynamicRangeProfilesMap dynamicRangeProf =
227 RequestAvailableDynamicRangeProfilesMap::
228 ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD,
229 RequestAvailableColorSpaceProfilesMap colorSpaceProf =
230 RequestAvailableColorSpaceProfilesMap::
231 ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED);
232
233 void configurePreviewStreams(
234 const std::string& name, const std::shared_ptr<ICameraProvider>& provider,
235 const AvailableStream* previewThreshold,
236 const std::unordered_set<std::string>& physicalIds,
237 std::shared_ptr<ICameraDeviceSession>* session /*out*/, Stream* previewStream /*out*/,
238 std::vector<HalStream>* halStreams /*out*/, bool* supportsPartialResults /*out*/,
239 int32_t* partialResultCount /*out*/, std::set<int32_t>* halBufManagedStreamIds /*out*/,
240 std::shared_ptr<DeviceCb>* cb /*out*/, int32_t streamConfigCounter = 0,
241 bool allowUnsupport = false);
242
243 void configurePreviewStream(
244 const std::string& name, const std::shared_ptr<ICameraProvider>& provider,
245 const AvailableStream* previewThreshold,
246 std::shared_ptr<ICameraDeviceSession>* session /*out*/, Stream* previewStream /*out*/,
247 std::vector<HalStream>* halStreams /*out*/, bool* supportsPartialResults /*out*/,
248 int32_t* partialResultCount /*out*/, bool* useHalBufManager /*out*/,
249 std::shared_ptr<DeviceCb>* cb /*out*/, uint32_t streamConfigCounter = 0);
250
251 void configureStreamUseCaseInternal(const AvailableStream &threshold);
252
253 void configureSingleStream(
254 const std::string& name, const std::shared_ptr<ICameraProvider>& provider,
255 const AvailableStream* previewThreshold, uint64_t bufferUsage,
256 RequestTemplate reqTemplate, std::shared_ptr<ICameraDeviceSession>* session /*out*/,
257 Stream* previewStream /*out*/, std::vector<HalStream>* halStreams /*out*/,
258 bool* supportsPartialResults /*out*/, int32_t* partialResultCount /*out*/,
259 bool* useHalBufManager /*out*/, std::shared_ptr<DeviceCb>* cb /*out*/,
260 uint32_t streamConfigCounter = 0);
261
262 void verifyLogicalOrUltraHighResCameraMetadata(const std::string& cameraName,
263 const std::shared_ptr<ICameraDevice>& device,
264 const CameraMetadata& chars,
265 const std::vector<std::string>& deviceNames);
266
267 static void verifyCameraCharacteristics(const CameraMetadata& chars);
268
269 static void verifyExtendedSceneModeCharacteristics(const camera_metadata_t* metadata);
270
271 void verifyHighSpeedRecordingCharacteristics(const std::string& cameraName,
272 const CameraMetadata& chars);
273
274 static void verifyZoomCharacteristics(const camera_metadata_t* metadata);
275
276 static void verifyRecommendedConfigs(const CameraMetadata& chars);
277
278 static void verifyMonochromeCharacteristics(const CameraMetadata& chars);
279
280 static void verifyManualFlashStrengthControlCharacteristics(
281 const camera_metadata_t* staticMeta);
282
283 static void verifyMonochromeCameraResult(
284 const ::android::hardware::camera::common::V1_0::helper::CameraMetadata& metadata);
285
286 static void verifyStreamUseCaseCharacteristics(const camera_metadata_t* metadata);
287
288 static void verifySettingsOverrideCharacteristics(const camera_metadata_t* metadata);
289
290 static void verifyStreamCombination(const std::shared_ptr<ICameraDevice>& device,
291 const StreamConfiguration& config, bool expectedStatus);
292
293 static void verifySessionCharacteristics(const CameraMetadata& session_chars,
294 const CameraMetadata& camera_chars);
295
296 static void verifyLogicalCameraResult(const camera_metadata_t* staticMetadata,
297 const std::vector<uint8_t>& resultMetadata);
298
299 static void verifyLensIntrinsicsResult(const std::vector<uint8_t>& resultMetadata);
300
301 static void verifyBuffersReturned(const std::shared_ptr<ICameraDeviceSession>& session,
302 int32_t streamId, const std::shared_ptr<DeviceCb>& cb,
303 uint32_t streamConfigCounter = 0);
304
305 void verifyBuffersReturned(const std::shared_ptr<ICameraDeviceSession>& session,
306 const std::vector<int32_t>& streamIds,
307 const std::shared_ptr<DeviceCb>& cb,
308 uint32_t streamConfigCounter = 0);
309
310 static void verifySessionReconfigurationQuery(
311 const std::shared_ptr<ICameraDeviceSession>& session, camera_metadata* oldSessionParams,
312 camera_metadata* newSessionParams);
313
314 static void verifyRequestTemplate(const camera_metadata_t* metadata,
315 RequestTemplate requestTemplate);
316
317 static void overrideRotateAndCrop(CameraMetadata* settings /*in/out*/);
318
319 static bool isDepthOnly(const camera_metadata_t* staticMeta);
320
321 static bool isUltraHighResolution(const camera_metadata_t* staticMeta);
322
323 static Status getAvailableOutputStreams(const camera_metadata_t* staticMeta,
324 std::vector<AvailableStream>& outputStreams,
325 const AvailableStream* threshold = nullptr,
326 bool maxResolution = false);
327
328 static Status getMaxOutputSizeForFormat(const camera_metadata_t* staticMeta, PixelFormat format,
329 Size* size, bool maxResolution = false);
330
331 static Status getMandatoryConcurrentStreams(const camera_metadata_t* staticMeta,
332 std::vector<AvailableStream>* outputStreams);
333
334 static bool supportsPreviewStabilization(const std::string& name,
335 const std::shared_ptr<ICameraProvider>& provider);
336
337 static Status getJpegBufferSize(camera_metadata_t* staticMeta, int32_t* outBufSize);
338
339 static Status isConstrainedModeAvailable(camera_metadata_t* staticMeta);
340
341 static Status isLogicalMultiCamera(const camera_metadata_t* staticMeta);
342
343 static bool isTorchSupported(const camera_metadata_t* staticMeta);
344
345 static bool isTorchStrengthControlSupported(const camera_metadata_t* staticMeta);
346
347 static Status isOfflineSessionSupported(const camera_metadata_t* staticMeta);
348
349 static bool isReadoutTimestampSupported(const camera_metadata_t* staticMeta);
350
351 static Status getPhysicalCameraIds(const camera_metadata_t* staticMeta,
352 std::unordered_set<std::string>* physicalIds /*out*/);
353
354 static Status getSupportedKeys(camera_metadata_t* staticMeta, uint32_t tagId,
355 std::unordered_set<int32_t>* requestIDs /*out*/);
356
357 static void fillOutputStreams(camera_metadata_ro_entry_t* entry,
358 std::vector<AvailableStream>& outputStreams,
359 const AvailableStream* threshold = nullptr,
360 const int32_t availableConfigOutputTag = 0u);
361
362 static void constructFilteredSettings(
363 const std::shared_ptr<ICameraDeviceSession>& session,
364 const std::unordered_set<int32_t>& availableKeys, RequestTemplate reqTemplate,
365 android::hardware::camera::common::V1_0::helper::CameraMetadata*
366 defaultSettings /*out*/,
367 android::hardware::camera::common::V1_0::helper::CameraMetadata* filteredSettings
368 /*out*/);
369
370 static Status pickConstrainedModeSize(camera_metadata_t* staticMeta,
371 AvailableStream& hfrStream);
372
373 static Status isZSLModeAvailable(const camera_metadata_t* staticMeta);
374
375 static Status isZSLModeAvailable(const camera_metadata_t* staticMeta, ReprocessType reprocType);
376
377 static Status getZSLInputOutputMap(camera_metadata_t* staticMeta,
378 std::vector<AvailableZSLInputOutput>& inputOutputMap);
379
380 static Status findLargestSize(const std::vector<AvailableStream>& streamSizes, int32_t format,
381 AvailableStream& result);
382
383 static Status isMonochromeCamera(const camera_metadata_t* staticMeta);
384
385 static Status getSystemCameraKind(const camera_metadata_t* staticMeta,
386 SystemCameraKind* systemCameraKind);
387
388 static void getMultiResolutionStreamConfigurations(
389 camera_metadata_ro_entry* multiResStreamConfigs,
390 camera_metadata_ro_entry* streamConfigs,
391 camera_metadata_ro_entry* maxResolutionStreamConfigs,
392 const camera_metadata_t* staticMetadata);
393
394 static void getPrivacyTestPatternModes(
395 const camera_metadata_t* staticMetadata,
396 std::unordered_set<int32_t>* privacyTestPatternModes /*out*/);
397
398 static Dataspace getDataspace(PixelFormat format);
399
400 void processCaptureRequestInternal(uint64_t bufferUsage, RequestTemplate reqTemplate,
401 bool useSecureOnlyCameras);
402
403 void processPreviewStabilizationCaptureRequestInternal(
404 bool previewStabilizationOn,
405 /*inout*/ std::unordered_map<std::string, nsecs_t>& cameraDeviceToTimeLag);
406
407 static bool is10BitDynamicRangeCapable(const camera_metadata_t* staticMeta);
408
409 static void get10BitDynamicRangeProfiles(
410 const camera_metadata_t* staticMeta,
411 std::vector<RequestAvailableDynamicRangeProfilesMap>* profiles);
412
413 static bool reportsColorSpaces(const camera_metadata_t* staticMeta);
414
415 static void getColorSpaceProfiles(
416 const camera_metadata_t* staticMeta,
417 std::vector<aidl::android::hardware::camera::metadata::
418 RequestAvailableColorSpaceProfilesMap>* profiles);
419
420 static bool isColorSpaceCompatibleWithDynamicRangeAndPixelFormat(
421 const camera_metadata_t* staticMeta, RequestAvailableColorSpaceProfilesMap colorSpace,
422 RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile,
423 aidl::android::hardware::graphics::common::PixelFormat pixelFormat);
424
425 static const char* getColorSpaceProfileString(RequestAvailableColorSpaceProfilesMap colorSpace);
426
427 static const char* getDynamicRangeProfileString(
428 RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile);
429
430 static int32_t halFormatToPublicFormat(
431 aidl::android::hardware::graphics::common::PixelFormat pixelFormat);
432
433 // Used by switchToOffline where a new result queue is created for offline reqs
434 void updateInflightResultQueue(const std::shared_ptr<ResultMetadataQueue>& resultQueue);
435
436 static Size getMinSize(Size a, Size b);
437
438 void processColorSpaceRequest(RequestAvailableColorSpaceProfilesMap colorSpace,
439 RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile);
440
441 void processZoomSettingsOverrideRequests(
442 int32_t frameCount, const bool *overrideSequence, const bool *expectedResults);
443
444 bool supportZoomSettingsOverride(const camera_metadata_t* staticMeta);
445 static bool supportsStreamUseCaseCap(const camera_metadata_t* staticMeta);
446 static bool supportsCroppedRawUseCase(const camera_metadata_t* staticMeta);
447 bool isPerFrameControl(const camera_metadata_t* staticMeta);
448
449 void getSupportedSizes(const camera_metadata_t* ch, uint32_t tag, int32_t format,
450 std::vector<std::tuple<size_t, size_t>>* sizes /*out*/);
451
452 void getSupportedDurations(const camera_metadata_t* ch, uint32_t tag, int32_t format,
453 const std::vector<std::tuple<size_t, size_t>>& sizes,
454 std::vector<int64_t>* durations /*out*/);
455
456 protected:
457 // In-flight queue for tracking completion of capture requests.
458 struct InFlightRequest {
459 // Set by notify() SHUTTER call.
460 nsecs_t shutterTimestamp;
461 nsecs_t shutterReadoutTimestamp;
462
463 bool errorCodeValid;
464 ErrorCode errorCode;
465
466 // Is partial result supported
467 bool usePartialResult;
468
469 // Partial result count expected
470 int32_t numPartialResults;
471
472 // Message queue
473 std::shared_ptr<ResultMetadataQueue> resultQueue;
474
475 // Set by process_capture_result call with valid metadata
476 bool haveResultMetadata;
477
478 // Decremented by calls to process_capture_result with valid output
479 // and input buffers
480 ssize_t numBuffersLeft;
481
482 // A 64bit integer to index the frame number associated with this result.
483 int64_t frameNumber;
484
485 // The partial result count (index) for this capture result.
486 int32_t partialResultCount;
487
488 // For buffer drop errors, the stream ID for the stream that lost a buffer.
489 // For physical sub-camera result errors, the Id of the physical stream
490 // for the physical sub-camera.
491 // Otherwise -1.
492 int32_t errorStreamId;
493
494 // If this request has any input buffer
495 bool hasInputBuffer;
496
497 // Result metadata
498 ::android::hardware::camera::common::V1_0::helper::CameraMetadata collectedResult;
499
500 // Inflight buffers
501 using OutstandingBuffers = std::unordered_map<uint64_t, buffer_handle_t>;
502 std::vector<OutstandingBuffers> mOutstandingBufferIds;
503
504 // A copy-able StreamBuffer using buffer_handle_t instead of AIDLs NativeHandle
505 struct NativeStreamBuffer {
506 int32_t streamId;
507 int64_t bufferId;
508 buffer_handle_t buffer;
509 aidl::android::hardware::camera::device::BufferStatus status;
510 buffer_handle_t acquireFence;
511 buffer_handle_t releaseFence;
512 };
513
514 // Buffers are added by process_capture_result when output buffers
515 // return from HAL but framework.
516 struct StreamBufferAndTimestamp {
517 NativeStreamBuffer buffer;
518 nsecs_t timeStamp;
519 };
520 std::vector<StreamBufferAndTimestamp> resultOutputBuffers;
521
522 std::unordered_set<std::string> expectedPhysicalResults;
523
InFlightRequestInFlightRequest524 InFlightRequest()
525 : shutterTimestamp(0),
526 shutterReadoutTimestamp(0),
527 errorCodeValid(false),
528 errorCode(ErrorCode::ERROR_BUFFER),
529 usePartialResult(false),
530 numPartialResults(0),
531 resultQueue(nullptr),
532 haveResultMetadata(false),
533 numBuffersLeft(0),
534 frameNumber(0),
535 partialResultCount(0),
536 errorStreamId(-1),
537 hasInputBuffer(false),
538 collectedResult(1, 10) {}
539
540 InFlightRequest(ssize_t numBuffers, bool hasInput, bool partialResults,
541 int32_t partialCount, std::shared_ptr<ResultMetadataQueue> queue = nullptr)
542 : shutterTimestamp(0),
543 shutterReadoutTimestamp(0),
544 errorCodeValid(false),
545 errorCode(ErrorCode::ERROR_BUFFER),
546 usePartialResult(partialResults),
547 numPartialResults(partialCount),
548 resultQueue(queue),
549 haveResultMetadata(false),
550 numBuffersLeft(numBuffers),
551 frameNumber(0),
552 partialResultCount(0),
553 errorStreamId(-1),
554 hasInputBuffer(hasInput),
555 collectedResult(1, 10) {}
556
557 InFlightRequest(ssize_t numBuffers, bool hasInput, bool partialResults,
558 int32_t partialCount,
559 const std::unordered_set<std::string>& extraPhysicalResult,
560 std::shared_ptr<ResultMetadataQueue> queue = nullptr)
561 : shutterTimestamp(0),
562 shutterReadoutTimestamp(0),
563 errorCodeValid(false),
564 errorCode(ErrorCode::ERROR_BUFFER),
565 usePartialResult(partialResults),
566 numPartialResults(partialCount),
567 resultQueue(queue),
568 haveResultMetadata(false),
569 numBuffersLeft(numBuffers),
570 frameNumber(0),
571 partialResultCount(0),
572 errorStreamId(-1),
573 hasInputBuffer(hasInput),
574 collectedResult(1, 10),
575 expectedPhysicalResults(extraPhysicalResult) {}
576
~InFlightRequestInFlightRequest577 ~InFlightRequest() {
578 for (auto& buffer : resultOutputBuffers) {
579 native_handle_t* acquireFenceHandle = const_cast<native_handle_t*>(
580 buffer.buffer.acquireFence);
581 native_handle_close(acquireFenceHandle);
582 native_handle_delete(acquireFenceHandle);
583
584 native_handle_t* releaseFenceHandle = const_cast<native_handle_t*>(
585 buffer.buffer.releaseFence);
586 native_handle_close(releaseFenceHandle);
587 native_handle_delete(releaseFenceHandle);
588 }
589 }
590 };
591
592 static bool matchDeviceName(const std::string& deviceName, const std::string& providerType,
593 std::string* deviceVersion, std::string* cameraId);
594
595 static void verify10BitMetadata(HandleImporter& importer, const InFlightRequest& request,
596 RequestAvailableDynamicRangeProfilesMap profile);
597
598 static void waitForReleaseFence(
599 std::vector<InFlightRequest::StreamBufferAndTimestamp>& resultOutputBuffers);
600
601 static void validateDefaultRequestMetadata(RequestTemplate reqTemplate,
602 const CameraMetadata& rawMetadata);
603
604 // Map from frame number to the in-flight request state
605 typedef std::unordered_map<uint32_t, std::shared_ptr<InFlightRequest>> InFlightMap;
606
607 std::mutex mLock; // Synchronize access to member variables
608 std::condition_variable mResultCondition; // Condition variable for incoming results
609 InFlightMap mInflightMap; // Map of all inflight requests
610
611 std::vector<NotifyMsg> mNotifyMessages; // Current notification message
612
613 std::mutex mTorchLock; // Synchronize access to torch status
614 std::condition_variable mTorchCond; // Condition variable for torch status
615 TorchModeStatus mTorchStatus; // Current torch status
616
617 // Camera provider service
618 std::shared_ptr<ICameraProvider> mProvider;
619
620 // Camera device session used by the tests
621 // Tests should take care of closing this session and setting it back to nullptr in successful
622 // case. Declared as a field to allow TeadDown function to close the session if a test assertion
623 // fails.
624 std::shared_ptr<ICameraDeviceSession> mSession;
625
626 // Camera provider type.
627 std::string mProviderType;
628
629 HandleImporter mHandleImporter;
630
631 bool mSupportReadoutTimestamp;
632
633 friend class DeviceCb;
634 friend class SimpleDeviceCb;
635 friend class TorchProviderCb;
636 };
637
638 namespace {
639 // device@<major>.<minor>/<type>/id
640 const char* kDeviceNameRE = "device@([0-9]+\\.[0-9]+)/\\s+/(.+)";
641 const std::string CAMERA_DEVICE_API_VERSION_1 = "1.1";
642 const int32_t CAMERA_DEVICE_API_MINOR_VERSION_3 = 3;
643
644 const int32_t kMaxVideoWidth = 4096;
645 const int32_t kMaxVideoHeight = 2160;
646
647 const int64_t kStreamBufferTimeoutSec = 3;
648 const int64_t kTorchTimeoutSec = 1;
649 const char* kDumpOutput = "/dev/null";
650 const uint32_t kMaxPreviewWidth = 1920;
651 const uint32_t kMaxPreviewHeight = 1080;
652 } // namespace
653 #endif // HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_CAMERA_AIDL_TEST_H_
654