/* * 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 "MockEvsCamera.h" #include "MockEvsDisplay.h" #include "MockEvsEnumerator.h" #include #include #include #include #include #include #include #include #include namespace aidl::android::automotive::evs::implementation { namespace aidlevs = ::aidl::android::hardware::automotive::evs; class MockEvsHal { public: MockEvsHal(size_t numCameras, size_t numDisplays) : mNumCameras(numCameras), mNumDisplays(numDisplays) {} ~MockEvsHal(); void initialize(); std::shared_ptr 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, std::vector* 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); std::shared_ptr mMockEvsEnumerator; std::vector> mMockEvsCameras; std::vector> mMockEvsDisplays; std::unordered_map> mCameraClient; struct CameraRecord { aidlevs::CameraDesc desc; std::weak_ptr activeInstance; CameraRecord(aidlevs::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); std::weak_ptr mActiveDisplay; bool mDisplayOwnedExclusively; aidlevs::DisplayState mCurrentDisplayState = aidlevs::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_set> mDeviceStatusCallbacks GUARDED_BY(mLock); std::unordered_map mCameraBufferPoolSize GUARDED_BY(mLock); std::unordered_map mCameraFrameThread GUARDED_BY(mLock); }; } // namespace aidl::android::automotive::evs::implementation