/* * Copyright (C) 2021–2022 Beijing OSWare Technology Co., Ltd * This file contains confidential and proprietary information of * OSWare Technology Co., Ltd * * 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. */ #ifndef HOS_CAMERA_V4L2_DEV_H #define HOS_CAMERA_V4L2_DEV_H #include #include #include #include #include #include #include #include #include #include #if !defined(V4L2_UTEST) && !defined (V4L2_MAIN_TEST) #include #include #else #include "v4l2_temp.h" #endif #include #include "v4l2_buffer.h" #include "v4l2_fileformat.h" #include "v4l2_stream.h" #include "v4l2_control.h" #include "v4l2_common.h" namespace OHOS::Camera { class HosV4L2Dev { public: HosV4L2Dev(); ~HosV4L2Dev(); RetCode start(const std::string& cameraID); RetCode stop(const std::string& cameraID); RetCode SetNumberCtrls (const std::string& cameraID, std::vector& control); RetCode GetNumberCtrls (const std::string& cameraID, std::vector& control); RetCode GetFmtDescs(const std::string& cameraID, std::vector& fmtDesc); RetCode GetControls(const std::string& cameraID, std::vector& control); RetCode ConfigSys(const std::string& cameraID, V4l2FmtCmd command, DeviceFormat& format); RetCode UpdateSetting(const std::string& cameraID, AdapterCmd command, const int* args); RetCode QuerySetting(const std::string& cameraID, AdapterCmd command, int* args); RetCode ReqBuffers(const std::string& cameraID, unsigned int buffCont, enum v4l2_memory memoryType); RetCode CreatBuffer(const std::string& cameraID, const std::shared_ptr& frameSpec); RetCode StartStream(const std::string& cameraID); RetCode QueueBuffer(const std::string& cameraID, const std::shared_ptr& frameSpec); RetCode ReleaseBuffers(const std::string& cameraID); RetCode StopStream(const std::string& cameraID); RetCode SetCallback(BufCallback cb); RetCode Flush(const std::string& cameraID); void SetMemoryType(uint8_t &memType); static RetCode Init(std::vector& cameraIDs); static std::map deviceMatch; static std::map fdMatch; static std::mutex deviceFdLock_; static std::map CreateDevMap(void) { std::map tmp_map; tmp_map.insert(std::pair("INVALID", "INVALID")); return tmp_map; } static std::map CreateFdMap(void) { std::map tmp_map; tmp_map.insert(std::pair("INVALID", 0)); return tmp_map; } private: int GetCurrentFd(const std::string& cameraID); void loopBuffers(void); RetCode CreateEpoll(int fd, const unsigned int streamNumber); void EraseEpoll(int fd); RetCode ConfigFps(const int fd, DeviceFormat& format, V4l2FmtCmd command); int eventFd_ = 0; std::thread* streamThread_ = nullptr; unsigned int streamNumber_ = 0; int epollFd_ = 0; std::vector epollEvent_; std::mutex epollLock_; std::shared_ptr myBuffers_ = nullptr; std::shared_ptr myStreams_ = nullptr; std::shared_ptr myFileFormat_ = nullptr; std::shared_ptr myControl_ = nullptr; enum v4l2_memory memoryType_ = V4L2_MEMORY_MMAP; enum v4l2_buf_type bufferType_ = V4L2_BUF_TYPE_PRIVATE; }; } // namespace OHOS::Camera #endif // HOS_CAMERA_V4L2_DEV_H