• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Status getPhysicalCameraIds(const camera_metadata_t* staticMeta,
350                                        std::unordered_set<std::string>* physicalIds /*out*/);
351 
352     static Status getSupportedKeys(camera_metadata_t* staticMeta, uint32_t tagId,
353                                    std::unordered_set<int32_t>* requestIDs /*out*/);
354 
355     static void fillOutputStreams(camera_metadata_ro_entry_t* entry,
356                                   std::vector<AvailableStream>& outputStreams,
357                                   const AvailableStream* threshold = nullptr,
358                                   const int32_t availableConfigOutputTag = 0u);
359 
360     static void constructFilteredSettings(
361             const std::shared_ptr<ICameraDeviceSession>& session,
362             const std::unordered_set<int32_t>& availableKeys, RequestTemplate reqTemplate,
363             android::hardware::camera::common::V1_0::helper::CameraMetadata*
364                     defaultSettings /*out*/,
365             android::hardware::camera::common::V1_0::helper::CameraMetadata* filteredSettings
366             /*out*/);
367 
368     static Status pickConstrainedModeSize(camera_metadata_t* staticMeta,
369                                           AvailableStream& hfrStream);
370 
371     static Status isZSLModeAvailable(const camera_metadata_t* staticMeta);
372 
373     static Status isZSLModeAvailable(const camera_metadata_t* staticMeta, ReprocessType reprocType);
374 
375     static Status getZSLInputOutputMap(camera_metadata_t* staticMeta,
376                                        std::vector<AvailableZSLInputOutput>& inputOutputMap);
377 
378     static Status findLargestSize(const std::vector<AvailableStream>& streamSizes, int32_t format,
379                                   AvailableStream& result);
380 
381     static Status isMonochromeCamera(const camera_metadata_t* staticMeta);
382 
383     static Status getSystemCameraKind(const camera_metadata_t* staticMeta,
384                                       SystemCameraKind* systemCameraKind);
385 
386     static void getMultiResolutionStreamConfigurations(
387             camera_metadata_ro_entry* multiResStreamConfigs,
388             camera_metadata_ro_entry* streamConfigs,
389             camera_metadata_ro_entry* maxResolutionStreamConfigs,
390             const camera_metadata_t* staticMetadata);
391 
392     static void getPrivacyTestPatternModes(
393             const camera_metadata_t* staticMetadata,
394             std::unordered_set<int32_t>* privacyTestPatternModes /*out*/);
395 
396     static Dataspace getDataspace(PixelFormat format);
397 
398     void processCaptureRequestInternal(uint64_t bufferUsage, RequestTemplate reqTemplate,
399                                        bool useSecureOnlyCameras);
400 
401     void processPreviewStabilizationCaptureRequestInternal(
402             bool previewStabilizationOn,
403             /*inout*/ std::unordered_map<std::string, nsecs_t>& cameraDeviceToTimeLag);
404 
405     static bool is10BitDynamicRangeCapable(const camera_metadata_t* staticMeta);
406 
407     static void get10BitDynamicRangeProfiles(
408             const camera_metadata_t* staticMeta,
409             std::vector<RequestAvailableDynamicRangeProfilesMap>* profiles);
410 
411     static bool reportsColorSpaces(const camera_metadata_t* staticMeta);
412 
413     static void getColorSpaceProfiles(
414             const camera_metadata_t* staticMeta,
415             std::vector<aidl::android::hardware::camera::metadata::
416                                 RequestAvailableColorSpaceProfilesMap>* profiles);
417 
418     static bool isColorSpaceCompatibleWithDynamicRangeAndPixelFormat(
419             const camera_metadata_t* staticMeta, RequestAvailableColorSpaceProfilesMap colorSpace,
420             RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile,
421             aidl::android::hardware::graphics::common::PixelFormat pixelFormat);
422 
423     static const char* getColorSpaceProfileString(RequestAvailableColorSpaceProfilesMap colorSpace);
424 
425     static const char* getDynamicRangeProfileString(
426             RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile);
427 
428     static int32_t halFormatToPublicFormat(
429             aidl::android::hardware::graphics::common::PixelFormat pixelFormat);
430 
431     // Used by switchToOffline where a new result queue is created for offline reqs
432     void updateInflightResultQueue(const std::shared_ptr<ResultMetadataQueue>& resultQueue);
433 
434     static Size getMinSize(Size a, Size b);
435 
436     void processColorSpaceRequest(RequestAvailableColorSpaceProfilesMap colorSpace,
437                                   RequestAvailableDynamicRangeProfilesMap dynamicRangeProfile);
438 
439     void processZoomSettingsOverrideRequests(
440             int32_t frameCount, const bool *overrideSequence, const bool *expectedResults);
441 
442     bool supportZoomSettingsOverride(const camera_metadata_t* staticMeta);
443     static bool supportsStreamUseCaseCap(const camera_metadata_t* staticMeta);
444     static bool supportsCroppedRawUseCase(const camera_metadata_t* staticMeta);
445     bool isPerFrameControl(const camera_metadata_t* staticMeta);
446 
447     void getSupportedSizes(const camera_metadata_t* ch, uint32_t tag, int32_t format,
448                            std::vector<std::tuple<size_t, size_t>>* sizes /*out*/);
449 
450     void getSupportedDurations(const camera_metadata_t* ch, uint32_t tag, int32_t format,
451                                const std::vector<std::tuple<size_t, size_t>>& sizes,
452                                std::vector<int64_t>* durations /*out*/);
453 
454   protected:
455     // In-flight queue for tracking completion of capture requests.
456     struct InFlightRequest {
457         // Set by notify() SHUTTER call.
458         nsecs_t shutterTimestamp;
459 
460         bool shutterReadoutTimestampValid;
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               shutterReadoutTimestampValid(false),
527               shutterReadoutTimestamp(0),
528               errorCodeValid(false),
529               errorCode(ErrorCode::ERROR_BUFFER),
530               usePartialResult(false),
531               numPartialResults(0),
532               resultQueue(nullptr),
533               haveResultMetadata(false),
534               numBuffersLeft(0),
535               frameNumber(0),
536               partialResultCount(0),
537               errorStreamId(-1),
538               hasInputBuffer(false),
539               collectedResult(1, 10) {}
540 
541         InFlightRequest(ssize_t numBuffers, bool hasInput, bool partialResults,
542                         int32_t partialCount, std::shared_ptr<ResultMetadataQueue> queue = nullptr)
543             : shutterTimestamp(0),
544               shutterReadoutTimestampValid(false),
545               shutterReadoutTimestamp(0),
546               errorCodeValid(false),
547               errorCode(ErrorCode::ERROR_BUFFER),
548               usePartialResult(partialResults),
549               numPartialResults(partialCount),
550               resultQueue(queue),
551               haveResultMetadata(false),
552               numBuffersLeft(numBuffers),
553               frameNumber(0),
554               partialResultCount(0),
555               errorStreamId(-1),
556               hasInputBuffer(hasInput),
557               collectedResult(1, 10) {}
558 
559         InFlightRequest(ssize_t numBuffers, bool hasInput, bool partialResults,
560                         int32_t partialCount,
561                         const std::unordered_set<std::string>& extraPhysicalResult,
562                         std::shared_ptr<ResultMetadataQueue> queue = nullptr)
563             : shutterTimestamp(0),
564               shutterReadoutTimestampValid(false),
565               shutterReadoutTimestamp(0),
566               errorCodeValid(false),
567               errorCode(ErrorCode::ERROR_BUFFER),
568               usePartialResult(partialResults),
569               numPartialResults(partialCount),
570               resultQueue(queue),
571               haveResultMetadata(false),
572               numBuffersLeft(numBuffers),
573               frameNumber(0),
574               partialResultCount(0),
575               errorStreamId(-1),
576               hasInputBuffer(hasInput),
577               collectedResult(1, 10),
578               expectedPhysicalResults(extraPhysicalResult) {}
579 
~InFlightRequestInFlightRequest580         ~InFlightRequest() {
581             for (auto& buffer : resultOutputBuffers) {
582                 native_handle_t* acquireFenceHandle = const_cast<native_handle_t*>(
583                         buffer.buffer.acquireFence);
584                 native_handle_close(acquireFenceHandle);
585                 native_handle_delete(acquireFenceHandle);
586 
587                 native_handle_t* releaseFenceHandle = const_cast<native_handle_t*>(
588                         buffer.buffer.releaseFence);
589                 native_handle_close(releaseFenceHandle);
590                 native_handle_delete(releaseFenceHandle);
591             }
592         }
593     };
594 
595     static bool matchDeviceName(const std::string& deviceName, const std::string& providerType,
596                                 std::string* deviceVersion, std::string* cameraId);
597 
598     static void verify10BitMetadata(HandleImporter& importer, const InFlightRequest& request,
599                                     RequestAvailableDynamicRangeProfilesMap profile);
600 
601     static void waitForReleaseFence(
602             std::vector<InFlightRequest::StreamBufferAndTimestamp>& resultOutputBuffers);
603 
604     static void validateDefaultRequestMetadata(RequestTemplate reqTemplate,
605                                                const CameraMetadata& rawMetadata);
606 
607     // Map from frame number to the in-flight request state
608     typedef std::unordered_map<uint32_t, std::shared_ptr<InFlightRequest>> InFlightMap;
609 
610     std::mutex mLock;                          // Synchronize access to member variables
611     std::condition_variable mResultCondition;  // Condition variable for incoming results
612     InFlightMap mInflightMap;                  // Map of all inflight requests
613 
614     std::vector<NotifyMsg> mNotifyMessages;  // Current notification message
615 
616     std::mutex mTorchLock;               // Synchronize access to torch status
617     std::condition_variable mTorchCond;  // Condition variable for torch status
618     TorchModeStatus mTorchStatus;        // Current torch status
619 
620     // Camera provider service
621     std::shared_ptr<ICameraProvider> mProvider;
622 
623     // Camera device session used by the tests
624     // Tests should take care of closing this session and setting it back to nullptr in successful
625     // case. Declared as a field to allow TeadDown function to close the session if a test assertion
626     // fails.
627     std::shared_ptr<ICameraDeviceSession> mSession;
628 
629     // Camera provider type.
630     std::string mProviderType;
631 
632     HandleImporter mHandleImporter;
633 
634     friend class DeviceCb;
635     friend class SimpleDeviceCb;
636     friend class TorchProviderCb;
637 };
638 
639 namespace {
640 // device@<major>.<minor>/<type>/id
641 const char* kDeviceNameRE = "device@([0-9]+\\.[0-9]+)/\\s+/(.+)";
642 const std::string CAMERA_DEVICE_API_VERSION_1 = "1.1";
643 const int32_t CAMERA_DEVICE_API_MINOR_VERSION_3 = 3;
644 
645 const int32_t kMaxVideoWidth = 4096;
646 const int32_t kMaxVideoHeight = 2160;
647 
648 const int64_t kStreamBufferTimeoutSec = 3;
649 const int64_t kTorchTimeoutSec = 1;
650 const char* kDumpOutput = "/dev/null";
651 const uint32_t kMaxPreviewWidth = 1920;
652 const uint32_t kMaxPreviewHeight = 1080;
653 }  // namespace
654 #endif  // HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_CAMERA_AIDL_TEST_H_
655