/* * Copyright 2022 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. */ #pragma once #include "MockHidlEvsCamera.h" #include "MockHidlEvsDisplay.h" #include "MockHidlEvsEnumerator.h" #include #include #include #include #include #include #include namespace aidl::android::automotive::evs::implementation { namespace hidlevs = ::android::hardware::automotive::evs; class MockHidlEvsHal { public: MockHidlEvsHal(size_t numCameras, size_t numDisplays) : mNumCameras(numCameras), mNumDisplays(numDisplays) {} ~MockHidlEvsHal(); void initialize(); ::android::sp getEnumerator(); bool addMockCameraDevice(const std::string& deviceId); void removeMockCameraDevice(const std::string& deviceId); bool addMockDisplayDevice(int id); void removeMockDisplayDevice(int id); size_t setNumberOfFramesToSend(size_t n); private: bool buildCameraMetadata(int32_t width, int32_t height, int32_t format, ::android::hardware::hidl_vec* out); void configureCameras(size_t n); void configureDisplays(size_t n); void configureEnumerator(); void forwardFrames(size_t numberOfFramesToForward, const std::string& deviceId); size_t initializeBufferPool(size_t size); void deinitializeBufferPoolLocked() REQUIRES(mLock); ::android::sp mMockHidlEvsEnumerator; std::vector<::android::sp> mMockHidlEvsCameras; std::vector<::android::sp> mMockHidlEvsDisplays; std::unordered_map> mCameraClient; struct CameraRecord { hidlevs::V1_1::CameraDesc desc; ::android::wp activeInstance; CameraRecord(hidlevs::V1_1::CameraDesc& desc) : desc(desc) {} }; mutable std::mutex mLock; std::condition_variable mBufferAvailableSignal; std::map mCameraList; std::map> mCameraExtendedInfo; std::map mCameraParams; std::vector mBufferPool GUARDED_BY(mLock); std::vector mBuffersInUse GUARDED_BY(mLock); std::unordered_map mBufferRecord GUARDED_BY(mLock); ::android::wp mActiveDisplay; bool mDisplayOwnedExclusively; hidlevs::V1_0::DisplayState mCurrentDisplayState = hidlevs::V1_0::DisplayState::NOT_OPEN; size_t mNumCameras = 0; size_t mNumDisplays = 0; size_t mBufferPoolSize = 0; size_t mNumberOfFramesToSend = 5; enum class StreamState { kStopped, kRunning, kStopping }; std::unordered_map> mStreamState GUARDED_BY(mLock); std::unordered_map mMockDeviceStatus GUARDED_BY(mLock); std::unordered_map mCameraBufferPoolSize GUARDED_BY(mLock); std::unordered_map mCameraFrameThread GUARDED_BY(mLock); }; } // namespace aidl::android::automotive::evs::implementation