blob: 82ca10ddcbbacfeeab01612606184786a332706d [file] [log] [blame]
Avichal Rakesh362242f2022-02-08 12:40:53 -08001/*
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_DEVICECB_H_
18#define HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_DEVICECB_H_
19
20#include <camera_aidl_test.h>
21
22#include <unordered_map>
23
24#include <CameraMetadata.h>
25#include <aidl/android/hardware/camera/device/BnCameraDeviceCallback.h>
26#include <aidl/android/hardware/camera/device/NotifyMsg.h>
27
28using ::aidl::android::hardware::camera::device::BnCameraDeviceCallback;
29using ::aidl::android::hardware::camera::device::BufferRequest;
30using ::aidl::android::hardware::camera::device::BufferRequestStatus;
31using ::aidl::android::hardware::camera::device::CaptureResult;
32using ::aidl::android::hardware::camera::device::HalStream;
33using ::aidl::android::hardware::camera::device::NotifyMsg;
34using ::aidl::android::hardware::camera::device::PhysicalCameraMetadata;
35using ::aidl::android::hardware::camera::device::Stream;
36using ::aidl::android::hardware::camera::device::StreamBuffer;
37using ::aidl::android::hardware::camera::device::StreamBufferRet;
38using ::aidl::android::hardware::common::NativeHandle;
39
40using ::ndk::ScopedAStatus;
41
42class CameraAidlTest;
43
44class DeviceCb : public BnCameraDeviceCallback {
45 public:
46 DeviceCb(CameraAidlTest* parent, camera_metadata_t* staticMeta);
47 ScopedAStatus notify(const std::vector<NotifyMsg>& msgs) override;
48 ScopedAStatus processCaptureResult(const std::vector<CaptureResult>& results) override;
49 ScopedAStatus requestStreamBuffers(const std::vector<BufferRequest>& bufReqs,
50 std::vector<StreamBufferRet>* buffers,
51 BufferRequestStatus* _aidl_return) override;
52 ScopedAStatus returnStreamBuffers(const std::vector<StreamBuffer>& buffers) override;
53
54 void setCurrentStreamConfig(const std::vector<Stream>& streams,
55 const std::vector<HalStream>& halStreams);
56
57 void waitForBuffersReturned();
58
59 private:
60 bool processCaptureResultLocked(const CaptureResult& results,
61 std::vector<PhysicalCameraMetadata> physicalCameraMetadata);
62 ScopedAStatus notifyHelper(const std::vector<NotifyMsg>& msgs,
63 const std::vector<std::pair<bool, nsecs_t>>& readoutTimestamps);
64
65 CameraAidlTest* mParent; // Parent object
66
67 camera_metadata_t* mStaticMetadata;
68 bool hasOutstandingBuffersLocked();
69
70 /* members for requestStreamBuffers() and returnStreamBuffers()*/
71 std::mutex mLock; // protecting members below
72 bool mUseHalBufManager = false;
73 std::vector<Stream> mStreams;
74 std::vector<HalStream> mHalStreams;
75 int64_t mNextBufferId = 1;
76 using OutstandingBuffers = std::unordered_map<uint64_t, NativeHandle>;
77 // size == mStreams.size(). Tracking each streams outstanding buffers
78 std::vector<OutstandingBuffers> mOutstandingBufferIds;
79 std::condition_variable mFlushedCondition;
80};
81
82#endif // HARDWARE_INTERFACES_CAMERA_PROVIDER_AIDL_VTS_DEVICECB_H_