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 "v4l2_common.h" 28 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST) 29 #include "v4l2_temp.h" 30 #else 31 #include <camera.h> 32 #endif 33 34 namespace OHOS::Camera { 35 class HosV4L2UVC { 36 public: 37 HosV4L2UVC(); 38 ~HosV4L2UVC(); 39 40 RetCode V4L2UvcDetectInit(UvcCallback cb); 41 void V4L2UvcDetectUnInit(); 42 43 private: 44 void V4L2UvcSearchCapability(const std::string devName, const std::string v4l2Device, bool inOut); 45 RetCode V4L2UvcGetCap(const std::string v4l2Device, struct v4l2_capability& cap); 46 void V4L2UvcMatchDev(const std::string name, const std::string v4l2Device, bool inOut); 47 void V4L2UvcEnmeDevices(); 48 void loopUvcDevice(); 49 int CheckBuf(unsigned int len, char *buf); 50 void UpdateV4L2UvcMatchDev(std::string& action, std::string& subsystem, std::string& devnode); 51 const char* V4L2GetUsbValue(const char* key, const char* str, int len); 52 void V4L2GetUsbString(std::string& action, std::string& subsystem, 53 std::string& devnode, char* buf, unsigned int len); 54 RetCode V4L2UVCGetCapability(int fd, const std::string devName, std::string& cameraId); 55 56 int uDevFd_ = -1; 57 int eventFd_ = -1; 58 int uvcDetectEnable_ = 0; 59 60 UvcCallback uvcCallbackFun_ = nullptr; 61 62 std::vector<DeviceControl> control_; 63 std::vector<DeviceFormat> format_; 64 65 std::thread* uvcDetectThread_ = nullptr; 66 }; 67 } // namespace OHOS::Camera 68 69 #endif // HOS_CAMERA_V4L2_UVC_H 70