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 
16 #ifndef HOS_CAMERA_V4L2_CONTROL_H
17 #define HOS_CAMERA_V4L2_CONTROL_H
18 
19 #include <linux/videodev2.h>
20 #include <errno.h>
21 #include <sys/ioctl.h>
22 #include "v4l2_common.h"
23 #if defined(V4L2_UTEST) || defined (V4L2_MAIN_TEST)
24 #include "v4l2_temp.h"
25 #else
26 #include <camera.h>
27 #endif
28 
29 namespace OHOS::Camera {
30 class HosV4L2Control {
31 public:
32     HosV4L2Control();
33     ~HosV4L2Control();
34 
35     void V4L2VidiocSCtrl (int fd, int ret, struct v4l2_ext_control* cList, int count);
36     RetCode V4L2GetCtrl(int fd, unsigned int id, int& value);
37     RetCode V4L2SetCtrl(int fd, unsigned int id, int value);
38     RetCode V4L2GetControls(int fd, std::vector<DeviceControl>& control);
39     RetCode V4L2SetCtrls(int fd, std::vector<DeviceControl>& control, const int numControls);
40     void V4L2VidiocGExtCtrls (int fd, int ret, int &count,
41         v4l2_ext_control *cList, std::vector<DeviceControl>& control);
42     RetCode V4L2GetCtrls(int fd, std::vector<DeviceControl>& control, const int numControls);
43 
44 private:
45     void V4L2SetValue(int fd, std::vector<DeviceControl>& control, DeviceControl& ctrl,
46         v4l2_queryctrl& qCtrl);
47     int ExtControl(int fd, struct v4l2_queryctrl *ctrl);
48     void V4L2EnumExtControl(int fd, v4l2_queryctrl &qCtrl, DeviceControl &ctrl);
49     void V4L2EnumExtControls(int fd, std::vector<DeviceControl>& control);
50     void V4L2EnumControls(int fd, std::vector<DeviceControl>& control);
51     int V4L2GetControl(int fd, std::vector<DeviceControl>& control, unsigned int id);
52 };
53 } // namespace OHOS::Camera
54 
55 #endif // HOS_CAMERA_V4L2_CONTROL_H
56