1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef HOS_CAMERA_V4L2_UVC_H 16 #define HOS_CAMERA_V4L2_UVC_H 17 18 #include <thread> 19 #include <fcntl.h> 20 #include <linux/netlink.h> 21 #include <linux/videodev2.h> 22 #include <sys/ioctl.h> 23 #include <sys/select.h> 24 #include <sys/socket.h> 25 #include <unistd.h> 26 #include <sys/eventfd.h> 27 #include <map> 28 #include "v4l2_common.h" 29 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST) 30 #include "v4l2_temp.h" 31 #else 32 #include <camera.h> 33 #endif 34 35 namespace OHOS::Camera { 36 class HosV4L2UVC { 37 public: 38 HosV4L2UVC(); 39 ~HosV4L2UVC(); 40 41 RetCode V4L2UvcDetectInit(UvcCallback cb); 42 void V4L2UvcDetectUnInit(); 43 44 private: 45 void V4L2UvcSearchCapability(const std::string devName, const std::string v4l2Device, bool inOut); 46 RetCode V4L2UvcGetCap(const std::string v4l2Device, struct v4l2_capability& cap); 47 int V4L2SprintfDev(std::pair<std::map<std::string, std::string>::iterator, bool> &iter, 48 char* devName, const std::string v4l2Device, uint32_t devNameSize); 49 void V4L2UvcMatchDev(const std::string name, const std::string v4l2Device, bool inOut); 50 void V4L2UvcEnmeDevices(); 51 void loopUvcDevice(); 52 int CheckBuf(unsigned int len, char *buf); 53 void UpdateV4L2UvcMatchDev(std::string& action, std::string& subsystem, std::string& devnode); 54 const char* V4L2GetUsbValue(const char* key, const char* str, int len); 55 void V4L2GetUsbString(std::string& action, std::string& subsystem, 56 std::string& devnode, char* buf, unsigned int len); 57 RetCode V4L2UVCGetCapability(int fd, const std::string devName, std::string& cameraId); 58 59 int uDevFd_ = -1; 60 int eventFd_ = -1; 61 int uvcDetectEnable_ = 0; 62 63 UvcCallback uvcCallbackFun_ = nullptr; 64 65 std::vector<DeviceControl> control_; 66 std::vector<DeviceFormat> format_; 67 68 std::thread* uvcDetectThread_ = nullptr; 69 }; 70 } // namespace OHOS::Camera 71 72 #endif // HOS_CAMERA_V4L2_UVC_H 73