• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <linux/netlink.h>
25 #include <sys/socket.h>
26 #include <unistd.h>
27 #include <sys/eventfd.h>
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     void V4L2UvcMatchDev(const std::string      name, const std::string v4l2Device, bool inOut);
48     void V4L2UvcEnmeDevices();
49     void loopUvcDevice();
50     const char* V4L2GetUsbValue(const char* key, const char* str, int len);
51     void V4L2GetUsbString(std::string& action, std::string& subsystem,
52         std::string& devnode, char* buf, unsigned int len);
53     RetCode V4L2UVCGetCapability(int fd, const std::string devName, std::string& cameraId);
54 
55     int uDevFd_ = -1;
56     int eventFd_ = -1;
57     int uvcDetectEnable_ = 0;
58 
59     UvcCallback uvcCallbackFun_ = nullptr;
60 
61     std::vector<DeviceControl> control_;
62     std::vector<DeviceFormat> format_;
63 
64     std::thread* uvcDetectThread_ = nullptr;
65 };
66 } // namespace OHOS::Camera
67 
68 #endif // HOS_CAMERA_V4L2_UVC_H
69